1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Delta encoding for fixed-size Ethereum consensus root buffers.
//!
//! Ethereum consensus stores historical roots (such as block roots and state
//! roots) in fixed-capacity circular buffers. Advancing the chain overwrites
//! the oldest entries once the buffer wraps.
//!
//! Rather than diffing the entire buffer, this module records only the sequence
//! of newly written roots between two slots. Applying the delta replays those
//! writes into another buffer using the same circular indexing logic.
//!
//! This representation is independent of the buffer capacity and works with
//! any fixed-size root ring.
use crate;
/// Computes the sequence of newly written roots between two slots.
///
/// The returned delta contains every root written during the half-open slot
/// range `[base_slot, target_slot)`.
///
/// The input `buffer` is treated as a circular buffer, with its length defining
/// the modulo capacity.
///
/// # Arguments
///
/// * `base_slot` - First slot represented by the delta.
/// * `target_slot` - Slot immediately following the final recorded root.
/// * `buffer` - Circular root buffer.
///
/// # Complexity
///
/// O(target_slot - base_slot)
/// Applies a root delta to a circular root buffer.
///
/// Each stored root is written back into the destination buffer using the same
/// slot-to-index mapping employed during diff generation.
///
/// After application, the destination buffer contains the same root values for
/// every slot represented by the delta.
///
/// # Complexity
///
/// O(number of recorded roots)