Expand description
Ledger history, format 2: transactions and state changes in separate streams.
The layout was chosen by measuring the alternatives:
- transactions: one frame per ledger (header and transactions with metadata), zstd with a dictionary, so a single transaction or an account_tx page is read without decompressing neighbouring ledgers (page p99 ~20 ms versus 383 ms with a shared block, a single tx 0.2 ms versus 5.8);
- state changes: blocks of
changes_groupledgers, zstd-19, since they are read only when rebuilding and verifying state.
Dictionaries are immutable files dicts/<hash>.zdict, named by the
SHA-512Half of their content. A transaction segment names its dictionary by
hash in its header, and the reader checks the file’s hash. Changing the dictionary
means a new file and new segments; old segments are read with their own dictionary.
Tampering with dictionary bytes is detected.
Files of a segment starting at ledger F:
txl-F.xwlt:XWLT\0\1, dictionary hash (32 bytes, zeros for no dictionary), then frames back to back; a frame is zstd of (118-byte header, u32 n, n pairs (u32 length, transaction, u32 length, metadata));txl-F.xwlt.idx:XWTI\0\1, per frameu32 ledger | u64 offset | u32 length;chg-F.xwlc:XWLC\0\1, then blocks; a block is zstd of (u32 n, n pairs (u32 ledger, u32 length), each ledger’s changes inLedgerformat);chg-F.xwlc.idx:XWCI\0\1, per blocku32 first | u32 n | u64 offset | u32 length.
ASTJ5 cold segments (module cold, files cold-*.{astj,asix,kinds,json})
in the same directory are read when a ledger is not in the hot segments; with
with_cold_first, before the hot ones (for checking the cold history).
Writing a group: transaction frames first, fsync, index, fsync; then the changes block the same way. A ledger is in the history only if both streams are written: a transaction tail without changes left by a crash is not read and gets rewritten in the next segment.
Structs§
- Dict
- An immutable zstd dictionary.
- History
Reader - History reader. New segments and groups become visible after
refresh;getcalls it itself when the ledger is past the known end. - History
Writer - Writes history in groups of
changes_groupledgers.
Functions§
- tx_
frame - Transaction frame: header, transaction count, pairs.
Type Aliases§
- PrevAt
- Previous version of an object as of a ledger:
(key, ledger) → object.