Skip to main content

Module participation

Module participation 

Source
Expand description

Compact delta encoding for Ethereum epoch participation flags.

This module computes and applies deltas between validator participation vectors.

Participation changes are typically sparse: during an epoch transition, most validators retain their existing participation flags while only a subset of validators receive new values. The delta therefore stores only modified indices and their replacement values rather than the complete target vector.

§Encoding

The delta has two representations:

For the sparse representation, modified indices are encoded as delta-varint gaps between successive modified indices. The corresponding replacement values are stored separately in new_values. This avoids storing unchanged participation flags and makes sequences of nearby changes particularly compact.

Validators present in the target vector but not in the base vector are stored separately in extension and appended during application.

§APIs

The module provides both slice-based and iterator-based APIs.

diff_participation and apply_participation operate on contiguous vectors and provide the specialized ParticipationDiff::AllZeros fast path.

diff_participation_iter and apply_participation_iter operate through iterators and crate::ListMutTarget, allowing consensus clients with tree-backed or otherwise non-contiguous state representations to compute and apply participation deltas without first materializing the complete vector.

The iterator-based diff API always produces the sparse representation. The slice-based API can additionally detect an all-zero target and use the more compact ParticipationDiff::AllZeros representation.

§Reconstruction

Applying a sparse delta updates only the modified indices of the existing collection and then appends any values in extension.

Applying an ParticipationDiff::AllZeros delta replaces the destination with a vector of the specified length containing only zero values.

§Complexity

Diff generation is O(n) time and O(m) additional space, where n is the number of participation flags examined and m is the number of modified entries.

Sparse delta application is O(m + e) time, where m is the number of modified entries and e is the number of appended participation flags.

The contiguous all-zero fast path performs O(n) work to initialize the resulting vector.

§Serialization

ParticipationDiff is designed to be serialized with rkyv and can be subsequently compressed with a general-purpose compressor such as zstd.

Functions§

apply_participation
Applies a participation delta to a contiguous vector in place.
apply_participation_iter
Applies a participation delta to a mutable collection in place.
diff_participation
Computes a compact delta between two participation flag slices.
diff_participation_iter
Computes a compact sparse delta between two participation flag iterators.