Overview
Flamenco implements the complete Solana runtime environment, including:- Transaction execution and validation
- Account state management
- Program execution (eBPF VM)
- Consensus and leader scheduling
- Stake and reward calculations
- Feature gate management
Flamenco aims for complete compatibility with the Solana Labs validator while providing significant performance improvements through optimized data structures and parallel execution.
Core Components
Runtime Engine
Runtime Engine
Runtime (runtime/)
The core execution engine for Solana transactions:Key structures:- Transaction execution orchestration
- Cross-program invocation (CPI) handling
- Compute unit metering
- Account locking and conflict detection
- Rent collection
- Sysvar updates
Transaction Processing (txn/)
- Parse and validate transaction format
- Verify signatures (via Ballet Ed25519)
- Load and lock accounts
- Execute instructions sequentially
- Update account states
- Calculate fees and rent
- Unlock accounts and commit
- Max transaction size: 1232 bytes (
FD_TPU_MTU) - Max signatures: Variable (typically 64)
- Max accounts: 256 per transaction
- Max instructions: 64 per transaction
Account Management
Account Management
Account Database (accdb/)
High-performance account storage and retrieval:Features:- Concurrent read access
- Write coalescing
- Account versioning
- Snapshot support
- Cache hierarchy (L1/L2)
Account Metadata
Borrowed Accounts
- Borrowed at transaction start
- Locked for write if writable
- Modified during execution
- Committed or rolled back at end
Account Manager (fd_acc_mgr_t)
- Account lifecycle management
- Memory pooling (
fd_acc_pool_t) - Efficient allocation/deallocation
Virtual Machine
Virtual Machine
eBPF VM (vm/)
Solana’s eBPF (extended Berkeley Packet Filter) virtual machine:Capabilities:- sBPF instruction set execution
- JIT compilation (optional)
- Compute unit metering
- Memory safety checks
- Call depth limiting
- Load program from account
- Verify program (via Ballet sBPF)
- Compile to native code (JIT)
- Execute with instruction context
- Meter compute units
- Return result or error
Program Cache (progcache/)
- Compiled program caching
- LRU eviction policy
- Concurrent access
- Invalidation on program upgrades
- Hot programs: JIT compiled, cached
- Cold programs: Interpreted or compiled on-demand
- Redeployment: Invalidate and recompile
Consensus & Leader Scheduling
Consensus & Leader Scheduling
Leader Schedule (leaders/)
Determines which validator is leader for each slot:Algorithm:- Get stake distribution at epoch boundary
- Apply weighted sampling (Ballet wsample)
- Generate deterministic leader sequence
- Cache for current and next epoch
- Leader rotation every 4 slots (typically)
- Epoch-based recalculation
- Stake-weighted selection
Stake Management (stakes/)
- Active stake per validator
- Delegated stake
- Activation/deactivation epochs
- Warm-up/cool-down periods
Rewards (rewards/)
Reward types:- Staking rewards (inflationary)
- Transaction fees
- Rent collection (deprecated)
- Calculated at epoch boundary
- Distributed to stake accounts
- Commission split to vote accounts
Gossip & Networking
Gossip & Networking
Gossip Protocol (gossip/)
Distributed cluster information exchange:Gossiped data:- Cluster topology (validator IPs/ports)
- Vote account information
- Shred versions
- Contact info updates
- Node health metrics
- Push messages: Broadcast new information
- Pull messages: Request missing data
- Prune messages: Stop forwarding
- Ping/pong: Liveness checks
- Eventually consistent
- Epidemic broadcast protocol
- Fanout-based propagation
- CRDT merge semantics
Features & Versioning
Features & Versioning
Feature Gates (features/)
- Defined in code (pending)
- Activated by stake vote
- Effective at next epoch
- Remains active forever
- Transaction version support
- Account rent changes
- Compute unit pricing
- New syscalls
- VM improvements
Utility Components
Utility Components
Genesis (genesis/)
- Initial account states
- System program accounts
- Stake pools
- Inflation parameters
- Epoch schedule
Capture (capture/)
- Transaction replay capture
- Account state snapshots
- Deterministic debugging
- Conformance testing
Log Collector (log_collector/)
- Syscall log output
- Error messages
- Return to RPC clients
Types (types/)
Solana protocol type definitions:- Serialization formats
- Wire protocol structures
- Custom type definitions (
fd_types_custom.h) - Type casting utilities (
fd_cast.h)
Address Utilities
Data Structures
Bank State
- Bank 0: Current leader slot
- Bank 1: Next slot preparation
- Bank N: Historical banks for forks
Synchronization
- Sort accounts by address
- Acquire locks in order
- Prevents deadlocks
- Enables parallel execution
Execution Flow
Instruction Execution
- Verify program ownership
- Check account permissions
- Execute program (native or eBPF)
- Meter compute units
- Update account data
- Handle cross-program invocations
Performance Features
- Parallel Execution: Banking stages execute transactions concurrently
- Account Sharding: Partition accounts for parallel access
- Program Caching: JIT-compiled programs cached in memory
- Optimized Data Structures: Custom allocators and pools
- SIMD Acceleration: Vectorized operations where applicable
Compatibility
Flamenco maintains compatibility with Solana Labs validator:- Identical transaction execution behavior
- Same account state transitions
- Compatible consensus rules
- Matching feature gate activation
- Equivalent RPC responses (via Agave integration)