From af71fd689ad21f4ce28260b42358e40f76a58698 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 24 Jul 2023 12:38:50 +0930 Subject: [PATCH] onchaind: keep trying to collect HTLC even if we're past timeout. The test actually triggers this: 1. We don't get our commitment tx mined at all (we block it). 2. By the time the peer does, the HTLC is expired. 3. We have the preimage but we don't even try, since it's expired. We should at least *try* to collect the HTLC in this case. Signed-off-by: Rusty Russell --- onchaind/onchaind.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index 46f56468c..729b23e69 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -1499,12 +1499,16 @@ static void handle_preimage(struct tracked_output **outs, if (!ripemd160_eq(&outs[i]->htlc.ripemd, &ripemd)) continue; - /* Too late? */ + /* If HTLC has timed out, we will already have + * proposed a "ignore this, it's their problem". But + * now try this proposal instead! */ if (outs[i]->resolved) { - status_broken("HTLC already resolved by %s" - " when we found preimage", - tx_type_name(outs[i]->resolved->tx_type)); - return; + if (outs[i]->resolved->tx_type != SELF) { + status_broken("HTLC already resolved by %s" + " when we found preimage", + tx_type_name(outs[i]->resolved->tx_type)); + return; + } } /* stash the payment_hash so we can track this coin movement */