From f5db8d2c27e858c81fff90178157c77b0d95697b Mon Sep 17 00:00:00 2001 From: Joe C Date: Tue, 23 Apr 2024 15:10:17 -0500 Subject: [PATCH] SVM: move `TransactionProcessingCallback` into its own module (#1004) --- runtime/benches/bank.rs | 2 +- runtime/src/bank.rs | 2 +- svm/src/account_loader.rs | 4 +-- svm/src/lib.rs | 1 + svm/src/transaction_processing_callback.rs | 38 ++++++++++++++++++++++ svm/src/transaction_processor.rs | 35 +++----------------- svm/tests/integration_test.rs | 5 ++- svm/tests/mock_bank.rs | 2 +- 8 files changed, 50 insertions(+), 39 deletions(-) create mode 100644 svm/src/transaction_processing_callback.rs diff --git a/runtime/benches/bank.rs b/runtime/benches/bank.rs index a64d075c5ef177..e6812030882577 100644 --- a/runtime/benches/bank.rs +++ b/runtime/benches/bank.rs @@ -20,7 +20,7 @@ use { signature::{Keypair, Signer}, transaction::Transaction, }, - solana_svm::transaction_processor::TransactionProcessingCallback, + solana_svm::transaction_processing_callback::TransactionProcessingCallback, std::{sync::Arc, thread::sleep, time::Duration}, test::Bencher, }; diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 62893750013217..4c454261fc47e9 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -167,9 +167,9 @@ use { account_loader::{TransactionCheckResult, TransactionLoadResult}, account_overrides::AccountOverrides, transaction_error_metrics::TransactionErrorMetrics, + transaction_processing_callback::TransactionProcessingCallback, transaction_processor::{ ExecutionRecordingConfig, TransactionBatchProcessor, TransactionLogMessages, - TransactionProcessingCallback, }, transaction_results::{ TransactionExecutionDetails, TransactionExecutionResult, TransactionResults, diff --git a/svm/src/account_loader.rs b/svm/src/account_loader.rs index bd3cc54d4c253d..6190fafa36c6b2 100644 --- a/svm/src/account_loader.rs +++ b/svm/src/account_loader.rs @@ -2,7 +2,7 @@ use { crate::{ account_overrides::AccountOverrides, account_rent_state::RentState, transaction_error_metrics::TransactionErrorMetrics, - transaction_processor::TransactionProcessingCallback, + transaction_processing_callback::TransactionProcessingCallback, }, itertools::Itertools, log::warn, @@ -455,7 +455,7 @@ mod tests { super::*, crate::{ transaction_account_state_info::TransactionAccountStateInfo, - transaction_processor::TransactionProcessingCallback, + transaction_processing_callback::TransactionProcessingCallback, }, nonce::state::Versions as NonceVersions, solana_program_runtime::{ diff --git a/svm/src/lib.rs b/svm/src/lib.rs index 131ac5aff50248..d1a4a46a4cdbfe 100644 --- a/svm/src/lib.rs +++ b/svm/src/lib.rs @@ -8,6 +8,7 @@ pub mod message_processor; pub mod runtime_config; pub mod transaction_account_state_info; pub mod transaction_error_metrics; +pub mod transaction_processing_callback; pub mod transaction_processor; pub mod transaction_results; diff --git a/svm/src/transaction_processing_callback.rs b/svm/src/transaction_processing_callback.rs new file mode 100644 index 00000000000000..dd5cf027d8a4e1 --- /dev/null +++ b/svm/src/transaction_processing_callback.rs @@ -0,0 +1,38 @@ +use { + crate::transaction_error_metrics::TransactionErrorMetrics, + solana_program_runtime::loaded_programs::ProgramCacheMatchCriteria, + solana_sdk::{ + account::AccountSharedData, feature_set::FeatureSet, hash::Hash, message::SanitizedMessage, + pubkey::Pubkey, rent_collector::RentCollector, transaction, + }, + std::sync::Arc, +}; + +/// Runtime callbacks for transaction processing. +pub trait TransactionProcessingCallback { + fn account_matches_owners(&self, account: &Pubkey, owners: &[Pubkey]) -> Option; + + 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 check_account_access( + &self, + _message: &SanitizedMessage, + _account_index: usize, + _account: &AccountSharedData, + _error_counters: &mut TransactionErrorMetrics, + ) -> transaction::Result<()> { + Ok(()) + } + + fn get_program_match_criteria(&self, _program: &Pubkey) -> ProgramCacheMatchCriteria { + ProgramCacheMatchCriteria::NoCriteria + } + + fn add_builtin_account(&self, _name: &str, _program_id: &Pubkey) {} +} diff --git a/svm/src/transaction_processor.rs b/svm/src/transaction_processor.rs index 002e0be2c44c34..bf54cce0a73a2c 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -8,6 +8,7 @@ use { runtime_config::RuntimeConfig, transaction_account_state_info::TransactionAccountStateInfo, transaction_error_metrics::TransactionErrorMetrics, + transaction_processing_callback::TransactionProcessingCallback, transaction_results::{ DurableNonceFee, TransactionExecutionDetails, TransactionExecutionResult, }, @@ -34,15 +35,12 @@ use { bpf_loader_upgradeable::{self, UpgradeableLoaderState}, clock::{Epoch, Slot}, epoch_schedule::EpochSchedule, - feature_set::FeatureSet, fee::FeeStructure, - hash::Hash, inner_instruction::{InnerInstruction, InnerInstructionsList}, instruction::{CompiledInstruction, InstructionError, TRANSACTION_LEVEL_STACK_HEIGHT}, loader_v4::{self, LoaderV4State, LoaderV4Status}, message::SanitizedMessage, pubkey::Pubkey, - rent_collector::RentCollector, saturating_add_assign, transaction::{self, SanitizedTransaction, TransactionError}, transaction_context::{ExecutionRecord, TransactionContext}, @@ -84,34 +82,6 @@ impl ExecutionRecordingConfig { } } -pub trait TransactionProcessingCallback { - fn account_matches_owners(&self, account: &Pubkey, owners: &[Pubkey]) -> Option; - - 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 check_account_access( - &self, - _message: &SanitizedMessage, - _account_index: usize, - _account: &AccountSharedData, - _error_counters: &mut TransactionErrorMetrics, - ) -> transaction::Result<()> { - Ok(()) - } - - fn get_program_match_criteria(&self, _program: &Pubkey) -> ProgramCacheMatchCriteria { - ProgramCacheMatchCriteria::NoCriteria - } - - fn add_builtin_account(&self, _name: &str, _program_id: &Pubkey) {} -} - #[derive(Debug)] enum ProgramAccountLoadResult { InvalidAccountData(ProgramCacheEntryOwner), @@ -1032,8 +1002,11 @@ mod tests { solana_sdk::{ account::{create_account_shared_data_for_test, WritableAccount}, bpf_loader, + feature_set::FeatureSet, fee_calculator::FeeCalculator, + hash::Hash, message::{LegacyMessage, Message, MessageHeader}, + rent_collector::RentCollector, rent_debits::RentDebits, reserved_account_keys::ReservedAccountKeys, signature::{Keypair, Signature}, diff --git a/svm/tests/integration_test.rs b/svm/tests/integration_test.rs index e90aa6f202f4ed..07b6eb2bb4fb40 100644 --- a/svm/tests/integration_test.rs +++ b/svm/tests/integration_test.rs @@ -34,9 +34,8 @@ use { account_loader::TransactionCheckResult, runtime_config::RuntimeConfig, transaction_error_metrics::TransactionErrorMetrics, - transaction_processor::{ - ExecutionRecordingConfig, TransactionBatchProcessor, TransactionProcessingCallback, - }, + transaction_processing_callback::TransactionProcessingCallback, + transaction_processor::{ExecutionRecordingConfig, TransactionBatchProcessor}, transaction_results::TransactionExecutionResult, }, std::{ diff --git a/svm/tests/mock_bank.rs b/svm/tests/mock_bank.rs index ff3fff77d2b6e4..38ae43f7259062 100644 --- a/svm/tests/mock_bank.rs +++ b/svm/tests/mock_bank.rs @@ -7,7 +7,7 @@ use { pubkey::Pubkey, rent_collector::RentCollector, }, - solana_svm::transaction_processor::TransactionProcessingCallback, + solana_svm::transaction_processing_callback::TransactionProcessingCallback, std::{cell::RefCell, collections::HashMap, sync::Arc}, };