Expand description
State tree (SHAMap) with the root recomputed on every ledger.
The XRPL tree rule: zero keys under a prefix is empty, one key is the hash
of its leaf SHA-512Half(MLN\0, object, key), two or more is an inner node
SHA-512Half(MIN\0, 16 children). The root is always an inner node. There is
no path compression: a chain of nodes with a single inner child is stored in full.
Two fjall keyspaces:
live: live state keys and their leaf hashes;tree: inner nodes by prefix, a bitmask of non-empty children (u16, big-endian) and their hashes. Of the 7.4 million nodes in the mainnet tree, most sit at depth 6 with two or three children, so 16 hashes in a row would take four times as much space. A 512-byte node without a mask is the older dense format and is still readable.
On each ledger the changes are overlaid on live in memory, only the nodes on
the paths of changed keys are recomputed, and the root is checked against the
header’s AccountHash before writing. If it does not match, the ledger is
rejected. New leaf hashes and nodes go into the same batch as the state changes.
Only the latest version of the tree is stored. For proofs against earlier
ledgers each update also reports the subtrees at depth LEVEL_DEPTH it
changed (4096 of them, about 1700 keys each on mainnet): with those hashes
kept per ledger, the top of the tree at any ledger is a few thousand
hashes, and the subtree below is rebuilt from the object versions.
Structs§
Constants§
- LEVEL_
DEPTH - Depth of the subtrees whose hashes are kept per ledger.
- LEVEL_
SLOTS - How many subtrees there are at that depth.
Functions§
- inner_
hash - leaf_
changes - Leaf hashes from state changes.
- level_
range - The key range of a subtree at
LEVEL_DEPTH. - level_
slot - The subtree at
LEVEL_DEPTHa key belongs to: its first three nibbles. - state_
leaf_ hash_ of - Leaf hash of an object version;
Nonefor a deletion (an empty version).
Type Aliases§
- Leaf
Changes - Leaf changes for a ledger: key → new leaf hash,
Noneif deleted.