Overview
The Ledger library provides persistent storage for the Proof of History ledger, including blocks, transactions, and shreds. It supports parallel verification, iterative append, and random access to the blockchain data.Blockstore
TheBlockstore struct is the main interface for ledger storage and retrieval.
Architecture
- Built on RocksDB for persistent key-value storage
- Stores data in multiple column families for different data types
- Supports shred-based block construction
- Provides transaction history and signature lookups
- Handles block metadata, rewards, and performance samples
Structure
Opening and Configuration
Open an existing blockstore or create a new one at the given path.Parameters:
ledger_path: Path to the ledger directory
Result<Blockstore>: The opened blockstore, or error
Open a blockstore with custom options.Parameters:
ledger_path: Path to the ledger directoryoptions: Configuration options
Result<Blockstore>: The opened blockstore, or error
Delete a blockstore and all its data.Parameters:
ledger_path: Path to the ledger directory to delete
Result<()>: Ok on success, error on failure
Shred Operations
insert_shreds
fn(&self, shreds: Vec<Shred>, leader_schedule: Option<&LeaderScheduleCache>, is_trusted: bool) -> Result<InsertResults>
Insert shreds into the blockstore.Parameters:
shreds: Vector of shreds to insertleader_schedule: Optional leader schedule for validationis_trusted: Whether shreds come from a trusted source
Result<InsertResults>: Information about completed data sets and duplicates
Get a data shred by slot and index.Parameters:
slot: The slot numberindex: The shred index within the slot
Result<Option<Vec<u8>>>: The shred data if found
Get a coding (erasure) shred by slot and index.Parameters:
slot: The slot numberindex: The shred index
Result<Option<Vec<u8>>>: The shred data if found
Block and Slot Operations
Get all entries for a slot.Parameters:
slot: The slot numbershred_start_index: Starting shred index (usually 0)
Result<Vec<Entry>>: Vector of entries
get_confirmed_block
fn(&self, slot: Slot, require_previous_blockhash: bool) -> Result<VersionedConfirmedBlock>
Get a confirmed block by slot.Parameters:
slot: The slot numberrequire_previous_blockhash: Whether to require previous blockhash
Result<VersionedConfirmedBlock>: The confirmed block with transactions and metadata
Check if a slot is full (all shreds received).Parameters:
slot: The slot number
bool: True if the slot is complete
Get metadata for a slot.Parameters:
slot: The slot number
Result<Option<SlotMeta>>: Slot metadata if found
Transaction Operations
Get transaction status by signature.Parameters:
signature: The transaction signature
Result<Option<TransactionStatusMeta>>: Transaction metadata if found
get_confirmed_transaction
fn(&self, signature: &Signature) -> Result<Option<ConfirmedTransactionWithStatusMeta>>
Get a confirmed transaction by signature.Parameters:
signature: The transaction signature
Result<Option<ConfirmedTransactionWithStatusMeta>>: Full transaction details
get_confirmed_signatures_for_address
fn(&self, address: &Pubkey, start_slot: Slot, end_slot: Slot) -> Result<Vec<Signature>>
Get all transaction signatures for an address in a slot range.Parameters:
address: The address to search forstart_slot: Starting slot (inclusive)end_slot: Ending slot (inclusive)
Result<Vec<Signature>>: Vector of signatures
Root and Finalization
Mark slots as roots (finalized).Parameters:
slots: Slice of slot numbers to mark as roots
Result<()>: Ok on success
Check if a slot is a root.Parameters:
slot: The slot number
bool: True if the slot is a root
Get the last root slot.Returns:
Slot: The most recent root slot number
Cleanup and Maintenance
Purge a range of slots from the blockstore.Parameters:
start_slot: Starting slot (inclusive)end_slot: Ending slot (inclusive)purge_type: Type of purge (e.g., CompactionFilter, Exact)
Result<bool>: True if any slots were purged
Clean up slots older than the threshold.Parameters:
slot_cleanup_threshold: Slots below this are eligible for cleanup
Result<()>: Ok on success
SlotMeta
Metadata about a slot’s completeness and ancestry.CompletedDataSetInfo
Information about a completed set of data shreds.Shred Types
Shred
Represents a piece of block data for transmission and storage. Variants:ShredData: Contains entry dataShredCode: Contains erasure coding data for recovery
slot(): Get the slot numberindex(): Get the shred indexsignature(): Get the shred signatureverify(): Verify the shred signature
Example Usage
Constants
MAX_COMPLETED_SLOTS_IN_CHANNEL: 100,000BLOCKSTORE_DIRECTORY_ROCKS_LEVEL: “rocksdb”
See Also
- Runtime API - Transaction processing
- Architecture Overview - System architecture
- Validator Configuration - Ledger configuration