pulse_attestations.rs

Overview

This file defines the PulseAttestations struct and its associated methods, which manage the process of monitoring and requesting missing attestations (blocks) in a distributed blockchain-like network. The main responsibilities include triggering requests for missing blocks based on time or queue length, managing block gap adjustments, and coordinating requests for missing block ranges from interested network peers.

The module interacts closely with block states, attestation targets, and network messaging components to ensure timely synchronization of block data among nodes. It uses atomic operations and timing mechanisms to manage request intervals and gap expansions, providing efficiency and reliability in block attestation collection.


PulseAttestations Struct

Purpose

PulseAttestations is designed to track the state of block finalization and trigger network requests for missing attestations dynamically. It encapsulates logic for deciding when to request missing blocks, how to manage request frequency, and how to adjust parameters like the block gap for retries.

Fields


Methods

pulse(&mut self, last_finalized_block: &BlockState) -> anyhow::Result<()>

Updates the internal state in response to a newly finalized block.

Parameters

Returns

Example Usage

pulse_attestations.pulse(&latest_finalized_block)?;

evaluate(&mut self, candidates: &UnfinalizedBlocksSnapshot, _block_state_repository: &BlockStateRepository, metrics: Option<&BlockProductionMetrics>) -> anyhow::Result<()>

Evaluates whether conditions to trigger requests for missing attestations are met and potentially increases the block gap parameter.

Parameters

Returns


_try_request_missing(&mut self, candidates: &UnfinalizedBlocksSnapshot, block_state_repository: &BlockStateRepository, metrics: Option<BlockProductionMetrics>) -> anyhow::Result<()>

Private method to identify missing blocks and send requests to interested peer nodes.

Parameters

Returns


_make_request(&mut self, attestation_interested_parties: HashSet<NodeIdentifier>, request_range_start: BlockSeqNo, request_range_end: BlockSeqNo, request_at_least_this_number_of_blocks: Option<usize>, metrics: Option<BlockProductionMetrics>) -> anyhow::Result<()>

Sends block range requests to the specified set of peer nodes.

Parameters

Returns


Implementation Details and Algorithms


Interaction with Other System Components


Mermaid Diagram: Structure of PulseAttestations

classDiagram
class PulseAttestations {
-node_id: NodeIdentifier
-thread_identifier: ThreadIdentifier
-send_tx: NetDirectSender
-last_finalized_block_seq_no: Option<BlockSeqNo>
-last_requested_range: Option<(BlockSeqNo, BlockSeqNo)>
-last_requested_time: Option<Instant>
-last_pulse: Instant
-trigger_by_time: Option<Duration>
-trigger_by_length: Option<usize>
-request_retry_timeout: Duration
-missing_blocks_were_requested: Arc<AtomicBool>
-trigger_increase_block_gap: Option<Duration>
-last_gap_increase: Instant
-block_gap: BlockGap
-min_generations_to_request: Option<usize>
+pulse()
+evaluate()
-_try_request_missing()
-_make_request()
}