memento.rs

Overview

This file defines two primary data structures, BlockProducerMemento and ProducedBlock, which serve as state snapshots (mementos) related to block production within a blockchain or distributed ledger system. These structures encapsulate the information about blocks produced, their associated optimistic state, feedback, and block state, as well as timing metrics and attestation notifications.

The purpose of these mementos is to preserve and manage the state of produced blocks and related metadata, enabling the system to track and update block-related information efficiently during block production and validation processes.

Structures and Their Functionalities

BlockProducerMemento

BlockProducerMemento acts as a container for multiple produced blocks along with optional metadata about attestation notifications. It provides mutable access to the collection of produced blocks and setters for updating attestation-related state.

Fields

Methods

Usage Example

let mut memento = BlockProducerMemento::builder()
    .produced_blocks(vec![])
    .build();

memento.produced_blocks_mut().push(produced_block_instance);
memento.set_last_attestation_notification(42);

ProducedBlock

ProducedBlock represents a single block created by the producer, along with its associated state and metadata necessary for tracking and validation.

Fields

Methods

Usage Example

let mut produced_block = ProducedBlock::builder()
    .block(some_block)
    .optimistic_state(Arc::new(optimistic_state_instance))
    .feedbacks(feedback_list)
    .block_state(block_state_instance)
    .build();

produced_block.set_memento_init_time(Instant::now());

Implementation Details

Interaction with Other System Components

Mermaid Diagram

classDiagram
class BlockProducerMemento {
-produced_blocks: Vec<ProducedBlock>
-last_attestation_notification: Option<u32>
+produced_blocks_mut()
+set_last_attestation_notification()
}
class ProducedBlock {
-block: AckiNackiBlock
-optimistic_state: Arc<OptimisticStateImpl>
-feedbacks: ExtMsgFeedbackList
-block_state: BlockState
-metrics_memento_init_time: Option<Instant>
+set_memento_init_time()
}
BlockProducerMemento "1" o-- "*" ProducedBlock : contains

This diagram illustrates the composition relationship where BlockProducerMemento contains multiple ProducedBlock instances and the key methods each provides for interaction.