pub fn diff_slashings(
base_slot: u64,
target_slot: u64,
base_buffer: &[u64],
target_buffer: &[u64],
) -> SlashingsDiffExpand description
Computes a sparse delta between two slashing ring buffers.
The function examines the ring-buffer positions corresponding to epoch
boundaries crossed between base_slot and target_slot.
For a base epoch B and target epoch T, the examined epochs are:
B + 1, B + 2, ..., TFor each examined epoch E, its ring-buffer position is:
index = E % buffer_capacityThe values at that position are then compared between base_buffer and
target_buffer. If they differ, the target value is recorded in the
returned SlashingsDiff.
If the transition spans multiple complete ring cycles, a ring index may be examined multiple times. In that case, the same index may produce multiple updates containing the same target value. This is redundant but remains correct because applying the updates leaves the destination with the target value at that index.
§Arguments
base_slot- Slot belonging to the base state.target_slot- Slot belonging to the target state.base_buffer- Slashing ring buffer belonging to the base state.target_buffer- Slashing ring buffer belonging to the target state.
§Returns
A SlashingsDiff containing updates for ring-buffer positions whose base
and target values differ at one or more epoch boundaries crossed by the
transition.
If base_slot and target_slot belong to the same epoch, the returned
delta contains no updates.
§Panics
Panics if target_slot < base_slot.
Panics if base_buffer or target_buffer is empty.
Panics if base_buffer and target_buffer have different lengths.
§Correctness
The two buffers must have the same capacity and correspond to the same logical slashing ring.
The delta stores ring indices rather than epoch numbers. Consequently, the buffer capacity and logical layout are part of the implicit encoding and must remain unchanged when applying the resulting delta.
§Example
use eth_state_diff::slashings::diff_slashings;
let base_buffer = vec![0u64; 4];
let mut target_buffer = vec![0u64; 4];
// The transition crosses from epoch 0 to epoch 1.
target_buffer[1] = 100;
let delta = diff_slashings(
0,
eth_state_diff::types::SLOTS_PER_EPOCH,
&base_buffer,
&target_buffer,
);
assert_eq!(delta.updates.len(), 1);
assert_eq!(delta.updates[0], (1, 100));§Complexity
If E epoch boundaries are crossed and U updates are recorded:
- Time: O(E)
- Additional space: O(U)