From: Matt Corallo Date: Fri, 24 Aug 2018 15:52:55 +0000 (-0400) Subject: Fix crash introduced in #124 X-Git-Tag: v0.0.12~339^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=4f77c812a4b0e42454cb92b8b460dfa1323016cb;p=rust-lightning Fix crash introduced in #124 I'm rapidly starting to regret holding failed HTLCs in Channel, given we allow them to violate the no-duplicate-hashes precondition. Found by fuzzer --- diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 47c05de2a..d6e23a283 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -1018,10 +1018,13 @@ impl Channel { for (idx, htlc) in self.pending_htlcs.iter().enumerate() { 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!"); + if let Some(PendingHTLCStatus::Fail(_)) = htlc.pending_forward_state { + } else { + if pending_idx != std::usize::MAX { + panic!("Duplicate HTLC payment_hash, ChannelManager should have prevented this!"); + } + pending_idx = idx; } - pending_idx = idx; } } if pending_idx == std::usize::MAX {