Overview
The SVM (Solana Virtual Machine) library provides low-level transaction processing functionality. It handles transaction loading, execution, and commitment without depending on the Bank abstraction, making it suitable for alternative blockchain implementations.TransactionBatchProcessor
TheTransactionBatchProcessor<FG: ForkGraph> is the main processor for executing batches of transactions.
Structure
Constructor Methods
Create a new, uninitialized
TransactionBatchProcessor with an empty program cache.Parameters:slot: The slot number for this processorepoch: The epoch number for this processor
Self: A new processor instance
set_fork_graph_in_program_cache and add_builtin to properly configure the processor.Create a new processor from an existing one, inheriting the program cache and builtin program IDs but resetting the sysvar cache.Parameters:
slot: The slot number for the new processorepoch: The epoch number for the new processor
Self: A new processor instance
Core Processing Method
load_and_execute_sanitized_transactions
fn<CB: TransactionProcessingCallback>(&self, callbacks: &CB, sanitized_txs: &[SanitizedTransaction], check_results: Vec<TransactionCheckResult>, environment: &TransactionProcessingEnvironment, config: &TransactionProcessingConfig) -> LoadAndExecuteSanitizedTransactionsOutput
Load and execute a batch of sanitized transactions.Parameters:
callbacks: Transaction processing callbacks for account loading and state managementsanitized_txs: Slice of sanitized transactions to executecheck_results: Pre-computed check results for each transactionenvironment: Runtime environment configurationconfig: Transaction processing configuration
LoadAndExecuteSanitizedTransactionsOutput: Contains processing results, error metrics, timings, and balance information
TransactionProcessingEnvironment
Configuration for the runtime environment used during transaction processing.TransactionProcessingConfig
Configuration options for processing transactions.ExecutionRecordingConfig
Controls what data is recorded during transaction execution.LoadAndExecuteSanitizedTransactionsOutput
The output from batch transaction processing.MessageProcessor
The message processor handles individual instruction execution.Core Function
process_message
fn<'ix_data>(message: &'ix_data impl SVMMessage, program_indices: &[IndexOfAccount], invoke_context: &mut InvokeContext, execute_timings: &mut ExecuteTimings, accumulated_consumed_units: &mut u64) -> Result<(), TransactionError>
Process a message by executing each instruction in sequence.Parameters:
message: The message to process (implements SVMMessage trait)program_indices: Indices of program accounts for each instructioninvoke_context: Mutable invoke context for executionexecute_timings: Mutable timing measurementsaccumulated_consumed_units: Mutable counter for compute units consumed
Result<(), TransactionError>: Ok if all instructions succeed, error otherwise
Key Traits
TransactionProcessingCallback
Callback interface for account loading and state management during transaction processing. Required Methods:get_account_shared_data: Load account dataadd_builtin_account: Add a builtin program account- Account state tracking and management
SVMMessage
Trait for transaction messages that can be processed by the SVM. Required Methods:num_instructions: Get the number of instructionsinstructions_iter: Iterate over instructionsprogram_instructions_iter: Iterate over program instructionsaccount_keys: Get account keys referenced in the message
Example Usage
See Also
- Runtime API - High-level Bank interface
- Accounts DB API - Account storage
- Program Runtime - Program execution environment