↑ ↓ navigate↵ open

Storage and recovery

Data directory layout, record formats, write order, startup replay, snapshots, index and verify.

On this page · 8
  1. 01Data directory
  2. 02Write order
  3. 03blocks.log
  4. 04Snapshots
  5. 05Startup
  6. 06Chain index (index.redb)
  7. 07genesis.txt
  8. 08verify

Data directory

data/

genesis.txt
chain id, genesis time, slot length, fee floor and target, validators, allocations
validator.key
the validator's key, a hex seed readable only by its owner; back it up
consensus.state
the core's state, replaced atomically before any of its actions run
pending/
a proposed block, written before it is proposed
blocks.log
finalized blocks, append-only, each record with a SHA3-256 checksum
snapshot
all accounts after a finalized block, and where that block sits in the log
snapshot.prev
the snapshot before it; startup begins from the older of the two
index.redb
blocks, transactions and account history for the API; rebuilt from the log if needed

blocks.log is opened for append and locked with try_lock; a second node on the same directory exits with “in use by another leansvm-node”.

Write order

StepWriteBefore
Consensus stepconsensus.state (atomic)executing any returned action
Proposalpending/<block hash> (atomic)proposing the block
Finalizationappend to blocks.log + sync_allapplying the block
After applyindex.redb (durability Immediate)—
Every snapshot_every slotssnapshot (atomic), old one → snapshot.prev—
write_atomic
write <name>.tmp → fsync → rename to <name> → fsync directory

blocks.log

record
len u32 LE ‖ block encoding (len bytes) ‖ SHA3-256(block encoding)

block encoding = slot u64 ‖ proposer u64 ‖ parent (32) ‖ tx_count u32 ‖ (tx_len u32 ‖ tx)*
Max record
8 MiB (larger length = damage)
Checksum
SHA3-256, 32 B, after the body
Empty block
≈ 88 B on disk
Reader
streaming, never cuts the file
On openConditionAction
Torn tailshort length/checksum or record past EOF, and consensus.state one block ahead, and pending/ holds that blockdrop the partial append, re-append from pending/
Torn tailany other caserefuse to start; file untouched
Checksum mismatchnot the last recordrefuse: “damaged at byte N … restore it from a backup”

Snapshots

snapshot v2 (LE)
"leansvm/snapshot" (16) ‖ version u32 = 2 ‖ genesis_hash (32)
‖ height u64 ‖ head_slot u64 ‖ head_hash (32)
‖ record_start u64 ‖ record_end u64          // the head block's record in blocks.log
‖ base_fee u64 ‖ burned u128 ‖ account_count u64
‖ (address (32) ‖ balance u64 ‖ nonce u64 ‖ key_flag u8 ‖ [public_key 1312])*   // address order
‖ SHA3-256(everything above)
Interval
--snapshot-every, default 3,600 slots
Generations
snapshot, snapshot.prev
Startup picks
older usable one whose record matches the log
Status retention
rejected / dropped kept one interval
Written on
main thread (holds every account)
Rejected if
bad checksum, other chain, version ≠ 2, duplicates, trailing bytes

Startup

  1. Lock blocks.log, open index.redb, load genesis.txt and validator.key (the key must match the genesis validator).
  2. Load the older usable snapshot whose height is not above the index height; if there is none, start from genesis.
  3. Replay the later blocks through applyTx and nextBaseFee (≈ 20,000 tx/s), indexing blocks the index lacks in batches of 1,000.
  4. If consensus.state shows a finalized block the log lacks, take it from pending/, drop a partial trailing record, then append and apply it. Any other unreadable record stops startup.
  5. Clear pending/. An index that does not match the log is rebuilt from genesis (INDEX_MISMATCH).

Chain index (index.redb)

TableKeyValue
blocksheight u64height, slot, hash, parent, proposer, txs, tx_bytes, base_fee, fees u128
block_hasheshash (32)height u64
txstx id (32)id, height, slot, index, sender, recipient, amount, nonce, max_fee, priority_fee, fee, size
block_txsheight u64 BE ‖ index u32 BEtx id
account_txsaddress (32) ‖ height u64 BE ‖ index u32 BEtx id (inserted for sender and recipient)

redb 5: copy-on-write B-trees, checksums, readers that do not block the writer. Derived data only; only applied transactions are indexed.

genesis.txt

genesis.txt
# Lean SVM genesis
chain_id=1
slot_ms=1000
genesis_time_ms=1764633600000
fee_floor=1
block_target_bytes=500000
validator=<1,312-byte public key, hex>
alloc=<address hex>:<units>
alloc=<address hex>:<units>
  • key=value, no spaces around =; # lines and blank lines ignored; unknown keys rejected.
  • alloc amounts are units, without duplicates, and must sum to exactly 10^15.
  • genesis_time_ms is when slot 1 starts; init sets it to the current time.
  • Genesis hash = SHA3-256("leansvm/genesis/v1" ‖ parameters ‖ validator key ‖ allocations).

verify

shell
leansvm-node verify data      # node stopped

Replays blocks.log from genesis through the core and compares the result with both snapshots, the chain index and consensus.state.