Architecture Overview
The SVM is organized into several key modules (~/workspace/source/svm/src/lib.rs:1):Transaction Processor
The TransactionBatchProcessor (~/workspace/source/svm/src/transaction_processor.rs:160) is the main entry point:Key Responsibilities
- Load and validate transactions
- Execute program instructions
- Manage program cache
- Track execution costs
- Collect execution logs
Transaction Processing Flow
1. Load Phase
The account loader (~/workspace/source/svm/src/account_loader.rs:161) loads all required accounts:Account Loading Steps
- Fee Payer Validation - Verify fee payer has sufficient balance
- Nonce Account Loading - Load nonce account if present
- Transaction Account Loading - Load all accounts referenced in transaction
- Program Account Loading - Load program accounts and their data
- Rent Validation - Check rent-exempt status
2. Execution Phase
The message processor (~/workspace/source/svm/src/message_processor.rs:15) executes instructions:Execution Steps
- Prepare Instruction - Set up instruction context
- Load Program - Get program from cache or load from account
- Execute Instruction - Call program entrypoint
- Track Compute Units - Monitor resource usage
- Validate Result - Check account mutations are valid
3. Commit Phase
After execution completes:- Validate Changes - Ensure account rules followed
- Collect Rent - Apply rent to modified accounts
- Update State - Write changes back to AccountsDb
- Record Logs - Save execution logs if enabled
Account Loader
The account loader manages loading accounts for transactions.Loading Strategy
- Batch Loading - Load multiple accounts efficiently
- Account Cache - Cache accounts within batch
- Override Support - Allow simulated account states
- Rent Calculation - Compute rent for each account
Transaction Account State
Accounts tracked through execution:Program Execution Model
Program Cache
The SVM maintains a cache of loaded programs:- Global Cache - Shared across all transactions
- Batch Cache - Transaction batch specific
- LRU Eviction - Remove least-recently used programs
- Recompilation - Handle program upgrades
Invoke Context
The InvokeContext provides programs with:- Account Access - Read/write account data
- System Variables - Clock, rent, epoch schedule
- Cross-Program Invocation - Call other programs
- Compute Budget - Track resource usage
- Return Data - Pass data back to caller
Execution Environment
Programs execute in isolated environment:Transaction Processing
Processing Configuration
Recording Configuration
Controls what data is captured during execution:Program Loader
The program loader (~/workspace/source/svm/src/program_loader.rs) handles:- Program Discovery - Find program for given account
- Program Validation - Verify program is executable
- Program Loading - Load program bytecode
- Program Caching - Cache compiled programs
Load Process
- Check if program is builtin
- Look up program in cache
- If not cached, load from account
- Validate program format
- Cache for future use
Compute Budget
The SVM enforces compute limits:- Compute Units - Maximum instructions executed
- Account Data Size - Maximum account data loaded
- Call Depth - Maximum cross-program invocation depth
- Log Data Size - Maximum log output size
Budget Tracking
Rollback Accounts
The SVM tracks original account states for rollback:- Restore original account states
- Deduct fee from fee payer only
- Update nonce if present
- Discard all other changes
Transaction Results
Execution produces detailed results:Error Handling
The SVM provides detailed error information:- Instruction Errors - Which instruction failed
- Custom Errors - Program-specific error codes
- Account Errors - Invalid account state
- Compute Budget Exceeded - Resource limits hit
Performance Features
Program Cache
- Avoids reloading programs
- Reduces disk I/O
- Enables hot-path optimization
Parallel Execution
- Non-conflicting transactions execute concurrently
- Read-only accounts allow parallelism
- Optimistic locking strategy
Account Batching
- Load multiple accounts together
- Reduce database roundtrips
- Better cache utilization
Key Files
- Transaction Processor: ~/workspace/source/svm/src/transaction_processor.rs
- Account Loader: ~/workspace/source/svm/src/account_loader.rs
- Message Processor: ~/workspace/source/svm/src/message_processor.rs
- Program Loader: ~/workspace/source/svm/src/program_loader.rs