pub fn diff_attestations(base_ssz: &[u8], target_ssz: &[u8]) -> AttestationsDiffExpand description
Computes a compact delta between two serialized SSZ attestation lists.
The function automatically selects between the supported delta representations:
- If the lists are identical,
AttestationsDiff::Unchangedis returned. - If the target list starts with the exact byte sequence of the base list,
only the trailing bytes are stored in
AttestationsDiff::Append. - Otherwise, the complete target list is stored in
AttestationsDiff::FullReplacement.
This covers both append-only updates, such as growth of
current_epoch_attestations, and epoch-boundary replacement of
previous_epoch_attestations.
An empty base list is naturally represented as an append of the complete target list.
§Arguments
base_ssz- Serialized SSZ representation of the base attestation list.target_ssz- Serialized SSZ representation of the target attestation list.
§Returns
A compact AttestationsDiff representing the transition from base_ssz
to target_ssz.
§Complexity
The prefix comparison takes O(min(n, m)) time, where n and m are the
lengths of base_ssz and target_ssz, respectively. Additional space is
proportional to the selected delta payload.
§Example
let base = b"AAAA";
// Append case.
let target = b"AAAABBBB";
assert_eq!(
diff_attestations(base, target),
AttestationsDiff::Append(b"BBBB".to_vec())
);
// Replacement case.
let target = b"CCCC";
assert_eq!(
diff_attestations(base, target),
AttestationsDiff::FullReplacement(b"CCCC".to_vec())
);