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 <rusty@rustcorp.com.au>
Fixes: https://github.com/ElementsProject/lightning/issues/8176
This commit is contained in:
Rusty Russell
2025-04-01 14:01:11 +10:30
parent 19f76e1f1f
commit e82f0c42f3

View File

@@ -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);
}
}