]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Fix crash introduced in #124
authorMatt Corallo <git@bluematt.me>
Fri, 24 Aug 2018 15:52:55 +0000 (11:52 -0400)
committerMatt Corallo <git@bluematt.me>
Fri, 24 Aug 2018 20:58:27 +0000 (16:58 -0400)
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

src/ln/channel.rs

index 47c05de2ab989ab69c00a8f219efb63adebb527a..d6e23a2839274fc5b84ecbc0e7e2d870469bbb0d 100644 (file)
@@ -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 {