Skip to content

fix(electrum): rewind local tip when server tip is lower - #2359

Open
h55n wants to merge 1 commit into
bitcoindevkit:masterfrom
h55n:fix-electrum-lower-tip
Open

h55n wants to merge 1 commit into
bitcoindevkit:masterfrom
h55n:fix-electrum-lower-tip

Conversation

@h55n

@h55n h55n commented Oct 9, 2026

Copy link
Copy Markdown

Description

When Electrum reported a tip height lower than the local tip, fetch_tip_and_latest_blocks returned the previous tip right away. After a re-org to a shorter chain (or a lagging server), LocalChain kept an orphaned tip and later syncs could not replace it.

Now only the local checkpoints above the server's tip are skipped, and the point of agreement is searched among the rest, so the chain update can lower the tip. The Esplora backend already behaves this way.

Notes to the reviewers

The early return and the assert that relied on it are removed. The new test invalidates 3 blocks and mines 2 new ones, so the server tip ends one block lower than the local tip with different hashes. It fails without the change (local tip stays at 11, server is at 10) and passes with it.

Changelog notice

Fixed bdk_electrum keeping an orphaned local tip when the Electrum server's tip height is lower than the local tip.

Checklists

All Submissions:

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

Fixes #2356

fetch_tip_and_latest_blocks returned the previous tip as soon as
Electrum reported a lower height. After a re-org to a shorter chain,
or when the server lags behind, the local chain kept an orphaned tip
and later syncs could not replace it.

Skip only the local checkpoints above the server's tip and search for
the point of agreement among the rest, so the update can lower the tip.
This matches how the Esplora backend handles the same case.

Add a test that replaces the last blocks with fewer new ones and checks
the local tip follows the server.
@h55n
h55n requested a review from a team as a code owner October 9, 2026 10:28
Copilot AI balanced review requested due to automatic review settings October 9, 2026 10:28

Copilot AI left a comment

Copy link
Copy Markdown

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 reached their quota limit.

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

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

Electrum: tip update skipped when server tip height is lower than local tip

2 participants