mod.rs

Overview

This file defines the core Repository trait and related types and errors used for managing blockchain-related data structures and state in a modular and extensible manner. It serves as an abstraction layer for accessing, storing, and manipulating blocks, optimistic states, attestations, and related blockchain metadata. The trait is designed to be implemented by concrete repository types that interact with persistent storage, caches, and synchronization services.

The file also declares and re-exports several submodules related to state management and data repositories, such as accounts, cross_thread_ref_repository, optimistic_state, and repository_impl. It provides error handling via the RepositoryError enum and integrates with various blockchain-specific types like BlockIdentifier, ThreadIdentifier, and AckiNackiBlock.

Modules and Re-exports

Re-exported Types

These re-exports allow external modules to access key data types and services without depending on internal module paths.

RepositoryError Enum

Defines error conditions related to repository operations:

Variant

Description

DepthSearchBlockCountLimitReached

Error when no optimistic state is found due to exceeding block count depth during search.

DepthSearchMinStateLimitReached

Error when no optimistic state is found due to reaching minimum state limit depth.

BlockNotFound(String)

General error for missing block, with a descriptive message.

This enum uses the thiserror crate for ergonomic error handling and debugging.

Repository Trait

The central abstraction in this file is the generic Repository trait, parametrized by multiple associated types to accommodate different blockchain implementations and cryptographic schemes.

Associated Types

Associated Type

Description

BLS

The BLS signature scheme used, implementing the BLSSignatureScheme trait.

CandidateBlock

Blocks candidates wrapped in BLS-signed envelopes with AckiNackiBlock data.

EnvelopeSignerIndex

Type used to index signers in envelopes.

NodeIdentifier

Identifier type for nodes in the network.

OptimisticState

Represents optimistic state snapshots, implementing the OptimisticState trait.

Attestation

Attestation data wrapped in BLS-signed envelopes with AttestationData.

StateSnapshot

A snapshot of the state serialized as bytes, convertible from and into Vec<u8>.

Methods

Block Access and Management

State Management

Metadata and Auxiliary Access

Implementation Details and Algorithms

Interactions with Other System Components

Usage Examples

Retrieving a Finalized Block

let block_id = BlockIdentifier::default(); // example block identifier
match repository.get_finalized_block(&block_id)? {
    Some(block) => {
        // Process the finalized block
    }
    None => {
        // Handle block not found case
    }
}

Marking a Block as Finalized

let candidate_block = ...; // an instance implementing CandidateBlock
let block_state = BlockState::new(...); // block state info
repository.mark_block_as_finalized(&candidate_block, block_state, None)?;

Loading Optimistic State

let thread_id = ThreadIdentifier::default();
let block_id = BlockIdentifier::default();
let optimistic_state = repository.get_optimistic_state(&block_id, &thread_id, None)?;
if let Some(state) = optimistic_state {
    // Use optimistic state
}

Initializing a Thread

let thread_id = ThreadIdentifier::default();
let parent_block_id = BlockIdentifier::default();
repository.init_thread(&thread_id, &parent_block_id)?;

Mermaid Diagram: Repository Trait Structure

classDiagram
class Repository {
<<trait>>
+get_finalized_block()
+get_block_from_repo_or_archive()
+last_finalized_optimistic_state()
+clear_verification_markers()
+has_thread_metadata()
+init_thread()
+select_thread_last_finalized_block()
+is_block_suspicious()
+mark_block_as_finalized()
+get_optimistic_state()
+get_full_optimistic_state()
+erase_block()
+is_block_already_applied()
+set_state_from_snapshot()
+sync_accounts_from_state()
+save_account_diffs()
+store_optimistic()
+store_optimistic_in_cache()
+get_latest_block_id_with_producer_group_change()
+load_sent_attestations()
+get_zero_state_for_thread()
+get_all_metadata()
+get_message_db()
+unfinalized_blocks()
+get_message_storage_service()
}
class RepositoryError {
<<enum>>
+DepthSearchBlockCountLimitReached
+DepthSearchMinStateLimitReached
+BlockNotFound
}

This diagram highlights the core trait Repository with its primary methods and the associated RepositoryError enum representing possible errors during repository operations.


For detailed explanations of types such as BlockIdentifier, ThreadIdentifier, or cryptographic components like BLSSignatureScheme, refer to their respective documentation sections such as BlockIdentifier and BLSSignatureScheme. The optimistic state management strategy is detailed in Optimistic State Management, and the repository's interaction with storage systems is explained in Storage Systems.