Skip to content

Commit

Permalink
Removes program_accounts / program_accounts_map from account_shared_d…
Browse files Browse the repository at this point in the history
…ata_from_program(), load_transaction_accounts() and load_accounts().
  • Loading branch information
Lichtso committed Apr 12, 2024
1 parent 8261960 commit 2593dd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 54 deletions.
63 changes: 10 additions & 53 deletions svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
log::warn,
solana_program_runtime::{
compute_budget_processor::process_compute_budget_instructions,
loaded_programs::LoadedProgramsForTxBatch,
loaded_programs::{LoadedProgram, LoadedProgramsForTxBatch},
},
solana_sdk::{
account::{Account, AccountSharedData, ReadableAccount, WritableAccount},
Expand All @@ -31,7 +31,7 @@ use {
transaction_context::{IndexOfAccount, TransactionAccount},
},
solana_system_program::{get_system_account_kind, SystemAccountKind},
std::{collections::HashMap, num::NonZeroUsize},
std::num::NonZeroUsize,
};

// for the load instructions
Expand Down Expand Up @@ -114,7 +114,6 @@ pub(crate) fn load_accounts<CB: TransactionProcessingCallback>(
error_counters: &mut TransactionErrorMetrics,
fee_structure: &FeeStructure,
account_overrides: Option<&AccountOverrides>,
program_accounts: &HashMap<Pubkey, (&Pubkey, u64)>,
loaded_programs: &LoadedProgramsForTxBatch,
) -> Vec<TransactionLoadResult> {
let feature_set = callbacks.get_feature_set();
Expand Down Expand Up @@ -145,7 +144,6 @@ pub(crate) fn load_accounts<CB: TransactionProcessingCallback>(
fee,
error_counters,
account_overrides,
program_accounts,
loaded_programs,
) {
Ok(loaded_transaction) => loaded_transaction,
Expand Down Expand Up @@ -182,7 +180,6 @@ fn load_transaction_accounts<CB: TransactionProcessingCallback>(
fee: u64,
error_counters: &mut TransactionErrorMetrics,
account_overrides: Option<&AccountOverrides>,
program_accounts: &HashMap<Pubkey, (&Pubkey, u64)>,
loaded_programs: &LoadedProgramsForTxBatch,
) -> Result<LoadedTransaction> {
let feature_set = callbacks.get_feature_set();
Expand Down Expand Up @@ -227,10 +224,13 @@ fn load_transaction_accounts<CB: TransactionProcessingCallback>(
.then_some(())
.and_then(|_| loaded_programs.find(key))
{
callbacks
.get_account_shared_data(key)
.ok_or(TransactionError::AccountNotFound)?;
// Optimization to skip loading of accounts which are only used as
// programs in top-level instructions and not passed as instruction accounts.
account_shared_data_from_program(key, program_accounts)
.map(|program_account| (program.account_size, program_account, 0))?
let program_account = account_shared_data_from_program(&program);
(program.account_size, program_account, 0)
} else {
callbacks
.get_account_shared_data(key)
Expand Down Expand Up @@ -410,20 +410,14 @@ fn get_requested_loaded_accounts_data_size_limit(
)
}

fn account_shared_data_from_program(
key: &Pubkey,
program_accounts: &HashMap<Pubkey, (&Pubkey, u64)>,
) -> Result<AccountSharedData> {
fn account_shared_data_from_program(loaded_program: &LoadedProgram) -> AccountSharedData {
// It's an executable program account. The program is already loaded in the cache.
// So the account data is not needed. Return a dummy AccountSharedData with meta
// information.
let mut program_account = AccountSharedData::default();
let (program_owner, _count) = program_accounts
.get(key)
.ok_or(TransactionError::AccountNotFound)?;
program_account.set_owner(**program_owner);
program_account.set_owner(loaded_program.account_owner());
program_account.set_executable(true);
Ok(program_account)
program_account
}

/// Accumulate loaded account data size into `accumulated_accounts_data_size`.
Expand Down Expand Up @@ -557,7 +551,6 @@ mod tests {
error_counters,
fee_structure,
None,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
)
}
Expand Down Expand Up @@ -1034,7 +1027,6 @@ mod tests {
&mut error_counters,
&FeeStructure::default(),
account_overrides,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
)
}
Expand Down Expand Up @@ -1410,26 +1402,6 @@ mod tests {
assert_eq!(shared_data, expected);
}

#[test]
fn test_account_shared_data_from_program() {
let key = Keypair::new().pubkey();
let other_key = Keypair::new().pubkey();

let mut accounts: HashMap<Pubkey, (&Pubkey, u64)> = HashMap::new();

let result = account_shared_data_from_program(&key, &accounts);
assert_eq!(result.err(), Some(TransactionError::AccountNotFound));

accounts.insert(key, (&other_key, 32));

let result = account_shared_data_from_program(&key, &accounts);
let mut expected = AccountSharedData::default();
expected.set_owner(other_key);
expected.set_executable(true);

assert_eq!(result.unwrap(), expected);
}

#[test]
fn test_load_transaction_accounts_fail_to_validate_fee_payer() {
let message = Message {
Expand Down Expand Up @@ -1460,7 +1432,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);

Expand Down Expand Up @@ -1505,7 +1476,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1572,7 +1542,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);

Expand Down Expand Up @@ -1616,7 +1585,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);

Expand Down Expand Up @@ -1660,7 +1628,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);

Expand Down Expand Up @@ -1711,7 +1678,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1780,7 +1746,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1838,7 +1803,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1901,7 +1865,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1990,7 +1953,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -2062,7 +2024,6 @@ mod tests {
&mut error_counters,
&FeeStructure::default(),
None,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
);

Expand Down Expand Up @@ -2147,7 +2108,6 @@ mod tests {
&mut error_counter,
&FeeStructure::default(),
None,
&HashMap::new(),
&loaded_programs,
);

Expand Down Expand Up @@ -2222,7 +2182,6 @@ mod tests {
&mut TransactionErrorMetrics::default(),
&fee_structure,
None,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
);

Expand All @@ -2241,7 +2200,6 @@ mod tests {
&mut TransactionErrorMetrics::default(),
&fee_structure,
None,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
);

Expand All @@ -2260,7 +2218,6 @@ mod tests {
&mut TransactionErrorMetrics::default(),
&fee_structure,
None,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
);

Expand Down
1 change: 0 additions & 1 deletion svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
error_counters,
&self.fee_structure,
account_overrides,
&program_accounts_map,
&programs_loaded_for_tx_batch.borrow(),
);
load_time.stop();
Expand Down

0 comments on commit 2593dd4

Please sign in to comment.