lightningd: use BIP86 derivation in p2wpkh_for_keyidx when available

When a peer doesn't support OPT_SHUTDOWN_ANYSEGWIT, we fall back to P2WPKH for the shutdown script. For BIP86 wallets, we need to use bip86_pubkey for derivation (matching p2tr_for_keyidx), otherwise the resulting script won't be recognized after restart.
This commit is contained in:
Sangbida Chaudhuri
2026-01-13 22:52:12 +10:30
committed by Rusty Russell
parent 4106a212ec
commit c17590379e

View File

@@ -203,7 +203,12 @@ u8 *p2wpkh_for_keyidx(const tal_t *ctx, struct lightningd *ld, u64 keyidx)
{
struct pubkey shutdownkey;
bip32_pubkey(ld, &shutdownkey, keyidx);
/* Use BIP86 derivation if wallet has BIP86 base, otherwise use BIP32 */
if (ld->bip86_base) {
bip86_pubkey(ld, &shutdownkey, keyidx);
} else {
bip32_pubkey(ld, &shutdownkey, keyidx);
}
return scriptpubkey_p2wpkh(ctx, &shutdownkey);
}