Skip to main content

Crate ethrex_blockchain

Crate ethrex_blockchain 

Source
Expand description

§ethrex Blockchain

Core blockchain logic for the ethrex Ethereum client.

§Overview

This module implements the blockchain layer, which is responsible for:

  • Block validation and execution
  • State management and transitions
  • Fork choice rule implementation
  • Transaction mempool management
  • Payload building for block production

§Key Components

  • Blockchain: Main interface for blockchain operations
  • Mempool: Transaction pool for pending transactions
  • fork_choice: Fork choice rule implementation
  • payload: Block payload building for consensus

§Block Execution Flow

1. Receive block from consensus/P2P
2. Validate block header (parent, timestamp, gas limit, etc.)
3. Execute transactions in EVM
4. Verify state root matches header
5. Store block and update canonical chain

§Usage

use ethrex_blockchain::Blockchain;

let blockchain = Blockchain::new(store, BlockchainOptions::default());

// Add a block
blockchain.add_block(&block)?;

// Add transaction to mempool
blockchain.add_transaction_to_mempool(tx).await?;

Modules§

constants
error
fork_choice
mempool
payload
tracing
vm

Structs§

BatchBlockProcessingFailure
Blockchain
Core blockchain implementation for block validation and execution.
BlockchainOptions
Configuration options for the blockchain.
L2Config
Configuration for L2 rollup operation.

Enums§

BlockchainType
Specifies whether the blockchain operates as L1 (mainnet/testnet) or L2 (rollup).

Functions§

find_parent_header
Searchs the header of the parent block header. If the parent header is missing, Returns a ChainError::ParentNotFound. If the storage has an error it propagates it
get_total_blob_gas
Calculates the blob gas required by a transaction.
is_canonical
latest_canonical_block_hash
new_evm
validate_block_access_list_hash
Validates that the block access list hash matches the block header (Amsterdam+). Also validates that all BlockAccessIndex values are within valid bounds per EIP-7928, and that the BAL size does not exceed the gas-derived limit.
validate_block_pre_execution
Performs pre-execution validation of the block’s header values in reference to the parent_header. Verifies that blob gas fields in the header are correct in reference to the block’s body. If a block passes this check, execution will still fail with execute_block when a transaction runs out of gas.
validate_gas_used
Validates that the block gas used matches the block header. For Amsterdam+ (EIP-7778), block_gas_used is PRE-REFUND and differs from receipt cumulative_gas_used which is POST-REFUND.
validate_receipts_root_and_logs_bloom
Validates both the receipts root and the header logs_bloom against the executed receipts in a single pass.
validate_requests_hash
Validates that the requests hash matches the block header (Prague+).
validate_state_root
Performs post-execution checks