From 1a1696f2f938ed849b56d2e2f2e4eb7c61039f97 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 4 Jun 2024 17:12:09 +0930 Subject: [PATCH] lightningd: don't try to "save" incoming channel by closing early if incoming already onchain. From test_penalty_htlc_tx_timeout[False] flake (with keys replaced by l2 and l5, for clarity) ``` lightningd-3 2024-06-04T04:34:00.942Z UNUSUAL l2-chan#1: Peer permanent failure in CHANNELD_NORMAL: Funding transaction spent lightningd-3 2024-06-04T04:34:01.570Z UNUSUAL l5-chan#3: Peer permanent failure in CHANNELD_NORMAL: Funding transaction spent lightningd-3 2024-06-04T04:34:01.655Z UNUSUAL l5-chan#3: Abandoning unresolved onchain HTLC at block 132 (expired at 125) to avoid peer closing incoming HTLC at block 131 lightningd-3 2024-06-04T04:34:02.802Z **BROKEN** l5-chan#3: FUNDS LOSS of 50000000msat: peer took funds onchain before we could time out the HTLC, but we abandoned incoming HTLC to save the incoming channel ``` So, we were already closing l2, no reason to abandon it. Signed-off-by: Rusty Russell --- lightningd/peer_htlcs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 9f8dd798e..37b51e4eb 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -2700,6 +2700,10 @@ static void consider_failing_incoming(struct lightningd *ld, if (height + 3 < hout->in->cltv_expiry) return; + /* Unless incoming is already onchain, then it can't get worse! */ + if (!channel_state_can_remove_htlc(hout->in->key.channel->state)) + return; + log_unusual(hout->key.channel->log, "Abandoning unresolved onchain HTLC at block %u" " (expired at %u) to avoid peer closing incoming HTLC at block %u",