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 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

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).expect("failed to serialize");
let archived = rkyv::access::<ArchivedSyncCommitteeDiff, rkyv::rancor::Error>(&bytes)
    .expect("failed to access");

apply_sync_committee(&mut base, archived);

assert_eq!(base, target);