Ledger Acquisition and Validation
← Back to Consensus I: Node, Consensus, and Ledger Fundamentals
Introduction
Nodes in the XRP Ledger network must maintain a consistent view of the ledger chain. This requires mechanisms to acquire missing ledgers from peers, validate their correctness, and integrate them into the local chain. This chapter covers the LedgerMaster orchestration layer, the InboundLedgers acquisition system, and the validation process.
LedgerMaster Overview
The LedgerMaster is the central coordinator for ledger state management:
┌─────────────────────────────────────────────────────────────┐
│ LEDGER MASTER │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Core State │ │
│ │ │ │
│ │ mPubLedger - Last published ledger │ │
│ │ mValidLedger - Last validated ledger │ │
│ │ mLedgerHistory - Historical ledger cache │ │
│ │ mClosedLedger - Last closed ledger │ │
│ │ mCurrentLedger - Working ledger (mutable) │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Key Functions │ │
│ │ │ │
│ │ doAdvance() - Advance ledger state │ │
│ │ fetchForHistory() - Acquire missing ledgers │ │
│ │ checkAccept() - Validate new ledger │ │
│ │ tryAdvance() - Continue state machine │ │
│ │ storeLedger() - Persist ledger │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘Ledger Types in LedgerMaster
Current
Open ledger accepting transactions
Mutable
Closed
Just closed, awaiting validation
Immutable
Validated
Network consensus achieved
Immutable
Published
Streamed to subscribers
Immutable
Gap Detection and Filling
When the node detects missing ledgers, it initiates acquisition:
InboundLedgers System
The InboundLedgers class manages ledger acquisition from peers:
Acquisition Architecture:
Acquisition Process
Step-by-Step Flow:
Validation Process
Validation Quorum:
checkAccept Flow:
Validation Checks:
Sequence check
Ensure forward progress
Trusted count
Verify UNL agreement
Minimum threshold
Require sufficient validations
Negative UNL
Exclude untrusted validators
tryAdvance State Machine
Ledger Storage
When a ledger is complete and validated:
Publication Stream
Validated ledgers are published to clients:
Error Handling and Recovery
Acquisition Failures:
Validation Mismatches:
Ledger Cleaning
The LedgerCleaner component maintains ledger integrity:
Summary
Key Components:
LedgerMaster
Central coordinator
InboundLedgers
Network acquisition
InboundLedger
Single ledger assembly
LedgerHistory
Cache management
LedgerCleaner
Integrity maintenance
Acquisition Flow:
Detection: doAdvance() finds missing ledgers
Request: InboundLedgers::acquire() starts acquisition
Gathering: InboundLedger collects data from peers
Assembly: SHAMaps built from received nodes
Validation: checkAccept() verifies sufficient validations
Storage: Persist to database and cache
Publication: Stream to subscribers
Key Properties:
Backwards filling for chain validation
Quorum-based acceptance
Automatic retry on failure
Continuous integrity checking
Efficient caching and storage
In the next chapter, we'll explore how transactions flow through the system via RPC and peer connections.
Last updated

