Expand description
Cold history: ASTJ5 / JC05 segments, canonical profile (codec in the
astj5 crate). For deep, closed history; the hot format (module
history) and the API stay the same.
A segment whose first ledger is F is four files in one directory:
cold-F.astj: an ASTJ5 archive of independent blocks of at most 1024 ledgers or 4 MiB of exact bytes (BLOCK_RAW); each block has a SHA-512Half of its exact bytes;cold-F.asix: only in segments written before 0.3, the codec’s four ASIX2 indexes (transaction and ledger by hash, account history, object history). Nothing reads them: lookups go through the partition indexes (coldindex).ColdSegment::drop_indexremoves them;cold-F.kinds: the kind of every state change (XWCK\0\1);cold-F.seal: optional, digests of every block’s stored bytes taken after the block passed the full check (XWCS\0\1, one per block, orXWCS\0\2, a list per block: a JC06 block has its head and each part), see below;cold-F.json: the manifest with range, profile, change kind mode, and size and SHA-512Half of every file. Written last, via a temporary file and rename: without a manifest there is no segment.
State patches are stored only where the metadata doesn’t give them
(coldpatch). A segment written that way has format astraea-cold/2, so a
server that doesn’t know the format refuses it; astraea-cold/1 segments
hold every patch and stay readable. Each ledger says which it is, so a segment
rewritten while it is being read is read correctly from either archive.
Change kinds. The codec row (Row) does not carry them, and they cannot be
guessed from the metadata. A source with explicit kinds (the node’s gRPC) uses
mode explicit: kinds are stored as a separate stream and count toward the size.
The XRPLA publication does not distinguish them, so it uses mode not_recorded:
such a segment serves transactions, and a request for a ledger with changes
gets an error rather than a guess.
Reading goes through the codec’s pool of prepared blocks (astj5::pool): before
a block enters the cache, its SHA-512Half, the transaction roots and the
header chain are checked. The check costs as much as preparing the block,
so it runs once, when the segment is written (or by write_seal for older
segments), and the seal keeps the result: a block whose stored bytes match
its digest is prepared without repeating it. A block that doesn’t match, or
a segment without a seal, is checked in full on every load. The seal is not
in the manifest; a damaged one only costs speed. A segment’s cache holds up to
BLOCK_BUDGET bytes of blocks, different blocks are prepared in parallel (at
most PREPARES at once), and a block wanted by concurrent requests is
prepared only once. The cache as a whole holds COLD_BUDGET bytes: past
that, and past COLD_OPEN open segments, the least recently read segments
are closed. A request for
many ledgers at once (Cold::ledgers) reads them block by block on up to
COLD_READERS threads.
Structs§
- Block
Limit - Archive block limit: ledgers and exact bytes, and the part size (0 writes JC05 blocks, decoded whole).
- Cold
- Cold segments of a directory, with a budget for open ones.
- Cold
Segment - A published cold segment. Files are opened on the first read.
Enums§
- Kinds
- Where change kinds come from.
Constants§
- BLOCK_
BUDGET - Most of the cold cache one segment may hold, and the number of concurrent prepares per segment. A block takes about 10 ms to prepare, and one account_tx page can need dozens of blocks from a single segment, so a segment prepares as many at once as one request reads in parallel. Below what one page needs, a page evicts its own blocks and reading it again costs as much as the first time.
- BLOCK_
LEDGERS - Default archive block: at most this many ledgers and exact bytes.
The research’s canonical profile uses 16 MiB. 4 MiB costs +18.7% in size
at the 104 million epoch and +26% on recent history, but a cold read takes
24 ms instead of 118.
A ledger larger than the limit gets a block sized to fit it (
write_with). - BLOCK_
RAW - COLD_
BUDGET - Byte budget for the prepared blocks of all open segments (codec estimate). Shared rather than split per segment: a busy account’s page can hold about 400 MB of one segment’s blocks, while most open segments hold one or two.
- COLD_
OPEN - Maximum number of cold segments open at once. One account_tx page over full history touches many segments; with too few open they are closed and reopened on every request. An open segment without cached blocks costs little.
- COLD_
READERS - Threads one
Cold::ledgerscall reads with. - PART_
RAW - Blocks are written as JC06: cut into parts of whole ledgers and at most this many exact bytes, each decoded on its own. Reading one transaction then costs one part instead of the whole block.
- PREPARES
Functions§
- canonical
- The canonical profile, as in the research’s
jointbench encode … canonical, notOptions::default(). - row_of
- Codec row from a ledger: changes as key and data (empty for a deleted object).
- write
- Writes a segment from consecutive ledgers and publishes it with a manifest. Before writing, the archive is unpacked again and compared with the rows, the indexes are checked by re-encoding the decoded form, and the kinds by parsing. Returns the manifest.
- write_
with writewith a different block limit.
Type Aliases§
- Ledger
Patches - A ledger’s header and its state patches: key and object, empty if deleted.