Overview
The consensus implementation is located inrs/consensus/ and provides:
- Byzantine fault-tolerant consensus
- Finality in seconds
- Random beacon for unpredictable randomness
- Distributed key generation (DKG)
- Threshold signatures for efficient verification
- Catch-up packages (CUPs) for fast synchronization
The consensus protocol can tolerate up to f Byzantine (malicious) nodes in a subnet of 3f+1 nodes, maintaining safety and liveness.
Consensus Architecture
Source Code Structure
The consensus implementation (rs/consensus/src/) contains:
Consensus Subcomponents
Fromrs/consensus/src/consensus.rs:87, the consensus system consists of nine subcomponents:
Random Beacon Maker
Generates random beacons using threshold signatures:- Produces one beacon per round
- Provides unpredictable, verifiable randomness
- Used for leader election and round progression
- Based on threshold BLS signatures
Random Beacon Properties
Random Beacon Properties
- Unpredictability: No party can predict future values
- Verifiability: Anyone can verify beacon validity
- Availability: Generated every round without coordination
- Uniqueness: Only one valid beacon per height
Random Tape Maker
Generates random tapes for deterministic randomness within a round:- One tape per round
- Used by execution environment for random number generation
- Deterministic across all nodes
- Based on threshold signatures
Block Maker
Proposes new blocks:- Selects block proposer using random beacon
- Constructs block payload via payload builders
- References parent block and random beacon
- Signs and publishes block proposal
- Parent block hash
- Height
- Random beacon reference
- Payload (ingress messages, XNet messages, etc.)
- DKG dealings (when applicable)
Payload Builder
Constructs block payloads from multiple sources:- Ingress: User-submitted messages
- XNet: Cross-subnet messages
- Self-Validating: Bitcoin, HTTPS outcalls
- Query Stats: Query statistics aggregation
- Canister HTTP: Outgoing HTTP requests
rs/consensus/src/consensus/payload_builder.rs
Notary
Notarizes valid blocks:- Validates proposed blocks
- Creates threshold signature shares
- Aggregates shares into notarizations
- Ensures only one block per height is notarized
A block is notarized when it receives threshold signature shares from ≥2f+1 nodes, where 3f+1 is the subnet size.
Share Aggregator
Aggregates threshold signature shares:- Collects shares from multiple nodes
- Combines shares once threshold is reached
- Produces full threshold signatures
- Used for notarizations, finalizations, and random beacons
rs/consensus/src/consensus/share_aggregator.rs
Finalizer
Finalizes notarized blocks:- Selects highest notarized block
- Creates finalization shares
- Aggregates shares into finalizations
- Triggers batch delivery to execution
- Finalized blocks are immutable
- No conflicting blocks can be finalized
- Finalization triggers execution
Validator
Validates consensus artifacts before accepting them:- Checks cryptographic signatures
- Verifies artifact structure and content
- Ensures artifacts follow protocol rules
- Validates membership and permissions
rs/consensus/src/consensus/validator.rs
Purger
Cleans up old artifacts from the consensus pool:- Removes artifacts below certified height
- Maintains bounded pool size
- Preserves artifacts needed for catch-up
- Runs periodically to prevent unbounded growth
rs/consensus/src/consensus/purger.rs
CatchUp Package Maker
Creates catch-up packages for fast synchronization:- Bundles finalized state with signatures
- Enables nodes to skip past rounds
- Created at DKG intervals
- Signed by subnet threshold key
rs/consensus/src/consensus/catchup_package_maker.rs
Height Bounds
To maintain bounded consensus pool size, the protocol enforces height gaps:- Notarization-Certification Gap: Maximum 70 heights between notarized and certified heights
- Notarization-CUP Gap: Maximum 130 heights between notarized height and next CUP
- Unbounded pool growth
- Resource exhaustion attacks
- Excessive validation work
Distributed Key Generation (DKG)
DKG generates threshold keys for subnet consensus:DKG Process
DKG Purposes
- Consensus Signing: Threshold signatures for consensus artifacts
- State Certification: Certifying replicated state
- Key Rotation: Periodic key refresh for security
- Membership Changes: New keys when subnet membership changes
Threshold Cryptography
The consensus protocol heavily relies on threshold signatures:Threshold Signature Properties
Non-Interactive
No coordination needed to create shares
Verifiable
Individual shares can be verified
Efficient
Single signature verifies like individual signature
Threshold
Requires t-of-n shares (typically 2f+1 of 3f+1)
Signature Types
BLS Signatures: Used for random beacon and consensus artifacts- Compact signatures
- Efficient aggregation
- Deterministic
- Compatible with external blockchains
- Secure key derivation
- Non-interactive signing
rs/crypto/
Consensus Pool
The consensus pool stores validated artifacts:- Blocks
- Notarizations
- Finalizations
- Random beacons
- Random tapes
- Catch-up packages
- DKG messages
Batch Delivery
Once a block is finalized, its batch is delivered to execution:- Finalizer detects finalized block
- Batch is extracted from block
- Batch sent to Message Routing
- Message Routing processes batch
- Execution Environment executes messages
rs/consensus/src/consensus/batch_delivery.rs
Parallelism
Consensus uses parallel processing for performance:- Block payload validation
- Artifact signature verification
- DKG dealing verification
- State hash computation
Testing Framework
The consensus crate includes a sophisticated test framework described inrs/consensus/README.adoc:3:
Multi-Node Simulation
Runs consensus without real networking:Configuration Parameters
Set via environment variables:Seed for deterministic randomness (default: 0)
Number of nodes in simulation (default: 10)
Rounds to run (default: random 10-100)
Maximum message latency in ms (default: 1000)
Execution strategy (default: random)
Message delivery strategy (default: random)
Graph degree for RandomGraph delivery (default: random)
Example Test Run
Stress Testing
Run continuous random tests:Performance Characteristics
Finality Time
- Target: 1-2 seconds per round
- Factors: Network latency, payload size, validation time
- Optimization: Parallel validation, efficient crypto
Throughput
- Block rate: ~1 block per second
- Batch size: Configurable, typically thousands of messages
- Scalability: Linear with subnet size up to limits
Resource Usage
- CPU: Primarily crypto operations (signatures, hashing)
- Memory: Bounded by pool size and height gaps
- Disk: Persistent pool grows with chain height
- Network: Broadcasts scale with subnet size
Security Properties
Safety
Safety
No two conflicting blocks can be finalized at the same height, even with f Byzantine nodes.
Liveness
Liveness
Progress continues as long as ≥2f+1 nodes are honest and network is eventually synchronous.
Unpredictability
Unpredictability
Random beacon provides unpredictable randomness that no party can bias.
Verifiability
Verifiability
All consensus artifacts are cryptographically verifiable by any party.
Integration Points
Registry
Consensus reads subnet configuration from registry:- Subnet membership
- DKG intervals
- Block time parameters
- Notarization delay settings
Message Routing
Consensus delivers finalized batches:P2P Layer
Consensus artifacts are distributed via P2P:State Manager
Consensus uses certified state for validation:Best Practices
Further Reading
Replica
Understand replica structure
Execution
Learn about message execution
Networking
Explore artifact distribution
Overview
Return to architecture overview