cross_thread_ref_data.rs

Overview

This file defines the CrossThreadRefData structure, which encapsulates the minimal and complete data necessary for threads to reference the blockchain's state at a specific block. The structure stores references to a particular block's identity, sequence number, thread information, outbound messages and accounts, and thread spawning details. It serves as a data container facilitating cross-thread interactions and references within the system's multi-threaded consensus or state management mechanism.

The main functionality includes providing reference state information, managing thread tables and block references, and identifying newly spawned threads within a block's context.


Structure: CrossThreadRefData

Description

CrossThreadRefData holds essential data related to a blockchain block's state, enabling cross-thread referencing. It includes identifiers of the block and thread, outbound messages and accounts relevant only to the block, the threads table, and references to parent and other related blocks.

Fields

Field Name

Type

Description

block_identifier

BlockIdentifier

Identifier for the block this data references.

block_seq_no

BlockSeqNo

Sequence number of the block within the thread.

block_thread_identifier

ThreadIdentifier

Identifier of the thread that produced this block.

outbound_messages

HashMap<AccountRouting, Vec<(MessageIdentifier, Arc<WrappedMessage>)>>

Outbound messages generated in this block only, keyed by account routing.

outbound_accounts

HashMap<AccountRouting, (Option<WrappedAccount>, Option<AccountInbox>)>

Outbound accounts and their inboxes related to this block.

threads_table

ThreadsTable

Table representing the state of threads at this block.

parent_block_identifier

BlockIdentifier

Identifier of the parent block.

block_refs

Vec<BlockIdentifier>

Vector of block identifiers referenced by this block.

Traits Derived


Methods

as_reference_state_data

pub fn as_reference_state_data(&self) -> (ThreadIdentifier, BlockIdentifier, BlockSeqNo)

Returns a tuple containing the thread identifier, block identifier, and block sequence number. This tuple represents the minimal reference state data for other components to identify the state this data refers to.


set_threads_table

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

Sets or updates the threads_table field with a new ThreadsTable instance.


set_block_refs

pub fn set_block_refs(&mut self, block_refs: Vec<BlockIdentifier>)

Sets or updates the block_refs field with a vector of new block identifiers.


get_produced_threads_table

pub fn get_produced_threads_table(&self) -> &ThreadsTable

Returns a reference to the stored threads_table.


refs

pub fn refs(&self) -> &Vec<BlockIdentifier>

Returns a reference to the vector of block references stored in block_refs.


spawned_threads

pub fn spawned_threads(&self) -> Vec<ThreadIdentifier>

Identifies and returns a vector of thread identifiers that this block has spawned. It filters the threads from the threads_table to include only those threads which are marked as spawning from the current block.


Implementation Details


Interactions with Other Components


Mermaid Diagram: Structure of CrossThreadRefData

classDiagram
class CrossThreadRefData {
-block_identifier: BlockIdentifier
-block_seq_no: BlockSeqNo
-block_thread_identifier: ThreadIdentifier
-outbound_messages: HashMap<AccountRouting, Vec<(MessageIdentifier, Arc<WrappedMessage>)>>
-outbound_accounts: HashMap<AccountRouting, (Option<WrappedAccount>, Option<AccountInbox>)>
-threads_table: ThreadsTable
-parent_block_identifier: BlockIdentifier
-block_refs: Vec<BlockIdentifier>
+as_reference_state_data()
+set_threads_table()
+set_block_refs()
+get_produced_threads_table()
+refs()
+spawned_threads()
}

This file is focused on managing and providing cross-thread block reference data within a system that handles concurrent thread-based block processing, enabling efficient referencing and synchronization of state across threads. For more on block identification, threading, and message handling, see the relevant topics such as Block Structure, Thread Management, and Message Passing.