pub fn apply_sync_committee(
base: &mut Vec<u8>,
delta: &ArchivedSyncCommitteeDiff,
)Expand description
Applies a sync committee delta to a serialized SSZ committee in place.
SyncCommitteeDiff::Unchanged leaves base unchanged.
SyncCommitteeDiff::FullReplacement clears base and replaces it with
the serialized target committee stored in the delta.
After successful execution, base contains the target committee
represented by delta.
§Arguments
base- Serialized SSZ bytes of the base committee. This buffer is modified in place.delta- Archived sync committee delta to apply.
§Correctness
For SyncCommitteeDiff::Unchanged, base is expected to already contain
the target committee because the delta represents no state change.
For SyncCommitteeDiff::FullReplacement, the original contents of
base are irrelevant because the entire buffer is replaced by the target
bytes stored in the delta.
§Complexity
SyncCommitteeDiff::Unchanged: O(1) time and O(1) additional space.SyncCommitteeDiff::FullReplacement: O(n) time, wherenis the replacement size.
The replacement case may allocate if base does not have sufficient
capacity for the target committee.
§Example
use eth_state_diff::sync_committee::{apply_sync_committee, diff_sync_committee};
use eth_state_diff::types::ArchivedSyncCommitteeDiff;
let mut base = b"committee-a".to_vec();
let target = b"committee-b";
let delta = diff_sync_committee(&base, target);
let bytes = rkyv::to_bytes::<rkyv::rancor::Error>(&delta).unwrap();
let archived = unsafe {
rkyv::access_unchecked::<ArchivedSyncCommitteeDiff>(&bytes)
};
apply_sync_committee(&mut base, archived);
assert_eq!(base, target);