Overview
The Banking Stage is the core transaction processing component in Agave validators. It receives transaction packets from the network, schedules them for execution, processes them against the current bank state, and commits results to the Proof of History (PoH) ledger. The banking stage operates differently depending on whether the node is a leader (producing blocks) or a validator (verifying blocks).Architecture
High-Level Pipeline
The banking stage implements a multi-stage software pipeline:banking_stage.rs:1-100:
- VoteWorker: Handles vote transactions separately for priority processing
- Consumer: Coordinates transaction execution and recording
- Committer: Commits executed transactions to PoH ledger
- DecisionMaker: Determines when to produce blocks (leader) or verify (validator)
- QosService: Quality of Service management and cost tracking
- TransactionScheduler: Schedules transactions respecting account conflicts
Transaction Flow
- Receive and Buffer: Packets arrive via TPU and are buffered
- Deduplication: Filter duplicate transactions
- Scheduling: Schedule non-conflicting transactions for execution
- Execution: Execute transactions against bank state
- Commitment: Record successful transactions in PoH ledger
- Forwarding: Forward unprocessed transactions (validators only)
Transaction Scheduling
Scheduler Architecture
Banking stage supports multiple scheduling strategies: GreedyScheduler (transaction_scheduler/greedy_scheduler.rs): Simple first-come-first-served scheduling with conflict detection.
PrioGraphScheduler (transaction_scheduler/prio_graph_scheduler.rs): Priority-based scheduling using transaction fees and dependency graphs.
The scheduler interface is defined in transaction_scheduler/scheduler.rs:13-52:
Conflict Detection
Schedulers detect account conflicts to enable parallel execution:- Read-Write Sets: Extract account read/write sets from transactions
- Conflict Graph: Build dependency graph based on shared accounts
- Batch Formation: Group non-conflicting transactions into batches
Scheduling Summary
Fromscheduler.rs:62-80, scheduling returns detailed metrics:
Transaction Execution
Consumer and Execution
TheConsumer component (consumer.rs:105-150) orchestrates execution:
- Pre-checks: Validate transaction signatures, check account locks
- Cost Model: Apply QoS cost limits to prevent block stuffing
- Bank Execution: Execute transactions via
Bank::load_and_execute_transactions - Post-processing: Collect results, update metrics
TARGET_NUM_TRANSACTIONS_PER_BATCH)
Execution Flags
Fromconsumer.rs:38-52, execution behavior is controlled by:
Quality of Service (QoS)
TheQosService (qos_service.rs) enforces resource limits:
- Compute Units: Track and limit compute budget consumption
- Account Limits: Prevent too many transactions touching same accounts
- Block Limits: Ensure block stays within resource constraints
- Cost Tracking: Monitor costs per account and per block
Leader vs Validator Roles
Leader Mode
When acting as leader for a slot:- Produce Blocks: Create new entries and add to ledger
- Schedule Aggressively: Fill blocks up to compute/account limits
- Record PoH: Commit transactions to PoH stream
- No Forwarding: Process all buffered transactions
Validator Mode
When not the leader:- Verify Blocks: Execute transactions from leader’s blocks
- Forward Transactions: Send unprocessed transactions to current leader
- Limited Buffering: Smaller buffer since not producing blocks
- Vote Processing: Prioritize vote transactions for consensus
Worker Threads
ConsumeWorker
Fromconsume_worker.rs, multiple workers execute transactions in parallel:
- Thread Pool: Configurable worker threads (default: 4, max: 64)
- Parallel Execution: Execute non-conflicting transaction batches concurrently
- Thread Affinity: Track which worker owns which account locks
DEFAULT_NUM_WORKERS: 4(banking_stage.rs:104)MAX_NUM_WORKERS: 64(banking_stage.rs:103)- Thread placement uses bitmask in
ThreadAwareAccountLocks
VoteWorker
Separate worker for vote transactions (vote_worker.rs):
- Priority Processing: Votes processed before regular transactions
- Separate Queue: Dedicated buffer for vote packets
- Fast Path: Optimized execution for simple vote updates
Buffering and Flow Control
Buffer Management
Frombanking_stage.rs:106-108:
- Capacity: 100k buffered packets maximum
- Deduplication: Drop duplicate transaction signatures
- Rebuffering: Retryable transactions placed back in buffer
- Expiration: Old transactions dropped based on age
Receive and Buffer
TheTransactionViewReceiveAndBuffer component:
- Receives packets from TPU channels
- Converts packets to transaction view objects
- Applies initial filters (duplicates, expired)
- Buffers transactions for scheduling
Committing Transactions
Committer Component
TheCommitter (committer.rs:1-150) finalizes transaction results:
- Validate Results: Ensure transactions executed successfully
- Create Entries: Bundle transactions into Entry objects
- Record in PoH: Send entries to PoH recorder
- Update Metrics: Track commit rates, failures
PoH Integration
Transactions are recorded in the Proof of History stream:- TransactionRecorder: Interface to PoH recorder
- Entry Creation: Group transactions into entries with PoH hashes
- Timing: Must commit within slot time bounds
- Backpressure: PoH recorder can apply backpressure if falling behind
Metrics and Monitoring
BankingStageStats
Frombanking_stage.rs:110-128, comprehensive metrics tracking:
Leader Slot Metrics
Detailed per-slot metrics tracked inleader_slot_metrics.rs:
- Transaction counts (processed, committed, failed)
- Execution timing
- Cost model throttling
- Buffer utilization
Configuration
Key Parameters
- Worker Threads: Control parallelism (4-64 workers)
- Buffer Size: Maximum buffered packets (100k default)
- Batch Size: Transactions per execution batch (64 default)
- Scheduler Type: Greedy vs Priority Graph
- Block Production Method: Legacy vs unified scheduler
SchedulerConfig
Fromscheduler_controller.rs:
Key Files
banking_stage.rs:1-200- Main banking stage coordinationconsumer.rs:1-150- Transaction execution orchestrationcommitter.rs- Transaction commitment to PoHtransaction_scheduler/scheduler.rs:1-81- Scheduler interfaceqos_service.rs- Quality of service enforcementdecision_maker.rs- Leader/validator behavior decisionsconsume_worker.rs- Parallel execution workers
Related Components
- PoH Recorder: Receives committed transactions for ledger
- TPU: Transaction Processing Unit providing input packets
- Bank: Executes transactions against account state
- Blockstore: Stores finalized entries and shreds