From d40da2b671ed51e565ea7f2ce1137534ce27a6f1 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 31 Mar 2025 11:25:19 +1030 Subject: [PATCH] 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 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 --- lightningd/opening_control.c | 8 +++++++- tests/test_closing.py | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 372cad2f5..20461cba0 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -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); diff --git a/tests/test_closing.py b/tests/test_closing.py index bd09de3ae..ac60117e7 100644 --- a/tests/test_closing.py +++ b/tests/test_closing.py @@ -4277,7 +4277,6 @@ def test_onchain_slow_anchor(node_factory, bitcoind): l1.daemon.wait_for_log(r"Low-priority anchorspend aiming for block {} \(feerate 7500\)".format(height + 12)) -@pytest.mark.xfail(strict=True) @unittest.skipIf(TEST_NETWORK != 'regtest', "elementsd doesn't use p2tr anyway") def test_onchain_close_no_p2tr(node_factory, bitcoind): """Closing with a peer which doesn't support OPT_SHUTDOWN_ANYSEGWIT"""