From e82f0c42f3670a97b94eaccfaaedc893f955db6e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 1 Apr 2025 14:01:11 +1030 Subject: [PATCH] lightningd: don't spam logs on dangling outgoing HTLCs. We pre-close incoming under some circumstances, so this does happen (it didn't when this code was written). Don't walk all the HTLCs complaining about them in this case, and don't freak out. Changelog-Fixed: lightningd: incorrect spamming of log and potential crash on testnet case of duplicate HTLCs and slow closing. Signed-off-by: Rusty Russell Fixes: https://github.com/ElementsProject/lightning/issues/8176 --- lightningd/peer_htlcs.c | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 8bfb9afa4..8d06d891d 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -1704,41 +1704,6 @@ static void check_already_failed(const struct channel *channel, struct htlc_out } } -/* This case searches harder to see if there are any incoming HTLCs */ -static void fail_dangling_htlc_in(struct lightningd *ld, - const struct sha256 *payment_hash) -{ - struct htlc_in *hin; - struct htlc_in_map_iter ini; - - for (hin = htlc_in_map_first(ld->htlcs_in, &ini); - hin; - hin = htlc_in_map_next(ld->htlcs_in, &ini)) { - if (!sha256_eq(&hin->payment_hash, payment_hash)) - continue; - if (hin->badonion) { - log_broken(hin->key.channel->log, - "htlc %"PRIu64" already failed with badonion", - hin->key.id); - } else if (hin->preimage) { - log_broken(hin->key.channel->log, - "htlc %"PRIu64" already succeeded with preimage", - hin->key.id); - } else if (hin->failonion) { - log_broken(hin->key.channel->log, - "htlc %"PRIu64" already failed with failonion %s", - hin->key.id, - tal_hex(tmpctx, hin->failonion->contents)); - } else { - log_broken(hin->key.channel->log, - "htlc %"PRIu64" has matching hash: failing", - hin->key.id); - local_fail_in_htlc(hin, - take(towire_permanent_channel_failure(NULL))); - } - } -} - void onchain_failed_our_htlc(const struct channel *channel, const struct htlc_stub *htlc, const char *why, @@ -1841,7 +1806,6 @@ void onchain_failed_our_htlc(const struct channel *channel, /* Immediate corruption sanity check if this happens */ htable_check(&ld->htlcs_out->raw, "onchain_failed_our_htlc out"); htable_check(&ld->htlcs_in->raw, "onchain_failed_our_htlc in"); - fail_dangling_htlc_in(ld, &hout->payment_hash); } }