From 7a04595269d69cfff52dd68e025c5c234e5556e4 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 20 Aug 2018 10:33:30 -0400 Subject: [PATCH 1/1] Only enforce no-dup-payment_hash precondition on non-removed HTLCs This fixes a panic found by fuzzer. --- src/ln/channel.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ln/channel.rs b/src/ln/channel.rs index c7c3208e..76d45dd7 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -1018,7 +1018,8 @@ impl Channel { let mut pending_idx = std::usize::MAX; for (idx, htlc) in self.pending_htlcs.iter().enumerate() { - if !htlc.outbound && htlc.payment_hash == payment_hash_calc { + if !htlc.outbound && htlc.payment_hash == payment_hash_calc && + htlc.state != HTLCState::LocalRemoved && htlc.state != HTLCState::LocalRemovedAwaitingCommitment { if pending_idx != std::usize::MAX { panic!("Duplicate HTLC payment_hash, ChannelManager should have prevented this!"); } @@ -1070,9 +1071,8 @@ impl Channel { // hopefully never happens. Instead, we make sure we get the preimage into the // channel_monitor and pretend we didn't just see the preimage. return Ok((None, Some(self.channel_monitor.clone()))); - } else if htlc.state == HTLCState::LocalRemoved || htlc.state == HTLCState::LocalRemovedAwaitingCommitment { - return Err(HandleError{err: "Unable to find a pending HTLC which matched the given payment preimage", action: None}); } else { + // LocalRemoved/LocalRemovedAwaitingCOmmitment handled in the search loop panic!("Have an inbound HTLC when not awaiting remote revoke that had a garbage state"); } htlc.htlc_id -- 2.30.2