Description
ethrex --network hoodi import --removedb hoodi-100k.rlp fails at block ~25602 with:
Error: EVM error: Database access error: DB error: Block hash not found for block number 25598
Root Cause
import_blocks processes blocks in batches of 1024 via add_blocks_in_batch. Each batch creates a StoreVmDatabase with a block_hash_cache containing only the current batch's block hashes.
When a block in batch N+1 executes the BLOCKHASH opcode for a block in batch N, the lookup fails because:
- The
block_hash_cache only has batch N+1's hashes
get_block_hash falls back to is_canonical_sync + get_canonical_block_hash_sync
- But blocks from batch N aren't marked as canonical yet -- canonicalization happens at the end of the entire import (
set_canonical_block in cli.rs:811+), not after each batch
- The ancestor walk also fails because the blocks aren't linked canonically
Reproduction
# Need a chain file with >25k blocks (first 10k blocks are mostly empty on Hoodi)
./target/release/ethrex --network hoodi import --removedb hoodi-100k.rlp
Fails at block ~25602 trying to look up block 25598's hash.
The 10k import works because early Hoodi blocks don't have transactions that call BLOCKHASH for blocks across batch boundaries.
Suggested Fix
After each add_blocks_in_batch call completes and blocks are stored, mark them as canonical before starting the next batch. Alternatively, extend the block_hash_cache to include the last 256 blocks from the store (not just the current batch).
Description
ethrex --network hoodi import --removedb hoodi-100k.rlpfails at block ~25602 with:Root Cause
import_blocksprocesses blocks in batches of 1024 viaadd_blocks_in_batch. Each batch creates aStoreVmDatabasewith ablock_hash_cachecontaining only the current batch's block hashes.When a block in batch N+1 executes the
BLOCKHASHopcode for a block in batch N, the lookup fails because:block_hash_cacheonly has batch N+1's hashesget_block_hashfalls back tois_canonical_sync+get_canonical_block_hash_syncset_canonical_blockincli.rs:811+), not after each batchReproduction
# Need a chain file with >25k blocks (first 10k blocks are mostly empty on Hoodi) ./target/release/ethrex --network hoodi import --removedb hoodi-100k.rlpFails at block ~25602 trying to look up block 25598's hash.
The 10k import works because early Hoodi blocks don't have transactions that call
BLOCKHASHfor blocks across batch boundaries.Suggested Fix
After each
add_blocks_in_batchcall completes and blocks are stored, mark them as canonical before starting the next batch. Alternatively, extend theblock_hash_cacheto include the last 256 blocks from the store (not just the current batch).