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 17, 2024
1 parent 235c54b commit 1e6ab0b
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 @@ -408,20 +408,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 @@ -555,7 +549,6 @@ mod tests {
error_counters,
fee_structure,
None,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
)
}
Expand Down Expand Up @@ -1032,7 +1025,6 @@ mod tests {
&mut error_counters,
&FeeStructure::default(),
account_overrides,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
)
}
Expand Down Expand Up @@ -1408,26 +1400,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 @@ -1458,7 +1430,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);

Expand Down Expand Up @@ -1503,7 +1474,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1570,7 +1540,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);

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

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

Expand Down Expand Up @@ -1709,7 +1676,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1778,7 +1744,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1836,7 +1801,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1899,7 +1863,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1988,7 +1951,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -2060,7 +2022,6 @@ mod tests {
&mut error_counters,
&FeeStructure::default(),
None,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
);

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

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

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

Expand All @@ -2258,7 +2216,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 @@ -253,7 +253,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 1e6ab0b

Please sign in to comment.