Expand description
Delta encoding for fixed-capacity Ethereum consensus root buffers.
Ethereum consensus stores historical roots, such as block roots and state roots, in fixed-capacity circular buffers. As new slots are processed, entries are written at positions derived from their slot number, eventually wrapping around and overwriting older entries.
Rather than storing the complete root buffer, this module records only the roots written during a requested slot range. Applying the delta replays those writes into another root buffer using the same slot-to-index mapping.
The delta contains no explicit buffer indices. Each index is reconstructed from the slot number and the buffer capacity:
buffer_index = slot % buffer_capacity§Representation
RootsDiff stores one 32-byte root for every slot in the half-open range
[base_slot, target_slot).
For example, a transition from slot 100 to slot 103 records the roots
for slots:
100, 101, 102The root for target_slot itself is not included.
§Correctness
The destination buffer must have the same capacity as the buffer supplied
to diff_roots. The delta does not store explicit buffer indices, so
changing the capacity changes the modulo mapping and can cause roots to be
written to different positions.
The base_slot supplied to apply_roots must also be the same starting
slot used to generate the delta. Because the delta stores only the sequence
of roots, changing the starting slot changes the positions at which those
roots are written.
The delta represents only the recorded slot writes. Contents at positions not covered by the slot range are preserved when the delta is applied.
§Complexity
If N = target_slot - base_slot:
diff_rootsruns in O(N) time and uses O(N) additional space.apply_rootsruns in O(N) time and uses O(1) additional space.
Functions§
- apply_
roots - Applies a root delta to a circular root buffer in place.
- diff_
roots - Computes the sequence of roots written during a slot range.