fix(electrum): refresh header cache with headers fetched for the chain update - #2319
Open
evanlinjin wants to merge 2 commits into
Open
evanlinjin wants to merge 2 commits into
evanlinjin wants to merge 2 commits into
Conversation
…n update `block_header_cache` was only written by `batch_fetch_anchors`, so after a reorg it kept serving the pre-reorg header for that height. The anchor cache is keyed by `(txid, hash)` from that header, so a tx re-mined at the same height hit the anchor cache with the stale hash, skipped proof validation, and was never re-anchored to the replacement block. `fetch_tip_and_latest_blocks` now writes the headers it fetches (the chain suffix and the agreement-walk checkpoints) into the header cache.
Checks the tx is re-anchored to the replacement block both when the reorged height is still in the synced chain suffix and when 20 blocks are mined before the next sync. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
block_header_cachewas only written bybatch_fetch_anchors, so after a reorg it kept the pre-reorg header for that height. A tx re-mined at the same height then hit the anchor cache under the stale block hash, skipped proof validation, and was never re-anchored to the replacement block. This happens even for a 1-block reorg.fetch_tip_and_latest_blocksnow writes the headers it fetches (the chain suffix and the agreement-walk checkpoints) into the header cache.Notes to the reviewers
The test covers two cases: syncing right after the reorg (header is in the suffix), and syncing after 20 more blocks (header comes from the agreement walk). Both fail on the base branch. The 20-block case also fails if only the agreement-walk insert is removed.
Related: #2312. That issue points at
chain_update, but checkpoints are already corrected by the agreement walk. The stale header cache is what leaves the anchor wrong.Changelog notice
bdk_electrumreturning a stale anchor for a transaction re-mined at the same height after a reorg.Checklists
All Submissions:
Bugfixes:
🤖 Generated with Claude Code