Skip to content

Allow wallet imports from arbitrary heights, forcing full scans#884

Open
tnull wants to merge 3 commits into
lightningdevkit:mainfrom
tnull:2026-04-abort-on-first-startup-tip-fetch-failure
Open

Allow wallet imports from arbitrary heights, forcing full scans#884
tnull wants to merge 3 commits into
lightningdevkit:mainfrom
tnull:2026-04-abort-on-first-startup-tip-fetch-failure

Conversation

@tnull

@tnull tnull commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Fixes #818.

Previously, we would always start syncing from the latest block height or were able to force a full-resync from genesis via recovery_mode = true. Here we add more fine-grained control and allow an initial wallet import from a known birthday height for bitcoind RPC/REST chain sources. Relatedly, we also fix a minor bug where, if we failed to retrieve the tip hash on first startup, we'd always resync from genesis, which can be very costly.

Moreover, we also add a flag that allows the user to force a full scan for Esplora/Electrum wallets.

@tnull tnull added this to the 0.8 milestone Apr 21, 2026
@ldk-reviews-bot

ldk-reviews-bot commented Apr 21, 2026

Copy link
Copy Markdown

I've assigned @wpaulino as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@tnull tnull marked this pull request as draft April 21, 2026 13:06
@tnull tnull force-pushed the 2026-04-abort-on-first-startup-tip-fetch-failure branch from c692081 to 608108a Compare April 21, 2026 13:07
tnull added 3 commits June 26, 2026 12:21
When a fresh node's bitcoind RPC/REST chain source fails to return the
current chain tip, we previously silently fell back to the genesis
block as the wallet birthday. The next successful startup would then
force a full-history rescan of the whole chain. Instead, return a new
BuildError::ChainTipFetchFailed on the first build so the
misconfiguration surfaces immediately and no stale fresh state is
persisted.

Restarts with a previously-persisted wallet are unaffected: a
transient chain source outage on an existing node still allows startup
to proceed. Esplora/Electrum backends currently never expose a tip at
build time so the guard only fires for bitcoind sources; the latent
wallet-birthday-at-genesis issue on those backends is left for a
follow-up.

Co-Authored-By: HAL 9000
Allow Bitcoin Core RPC and REST chain-source configuration to specify
the wallet birthday height used when creating a fresh wallet. This lets
restored wallets rescan from a known height, including genesis, without
overloading a global recovery toggle.

Reject requested heights above the current chain tip with an explicit
build error before wallet state is created. Existing wallets are not
rewound by this option because a safe rewind must invalidate persisted
wallet and LDK state before replaying blocks.

Co-Authored-By: HAL 9000
Let Esplora and Electrum sync configs request BDK full scans
until one succeeds. This keeps recovery scans retryable after
transient sync failures while preserving normal incremental syncs
once recovery has completed.

Co-Authored-By: HAL 9000
@tnull tnull force-pushed the 2026-04-abort-on-first-startup-tip-fetch-failure branch from 608108a to 494a448 Compare June 26, 2026 12:19
@tnull tnull changed the title 2026 04 abort on first startup tip fetch failure Allow wallet imports from arbitrary heights, forcing full scans Jun 26, 2026
@tnull tnull marked this pull request as ready for review June 26, 2026 12:25
@ldk-reviews-bot ldk-reviews-bot requested a review from wpaulino June 26, 2026 12:25
@tnull

tnull commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased & refactored a bit, ready for review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wallet birthday height for seed recovery on pruned nodes

2 participants