Skip to content

ibd: reuse the confirmed getheaders tail until the tip changes - #1056

Merged
reardencode merged 6 commits into
masterfrom
ibd/locator-tail
Oct 17, 2026
Merged

reardencode merged 6 commits into
masterfrom
ibd/locator-tail

Conversation

@rearden-grok

@rearden-grok rearden-grok Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Catch-up getheaders still builds the work-path prefix from the in-memory header walk on every ask. The confirmed-chain tail that query.locator_hashes used to rebuild on each send is remembered on IBD work state until the published tip height and hash both change. A second ask at the same tip does not walk the header store. Tip-follow locators are unchanged.

Test plan

  • cargo test -p rbitcoin-net --lib second_getheaders_reuses_confirmed_locator_tail (same tip reuses the tail; a new tip hash rebuilds it; the locator still starts at the stored path tip)
  • Targeted rbitcoin-net filters for header period, unsolicited lookahead, stored-queue refill, stray batches, stall disconnect, redial budget, below-floor intake, and rate-limit disconnect
  • CI

Catch-up getheaders still builds the work-path prefix from the in-memory
walk on every ask. The confirmed-chain tail is remembered on the IBD work
state, keyed by published tip height and hash, and reused until that pair
changes. Tip-follow locators are unchanged.
Clippy rejects the nested height, hash, and hash-list tuple on the IBD
work state. The cache is a small struct with those three fields.

@rearden-grok rearden-grok Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Summary

The change caches the confirmed-chain getheaders tail on IbdWorkState, keyed by Query::published_tip() height and hash, and still builds the work-path prefix on every ask through header_ask_locator → ibd_header_locator. That split is correct: a same-height reorg changes the published hash (disconnect lowers the tip, then the new block publishes a different hash), locator_hashes errors are not cached, and hub.tip_hash() is the in-memory published snapshot rather than a header_at_height walk, so it does not bump header_lookup_count. Production send_getheaders runs only on the header thread while it holds the state mutex, and tip-follow locators are untouched. No correctness bug turned up; the residual gaps are a change-narrating comment and a test that never holds height fixed while swapping the tip hash.

Issue counts by severity

  • bugs: 0
  • suggestions: 2
  • nits: 0

Comment thread crates/rbitcoin-net/src/ibd/header_walk.rs Outdated
Comment thread crates/rbitcoin-net/src/ibd/header_walk.rs Outdated
The doc named the old per-ask store read. Say when the tail is rebuilt.
Invalidate the tip and confirm a different block at that height. The next
due ask rebuilds the confirmed tail and drops the replaced hash. The walk
prefix can still name the hash it learned at origin.
The separate test opened another hub and mined thirty blocks. Those
asks now run on the seeded header-walk hub after a two-block chain.
Folding the tail checks into the seeded walk put that test over the
cognitive-complexity limit. The same hub still runs them, from helpers.
@reardencode
reardencode merged commit 71d1f52 into master Oct 17, 2026
18 checks passed
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.

1 participant