Skip to content

Import fails at ~25k blocks: BLOCKHASH can't find hashes from previous batch #6385

Description

@edg-l

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:

  1. The block_hash_cache only has batch N+1's hashes
  2. get_block_hash falls back to is_canonical_sync + get_canonical_block_hash_sync
  3. 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
  4. 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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions