Add wallet birthday height for seed recovery on pruned nodes#822
Draft
FreeOnlineUser wants to merge 2 commits intolightningdevkit:mainfrom
Draft
Add wallet birthday height for seed recovery on pruned nodes#822FreeOnlineUser wants to merge 2 commits intolightningdevkit:mainfrom
FreeOnlineUser wants to merge 2 commits intolightningdevkit:mainfrom
Conversation
When set_wallet_birthday_height(height) is called, the BDK wallet checkpoint is set to the birthday block instead of the current chain tip. This allows the wallet to sync from the birthday forward, recovering historical UTXOs without scanning from genesis. This is critical for pruned nodes where blocks before the birthday are unavailable, making recovery_mode (which scans from genesis) unusable. Three-way logic: - Birthday set: checkpoint at birthday block - No birthday, no recovery mode: checkpoint at current tip (existing) - Recovery mode without birthday: sync from genesis (existing) Falls back to current tip if the birthday block hash cannot be fetched. Resolves the TODO: 'Use a proper wallet birthday once BDK supports it.' Closes lightningdevkit#818
|
👋 Hi! I see this is a draft PR. |
Extend get_block_hash_by_height to work with Esplora and Electrum in addition to bitcoind. Esplora uses its native get_block_hash API. Electrum uses block_header_raw and extracts the hash from the header. For Electrum, if the runtime client hasn't started yet (called during build), a temporary connection is created for the lookup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
set_wallet_birthday_height(height)to the builder, allowing the on-chain wallet to sync from a specific block height instead of the current tip or genesis.This complements the existing
set_wallet_recovery_mode()from #769 by supporting pruned nodes where scanning from genesis fails due to missing blocks.Motivation
When restoring a wallet from seed on a pruned node:
recovery_mode(scan from genesis) fails: blocks are prunedWith a birthday height, the wallet checkpoints at a known block before the first transaction, recovering funds without needing the full chain.
How it works
Three-way logic in wallet creation:
Falls back to current tip if the birthday block hash cannot be fetched.
Real-world use
Built and verified in Bitcoin Pocket Node, an Android app running bitcoind + ldk-node on GrapheneOS with pruned storage. Recovery flow:
scantxoutsetto find UTXOs and their block heightsmin(heights) - 10Tested end-to-end on real hardware: 10,844 sats recovered in seconds.
Closes #818