mod.rs

Overview

This file defines core data structures and logic related to the construction and management of blockchain blocks within a shard environment. It focuses on preparing blocks (PreparedBlock), managing thread execution results (ThreadResult), and orchestrating the block building process (BlockBuilder). The file also introduces error types related to block execution and provides supporting constructs for message handling, account state updates, and cross-thread interactions in a concurrent block production context.

Public Structs and Their Usage

PreparedBlock

Represents a fully or partially constructed block ready for further processing or committing to the chain state.

Fields:

ThreadResult

Encapsulates the outcome of executing a single thread of transactions.

Fields:

ActiveThread

Keeps track of currently executing threads during block production.

Fields:

EngineTraceInfoData

Provides detailed tracing information for VM execution steps, useful for debugging or telemetry.

Fields:

BlockBuilder

Primary structure that manages block construction within a shard and thread context.

Fields (key highlights):

Methods

is_limits_reached(&mut self) -> bool

Checks if the block builder should stop producing the block due to external stop requests or gas limits.

Usage Example
let mut builder = BlockBuilder::new(...);
if builder.is_limits_reached() {
    // Stop further processing
}

Error Types

ExecuteError

Enumerates possible errors during execution in block building context.

Variants:

Important Implementation Details

Interactions with Other Modules

The BlockBuilder serves as a central orchestrator integrating these modules to build blocks respecting shard and thread boundaries, message passing semantics, and gas/resource constraints.

Visual Diagram

classDiagram
class PreparedBlock {
+block: Block
+remain_fees: Grams
+state: OptimisticStateImpl
+is_empty: bool
+active_threads: Vec<(Cell, ActiveThread)>
+tx_cnt: usize
+block_keeper_set_changes: Vec<BlockKeeperSetChange>
+cross_thread_ref_data: CrossThreadRefData
}
class ThreadResult {
+transaction: Transaction
+lt: u64
+account_root: Cell
+account_id: AccountAddress
+minted_shell: i128
+initial_dapp_id: Option<DAppIdentifier>
+initial_code_hash: Option<UInt256>
+initial_account: Option<Account>
+in_msg_is_ext: bool
+in_msg: Message
}
class ActiveThread {
+result_rx: InstrumentedReceiver
+message: Message
+vm_execution_is_block_related: Arc<Mutex<bool>>
+block_production_was_finished: Arc<Mutex<bool>>
}
class BlockBuilder {
+thread_id: ThreadIdentifier
+shard_state: Arc<ShardStateUnsplit>
+accounts: ShardAccounts
+block_info: BlockInfo
+rand_seed: UInt256
+new_messages: BTreeMap
+in_msg_descr: InMsgDescr
+out_msg_descr: OutMsgDescr
+block_gas_limit: u64
+total_gas_used: u64
+copyleft_rewards: CopyleftRewards
+parallelization_level: usize
+tx_cnt: usize
+wasm_cache: WasmNodeCache
+accounts_repository: AccountsRepository
+metrics: Option<BlockProductionMetrics>
+consumed_internal_messages: HashMap
+produced_internal_messages_to_the_current_thread: HashMap
+produced_internal_messages_to_other_threads: HashMap
}
PreparedBlock --> "many" ActiveThread : has
ActiveThread --> ThreadResult : produces
BlockBuilder --> PreparedBlock : builds
BlockBuilder --> ActiveThread : manages
BlockBuilder --> BlockInfo : uses
BlockBuilder --> AccountsRepository : uses

This diagram shows the relationship between the primary entities managing block construction and execution threads, highlighting that BlockBuilder is the main controller that manages multiple ActiveThread instances which produce ThreadResults culminating in a PreparedBlock.