Module sc_client_api::cht[][src]

Expand description

Canonical hash trie definitions and helper functions.

Each CHT is a trie mapping block numbers to canonical hash. 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 hash. A correct proof implies that the claimed block is identical to the one we discarded.

Functions

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

Build CHT-based header proof.

Check CHT-based header proof.

Check CHT-based header proof on pre-created proving backend.

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

Convert CHT value into block header hash.

Convert header number into CHT key.

Get the ending block of a given CHT.

Group ordered blocks by CHT number and call functor with blocks of each group.

Returns Some(cht_number) if CHT is need to be built when the block with given number is canonized.

Returns Some(max_cht_number) if CHT has ever been built given maximal canonical block number.

Gets default CHT size.

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.