Skip to content

fix(live_builder): fall back to header_by_number when parent hash lookup misses - #939

Open
Xtley001 wants to merge 1 commit into
flashbots:developfrom
Xtley001:fix/issue-853-parent-header-fallback
Open

Xtley001 wants to merge 1 commit into
flashbots:developfrom
Xtley001:fix/issue-853-parent-header-fallback

Conversation

@Xtley001

Copy link
Copy Markdown

Summary

Resolves #853. When provider.header(&parent_hash) returns None due to Reth secondary index lag, falls back to provider.header_by_number(block - 1) and verifies hash_slow() == parent_hash before entering the polling sleep loop.

Problem

In Reth, canonical commits write to the primary Headers table before updating the secondary HeaderNumbers (BlockHash -> BlockNumber) index. During slot transitions, provider.header(&parent_hash) can return None for hundreds of milliseconds. try_to_read_block_header queried provider.header_by_number but discarded the header and returned an error, forcing wait_for_block_header into repeated polling sleeps and delaying block building.

Solution

  • When provider.header(&parent_hash)? yields None, inspect provider.header_by_number(block - 1).
  • If header.hash_slow() == parent_hash, return Ok(header) immediately.
  • If the hash mismatches or the header is absent, preserve the existing diagnostic logging and return the error.
  • Protect against block 0 underflow via block.checked_sub(1).
  • Added regression tests covering:
    1. Primary hash lookup hit
    2. Number lookup fallback hit on hash miss
    3. Hash mismatch (fork / reorg safety)
    4. Block 0 underflow protection

Testing

  • Automated regression tests added in crates/rbuilder/src/live_builder/mod.rs

…kup misses

When Reth commits canonical headers, the primary Headers table is immediately
available while the secondary HeaderNumbers (hash -> number) index can lag.
In try_to_read_block_header, if provider.header(&parent_hash) returns None,
fall back to provider.header_by_number(block - 1) and verify hash_slow().
If the hashes match, return Ok(header) immediately instead of polling.
Copilot AI balanced review requested due to automatic review settings October 31, 2026 04:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parent header sometimes not found via hash lookup even after canonical commit in reth

2 participants