Overview
The runtime is responsible for:- Executing smart contract programs (Solana programs)
- Managing account state and balances
- Enforcing access control and security rules
- Parallelizing non-conflicting transactions
- Recording execution in Proof of History
docs/src/validator/runtime.md:1
Core Design Principles
Explicit Dependencies
Transactions must declare all accounts they will access upfront:- Detect conflicts before execution
- Schedule non-conflicting transactions in parallel
- Prevent dynamic memory allocation during execution
docs/src/validator/runtime.md:8
Parallel Execution
Transactions are batched and analyzed for conflicts:- Load accounts - Fetch account data from AccountsDB
- Detect conflicts - Identify transactions accessing the same writable accounts
- Execute in parallel - Run non-conflicting transactions simultaneously
- Commit atomically - All instructions in a transaction succeed or all fail
docs/src/validator/runtime.md:20
At the execute stage, loaded accounts have no data dependencies, so all programs can be executed in parallel across available CPU cores.
Account Model
Solana uses an account-based model where each account contains:docs/src/validator/runtime.md:12
Account Ownership Rules
-
Only the owner program may modify account data
- Prevents unauthorized state changes
- Data is zero-initialized on assignment
-
Only the owner can spend lamports
- Programs can only debit accounts they own
- Anyone can credit (send to) any account
-
Accounts assigned to a program cannot be reassigned
- Once owned, always owned by that program
docs/src/validator/runtime.md:30
Transaction Execution
Execution Pipeline
Transactions flow through the runtime in stages:- Load - Fetch all accounts into memory
- Execute - Run each instruction in sequence
- Verify - Check balance invariants and rules
- Commit - Write changes back to AccountsDB
docs/src/validator/runtime.md:16
Runtime Invariants
The runtime enforces critical safety rules:- Balance conservation - Total lamports before = total after
- Read-only accounts unchanged - Balances remain identical
- Atomic execution - All instructions succeed or all fail
- Owner exclusivity - Only owners modify account data
docs/src/validator/runtime.md:30
These invariants are checked after execution. If any invariant is violated, the entire transaction is rolled back and marked as failed.
Program Execution
Programs are executed through a well-defined entrypoint:program-runtime/src/invoke_context.rs:1
Instruction Processing
Each instruction in a transaction:- Loads accounts - Maps public keys to account data
- Invokes program - Calls the program’s entrypoint
- Returns result - Success or error
- Commits changes - Updates account state on success
docs/src/validator/runtime.md:37
Cross-Program Invocation (CPI)
Programs can call other programs using CPI:- Program composability
- Modular smart contract design
- Shared program logic
- Secure delegation of authority
program-runtime/src/cpi.rs:1
Solana Virtual Machine (SVM)
Programs execute in the Solana Virtual Machine, which provides:eBPF Runtime
Solana programs compile to eBPF bytecode:- Deterministic - Same input always produces same output
- Fast - JIT compilation for near-native performance
- Safe - Sandboxed execution prevents system access
- Verifiable - Bytecode is verified before deployment
program-runtime/src/vm.rs:1
Compute Budget
Each transaction has a compute budget:- 200,000 compute units per instruction
- 1,400,000 compute units per transaction
- 32 KB heap per program invocation
program-runtime/src/execution_budget.rs:1
Syscalls
Programs interact with the runtime through syscalls:sol_log_*- Logging for debuggingsol_invoke_signed- Cross-program invocationsol_create_program_address- PDA derivationsol_get_clock_sysvar- Access cluster timesol_keccak256- Cryptographic hashing
syscalls/src/lib.rs:1
Banking Stage Integration
The Banking Stage coordinates runtime execution:- Receives transactions - From SigVerify stage
- Locks accounts - Reserves accounts for execution
- Schedules execution - Assigns to worker threads
- Records in PoH - Timestamps executed transactions
- Returns results - Success or failure per transaction
core/src/banking_stage.rs:1
Unified Scheduler
Agave’s default scheduler uses advanced parallelism:- Multi-threaded execution - Distributes work across cores
- Account locking - Prevents conflicting access
- Priority queue - Processes high-fee transactions first
- Look-ahead scheduling - Finds parallelizable transactions
unified-scheduler-pool/src/lib.rs:1
The Unified Scheduler can execute 50,000+ TPS on modern hardware by maximizing parallel execution.
Sysvar Accounts
Special read-only accounts provide cluster state:- Clock - Current slot, epoch, and timestamp
- EpochSchedule - Slots per epoch configuration
- Rent - Rent calculation parameters
- StakeHistory - Historical stake activations
- SlotHashes - Recent slot hashes for verification
runtime/src/sysvar_cache.rs:1
Program Loading and Caching
Programs are loaded and cached for performance:- Programs are compiled once and reused
- Cache is updated when programs are upgraded
- LRU eviction prevents unbounded growth
program-runtime/src/loaded_programs.rs:1
Transaction Fees
The runtime calculates and deducts fees:- Base fee - Minimum fee per signature
- Compute fee - Based on compute units consumed
- Prioritization fee - Optional fee for priority
- Account creation - Rent-exempt minimum for new accounts
State Commitment
Successful transactions result in state changes:- AccountsDB update - Modified accounts written to cache
- Bank hash update - Cryptographic hash of all accounts
- PoH recording - Transaction hash recorded in PoH stream
- Status recorded - Success/failure logged for RPC queries
runtime/src/bank.rs:1
Built-in Programs
Agave includes native programs:- System Program - Account creation and transfers
- Stake Program - Staking and delegation
- Vote Program - Validator voting
- BPF Loader - Deploys and upgrades programs
- Config Program - Stores configuration data
builtins/src/lib.rs:1
Next Steps
- Learn about validator anatomy
- Understand consensus mechanisms
- Explore cluster operations