checkpoint.rs

Overview

This file defines the Checkpoint struct and its associated functionality. The Checkpoint represents a snapshot in the blockchain or distributed ledger state progression, encapsulating an optional block and the optimistic state of the system after applying that block. It manages the application of new blocks to transition the system state forward, ensuring that blocks have been signature-verified before processing. The file emphasizes minimizing expensive clone operations on the state by employing ownership moves instead.

The file integrates multiple core components such as cryptographic envelopes (Envelope), block data (AckiNackiBlock), and an optimistic state implementation (OptimisticStateImpl). It also interacts with shared services and various repositories to persist and manage blockchain-related data.


Structs and Fields

Checkpoint

The central data structure in this file. It is marked with TypedBuilder and Getters for ergonomic construction and access.


Methods

apply(self, next_block: Envelope<GoshBLS, AckiNackiBlock>) -> anyhow::Result<Self>

Purpose:
Applies a new block to the current checkpoint state, producing a new checkpoint with an updated state after the block is applied.

Parameters:

Returns:

Usage:
The method consumes the current checkpoint instance (taking ownership), applies the given block to its optimistic state, updates cross-thread reference data via shared services, and returns a new checkpoint encapsulating the updated state.

let current_checkpoint: Checkpoint = ...;
let new_block: Envelope<GoshBLS, AckiNackiBlock> = ...;

match current_checkpoint.apply(new_block) {
    Ok(updated_checkpoint) => {
        // Proceed with the updated checkpoint
    }
    Err(e) => {
        // Handle failure, possibly triggering NACK and slashing
    }
}

Implementation Details:


Important Implementation Notes


Interactions with Other Components


Mermaid Diagram

classDiagram
class Checkpoint {
-block: Option<Envelope>
-state_after_block_applied: Arc<OptimisticStateImpl>
-shared_services: SharedServices
-block_state_repository: BlockStateRepository
-accounts_repository: AccountsRepository
-message_db: MessageDurableStorage
-nack_set_cache: Arc<Mutex<FixedSizeHashSet>>
+apply()
}
Checkpoint --> Envelope : contains
Checkpoint --> OptimisticStateImpl : uses
Checkpoint --> SharedServices : uses
Checkpoint --> BlockStateRepository : uses
Checkpoint --> AccountsRepository : uses
Checkpoint --> MessageDurableStorage : uses
Checkpoint --> FixedSizeHashSet : uses

Additional References