diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index bd32a24ea09aad..89615f81dca98d 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -176,7 +176,7 @@ use { transaction_processing_callback::TransactionProcessingCallback, transaction_processor::{ ExecutionRecordingConfig, TransactionBatchProcessor, TransactionLogMessages, - TransactionProcessingConfig, + TransactionProcessingConfig, TransactionProcessingEnvironment, }, transaction_results::{ TransactionExecutionDetails, TransactionExecutionResult, @@ -3712,12 +3712,23 @@ impl Bank { debug!("check: {}us", check_time.as_us()); timings.saturating_add_in_place(ExecuteTimingType::CheckUs, check_time.as_us()); + let (blockhash, lamports_per_signature) = self.last_blockhash_and_lamports_per_signature(); + let processing_environment = TransactionProcessingEnvironment { + blockhash, + epoch_total_stake: self.epoch_total_stake(self.epoch()), + epoch_vote_accounts: self.epoch_vote_accounts(self.epoch()), + feature_set: Arc::clone(&self.feature_set), + lamports_per_signature, + rent_collector: Some(&self.rent_collector), + }; + let sanitized_output = self .transaction_processor .load_and_execute_sanitized_transactions( self, sanitized_txs, check_results, + &processing_environment, &processing_config, ); @@ -6878,26 +6889,6 @@ impl TransactionProcessingCallback for Bank { .map(|(acc, _)| acc) } - fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64) { - self.last_blockhash_and_lamports_per_signature() - } - - fn get_rent_collector(&self) -> &RentCollector { - &self.rent_collector - } - - fn get_feature_set(&self) -> Arc { - self.feature_set.clone() - } - - fn get_epoch_total_stake(&self) -> Option { - self.epoch_total_stake(self.epoch()) - } - - fn get_epoch_vote_accounts(&self) -> Option<&VoteAccountsHashMap> { - self.epoch_vote_accounts(self.epoch()) - } - fn get_program_match_criteria(&self, program: &Pubkey) -> ProgramCacheMatchCriteria { if self.check_program_modification_slot { self.program_modification_slot(program) diff --git a/svm/src/account_loader.rs b/svm/src/account_loader.rs index 0bc014749d6711..8eb2f9fa3e81f3 100644 --- a/svm/src/account_loader.rs +++ b/svm/src/account_loader.rs @@ -163,6 +163,8 @@ pub(crate) fn load_accounts( validation_results: Vec, error_metrics: &mut TransactionErrorMetrics, account_overrides: Option<&AccountOverrides>, + feature_set: &FeatureSet, + rent_collector: &RentCollector, loaded_programs: &ProgramCacheForTxBatch, ) -> Vec { txs.iter() @@ -178,6 +180,8 @@ pub(crate) fn load_accounts( tx_details, error_metrics, account_overrides, + feature_set, + rent_collector, loaded_programs, ) } @@ -192,15 +196,14 @@ fn load_transaction_accounts( tx_details: ValidatedTransactionDetails, error_metrics: &mut TransactionErrorMetrics, account_overrides: Option<&AccountOverrides>, + feature_set: &FeatureSet, + rent_collector: &RentCollector, loaded_programs: &ProgramCacheForTxBatch, ) -> Result { - let feature_set = callbacks.get_feature_set(); - let mut tx_rent: TransactionRent = 0; let account_keys = message.account_keys(); let mut accounts_found = Vec::with_capacity(account_keys.len()); let mut rent_debits = RentDebits::default(); - let rent_collector = callbacks.get_rent_collector(); let requested_loaded_accounts_data_size_limit = get_requested_loaded_accounts_data_size_limit(message)?; @@ -253,7 +256,7 @@ fn load_transaction_accounts( .map(|mut account| { if message.is_writable(i) { let rent_due = collect_rent_from_account( - &feature_set, + feature_set, rent_collector, key, &mut account, @@ -466,15 +469,12 @@ mod tests { transaction::{Result, SanitizedTransaction, Transaction, TransactionError}, transaction_context::{TransactionAccount, TransactionContext}, }, - solana_vote::vote_account::VoteAccountsHashMap, std::{borrow::Cow, collections::HashMap, convert::TryFrom, sync::Arc}, }; #[derive(Default)] struct TestCallbacks { accounts_map: HashMap, - rent_collector: RentCollector, - feature_set: Arc, } impl TransactionProcessingCallback for TestCallbacks { @@ -485,26 +485,6 @@ mod tests { fn get_account_shared_data(&self, pubkey: &Pubkey) -> Option { self.accounts_map.get(pubkey).cloned() } - - fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64) { - (Hash::new_unique(), 0) - } - - fn get_rent_collector(&self) -> &RentCollector { - &self.rent_collector - } - - fn get_feature_set(&self) -> Arc { - self.feature_set.clone() - } - - fn get_epoch_total_stake(&self) -> Option { - None - } - - fn get_epoch_vote_accounts(&self) -> Option<&VoteAccountsHashMap> { - None - } } fn load_accounts_with_features_and_rent( @@ -521,11 +501,7 @@ mod tests { for (pubkey, account) in accounts { accounts_map.insert(*pubkey, account.clone()); } - let callbacks = TestCallbacks { - accounts_map, - rent_collector: rent_collector.clone(), - feature_set: Arc::new(feature_set.clone()), - }; + let callbacks = TestCallbacks { accounts_map }; load_accounts( &callbacks, &[sanitized_tx], @@ -535,6 +511,8 @@ mod tests { })], error_metrics, None, + feature_set, + rent_collector, &ProgramCacheForTxBatch::default(), ) } @@ -811,17 +789,15 @@ mod tests { for (pubkey, account) in accounts { accounts_map.insert(*pubkey, account.clone()); } - let callbacks = TestCallbacks { - accounts_map, - rent_collector: RentCollector::default(), - feature_set: Arc::new(FeatureSet::all_enabled()), - }; + let callbacks = TestCallbacks { accounts_map }; load_accounts( &callbacks, &[tx], vec![Ok(ValidatedTransactionDetails::default())], &mut error_metrics, account_overrides, + &FeatureSet::all_enabled(), + &RentCollector::default(), &ProgramCacheForTxBatch::default(), ) } @@ -1183,6 +1159,8 @@ mod tests { }, &mut error_metrics, None, + &FeatureSet::default(), + &RentCollector::default(), &loaded_programs, ); @@ -1246,6 +1224,8 @@ mod tests { ValidatedTransactionDetails::default(), &mut error_metrics, None, + &FeatureSet::default(), + &RentCollector::default(), &loaded_programs, ); @@ -1288,6 +1268,8 @@ mod tests { ValidatedTransactionDetails::default(), &mut error_metrics, None, + &FeatureSet::default(), + &RentCollector::default(), &loaded_programs, ); @@ -1330,6 +1312,8 @@ mod tests { ValidatedTransactionDetails::default(), &mut error_metrics, None, + &FeatureSet::default(), + &RentCollector::default(), &loaded_programs, ); @@ -1387,6 +1371,8 @@ mod tests { }, &mut error_metrics, None, + &FeatureSet::default(), + &RentCollector::default(), &loaded_programs, ); @@ -1452,6 +1438,8 @@ mod tests { ValidatedTransactionDetails::default(), &mut error_metrics, None, + &FeatureSet::default(), + &RentCollector::default(), &loaded_programs, ); @@ -1503,6 +1491,8 @@ mod tests { ValidatedTransactionDetails::default(), &mut error_metrics, None, + &FeatureSet::default(), + &RentCollector::default(), &loaded_programs, ); @@ -1567,6 +1557,8 @@ mod tests { }, &mut error_metrics, None, + &FeatureSet::default(), + &RentCollector::default(), &loaded_programs, ); @@ -1660,6 +1652,8 @@ mod tests { }, &mut error_metrics, None, + &FeatureSet::default(), + &RentCollector::default(), &loaded_programs, ); @@ -1728,6 +1722,8 @@ mod tests { vec![Ok(ValidatedTransactionDetails::default())], &mut error_metrics, None, + &FeatureSet::default(), + &RentCollector::default(), &ProgramCacheForTxBatch::default(), ); @@ -1816,6 +1812,8 @@ mod tests { vec![validation_result], &mut error_metrics, None, + &FeatureSet::default(), + &RentCollector::default(), &loaded_programs, ); @@ -1855,6 +1853,9 @@ mod tests { #[test] fn test_load_accounts_error() { let mock_bank = TestCallbacks::default(); + let feature_set = FeatureSet::default(); + let rent_collector = RentCollector::default(); + let message = Message { account_keys: vec![Pubkey::new_from_array([0; 32])], header: MessageHeader::default(), @@ -1886,6 +1887,8 @@ mod tests { vec![validation_result.clone()], &mut TransactionErrorMetrics::default(), None, + &feature_set, + &rent_collector, &ProgramCacheForTxBatch::default(), ); @@ -1902,6 +1905,8 @@ mod tests { vec![validation_result], &mut TransactionErrorMetrics::default(), None, + &feature_set, + &rent_collector, &ProgramCacheForTxBatch::default(), ); diff --git a/svm/src/program_loader.rs b/svm/src/program_loader.rs index 8d3837decda63c..6060e8bb3db453 100644 --- a/svm/src/program_loader.rs +++ b/svm/src/program_loader.rs @@ -228,11 +228,7 @@ mod tests { loaded_programs::{BlockRelation, ForkGraph, ProgramRuntimeEnvironments}, solana_rbpf::program::BuiltinProgram, }, - solana_sdk::{ - account::WritableAccount, bpf_loader, bpf_loader_upgradeable, feature_set::FeatureSet, - hash::Hash, rent_collector::RentCollector, - }, - solana_vote::vote_account::VoteAccountsHashMap, + solana_sdk::{account::WritableAccount, bpf_loader, bpf_loader_upgradeable}, std::{ cell::RefCell, collections::HashMap, @@ -252,8 +248,6 @@ mod tests { #[derive(Default, Clone)] pub struct MockBankCallback { - rent_collector: RentCollector, - feature_set: Arc, pub account_shared_data: RefCell>, } @@ -274,26 +268,6 @@ mod tests { self.account_shared_data.borrow().get(pubkey).cloned() } - fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64) { - (Hash::new_unique(), 2) - } - - fn get_rent_collector(&self) -> &RentCollector { - &self.rent_collector - } - - fn get_feature_set(&self) -> Arc { - self.feature_set.clone() - } - - fn get_epoch_total_stake(&self) -> Option { - None - } - - fn get_epoch_vote_accounts(&self) -> Option<&VoteAccountsHashMap> { - None - } - fn add_builtin_account(&self, name: &str, program_id: &Pubkey) { let mut account_data = AccountSharedData::default(); account_data.set_data(name.as_bytes().to_vec()); diff --git a/svm/src/transaction_processing_callback.rs b/svm/src/transaction_processing_callback.rs index f92dc6e2299b39..bca549b12013cc 100644 --- a/svm/src/transaction_processing_callback.rs +++ b/svm/src/transaction_processing_callback.rs @@ -1,11 +1,6 @@ use { solana_program_runtime::loaded_programs::ProgramCacheMatchCriteria, - solana_sdk::{ - account::AccountSharedData, feature_set::FeatureSet, hash::Hash, pubkey::Pubkey, - rent_collector::RentCollector, - }, - solana_vote::vote_account::VoteAccountsHashMap, - std::sync::Arc, + solana_sdk::{account::AccountSharedData, pubkey::Pubkey}, }; /// Runtime callbacks for transaction processing. @@ -14,16 +9,6 @@ pub trait TransactionProcessingCallback { fn get_account_shared_data(&self, pubkey: &Pubkey) -> Option; - fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64); - - fn get_rent_collector(&self) -> &RentCollector; - - fn get_feature_set(&self) -> Arc; - - fn get_epoch_total_stake(&self) -> Option; - - fn get_epoch_vote_accounts(&self) -> Option<&VoteAccountsHashMap>; - fn get_program_match_criteria(&self, _program: &Pubkey) -> ProgramCacheMatchCriteria { ProgramCacheMatchCriteria::NoCriteria } diff --git a/svm/src/transaction_processor.rs b/svm/src/transaction_processor.rs index f39fd5037ef775..cc0cbcdac5775e 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -44,14 +44,17 @@ use { remove_rounding_in_fee_calculation, FeatureSet, }, fee::{FeeDetails, FeeStructure}, + hash::Hash, inner_instruction::{InnerInstruction, InnerInstructionsList}, instruction::{CompiledInstruction, TRANSACTION_LEVEL_STACK_HEIGHT}, message::SanitizedMessage, pubkey::Pubkey, + rent_collector::RentCollector, saturating_add_assign, transaction::{self, SanitizedTransaction, TransactionError}, transaction_context::{ExecutionRecord, TransactionContext}, }, + solana_vote::vote_account::VoteAccountsHashMap, std::{ cell::RefCell, collections::{hash_map::Entry, HashMap, HashSet}, @@ -118,6 +121,23 @@ pub struct TransactionProcessingConfig<'a> { pub transaction_account_lock_limit: Option, } +/// Runtime environment for transaction batch processing. +#[derive(Default)] +pub struct TransactionProcessingEnvironment<'a> { + /// The blockhash to use for the transaction batch. + pub blockhash: Hash, + /// The total stake for the current epoch. + pub epoch_total_stake: Option, + /// The vote accounts for the current epoch. + pub epoch_vote_accounts: Option<&'a VoteAccountsHashMap>, + /// Runtime feature set to use for the transaction batch. + pub feature_set: Arc, + /// Lamports per signature to charge per transaction. + pub lamports_per_signature: u64, + /// Rent collector to use for the transaction batch. + pub rent_collector: Option<&'a RentCollector>, +} + #[cfg_attr(feature = "frozen-abi", derive(AbiExample))] pub struct TransactionBatchProcessor { /// Bank slot (i.e. block) @@ -220,6 +240,7 @@ impl TransactionBatchProcessor { callbacks: &CB, sanitized_txs: &[SanitizedTransaction], check_results: Vec, + environment: &TransactionProcessingEnvironment, config: &TransactionProcessingConfig, ) -> LoadAndExecuteSanitizedTransactionsOutput { // Initialize metrics. @@ -230,6 +251,10 @@ impl TransactionBatchProcessor { callbacks, sanitized_txs, check_results, + &environment.feature_set, + environment + .rent_collector + .unwrap_or(&RentCollector::default()), &mut error_metrics )); @@ -271,6 +296,10 @@ impl TransactionBatchProcessor { validation_results, &mut error_metrics, config.account_overrides, + &environment.feature_set, + environment + .rent_collector + .unwrap_or(&RentCollector::default()), &program_cache_for_tx_batch.borrow(), ); load_time.stop(); @@ -305,13 +334,13 @@ impl TransactionBatchProcessor { }; let result = self.execute_loaded_transaction( - callbacks, tx, loaded_transaction, compute_budget, &mut execute_timings, &mut error_metrics, &program_cache_for_tx_batch.borrow(), + environment, config, ); @@ -385,6 +414,8 @@ impl TransactionBatchProcessor { callbacks: &CB, sanitized_txs: &[impl core::borrow::Borrow], check_results: Vec, + feature_set: &FeatureSet, + rent_collector: &RentCollector, error_counters: &mut TransactionErrorMetrics, ) -> Vec { sanitized_txs @@ -401,7 +432,9 @@ impl TransactionBatchProcessor { .validate_transaction_fee_payer( callbacks, message, + feature_set, lamports_per_signature, + rent_collector, error_counters, )?; @@ -435,12 +468,11 @@ impl TransactionBatchProcessor { &self, callbacks: &CB, message: &SanitizedMessage, + feature_set: &FeatureSet, lamports_per_signature: u64, + rent_collector: &RentCollector, error_counters: &mut TransactionErrorMetrics, ) -> transaction::Result<(FeeDetails, AccountSharedData, u64)> { - let feature_set = callbacks.get_feature_set(); - let rent_collector = callbacks.get_rent_collector(); - let fee_payer_address = message.fee_payer(); let Some(mut fee_payer_account) = callbacks.get_account_shared_data(fee_payer_address) else { @@ -449,7 +481,7 @@ impl TransactionBatchProcessor { }; let fee_payer_rent_debit = collect_rent_from_account( - &feature_set, + feature_set, rent_collector, fee_payer_address, &mut fee_payer_account, @@ -682,15 +714,16 @@ impl TransactionBatchProcessor { /// Execute a transaction using the provided loaded accounts and update /// the executors cache if the transaction was successful. - fn execute_loaded_transaction( + #[allow(clippy::too_many_arguments)] + fn execute_loaded_transaction( &self, - callback: &CB, tx: &SanitizedTransaction, loaded_transaction: &mut LoadedTransaction, compute_budget: ComputeBudget, execute_timings: &mut ExecuteTimings, error_metrics: &mut TransactionErrorMetrics, program_cache_for_tx_batch: &ProgramCacheForTxBatch, + environment: &TransactionProcessingEnvironment, config: &TransactionProcessingConfig, ) -> TransactionExecutionResult { let transaction_accounts = std::mem::take(&mut loaded_transaction.accounts); @@ -707,23 +740,25 @@ impl TransactionBatchProcessor { Some(lamports_sum) } + let rent = environment + .rent_collector + .map(|rent_collector| rent_collector.rent.clone()) + .unwrap_or_default(); + let lamports_before_tx = transaction_accounts_lamports_sum(&transaction_accounts, tx.message()).unwrap_or(0); let mut transaction_context = TransactionContext::new( transaction_accounts, - callback.get_rent_collector().rent.clone(), + rent.clone(), compute_budget.max_invoke_stack_height, compute_budget.max_instruction_trace_length, ); #[cfg(debug_assertions)] transaction_context.set_signature(tx.signature()); - let pre_account_state_info = TransactionAccountStateInfo::new( - &callback.get_rent_collector().rent, - &transaction_context, - tx.message(), - ); + let pre_account_state_info = + TransactionAccountStateInfo::new(&rent, &transaction_context, tx.message()); let log_collector = if config.recording_config.enable_log_recording { match config.log_messages_bytes_limit { @@ -736,8 +771,8 @@ impl TransactionBatchProcessor { None }; - let (blockhash, lamports_per_signature) = - callback.get_last_blockhash_and_lamports_per_signature(); + let blockhash = environment.blockhash; + let lamports_per_signature = environment.lamports_per_signature; let mut executed_units = 0u64; let mut programs_modified_by_tx = ProgramCacheForTxBatch::new( @@ -753,9 +788,9 @@ impl TransactionBatchProcessor { program_cache_for_tx_batch, EnvironmentConfig::new( blockhash, - callback.get_epoch_total_stake(), - callback.get_epoch_vote_accounts(), - callback.get_feature_set(), + environment.epoch_total_stake, + environment.epoch_vote_accounts, + Arc::clone(&environment.feature_set), lamports_per_signature, sysvar_cache, ), @@ -783,11 +818,8 @@ impl TransactionBatchProcessor { let mut status = process_result .and_then(|info| { - let post_account_state_info = TransactionAccountStateInfo::new( - &callback.get_rent_collector().rent, - &transaction_context, - tx.message(), - ); + let post_account_state_info = + TransactionAccountStateInfo::new(&rent, &transaction_context, tx.message()); TransactionAccountStateInfo::verify_changes( &pre_account_state_info, &post_account_state_info, @@ -993,7 +1025,6 @@ mod tests { transaction::{SanitizedTransaction, Transaction, TransactionError}, transaction_context::TransactionContext, }, - solana_vote::vote_account::VoteAccountsHashMap, std::{ env, fs::{self, File}, @@ -1019,8 +1050,6 @@ mod tests { #[derive(Default, Clone)] pub struct MockBankCallback { - rent_collector: RentCollector, - feature_set: Arc, pub account_shared_data: Arc>>, } @@ -1045,26 +1074,6 @@ mod tests { .cloned() } - fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64) { - (Hash::new_unique(), 2) - } - - fn get_rent_collector(&self) -> &RentCollector { - &self.rent_collector - } - - fn get_feature_set(&self) -> Arc { - self.feature_set.clone() - } - - fn get_epoch_total_stake(&self) -> Option { - None - } - - fn get_epoch_vote_accounts(&self) -> Option<&VoteAccountsHashMap> { - None - } - fn add_builtin_account(&self, name: &str, program_id: &Pubkey) { let mut account_data = AccountSharedData::default(); account_data.set_data(name.as_bytes().to_vec()); @@ -1141,7 +1150,6 @@ mod tests { let sanitized_message = new_unchecked_sanitized_message(message); let program_cache_for_tx_batch = ProgramCacheForTxBatch::default(); - let mock_bank = MockBankCallback::default(); let batch_processor = TransactionBatchProcessor::::default(); let sanitized_transaction = SanitizedTransaction::new_for_tests( @@ -1160,17 +1168,19 @@ mod tests { loaded_accounts_data_size: 32, }; + let processing_environment = TransactionProcessingEnvironment::default(); + let mut processing_config = TransactionProcessingConfig::default(); processing_config.recording_config.enable_log_recording = true; let result = batch_processor.execute_loaded_transaction( - &mock_bank, &sanitized_transaction, &mut loaded_transaction, ComputeBudget::default(), &mut ExecuteTimings::default(), &mut TransactionErrorMetrics::default(), &program_cache_for_tx_batch, + &processing_environment, &processing_config, ); @@ -1186,13 +1196,13 @@ mod tests { processing_config.log_messages_bytes_limit = Some(2); let result = batch_processor.execute_loaded_transaction( - &mock_bank, &sanitized_transaction, &mut loaded_transaction, ComputeBudget::default(), &mut ExecuteTimings::default(), &mut TransactionErrorMetrics::default(), &program_cache_for_tx_batch, + &processing_environment, &processing_config, ); @@ -1216,13 +1226,13 @@ mod tests { processing_config.log_messages_bytes_limit = None; let result = batch_processor.execute_loaded_transaction( - &mock_bank, &sanitized_transaction, &mut loaded_transaction, ComputeBudget::default(), &mut ExecuteTimings::default(), &mut TransactionErrorMetrics::default(), &program_cache_for_tx_batch, + &processing_environment, &processing_config, ); @@ -1262,7 +1272,6 @@ mod tests { let sanitized_message = new_unchecked_sanitized_message(message); let program_cache_for_tx_batch = ProgramCacheForTxBatch::default(); - let mock_bank = MockBankCallback::default(); let batch_processor = TransactionBatchProcessor::::default(); let sanitized_transaction = SanitizedTransaction::new_for_tests( @@ -1293,13 +1302,13 @@ mod tests { let mut error_metrics = TransactionErrorMetrics::new(); let _ = batch_processor.execute_loaded_transaction( - &mock_bank, &sanitized_transaction, &mut loaded_transaction, ComputeBudget::default(), &mut ExecuteTimings::default(), &mut error_metrics, &program_cache_for_tx_batch, + &TransactionProcessingEnvironment::default(), &processing_config, ); @@ -1981,8 +1990,6 @@ mod tests { mock_accounts.insert(*fee_payer_address, fee_payer_account.clone()); let mock_bank = MockBankCallback { account_shared_data: Arc::new(RwLock::new(mock_accounts)), - rent_collector, - ..MockBankCallback::default() }; let mut error_counters = TransactionErrorMetrics::default(); @@ -1990,7 +1997,9 @@ mod tests { let result = batch_processor.validate_transaction_fee_payer( &mock_bank, &message, + &FeatureSet::default(), lamports_per_signature, + &rent_collector, &mut error_counters, ); @@ -2039,8 +2048,6 @@ mod tests { mock_accounts.insert(*fee_payer_address, fee_payer_account.clone()); let mock_bank = MockBankCallback { account_shared_data: Arc::new(RwLock::new(mock_accounts)), - rent_collector, - ..MockBankCallback::default() }; let mut error_counters = TransactionErrorMetrics::default(); @@ -2048,7 +2055,9 @@ mod tests { let result = batch_processor.validate_transaction_fee_payer( &mock_bank, &message, + &FeatureSet::default(), lamports_per_signature, + &rent_collector, &mut error_counters, ); @@ -2081,7 +2090,9 @@ mod tests { let result = batch_processor.validate_transaction_fee_payer( &mock_bank, &message, + &FeatureSet::default(), lamports_per_signature, + &RentCollector::default(), &mut error_counters, ); @@ -2100,7 +2111,6 @@ mod tests { mock_accounts.insert(*fee_payer_address, fee_payer_account.clone()); let mock_bank = MockBankCallback { account_shared_data: Arc::new(RwLock::new(mock_accounts)), - ..MockBankCallback::default() }; let mut error_counters = TransactionErrorMetrics::default(); @@ -2108,7 +2118,9 @@ mod tests { let result = batch_processor.validate_transaction_fee_payer( &mock_bank, &message, + &FeatureSet::default(), lamports_per_signature, + &RentCollector::default(), &mut error_counters, ); @@ -2131,8 +2143,6 @@ mod tests { mock_accounts.insert(*fee_payer_address, fee_payer_account.clone()); let mock_bank = MockBankCallback { account_shared_data: Arc::new(RwLock::new(mock_accounts)), - rent_collector, - ..MockBankCallback::default() }; let mut error_counters = TransactionErrorMetrics::default(); @@ -2140,7 +2150,9 @@ mod tests { let result = batch_processor.validate_transaction_fee_payer( &mock_bank, &message, + &FeatureSet::default(), lamports_per_signature, + &rent_collector, &mut error_counters, ); @@ -2161,7 +2173,6 @@ mod tests { mock_accounts.insert(*fee_payer_address, fee_payer_account.clone()); let mock_bank = MockBankCallback { account_shared_data: Arc::new(RwLock::new(mock_accounts)), - ..MockBankCallback::default() }; let mut error_counters = TransactionErrorMetrics::default(); @@ -2169,7 +2180,9 @@ mod tests { let result = batch_processor.validate_transaction_fee_payer( &mock_bank, &message, + &FeatureSet::default(), lamports_per_signature, + &RentCollector::default(), &mut error_counters, ); @@ -2179,7 +2192,9 @@ mod tests { #[test] fn test_validate_transaction_fee_payer_is_nonce() { + let feature_set = FeatureSet::default(); let lamports_per_signature = 5000; + let rent_collector = RentCollector::default(); let compute_unit_limit = 2 * solana_compute_budget_program::DEFAULT_COMPUTE_UNITS; let message = new_unchecked_sanitized_message(Message::new_with_blockhash( &[ @@ -2209,7 +2224,6 @@ mod tests { mock_accounts.insert(*fee_payer_address, fee_payer_account.clone()); let mock_bank = MockBankCallback { account_shared_data: Arc::new(RwLock::new(mock_accounts)), - ..MockBankCallback::default() }; let mut error_counters = TransactionErrorMetrics::default(); @@ -2217,7 +2231,9 @@ mod tests { let result = batch_processor.validate_transaction_fee_payer( &mock_bank, &message, + &feature_set, lamports_per_signature, + &rent_collector, &mut error_counters, ); @@ -2253,7 +2269,6 @@ mod tests { mock_accounts.insert(*fee_payer_address, fee_payer_account.clone()); let mock_bank = MockBankCallback { account_shared_data: Arc::new(RwLock::new(mock_accounts)), - ..MockBankCallback::default() }; let mut error_counters = TransactionErrorMetrics::default(); @@ -2261,7 +2276,9 @@ mod tests { let result = batch_processor.validate_transaction_fee_payer( &mock_bank, &message, + &feature_set, lamports_per_signature, + &rent_collector, &mut error_counters, ); diff --git a/svm/tests/conformance.rs b/svm/tests/conformance.rs index fc83557dfad9ea..ec5bbe0c9fd529 100644 --- a/svm/tests/conformance.rs +++ b/svm/tests/conformance.rs @@ -41,6 +41,7 @@ use { transaction_processing_callback::TransactionProcessingCallback, transaction_processor::{ ExecutionRecordingConfig, TransactionBatchProcessor, TransactionProcessingConfig, + TransactionProcessingEnvironment, }, }, std::{ @@ -279,9 +280,6 @@ fn run_fixture(fixture: InstrFixture, filename: OsString, execute_as_instr: bool .map(|x| (x.blockhash, x.fee_calculator.lamports_per_signature)) .unwrap_or_default(); - mock_bank.lamports_per_sginature = lamports_per_signature; - mock_bank.blockhash = blockhash; - let recording_config = ExecutionRecordingConfig { enable_log_recording: true, enable_return_data_recording: true, @@ -313,6 +311,11 @@ fn run_fixture(fixture: InstrFixture, filename: OsString, execute_as_instr: bool &mock_bank, &transactions, transaction_check, + &TransactionProcessingEnvironment { + blockhash, + lamports_per_signature, + ..Default::default() + }, &processor_config, ); @@ -462,11 +465,11 @@ fn execute_fixture_as_instr( let sysvar_cache = &batch_processor.sysvar_cache.read().unwrap(); let env_config = EnvironmentConfig::new( - mock_bank.blockhash, + Hash::default(), None, None, mock_bank.feature_set.clone(), - mock_bank.lamports_per_sginature, + 0, sysvar_cache, ); diff --git a/svm/tests/integration_test.rs b/svm/tests/integration_test.rs index 61214200ec36e0..9816d41cbc4dae 100644 --- a/svm/tests/integration_test.rs +++ b/svm/tests/integration_test.rs @@ -34,6 +34,7 @@ use { transaction_processing_callback::TransactionProcessingCallback, transaction_processor::{ ExecutionRecordingConfig, TransactionBatchProcessor, TransactionProcessingConfig, + TransactionProcessingEnvironment, }, transaction_results::TransactionExecutionResult, }, @@ -470,6 +471,7 @@ fn svm_integration() { &mock_bank, &transactions, check_results, + &TransactionProcessingEnvironment::default(), &processing_config, ); diff --git a/svm/tests/mock_bank.rs b/svm/tests/mock_bank.rs index 7ee17547577957..f67b63346e95b7 100644 --- a/svm/tests/mock_bank.rs +++ b/svm/tests/mock_bank.rs @@ -4,14 +4,11 @@ use { account::{AccountSharedData, ReadableAccount}, clock::Epoch, feature_set::FeatureSet, - hash::Hash, native_loader, pubkey::Pubkey, - rent_collector::RentCollector, slot_hashes::Slot, }, solana_svm::transaction_processing_callback::TransactionProcessingCallback, - solana_vote::vote_account::VoteAccountsHashMap, std::{cell::RefCell, cmp::Ordering, collections::HashMap, sync::Arc}, }; @@ -33,10 +30,7 @@ impl ForkGraph for MockForkGraph { #[derive(Default)] pub struct MockBankCallback { - rent_collector: RentCollector, pub feature_set: Arc, - pub blockhash: Hash, - pub lamports_per_sginature: u64, pub account_shared_data: RefCell>, } @@ -57,27 +51,6 @@ impl TransactionProcessingCallback for MockBankCallback { self.account_shared_data.borrow().get(pubkey).cloned() } - fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64) { - // Mock a hash and a value - (self.blockhash, self.lamports_per_sginature) - } - - fn get_rent_collector(&self) -> &RentCollector { - &self.rent_collector - } - - fn get_feature_set(&self) -> Arc { - self.feature_set.clone() - } - - fn get_epoch_total_stake(&self) -> Option { - None - } - - fn get_epoch_vote_accounts(&self) -> Option<&VoteAccountsHashMap> { - None - } - fn add_builtin_account(&self, name: &str, program_id: &Pubkey) { let account_data = native_loader::create_loadable_account_with_fields(name, (5000, 0));