mod.rs

Overview

This file implements the management and aggregation of attestations related to blockchain blocks within the system. It provides data structures and methods to collect, store, fold (aggregate), and manage attestations that represent validators' signatures on block data. The attestations are organized in a compacted form keyed by block sequence number, block identifier, and attestation type.

The file's core functionality revolves around:

This functionality supports consensus and validation processes by ensuring that sufficient valid attestations are gathered and combined to form proofs of block finalization or approval.

Data Structures and Types

CollectedAttestations

A struct that holds collections of attestations in two main forms:

Other fields include:

Key Methods

Debug Trait

Implements a custom Debug trait that displays the cutoff value.

Guarded Mutability

Implements the AllowGuardedMut trait to allow controlled mutable access in guarded contexts.


AggregateFilter

A builder-based struct defining criteria for aggregation of attestations:

It supports construction from an AttestationTargetCheckpoint to map checkpoint requirements to aggregation filters.


AggregateActionOnConditionMissed

An enum defining actions when aggregation conditions fail. Currently, it only supports the Skip action, which ignores failed aggregations.


Key Types and Aliases


Detailed Function and Method Descriptions

CollectedAttestations::notifications

pub fn notifications(&self) -> &Arc<(parking_lot::Mutex<u32>, parking_lot::Condvar)>

Returns a reference to the notification synchronization primitive that can be used to wait for updates to the attestation collections.


CollectedAttestations::touch

pub fn touch(&self)

Increments the internal notification counter and notifies all waiting threads. This method is called whenever the attestation collections are modified.


CollectedAttestations::add

pub fn add(
    &mut self,
    attestation: Envelope<GoshBLS, AttestationData>,
    enable_cutoff: bool,
) -> anyhow::Result<bool>

Adds a single attestation to the unverified set if it is newer than the cutoff (when cutoff is enabled).

let mut collected = CollectedAttestations::default();
let result = collected.add(attestation_envelope, true)?;
if result {
    println!("New attestation added");
}

CollectedAttestations::add_bunch

pub fn add_bunch(
    &mut self,
    attestations: Vec<Envelope<GoshBLS, AttestationData>>,
    enable_cutoff: bool,
) -> anyhow::Result<bool>

Adds multiple attestations at once, applying cutoff filtering if enabled.

let mut collected = CollectedAttestations::default();
let added = collected.add_bunch(attestation_vec, false)?;
if added {
    println!("Some attestations added");
}

CollectedAttestations::move_cutoff

pub fn move_cutoff(&mut self, block_seq_no: BlockSeqNo, _block_id: BlockIdentifier)

Moves the cutoff to a new block sequence number and prunes all attestations with sequence numbers less or equal to the cutoff, both in unverified and folded collections.


CollectedAttestations::aggregate

pub fn aggregate(
    &mut self,
    required: &[(BlockState, AggregateFilter)],
) -> anyhow::Result<Vec<Envelope<GoshBLS, AttestationData>>>

Aggregates attestations for a set of required block states and corresponding aggregation filters.

let aggregated = collected_attestations.aggregate(&[(block_state, aggregate_filter)])?;
for attestation in aggregated {
    println!("Aggregated attestation: {:?}", attestation);
}

Implementation Details and Algorithms


Interactions with Other System Components

This module serves as a core part of the attestation management subsystem and interacts closely with block state management, cryptographic verification, and network layers.


Visual Diagram

classDiagram
class CollectedAttestations {
-compacted_unverified_attestations: CompactedMap<HashSet<CompactedAttestation>>
-folded_attestations: CompactedMap<Envelope>
-cutoff: BlockSeqNo
-notifications: Arc<(Mutex<u32>, Condvar)>
+notifications()
+touch()
+add()
+add_bunch()
+move_cutoff()
+aggregate()
}
class AggregateFilter {
-attestation_type: AttestationTargetType
-min_signatures_inclusive: usize
-action_on_condition_missed: AggregateActionOnConditionMissed
+from(AttestationTargetCheckpoint)
}
class AggregateActionOnConditionMissed {
<<enumeration>>
+Skip
}
CollectedAttestations ..> AggregateFilter : uses
CollectedAttestations ..> AggregateActionOnConditionMissed : uses
CollectedAttestations --> Envelope : stores
CollectedAttestations --> CompactedAttestation : stores
AggregateFilter --> AttestationTargetCheckpoint : from

This diagram shows the primary data structures and their relationships within the file, highlighting key methods and composition.