single_block_producer.rs

Overview

This file implements the functionality for producing a single block within a blockchain system. It defines a generic trait BlockProducer that outlines the contract for block production and provides a concrete implementation TVMBlockProducer tailored for a TVM-based blockchain environment. The block production process involves pre-processing of input states and messages, building the new block, managing cross-thread references, handling slashing messages, and performing load balancing checks.

The file orchestrates interactions between various components such as message storage, blockchain configuration, block state repositories, shared services, and WASM caching to produce a valid block. It ensures that block production respects execution time limits and parallelization constraints while managing thread activity and cross-thread communication.

Key Components

Trait: BlockProducer

Defines the interface for producing a single block.

Associated Types

Method: produce

fn produce<'a, I>(
    self,
    thread_identifier: ThreadIdentifier,
    parent_state: Self::OptimisticState,
    refs: I,
    control_rx_stop: InstrumentedReceiver<()>,
    message_db: MessageDurableStorage,
    time_limits: &ExecutionTimeLimits,
    block_round: BlockRound,
    parent_block_state: BlockState,
) -> anyhow::Result<(
    AckiNackiBlock,
    Self::OptimisticState,
    Vec<(Cell, ActiveThread)>,
    CrossThreadRefData,
    Vec<Stamp>,
    ExtMsgFeedbackList,
    BlockState,
)>
where
    I: std::iter::Iterator<Item = &'a CrossThreadRefData> + Clone,
    CrossThreadRefData: 'a;
let produced_result = block_producer.produce(
    thread_id,
    parent_state,
    refs_iter,
    control_receiver,
    message_storage,
    &time_limits,
    block_round,
    parent_block_state,
)?;

Struct: TVMBlockProducer

Concrete implementation of the BlockProducer trait for TVM-based blockchains.

Fields

Methods

print_block_info
fn print_block_info(block: &tvm_block::Block)
produce (implementation of BlockProducer trait)

Important Implementation Details and Algorithms

Interactions with Other System Components

Mermaid Class Diagram

classDiagram
class BlockProducer {
<<trait>>
produce()
}
class TVMBlockProducer {
-active_threads: Vec<(Cell, ActiveThread)>
-blockchain_config: Arc<BlockchainConfig>
-message_queue: HashMap<AccountAddress, VecDeque<(Stamp, tvm_block::Message)>>
-producer_node_id: NodeIdentifier
-thread_count_soft_limit: usize
-parallelization_level: usize
-block_keeper_epoch_code_hash: String
-block_keeper_preepoch_code_hash: String
-epoch_block_keeper_data: Vec<BlockKeeperData>
-shared_services: SharedServices
-block_nack: Vec<Envelope<GoshBLS, NackData>>
-accounts: AccountsRepository
-block_state_repository: BlockStateRepository
-metrics: Option<BlockProductionMetrics>
-wasm_cache: WasmNodeCache
+print_block_info(block: &tvm_block::Block)
+produce()
}
BlockProducer <|.. TVMBlockProducer

This diagram illustrates the trait BlockProducer and its implementation TVMBlockProducer, showing the main fields and methods of the latter. It highlights the key properties used for block production and the core methods involved.


For details on related concepts such as optimistic state management, message handling, execution time limits, and block building algorithms, see these topics: