]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Fix crash that #127 intended to fix but did not completely fix
authorMatt Corallo <git@bluematt.me>
Thu, 30 Aug 2018 16:35:52 +0000 (12:35 -0400)
committerMatt Corallo <git@bluematt.me>
Thu, 30 Aug 2018 16:37:21 +0000 (12:37 -0400)
Introduced in #124, and found by fuzzer

src/ln/channel.rs

index f890f03968903b137b99e34db09f6f4e4f4890ee..14a5589e7891ab661f275c74e8e292077b4d83c3 100644 (file)
@@ -1133,9 +1133,6 @@ impl Channel {
                let mut htlc_amount_msat = 0;
                for htlc in self.pending_htlcs.iter_mut() {
                        if !htlc.outbound && htlc.payment_hash == *payment_hash_arg {
-                               if htlc_id != 0 {
-                                       panic!("Duplicate HTLC payment_hash, you probably re-used payment preimages, NEVER DO THIS!");
-                               }
                                if htlc.state == HTLCState::Committed {
                                        htlc.state = HTLCState::LocalRemoved;
                                } else if htlc.state == HTLCState::RemoteAnnounced {
@@ -1152,6 +1149,9 @@ impl Channel {
                                } else {
                                        panic!("Have an inbound HTLC when not awaiting remote revoke that had a garbage state");
                                }
+                               if htlc_id != 0 {
+                                       panic!("Duplicate HTLC payment_hash, you probably re-used payment preimages, NEVER DO THIS!");
+                               }
                                htlc_id = htlc.htlc_id;
                                htlc_amount_msat += htlc.amount_msat;
                        }