Skip to content

Commit 994c56a

Browse files
authored
rpc: fix simulated loaded size tests (#6412)
1 parent d2f2b95 commit 994c56a

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ solana-runtime = { workspace = true, features = ["dev-context-only-utils"] }
110110
solana-runtime-transaction = { workspace = true, features = [
111111
"dev-context-only-utils",
112112
] }
113+
solana-sdk-ids = { workspace = true }
113114
solana-send-transaction-service = { workspace = true, features = ["dev-context-only-utils"] }
114115
solana-sha256-hasher = { workspace = true }
115116
solana-stake-interface = { workspace = true }

rpc/src/rpc.rs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4547,12 +4547,14 @@ pub mod tests {
45474547
commitment::{BlockCommitment, CommitmentSlots},
45484548
non_circulating_supply::non_circulating_accounts,
45494549
},
4550+
solana_sdk_ids::bpf_loader_upgradeable,
45504551
solana_send_transaction_service::{
45514552
tpu_info::NullTpuInfo,
45524553
transaction_client::{ConnectionCacheClient, TpuClientNextClient},
45534554
},
45544555
solana_sha256_hasher::hash,
45554556
solana_signer::Signer,
4557+
solana_svm::account_loader::TRANSACTION_ACCOUNT_BASE_SIZE,
45564558
solana_system_interface::{instruction as system_instruction, program as system_program},
45574559
solana_system_transaction as system_transaction,
45584560
solana_sysvar::slot_hashes::SlotHashes,
@@ -4629,6 +4631,22 @@ pub mod tests {
46294631
}
46304632
}
46314633

4634+
fn expected_loaded_accounts_data_size(bank: &Bank, tx: &Transaction) -> u32 {
4635+
let mut loaded_accounts_data_size = 0;
4636+
for key in tx.message.account_keys.iter() {
4637+
if let Some(account) = bank.get_account(key) {
4638+
assert!(
4639+
*account.owner() != bpf_loader_upgradeable::id(),
4640+
"LoaderV3 is not supported; to add it, parse the program account and add its programdata size.",
4641+
);
4642+
loaded_accounts_data_size +=
4643+
(account.data().len() + TRANSACTION_ACCOUNT_BASE_SIZE) as u32;
4644+
}
4645+
}
4646+
4647+
loaded_accounts_data_size
4648+
}
4649+
46324650
fn test_builtin_processor(
46334651
invoke_context: &mut InvokeContext,
46344652
) -> std::result::Result<u64, Box<dyn std::error::Error>> {
@@ -5975,11 +5993,7 @@ pub mod tests {
59755993
// Simulation bank must be frozen
59765994
bank.freeze();
59775995

5978-
let loaded_account_data_size = bank
5979-
.get_account(&system_program::id())
5980-
.unwrap()
5981-
.data()
5982-
.len() as u32;
5996+
let loaded_accounts_data_size = expected_loaded_accounts_data_size(&bank, &tx);
59835997

59845998
// Good signature with sigVerify=true
59855999
let req = format!(
@@ -6020,7 +6034,7 @@ pub mod tests {
60206034
],
60216035
"err":null,
60226036
"innerInstructions": null,
6023-
"loadedAccountsDataSize": loaded_account_data_size,
6037+
"loadedAccountsDataSize": loaded_accounts_data_size,
60246038
"logs":[
60256039
"Program 11111111111111111111111111111111 invoke [1]",
60266040
"Program 11111111111111111111111111111111 success"
@@ -6107,7 +6121,7 @@ pub mod tests {
61076121
"accounts":null,
61086122
"err":null,
61096123
"innerInstructions":null,
6110-
"loadedAccountsDataSize": loaded_account_data_size,
6124+
"loadedAccountsDataSize": loaded_accounts_data_size,
61116125
"logs":[
61126126
"Program 11111111111111111111111111111111 invoke [1]",
61136127
"Program 11111111111111111111111111111111 success"
@@ -6138,7 +6152,7 @@ pub mod tests {
61386152
"accounts":null,
61396153
"err":null,
61406154
"innerInstructions":null,
6141-
"loadedAccountsDataSize": loaded_account_data_size,
6155+
"loadedAccountsDataSize": loaded_accounts_data_size,
61426156
"logs":[
61436157
"Program 11111111111111111111111111111111 invoke [1]",
61446158
"Program 11111111111111111111111111111111 success"
@@ -6227,7 +6241,7 @@ pub mod tests {
62276241
"accounts":null,
62286242
"err":null,
62296243
"innerInstructions":null,
6230-
"loadedAccountsDataSize": loaded_account_data_size,
6244+
"loadedAccountsDataSize": loaded_accounts_data_size,
62316245
"logs":[
62326246
"Program 11111111111111111111111111111111 invoke [1]",
62336247
"Program 11111111111111111111111111111111 success"
@@ -6320,16 +6334,7 @@ pub mod tests {
63206334
// Simulation bank must be frozen
63216335
bank.freeze();
63226336

6323-
let loaded_accounts_data_size = bank
6324-
.get_account(&token_account_pubkey)
6325-
.unwrap()
6326-
.data()
6327-
.len() as u32
6328-
+ bank
6329-
.get_account(&system_program::id())
6330-
.unwrap()
6331-
.data()
6332-
.len() as u32;
6337+
let loaded_accounts_data_size = expected_loaded_accounts_data_size(&bank, &tx);
63336338

63346339
let req = format!(
63356340
r#"{{"jsonrpc":"2.0",
@@ -6444,16 +6449,7 @@ pub mod tests {
64446449
// Simulation bank must be frozen
64456450
bank.freeze();
64466451

6447-
let loaded_accounts_data_size = bank
6448-
.get_account(&TestBuiltinEntrypoint::PROGRAM_ID)
6449-
.unwrap()
6450-
.data()
6451-
.len() as u32
6452-
+ bank
6453-
.get_account(&system_program::id())
6454-
.unwrap()
6455-
.data()
6456-
.len() as u32;
6452+
let loaded_accounts_data_size = expected_loaded_accounts_data_size(&bank, &tx);
64576453

64586454
// `innerInstructions` not provided, should not be in response
64596455
let req = format!(

svm/src/account_loader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[cfg(feature = "dev-context-only-utils")]
2-
use qualifier_attr::field_qualifiers;
2+
use qualifier_attr::{field_qualifiers, qualifiers};
33
use {
44
crate::{
55
account_overrides::AccountOverrides, nonce_info::NonceInfo,
@@ -39,6 +39,7 @@ use {
3939

4040
// Per SIMD-0186, all accounts are assigned a base size of 64 bytes to cover
4141
// the storage cost of metadata.
42+
#[cfg_attr(feature = "dev-context-only-utils", qualifiers(pub))]
4243
pub(crate) const TRANSACTION_ACCOUNT_BASE_SIZE: usize = 64;
4344

4445
// Per SIMD-0186, resolved address lookup tables are assigned a base size of 8248

0 commit comments

Comments
 (0)