Skip to main content

diff_eth1_votes

Function diff_eth1_votes 

Source
pub fn diff_eth1_votes(base: &[u8], target: &[u8]) -> Eth1DataVotesDiff
Expand description

Computes a delta between two serialized Eth1 data vote lists.

If the target preserves the complete serialized base list, only the bytes appended to the base are stored in Eth1DataVotesDiff::Append. Otherwise, the complete target list is stored in Eth1DataVotesDiff::ResetAndAppend.

This covers both accumulation of votes during an Eth1 voting period and replacement of the vote list when the voting period changes.

This function operates directly on serialized SSZ bytes and does not deserialize individual votes.

§Arguments

  • base - Serialized SSZ representation of the current vote list.
  • target - Serialized SSZ representation of the target vote list.

§Returns

A delta representing the transition from base to target.

§Complexity

O(n), where n is the length of base, for the prefix comparison. Additional space is proportional to the selected delta payload.

§Example

use eth_state_diff::eth1_data_votes::diff_eth1_votes;
use eth_state_diff::types::Eth1DataVotesDiff;

let base = b"AAAA";
let target = b"AAAABBBB";

let delta = diff_eth1_votes(base, target);

assert_eq!(delta, Eth1DataVotesDiff::Append(b"BBBB".to_vec()));