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
//! Delta encoding for Ethereum RANDAO mix buffers.
//!
//! Ethereum consensus stores historical RANDAO mixes in a fixed-capacity
//! circular buffer indexed by epoch.
//!
//! Rather than storing the entire buffer, this module records only the sequence
//! of mixes written while advancing from one epoch to another. Applying the
//! delta replays those writes into another buffer using the same circular
//! indexing logic.
//!
//! The encoding is independent of the buffer capacity and relies only on the
//! starting slot and the destination buffer.
use crate;
/// Computes the sequence of RANDAO mixes written between two slots.
///
/// The returned delta contains one mix for every epoch in the inclusive range
/// from the epoch containing `base_slot` through the epoch containing
/// `target_slot`.
///
/// The target buffer is treated as a circular buffer, with its length defining
/// the modulo capacity.
///
/// # Arguments
///
/// * `base_slot` - Starting slot.
/// * `target_slot` - Ending slot.
/// * `target_buffer` - Circular RANDAO mix buffer.
/// * `slots_per_epoch` - Number of slots in a consensus epoch.
///
/// # Complexity
///
/// O(number of epochs)
///
/// # Panics
///
/// Panics if `target_slot < base_slot`.
/// Applies a RANDAO delta to a circular mix buffer.
///
/// Each recorded mix is written back into the destination buffer beginning at
/// the epoch containing `base_slot`.
///
/// After successful application, the destination buffer contains the same
/// RANDAO mixes as the original target buffer for every epoch represented by
/// the delta.
///
/// # Complexity
///
/// O(number of encoded epochs)