Skip to main content

apply_historical_log

Function apply_historical_log 

Source
pub fn apply_historical_log(
    base: &mut Vec<u8>,
    delta: &ArchivedHistoricalLogDiff,
)
Expand description

Applies a historical log delta to a serialized historical log in place.

HistoricalLogDiff::Unchanged leaves the existing log untouched.

HistoricalLogDiff::Append appends the serialized historical items contained in the delta to the existing log.

The delta is assumed to have been generated for the supplied base state. This function does not validate that the base log corresponds to the state from which the delta was created.

§Complexity

§Example

use eth_state_diff::historical_log::{
    apply_historical_log,
    diff_historical_log,
};
use eth_state_diff::types::ArchivedHistoricalLogDiff;

const ITEM_SIZE: usize = 4;

let mut base = vec![1u8, 2, 3, 4];
let target = vec![1u8, 2, 3, 4, 5, 6, 7, 8];

let delta = diff_historical_log(
    8191,
    16384,
    &target,
    ITEM_SIZE,
    None,
);

let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&delta).unwrap();
let archived = unsafe {
    rkyv::access_unchecked::<ArchivedHistoricalLogDiff>(&bytes)
};

apply_historical_log(&mut base, archived);

assert_eq!(base, target);