Skip to main content

batch_checkpoints

Function batch_checkpoints 

Source
pub fn batch_checkpoints<SH, OH>(
    from_state: &ChainState,
    last_scanned_height: BlockHeight,
    chain_tip: Option<BlockHeight>,
    anchor_retention: Option<&AnchorRetention>,
    sapling_commitments: &[Option<(SH, Retention<BlockHeight>)>],
    orchard_commitments: &[Option<(OH, Retention<BlockHeight>)>],
    ironwood_commitments: &[Option<(OH, Retention<BlockHeight>)>],
) -> BatchCheckpoints
Expand description

Computes the checkpoints that the batch of scanned blocks above from_state through last_scanned_height must add to each note commitment tree beyond those its own commitments create. Each *_commitments slice is a pool’s commitment stream for the batch as put_blocks_rows returns it, with the scanner’s Checkpoint retention still on every block end: the stream is read before any demotion, so that a checkpoint ensured below the window (a retained anchor) still lands on the right tree state.

Every tree gains a checkpoint at every height that is checkpointed in any of the other trees, so that anchors align across trees. Every scanned height inside the checkpoint window (checkpoint_floor) is checkpointed in every tree, whether or not a block there carries a commitment, so that an anchor exists at the confirmations-policy depth. The heights the anchor-retention policy retains within the batch are checkpointed likewise: a grid boundary landing on a block with no shielded outputs in ANY pool would otherwise never be checkpointed at all, and a retention policy can only keep alive a checkpoint that exists. An ensured checkpoint carries the tree state as of the last commitment at or before its height, which is exactly the state an anchor at that height commits to. A height whose block end keeps its own checkpoint (keeps_checkpoint) is left to that block end.

This is the checkpoint planning of put_blocks, exposed so that a store that maintains its note commitment trees by other means (accumulating updates in memory and flushing them in bulk, or building shards out of band) applies the same rule rather than rediscovering it. Such a caller assigns the block-end retentions of the commitments it builds with assign_block_end_retention, then hands the entries that remain to update_tree.