Repository navigation
Conversation
tankyleo
commented
Dec 4, 2026
For wallets using Bitcoin Core, a reorg that removes the birthday checkpoint can leave BDK unable to connect replacement blocks to its saved checkpoints. The wallet then stops tracking the active chain: incoming payments can go undiscovered and balances can remain stale. Restarting reloads the same orphaned checkpoint, leaving the user needing wallet recovery. Using the current tip as the birthday exposes a newly created wallet to this failure after even a one-block reorg, including before its first sync. Avoiding historical scanning should not make ordinary chain reorganizations require user intervention. We budget for reorgs of up to 10 blocks. Accepting up to 10 additional blocks of initial scanning gives the wallet a checkpoint outside that window. This bounded startup cost is preferable to leaving a fresh wallet unable to synchronize until recovered. Co-Authored-By: Codex
Requesting a recent rescan height should not leave a new Bitcoin Core wallet more vulnerable to reorgs than using the default. If its birthday checkpoint is removed, the wallet can stop following the active chain. Restarting reloads the same checkpoint, leaving the user needing wallet recovery. Treat the requested height as history we must include, while retaining at least the same 10-block margin as the default. Scanning a little extra history is preferable to requiring wallet recovery after an ordinary reorg, and earlier requests must never lose any requested history. A fresh wallet therefore needs a known chain tip even when an explicit rescan height is supplied. Co-Authored-By: Codex
|
👋 Thanks for assigning @tnull as a reviewer! |
tnull
left a comment
There was a problem hiding this comment.
No blockers from my side, a few comments:
-
tests/integration_tests_rust.rs:2885-2887: The comment says finding the payments "must now depend on the explicit, inclusive rescan height" after mining 10 more blocks, but nothing asserts that. Could we build a default-config node at that point and check that it sees a zero balance? -
src/builder.rs:125: Rather than a bare10, could we deriveWALLET_BIRTHDAY_BLOCK_BUFFERfromANTI_REORG_DELAY * 2? That is the depth ofBlockLocator::previous_blocks, i.e., how deep a reorg LDK's own listeners can lose their tip and still find a known ancestor, so the wallet
would get the same tolerance for a stated reason. It would mean updating the "10 blocks" wording in the four builder doc comments and the changelog, plus the block counts the tests are built around. -
src/builder.rs:1924-1951: A fresh wallet without a rescan height now needs aget_block_hash_by_heightcall after the tip fetch. If that fails we returnWalletSetupFailedrather thanChainTipFetchFailed, although the cause is the same kind of backend problem. Should we map it to
the same error, or at least document it? -
src/builder.rs:1903:chain_tip_opt.ok_or(BuildError::ChainTipFetchFailed)?can never fire: the guard at:1876already returns for bitcoind without a tip, and a rescan height can only be set with bitcoind. Harmless, but it is an unlogged duplicate of the logged path above. -
tests/integration_tests_rust.rs:2889-2890: "both transactions are found 11 blocks after the configured rescan height" is now about 21 blocks given the extra 10 mined just above. "Retaining the previous test's case" also describes history rather than what the test does. -
Docs/changelog: A reorg that goes deeper than the buffer before the wallet has synced past its checkpoint still leaves
apply_block_eventsfailing inWallet::block_connected(src/wallet/mod.rs:4655-4665), with only an error log per block. That is pre-existing and this PR narrows the
window considerably, but could we mention that the protection is bounded?
Also, did you confirm that wallet_birthday_margin_survives_reorg fails on main?
|
All comments should be addressed in these fixups thank you.
Yes confirmed here. |