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

Ledger Type
Description
Mutability

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:

Check
Purpose

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:

Component
Role

LedgerMaster

Central coordinator

InboundLedgers

Network acquisition

InboundLedger

Single ledger assembly

LedgerHistory

Cache management

LedgerCleaner

Integrity maintenance

Acquisition Flow:

  1. Detection: doAdvance() finds missing ledgers

  2. Request: InboundLedgers::acquire() starts acquisition

  3. Gathering: InboundLedger collects data from peers

  4. Assembly: SHAMaps built from received nodes

  5. Validation: checkAccept() verifies sufficient validations

  6. Storage: Persist to database and cache

  7. 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