lightningd: scan outputs for BIP86 addresses

This commit fixes an issue where BIP86 addresses were not being
discovered during wallet recovery/rescan operations.

The root cause was that init_txfilter() only populated the transaction
filter with BIP32-derived keys, preventing lightningd from recognizing
BIP86 UTXOs during blockchain scans. Now both BIP32 and BIP86 derived
scripts are included in the filter when BIP86 derivation is enabled.

This ensures that wallets restored from BIP39 mnemonics can properly
discover and display previously funded BIP86 addresses without requiring
manual address generation first.

[ We also move the slightly-lost comment about libbacktrace so it is
  where we actually include <backtrace.h> --RR ]
This commit is contained in:
Sangbida Chaudhuri
2025-10-24 13:57:47 +10:30
committed by Rusty Russell
parent 7f3a57cc41
commit 249fa03674
4 changed files with 41 additions and 6 deletions

View File

@@ -148,6 +148,12 @@ static void our_addresses_add_for_index(struct wallet *w, u32 i)
/* FIXME: We could deprecate P2SH once we don't see
* any, since we stopped publishing them in 24.02 */
if (!wallet_get_addrtype(w, i, &addrtype)) {
if (w->ld->bip86_base) {
/* Derive and add BIP86 script for this index */
our_addresses_add_bip86_for_index(w, i);
return;
}
const u8 *addr;
scriptpubkey = scriptpubkey_p2wpkh_derkey(NULL, ext.pub_key);
addr = scriptpubkey_p2sh(NULL, scriptpubkey);
@@ -205,7 +211,17 @@ static void our_addresses_init(struct wallet *w)
w->our_addresses_maxindex = 0;
w->our_addresses = new_htable(w, wallet_address_htable);
our_addresses_add_for_index(w, w->our_addresses_maxindex);
/* If BIP86 is enabled, prefill the address table up to keyscan_gap so
* rescans immediately include BIP86 scripts without needing prior
* address allocations. */
if (w->ld->bip86_base) {
for (u32 i = 0; i <= w->keyscan_gap; i++) {
our_addresses_add_for_index(w, i);
}
w->our_addresses_maxindex = w->keyscan_gap;
} else {
our_addresses_add_for_index(w, w->our_addresses_maxindex);
}
}
static void outpointfilters_init(struct wallet *w)