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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Delta encoding for Ethereum slashing vectors.
//!
//! Ethereum consensus stores slashing totals in a fixed-capacity circular
//! buffer indexed by epoch.
//!
//! Unlike root and RANDAO buffers, slashing values change infrequently. This
//! module therefore records only epochs whose values differ between two states,
//! producing a sparse delta representation.
//!
//! Applying a delta updates only the modified epochs while leaving all other
//! entries unchanged.
use crate;
/// Computes a sparse delta between two slashing buffers.
///
/// The encoder compares the epochs traversed while advancing from
/// `base_slot` to `target_slot` and records only entries whose values have
/// changed.
///
/// The returned delta contains pairs of `(ring_index, value)` representing the
/// updated slashing totals.
///
/// # Arguments
///
/// * `base_slot` - Starting slot.
/// * `target_slot` - Ending slot.
/// * `base_buffer` - Base slashing ring buffer.
/// * `target_buffer` - Target slashing ring buffer.
/// * `slots_per_epoch` - Number of slots in a consensus epoch.
///
/// # Complexity
///
/// O(number of traversed epochs)
///
/// # Panics
///
/// Panics if `target_slot < base_slot`.
/// Applies a slashing delta to a circular slashing buffer.
///
/// Each recorded update replaces the value at its corresponding ring-buffer
/// index. Entries not present in the delta remain unchanged.
///
/// After successful application, the destination buffer contains the same
/// slashing values as the target buffer used to produce `delta`.
///
/// # Complexity
///
/// O(number of recorded updates)