Skip to main content

apply_sync_committee

Function apply_sync_committee 

Source
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 untouched.

SyncCommitteeDiff::FullReplacement clears base and replaces it with the serialized committee stored in the delta.

After successful execution, base contains the serialized 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.

§Complexity

The replacement case may allocate when base does not have sufficient capacity for the target committee.

§Example

use eth_state_diff::sync_committee::diff_sync_committee;
use eth_state_diff::sync_committee::apply_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);