Skip to main content

Module pool

Module pool 

Source
Expand description

Pool of prepared blocks. Serving pool of prepared blocks for the Ledger Engine.

A reader with one prepared block behind &mut self would serialize concurrent readers of different blocks and re-prepare on every switch. The pool keeps several prepared blocks under a byte budget, prepares different blocks in parallel (at most max_prepares at a time), and concurrent requests for the same block wait for one preparation. Verification before a block is cached: exact framing hashed one ledger at a time against the directory SHA512Half, ledger sequence, transaction roots and the internal parent chain.

JC06 blocks open with their shared section only, and a part compiles when one of its ledgers is first read; the cached size of a block grows with its compiled parts. tx_with_index reads one transaction that way.

That check costs about as much as preparing the block. A seal (Pool::seal) records, for every block that passed it, a digest of the stored block bytes. With a seal set (set_seal), a block whose bytes still match its digest is prepared without repeating the check; any other block is checked in full as before. A JC06 block has a digest of its head (sizes and shared section) and one per part: a read checks the head and the parts it compiles, not the whole block.

A block evicted from the cache and read again is prepared again, and its parts compile again. What the first preparation established is not repeated: the pool remembers, for every seal digest, that the stored bytes matched it once in this process, and for sealed JC06 blocks the hashes of their transactions (at most MEMO_BYTES of them, least recently prepared blocks dropped first). So a head or part is hashed against its digest the first time it is used and trusted after that for as long as the pool is open; a part that does not match is refused every time, since only a match is remembered. The archive file is expected not to change under an open pool: a segment is rewritten through a new file, not in place.

Structsยง

Pool
TxAt
One transaction with the header of its ledger.