Skip to content

Commit

Permalink
SVM: move TransactionProcessingCallback into its own module (#1004)
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec authored Apr 23, 2024
1 parent b8cc66e commit f5db8d2
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 39 deletions.
2 changes: 1 addition & 1 deletion runtime/benches/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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::{
Expand Down
1 change: 1 addition & 0 deletions svm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
38 changes: 38 additions & 0 deletions svm/src/transaction_processing_callback.rs
Original file line number Diff line number Diff line change
@@ -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<usize>;

fn get_account_shared_data(&self, pubkey: &Pubkey) -> Option<AccountSharedData>;

fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64);

fn get_rent_collector(&self) -> &RentCollector;

fn get_feature_set(&self) -> Arc<FeatureSet>;

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) {}
}
35 changes: 4 additions & 31 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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},
Expand Down Expand Up @@ -84,34 +82,6 @@ impl ExecutionRecordingConfig {
}
}

pub trait TransactionProcessingCallback {
fn account_matches_owners(&self, account: &Pubkey, owners: &[Pubkey]) -> Option<usize>;

fn get_account_shared_data(&self, pubkey: &Pubkey) -> Option<AccountSharedData>;

fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64);

fn get_rent_collector(&self) -> &RentCollector;

fn get_feature_set(&self) -> Arc<FeatureSet>;

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),
Expand Down Expand Up @@ -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},
Expand Down
5 changes: 2 additions & 3 deletions svm/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion svm/tests/mock_bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down

0 comments on commit f5db8d2

Please sign in to comment.