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 operationsMempool: Transaction pool for pending transactionsfork_choice: Fork choice rule implementationpayload: 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§
Structs§
- Batch
Block Processing Failure - Blockchain
- Core blockchain implementation for block validation and execution.
- Blockchain
Options - Configuration options for the blockchain.
- L2Config
- Configuration for L2 rollup operation.
Enums§
- Blockchain
Type - 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_bloomagainst 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