Skip to content

Explicitly persist wallet birthday - #1250

Open
tnull wants to merge 2 commits into
lightningdevkit:mainfrom
tnull:2026-11-persist-wallet-birthday
Open

tnull wants to merge 2 commits into
lightningdevkit:mainfrom
tnull:2026-11-persist-wallet-birthday

Conversation

@tnull

@tnull tnull commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

When creating a new on-chain wallet, we insert a first checkpoint as
its birthday, but never persisted it explicitly. It only reached the
store because filling the address pool later in the build happens to
flush the wallet's staged changes. Without that side effect, a node
restarted before its first sync would reload the wallet at genesis and
try to rescan the whole chain, which never succeeds against a pruned
bitcoind.

We now persist the wallet right after applying the checkpoint, failing
the build if that doesn't succeed, so the birthday no longer depends
on unrelated wallet persistence.

@tnull tnull added this to the 0.8 milestone Nov 19, 2026
@tnull
tnull requested a review from tankyleo November 19, 2026 10:35
@ldk-reviews-bot

ldk-reviews-bot commented Nov 19, 2026 •

Copy link
Copy Markdown

👋 Thanks for assigning @tankyleo 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.

@tankyleo tankyleo 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.

Could we persist the checkpoint as part of the first write of the wallet? I had codex generate this commit here for illustration: tankyleo@6afa6af

This would avoid persisting an intermediate genesis-only wallet when we intend to start from a later checkpoint. Otherwise, a crash or failed write between wallet creation and checkpoint persistence can leave the wallet starting from genesis on the next build.

When creating a new on-chain wallet, we first persisted it at genesis
and only then inserted the checkpoint acting as its birthday, which was
never persisted explicitly. It only reached the store because filling
the address pool later in the build happens to flush the wallet's
staged changes. A crash or failed write in between left a persisted
wallet that reloads at genesis and tries to rescan the whole chain,
which never succeeds against a pruned bitcoind.

We now apply the checkpoint before the wallet is first persisted, so
that its initial state always includes the birthday. As BDK can't turn
a wallet created in memory into a persisted one, we write that state
ourselves and load the wallet back from the persister.

Reported-by: vnprclanker
Co-Authored-By: HAL 9000
Nothing covered that a node restarted between its first build and its
first wallet sync keeps the wallet birthday rather than rescanning
from genesis, nor that a rejected build leaves no wallet behind.

We add an integration test that builds a fresh node against bitcoind,
drops it before it syncs, and checks that the wallet's chain state was
written exactly once and that the rebuilt node doesn't pick up a
payment confirmed before its birthday. It covers the RPC and REST
chain sources, with and without an explicit rescan height.

Co-Authored-By: HAL 9000
@tnull
tnull force-pushed the 2026-11-persist-wallet-birthday branch from 1eaaa38 to 58941dd Compare November 23, 2026 09:39
@tnull

tnull commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

Could we persist the checkpoint as part of the first write of the wallet? I had codex generate this commit here for illustration: tankyleo@6afa6af

This would avoid persisting an intermediate genesis-only wallet when we intend to start from a later checkpoint. Otherwise, a crash or failed write between wallet creation and checkpoint persistence can leave the wallet starting from genesis on the next build.

Alright, adopted that approach.

@tnull
tnull requested a review from tankyleo November 23, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants