Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor - Remove program_accounts_map from account_loader #768

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -556,7 +550,6 @@ mod tests {
error_counters,
fee_structure,
None,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
)
}
Expand Down Expand Up @@ -1045,7 +1038,6 @@ mod tests {
&mut error_counters,
&FeeStructure::default(),
account_overrides,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
)
}
Expand Down Expand Up @@ -1421,26 +1413,6 @@ mod tests {
assert_eq!(shared_data, expected);
}

#[test]
buffalojoec marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -1470,7 +1442,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);

Expand Down Expand Up @@ -1514,7 +1485,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1580,7 +1550,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);

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

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

Expand Down Expand Up @@ -1716,7 +1683,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1784,7 +1750,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1841,7 +1806,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1903,7 +1867,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -1991,7 +1954,6 @@ mod tests {
32,
&mut error_counter,
None,
&HashMap::new(),
&loaded_programs,
);
mock_bank
Expand Down Expand Up @@ -2063,7 +2025,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 @@ -2221,7 +2181,6 @@ mod tests {
&mut TransactionErrorMetrics::default(),
&fee_structure,
None,
&HashMap::new(),
&LoadedProgramsForTxBatch::default(),
);

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

Expand All @@ -2259,7 +2217,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
Loading