From 7e062fd6378b2362f2ca37895dbd91d8bbea3690 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 2 Jan 2018 14:18:22 +1030 Subject: [PATCH] onchaind: don't assert() when htlc fulfilled twice. In the normal (peer-to-peer) path, the HTLC state prevents us fulfilling twice, but this goes out the window with onchain HTLCs. The actual assert which caught it was lightningd/pay.c:70 (payment_succeeded) in the test_htlc_in_timeout test, after the next commit. So add an assert earlier (in fulfill_our_htlc_out) and check in the one caller where it can be true. Signed-off-by: Rusty Russell --- lightningd/peer_htlcs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 0d98685d6..828823fcd 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -651,6 +651,7 @@ out: static void fulfill_our_htlc_out(struct peer *peer, struct htlc_out *hout, const struct preimage *preimage) { + assert(!hout->preimage); hout->preimage = tal_dup(hout, struct preimage, preimage); htlc_out_check(hout, __func__); @@ -700,7 +701,11 @@ void onchain_fulfilled_htlc(struct peer *peer, const struct preimage *preimage) if (!structeq(&hout->payment_hash, &payment_hash)) continue; - fulfill_our_htlc_out(peer, hout, preimage); + /* We may have already fulfilled before going onchain, or + * we can fulfill onchain multiple times. */ + if (!hout->preimage) + fulfill_our_htlc_out(peer, hout, preimage); + /* We keep going: this is something of a leak, but onchain * we have no real way of distinguishing HTLCs anyway */ }