lightningd: make sure we register all addresses at opening if peer doesn't support OPT_SHUTDOWN_ANYSEGWIT.

We select the close key index at opening time, but the non-DF code didn't correctly register the
address as possibly used for P2WPKH for older nodes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: wallet: we could miss our own returned outputs on mutual closes if peer doesn't support option_shutdown_anysegwit (you will still need to rescan after update, if this happened to you!)
Reported-by: Grubles
This commit is contained in:
Rusty Russell
2025-03-31 11:25:19 +10:30
parent 46690cb2a6
commit d40da2b671
2 changed files with 7 additions and 2 deletions

View File

@@ -122,8 +122,14 @@ wallet_commit_channel(struct lightningd *ld,
/* FIXME: P2TR for elements! */
if (chainparams->is_elements)
addrtype = ADDR_BECH32;
else
else if (feature_negotiated(ld->our_features,
uc->peer->their_features,
OPT_SHUTDOWN_ANYSEGWIT))
addrtype = ADDR_P2TR;
else
/* They *may* update to OPT_SHUTDOWN_ANYSEGWIT by the
* time we close, so be prepared for both. */
addrtype = ADDR_ALL;
/* Get a key to use for closing outputs from this tx */
final_key_idx = wallet_get_newindex(ld, addrtype);