Module vapcore_light::cht[][src]

Canonical hash trie definitions and helper functions.

Each CHT is a trie mapping block numbers to canonical hashes and total difficulty. One is generated for every SIZE blocks, allowing us to discard those blocks in favor of the trie root. When the “ancient” blocks need to be accessed, we simply request an inclusion proof of a specific block number against the trie with the root has. A correct proof implies that the claimed block is identical to the one we discarded.

Structs

BlockInfo

Block information necessary to build a CHT.

CHT

A canonical hash trie. This is generic over any database it can query. See module docs for more details.

Constants

SIZE

The size of each CHT.

Functions

block_to_cht_number

Convert a block number to a CHT number. Returns None for block_num == 0, Some otherwise.

build

Build an in-memory CHT from a closure which provides necessary information about blocks. If the fetcher ever fails to provide the info, the CHT will not be generated.

check_proof

Check a proof for a CHT. Given a set of a trie nodes, a number to query, and a trie root, verify the given trie branch and extract the canonical hash and total difficulty.

compute_root

Compute a CHT root from an iterator of (hash, td) pairs. Fails if shorter than SIZE items. The items are assumed to proceed sequentially from start_number(cht_num). Discards the trie’s nodes.

start_number

Get the starting block of a given CHT. CHT 0 includes block 1…SIZE, CHT 1 includes block SIZE + 1 … 2SIZE More generally: CHT N includes block (1 + NSIZE)…((N+1)*SIZE). This is because the genesis hash is assumed to be known and including it would be redundant.