From 6c96bcacd763cf5cd81226e3b161be161c3818ed Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 9 Oct 2018 19:28:52 +1030 Subject: [PATCH] lightningd: fix inconsistency without COMPAT enabled. We don't expect payment or payment->route_channels to be NULL without an old db, but putting an assert there reveals that we try to fail an HTLC which has already succeeded in 'test_onchain_unwatch'. Obviously we only want to fail an HTLC which goes onchain if we don't already have the preimage! Signed-off-by: Rusty Russell --- lightningd/pay.c | 3 +++ lightningd/peer_htlcs.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lightningd/pay.c b/lightningd/pay.c index c0545ad14..4d511160a 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -482,6 +482,9 @@ void payment_failed(struct lightningd *ld, const struct htlc_out *hout, PAYMENT_FAILED, NULL); return; } +#else + assert(payment); + assert(payment->route_channels); #endif /* This gives more details than a generic failure message */ diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 3d691e37c..c03c9d4cb 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -860,8 +860,8 @@ void onchain_failed_our_htlc(const struct channel *channel, struct lightningd *ld = channel->peer->ld; struct htlc_out *hout = find_htlc_out_by_ripemd(channel, &htlc->ripemd); - /* Don't fail twice! */ - if (hout->failuremsg || hout->failcode) + /* Don't fail twice (or if already succeeded)! */ + if (hout->failuremsg || hout->failcode || hout->preimage) return; hout->failcode = WIRE_PERMANENT_CHANNEL_FAILURE;