Skip to content

fix(bitcoind_rpc): emit invalidated heights when start_height is above agreement point#2167

Open
evanlinjin wants to merge 1 commit intobitcoindevkit:masterfrom
evanlinjin:fix/rpc-reorg
Open

fix(bitcoind_rpc): emit invalidated heights when start_height is above agreement point#2167
evanlinjin wants to merge 1 commit intobitcoindevkit:masterfrom
evanlinjin:fix/rpc-reorg

Conversation

@evanlinjin
Copy link
Copy Markdown
Member

@evanlinjin evanlinjin commented Apr 6, 2026

Description

When a reorg drops the agreement point below start_height, the emitter would skip directly to start_height, producing a checkpoint that could not connect with the caller's local chain (CannotConnectError).

This affects callers that create a new Emitter on each sync with start_height = tip_height — a common pattern.

Fix: Override start_height to the agreement height when a reorg is detected (agreement point below both start_height and last_cp), so the emitter revisits the invalidated block heights.

Context: https://discord.com/channels/753336465005608961/753367451319926827/1489544612094808235

cc @stevenroose

Notes to the reviewers

The key change is in poll() in crates/bitcoind_rpc/src/lib.rs: when AgreementFound is handled and the agreement point is below both start_height and last_cp.height(), we lower start_height to the agreement height. This ensures the emitter emits the invalidated blocks instead of skipping over them.

Changelog notice

Fixed:
- `Emitter` producing un-connectable checkpoints when `start_height` is above the agreement point after a reorg.

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

…e agreement point

When a reorg drops the agreement point below `start_height`, the emitter
would skip directly to `start_height`, producing a checkpoint that could
not connect with the caller's local chain (`CannotConnectError`).

Fix: override `start_height` to the agreement height when a reorg is
detected (agreement point below both `start_height` and `last_cp`), so
the emitter revisits the invalidated block heights.
@evanlinjin evanlinjin changed the title fix(bitcoind_rpc): Update from emitter initialized after reorg fix(bitcoind_rpc): emit invalidated heights when start_height is above agreement point Apr 8, 2026
@evanlinjin evanlinjin marked this pull request as ready for review April 8, 2026 07:45
@evanlinjin evanlinjin requested a review from ValuedMammal as a code owner April 8, 2026 07:46
@evanlinjin evanlinjin self-assigned this Apr 8, 2026
@evanlinjin evanlinjin added the bug Something isn't working label Apr 8, 2026
@notmandatory notmandatory moved this to Needs Review in BDK Chain Apr 8, 2026
@notmandatory notmandatory modified the milestone: Chain 0.24.0 Apr 8, 2026
@luisschwab luisschwab self-requested a review April 8, 2026 14:34
Copy link
Copy Markdown
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

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

utACK f47addd

Thanks for getting this fixed so fast, code looks good to me but I would like someone besides me to review before merging.

@luisschwab
Copy link
Copy Markdown
Member

I'll take a look in a bit

Copy link
Copy Markdown
Member

@luisschwab luisschwab left a comment

Choose a reason for hiding this comment

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

ACK f47addd

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

Labels

bug Something isn't working

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

4 participants