From: Matt Corallo Date: Mon, 20 Aug 2018 14:33:30 +0000 (-0400) Subject: Only enforce no-dup-payment_hash precondition on non-removed HTLCs X-Git-Tag: v0.0.12~345^2~5 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=7a04595269d69cfff52dd68e025c5c234e5556e4;p=rust-lightning Only enforce no-dup-payment_hash precondition on non-removed HTLCs This fixes a panic found by fuzzer. --- diff --git a/src/ln/channel.rs b/src/ln/channel.rs index c7c3208e7..76d45dd71 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