Skip to main content

Module state

Module state 

Source
Expand description

Ledger state over time: a snapshot plus object versions (fjall).

Every object version is a separate record: the key is the object key (32 bytes) and the ledger sequence (4 bytes, big-endian), the value is the object after the change; an empty value means deletion. The object as of ledger N is the last version with a sequence no greater than N: one reverse step over the key’s range.

The starting point is a snapshot of the whole state at one ledger, then the changes of each following ledger, strictly in order and atomically. Headers of applied ledgers are stored here too; they are used to check the state root.

The loader also puts the ledger itself into the same batch, as “pending”, until its block is written to block storage. That gives loading a single recovery point: everything applied to the state is either already in blocks or waiting here.

The same batch carries the indexes (module index): transaction by hash (tx: hash → ledger, position in the ledger), ledger by hash (ledger_hash) and account history (account_tx: account, ledger, TransactionIndex → position). History keys are big-endian, so a range scan follows the order in which transactions were applied, forward or backward.

The same batch also carries the state tree (module statetree): the root after the ledger’s changes is checked against its header’s AccountHash before writing. If it does not match, the ledger is rejected and the state stays at the previous one.

And the tree’s history (levels): ledger → the subtrees at depth 3 that the ledger changed, as (slot u16, hash) pairs, all 4096 of them every 256 ledgers. A path at an earlier ledger takes the top of the tree from there and rebuilds the subtree below from the object versions (state_path_at).

And the NFT index (module nftindex), Clio’s four NFT tables: nft_owner (token, ledger → owner and whether burned), nft_uri (token, ledger → URI), nft_issuer (issuer, taxon, token) and nft_tx (token, ledger, TransactionIndex → position in the ledger). Ledgers from the one the index started at are indexed as they are applied; earlier ones are filled in once, in the background (backfill_nfts).

Structs§

AccountTx
A transaction in an account’s history.
AccountTxPage
A page of account history.
ColdOldState
The version index over cold history and the cold segments it points into.
StateStore
TreePath
Path in the state tree to a key, as of the tree’s ledger.
TxPosition
Transaction position: the ledger and the order within it.

Enums§

Leaf
What the tree holds at a key’s position.

Traits§

OldState
State before the snapshot, from another store: version with the same contract as StateStore::version, for ledgers in range.

Type Aliases§

MptHolder
MPT holder: the account and the key of its MPToken object.
ReadLedgers
Reads the asked ledgers, in order.