pub fn diff_historical_log(
base_slot: u64,
target_slot: u64,
target_ssz: &[u8],
item_ssz_size: usize,
activation_slot: Option<u64>,
) -> HistoricalLogDiffExpand description
Computes a delta between two historical log states.
The number of appended items is derived from base_slot and target_slot
using the protocol-defined historical period rather than by comparing the
serialized base and target logs.
Only the newly appended portion of target_ssz is stored in the returned
HistoricalLogDiff.
§Arguments
base_slot- Slot corresponding to the base state.target_slot- Slot corresponding to the target state.target_ssz- Complete serialized SSZ representation of the target historical log.item_ssz_size- Serialized SSZ size of one historical log item.activation_slot- Optional slot at which the historical log becomes active. This is used for logs introduced by a later fork.
§Returns
HistoricalLogDiff::Unchangedif the protocol-derived log length has not increased between the two slots.HistoricalLogDiff::Appendcontaining the newly appended serialized items otherwise.
§Panics
This function does not intentionally panic in release builds. In debug
builds, it asserts that target_ssz contains enough bytes for the number
of items derived from the slot calculation.
The caller must provide a non-zero item_ssz_size and a target SSZ buffer
consistent with the protocol-derived log length.
§Complexity
O(k) time and O(k) additional space, where k is the number of newly appended serialized bytes. The number of existing log entries does not affect the computation.
§Example
use eth_state_diff::historical_log::diff_historical_log;
use eth_state_diff::types::HistoricalLogDiff;
const ITEM_SIZE: usize = 32;
// One historical period has elapsed, so one item is appended.
let target = vec![0u8; ITEM_SIZE];
let delta = diff_historical_log(
0,
8192,
&target,
ITEM_SIZE,
None,
);
assert_eq!(
delta,
HistoricalLogDiff::Append(target),
);