Skip to content

fix(rpc): error when the node lacks our genesis, and a README from #2244 - #2398

Open
evanlinjin wants to merge 2 commits into
bitcoindevkit:masterfrom
evanlinjin:dv/replace-2244
Open

evanlinjin wants to merge 2 commits into
bitcoindevkit:masterfrom
evanlinjin:dv/replace-2244

Conversation

@evanlinjin

Copy link
Copy Markdown
Contributor

Description

The parts of #2244 that don't depend on moving to bdk_bitcoind_client, on top of bitcoincore-rpc:

  • Error when the node doesn't have our genesis (Emitter silently replaces the caller’s genesis on a network mismatch #2290). With a node on another network, Emitter replaced its checkpoint chain with the node's genesis and kept emitting blocks that don't connect to the caller's chain. next_block now returns the node's "not found" RPC error instead. This is fix(bitcoind_rpc): surface RPC error on genesis mismatch #2365's approach: it isn't breaking, and it covers every last_cp from a LocalChain (which always has genesis). A hand-built last_cp without genesis still re-roots, which is the right recovery after a re-org deeper than all of its checkpoints.
  • README. It's now the crate doc (include_str!, as for bdk_esplora), keeps the trust section, and has a usage example syncing a LocalChain.

Compared with #2244, this keeps bitcoincore-rpc and the current Emitter::new signature, and leaves out EmitterError, the connected_to() fallback and the NO_EXPECTED_MEMPOOL_TXS removal. Emitter never emits a checkpoint without a previous one, so that fallback only affected hand-built events. The constant is what lets an empty expected_mempool_txs infer its item type, so it stays. It also leaves out the generic checkpoint data (#2105), the start_height builder and the electrsd/bitcoind bump.

Replaces #2244
Fixes #2290

Changelog notice

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

🤖 Generated with Claude Code

evanlinjin and others added 2 commits October 19, 2026 20:28
When the node didn't have `last_cp`'s genesis (e.g. it's on another
network), `Emitter` replaced its checkpoint chain with the node's
genesis and kept emitting. The emitted checkpoints then no longer
connected to the caller's chain.

`Emitter::next_block` now returns the node's "not found" RPC error
instead.

Fixes bitcoindevkit#2290

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The README is now the crate doc (`include_str!`), as for `bdk_esplora`
and `bdk_file_store`, so crates.io and docs.rs show the same text. It
keeps the old crate docs (including the trust section) and adds an
example syncing a `LocalChain` from `Emitter`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-project-automation github-project-automation Bot moved this to Triage in BDK Chain Oct 19, 2026
@evanlinjin
evanlinjin marked this pull request as ready for review October 19, 2026 10:20
@evanlinjin
evanlinjin requested a review from a team as a code owner October 19, 2026 10:20
@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.17%. Comparing base (634b42c) to head (66dc95c).

Files with missing lines Patch % Lines
crates/bitcoind_rpc/src/lib.rs 0.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2398      +/-   ##
==========================================
- Coverage   80.26%   80.17%   -0.10%     
==========================================
  Files          31       31              
  Lines        6168     6179      +11     
  Branches      292      293       +1     
==========================================
+ Hits         4951     4954       +3     
- Misses       1147     1152       +5     
- Partials       70       73       +3     
Flag Coverage Δ
rust 80.17% <0.00%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tvpeter tvpeter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tACK 66dc95c

Thank you for working on this.

nit: for the same situation, FilterIter::find_base returns Error::ReorgDepthExceeded, so the two emitters in this crate report a network mismatch differently.

Out of curiosity I looked at how Bitcoin Core handles a wallet attached to a node on another chain. In CWallet::AttachChain (bitcoin/bitcoin#18554) it compares the wallet's stored genesis with the node's genesis up front, and refuses to load the wallet if they differ. This is a single comparison, done before any fork-finding.

This PR reaches the same result, but only after poll_once has called getblock on every checkpoint in last_cp. A LocalChain synced through the Emitter holds one checkpoint per block, so on a node from another network the number of RPC calls grows linearly with the chain (O(n)).

Checking genesis once the tip fails to match will bring this down to 2 RPC calls at any chain size. The normal path is unchanged, and the error this PR documents is kept. I don't think this should block the PR, so I will open an issue as a follow-up.

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.

Emitter silently replaces the caller’s genesis on a network mismatch

2 participants