mod.rs

Overview

This file defines the core data structure ZeroState and its associated methods, which represent the initial or root state of a multi-threaded blockchain shard system. It handles collections of optimistic states and block keeper sets indexed by thread identifiers, providing interfaces to access, modify, and initialize these per-thread states. The file also imports auxiliary modules responsible for parsing, serialization, and updating functionality related to the zero state.

The ZeroState struct acts as a container that maintains the mapping from each thread to its optimistic state and block keeper set. It offers operations to retrieve shard states, access thread tables, and manage the lifecycle of thread-specific data. This file is central to managing the system's view of the shard state at genesis or reset points and interacts closely with types and modules involved in optimistic state management and block keeping.


Modules and Imports


Struct: ZeroState

pub struct ZeroState {
    states: HashMap<ThreadIdentifier, OptimisticStateImpl>,
    block_keeper_set: HashMap<ThreadIdentifier, BlockKeeperSet>,
}

Description

ZeroState maintains two primary collections keyed by ThreadIdentifier:

This design supports multiple threads operating in parallel with their own state and block keeping logic, while still allowing centralized access and management.

Traits Derived


Methods on ZeroState

get_shard_state

pub(crate) fn get_shard_state(
    &mut self,
    thread_identifier: &ThreadIdentifier,
) -> anyhow::Result<Arc<ShardStateUnsplit>>

get_threads_table

pub fn get_threads_table(&self) -> &ThreadsTable

get_block_keeper_set

pub fn get_block_keeper_set(&self) -> anyhow::Result<BlockKeeperSet>

unwrapped_block_keeper_sets

pub fn unwrapped_block_keeper_sets(&self) -> &HashMap<ThreadIdentifier, BlockKeeperSet>

states

pub fn states(&self) -> &HashMap<ThreadIdentifier, OptimisticStateImpl>

states_mut

pub fn states_mut(&mut self) -> &mut HashMap<ThreadIdentifier, OptimisticStateImpl>

state_mut

pub fn state_mut(
    &mut self,
    thread_identifier: &ThreadIdentifier,
) -> anyhow::Result<&mut OptimisticStateImpl>

state

pub fn state(
    &self,
    thread_identifier: &ThreadIdentifier,
) -> anyhow::Result<&OptimisticStateImpl>

init_thread

pub fn init_thread(&mut self, thread_identifier: ThreadIdentifier)

set_threads_table

pub fn set_threads_table(&mut self, threads_table: ThreadsTable)

list_threads

pub fn list_threads(&self) -> impl Iterator<Item = &'_ ThreadIdentifier>

Important Implementation Details


Interactions with Other Components


Visual Diagram

classDiagram
class ZeroState {
-states: HashMap<ThreadIdentifier, OptimisticStateImpl>
-block_keeper_set: HashMap<ThreadIdentifier, BlockKeeperSet>
+get_shard_state()
+get_threads_table()
+get_block_keeper_set()
+unwrapped_block_keeper_sets()
+states()
+states_mut()
+state_mut()
+state()
+init_thread()
+set_threads_table()
+list_threads()
}
ZeroState --> "0..*" OptimisticStateImpl : states
ZeroState --> "0..*" BlockKeeperSet : block_keeper_set