Skip to content

ibd: stop header prefix retries when first header fails - #798

Merged
reardencode merged 2 commits into
reardencode:masterfrom
bobberb:fix/ibd-header-prefix-first-failure
Sep 28, 2026
Merged

reardencode merged 2 commits into
reardencode:masterfrom
bobberb:fix/ibd-header-prefix-first-failure

Conversation

@bobberb

@bobberb bobberb commented Sep 28, 2026

Copy link
Copy Markdown

Problem

On mainnet IBD at ~458k, 2,000-header peer events with no accepted prefix blocked the IBD loop for ~12–13 seconds apiece. Instrumentation measured accepted_headers as the cost, with accepted=0, stored_prefix=0, one failed full-batch attempt and 10 failed prefix probes. The same window processed block-body events in milliseconds. See #790.

Change

After a failed full batch, validate the first header alone before searching for a longer accepted prefix. If that first header fails, no prefix is acceptable; return without the 10 longer probes. If it succeeds, retain its FK and binary-search the remaining prefix exactly as before. No header validation or store format changes.

Reproduction and validation

  • The first-header failure test was red before the change; now the fallback invokes only one probe. Tests also cover an accepted prefix with a rejected tail and the stored-header path.
  • Live temporary musl build on the same /ssd/rbitcoin datadir with --milestone=840000: failed 2,000-header batch fell from ~12–13 s / 11 attempts to ~2.3–2.5 s / 2 attempts. Progress checks moved from ~25 s to ~9–12 s during the brief trial; throughput was variable and is not claimed as a sustained A/B improvement. The node has been restored to the original committed INFO binary.
  • cargo fmt --all -- --check; cargo clippy --workspace --all-targets -- -D warnings; cargo test -p rbitcoin-net --lib (646 passed); cargo test --workspace --no-fail-fast --quiet (passed before a final test-only assertion was added); musl Nix build of the live-tested candidate.

Follow-up: the first full-batch attempt still costs ~1.1–1.3 s in the live sample; this PR addresses only redundant retries when the first header cannot be accepted.

@reardencode

Copy link
Copy Markdown
Owner

we may have an alternative fix for this coming up, but I'll have grok pause and look at yours before continuing. Thank you!!!

A headers batch that cannot connect used to search longer prefixes after
the full batch failed. The release note records that the search now stops
when the first header is rejected.

Co-authored-by: Cursor <cursoragent@cursor.com>
@reardencode
reardencode merged commit 4670a3e into reardencode:master Sep 28, 2026
18 checks passed
@bobberb
bobberb deleted the fix/ibd-header-prefix-first-failure branch September 28, 2026 16:10
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.

2 participants