Add wallet birthday height for seed recovery on pruned nodes#822
Add wallet birthday height for seed recovery on pruned nodes#822FreeOnlineUser wants to merge 2 commits intolightningdevkit:mainfrom
Conversation
|
I've assigned @tnull as a reviewer! |
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
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.
5f532f9 to
caa173d
Compare
|
🔔 1st Reminder Hey @tnull! This PR has been waiting for your review. |
|
🔔 2nd Reminder Hey @tnull! This PR has been waiting for your review. |
|
🔔 3rd Reminder Hey @tnull! This PR has been waiting for your review. |
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