From 599113e99089df828261066a469149a9c497fa1e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 10 Mar 2021 19:59:06 +1030 Subject: [PATCH] onchaind: see closes when wrong_funding shutdowns are used. Fairly easy to do, though we also have to add the watch when we load from the database. Signed-off-by: Rusty Russell --- lightningd/channel_control.c | 3 +++ lightningd/peer_control.c | 13 +++++++++++++ lightningd/peer_control.h | 2 ++ tests/test_closing.py | 5 ++--- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index e6ba176b87ee..738096b659db 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -264,6 +264,9 @@ static void peer_got_shutdown(struct channel *channel, const u8 *msg) if (!channel->shutdown_wrong_funding) channel->shutdown_wrong_funding = wrong_funding; + /* We now watch the "wrong" funding, in case we spend it. */ + channel_watch_wrong_funding(ld, channel); + /* TODO(cdecker) Selectively save updated fields to DB */ wallet_channel_save(ld->wallet, channel); } diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 8946a9c65382..17b6d7278b61 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1353,6 +1353,18 @@ static enum watch_result funding_spent(struct channel *channel, return onchaind_funding_spent(channel, tx, block->height, false); } +void channel_watch_wrong_funding(struct lightningd *ld, struct channel *channel) +{ + /* Watch the "wrong" funding too, in case we spend it. */ + if (channel->shutdown_wrong_funding) { + /* FIXME: Remove arg from cb? */ + watch_txo(channel, ld->topology, channel, + &channel->shutdown_wrong_funding->txid, + channel->shutdown_wrong_funding->n, + funding_spent); + } +} + void channel_watch_funding(struct lightningd *ld, struct channel *channel) { /* FIXME: Remove arg from cb? */ @@ -1361,6 +1373,7 @@ void channel_watch_funding(struct lightningd *ld, struct channel *channel) watch_txo(channel, ld->topology, channel, &channel->funding_txid, channel->funding_outnum, funding_spent); + channel_watch_wrong_funding(ld, channel); } static void json_add_peer(struct lightningd *ld, diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index cf8843274663..b2cc8fadf264 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -87,6 +87,8 @@ void activate_peers(struct lightningd *ld); void drop_to_chain(struct lightningd *ld, struct channel *channel, bool cooperative); void channel_watch_funding(struct lightningd *ld, struct channel *channel); +/* If this channel has a "wrong funding" shutdown, watch that too. */ +void channel_watch_wrong_funding(struct lightningd *ld, struct channel *channel); struct amount_msat channel_amount_receivable(const struct channel *channel); diff --git a/tests/test_closing.py b/tests/test_closing.py index b3be1df038a3..5fbac8a911d2 100644 --- a/tests/test_closing.py +++ b/tests/test_closing.py @@ -2738,6 +2738,5 @@ def test_shutdown_alternate_txid(node_factory, bitcoind): # We will see our funds return. assert len(l1.rpc.listfunds()['outputs']) == 1 - # FIXME: we should close channels, but we don't! - # wait_for(lambda: l2.rpc.listpeers()['peers'] == []) - # wait_for(lambda: l1.rpc.listpeers()['peers'] == []) + wait_for(lambda: l2.rpc.listpeers()['peers'] == []) + wait_for(lambda: l1.rpc.listpeers()['peers'] == [])