verify.rs

Overview

This file provides functionality to verify blocks within the blockchain's block production and validation process. It contains mechanisms to validate the integrity, consistency, and correctness of candidate blocks before they are accepted by the node. The verification process compares candidate blocks against expected state updates and blockchain configurations, ensuring that only valid blocks propagate through the network.

The core functionality is exposed via the verify_block function, which performs comprehensive checks and produces a verification result indicating whether the block is valid, invalid, or too complex to execute within constraints. The file also provides support functions to prepare previous block metadata and debug transaction details during verification failures.


Enumerations

VerificationResult

Represents the possible outcomes of a block verification attempt.

pub enum VerificationResult {
    ValidBlock,
    BadBlock,
    TooComplexExecution,
}

Functions

verify_block

pub fn verify_block(
    block_candidate: &AckiNackiBlock,
    blockchain_config: Arc<BlockchainConfig>,
    prev_block_optimistic_state: &mut OptimisticStateImpl,
    node_config: Config,
    refs: Vec<CrossThreadRefData>,
    shared_services: SharedServices,
    block_nack: Vec<Envelope<GoshBLS, NackData>>,
    block_state_repo: BlockStateRepository,
    accounts_repo: AccountsRepository,
    metrics: Option<BlockProductionMetrics>,
    wasm_cache: WasmNodeCache,
    message_db: MessageDurableStorage,
) -> anyhow::Result<VerificationResult>

Performs full verification of a candidate block against the blockchain state and configuration.

let verification_result = verify_block(
    &candidate_block,
    blockchain_config.clone(),
    &mut prev_block_state,
    node_config.clone(),
    cross_thread_refs,
    shared_services.clone(),
    block_nack,
    block_state_repo.clone(),
    accounts_repo.clone(),
    Some(metrics),
    wasm_cache.clone(),
    message_storage.clone(),
)?;

if verification_result.is_valid() {
    // Proceed with next steps for a valid block
} else {
    // Handle invalid or too complex blocks accordingly
}

prepare_prev_block_info

pub fn prepare_prev_block_info(block_candidate: &AckiNackiBlock) -> BlockInfo

Prepares and extracts summary information about the previous block, encapsulated in a BlockInfo structure.

let prev_block_info = prepare_prev_block_info(&block_candidate);

display_block_transactions

fn display_block_transactions(block: &AckiNackiBlock)

A helper function to output detailed transaction information from a block to tracing logs, mainly for debugging purposes during verification failures.


Implementation Details and Algorithms


Interactions with Other Components


File Structure Diagram

flowchart TD
A[verify_block] -->|calls| B[TVMBlockVerifier::generate_verify_block]
B -->|returns| C[VerificationResult]
A -->|calls| D[prepare_prev_block_info]
A -->|calls| E[display_block_transactions]
D --> F[BlkPrevInfo::Block]
E --> G[logs transaction details]
A -->|updates| H[OptimisticStateImpl]