]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Skip some a needless temporary vec and clean indentation after #32
authorMatt Corallo <git@bluematt.me>
Fri, 29 Jun 2018 19:40:47 +0000 (15:40 -0400)
committerMatt Corallo <git@bluematt.me>
Fri, 29 Jun 2018 20:44:19 +0000 (16:44 -0400)
src/ln/channelmonitor.rs

index 2b4d28e14d48aa5549d5c12dff2c509e32e3e44b..f9fa36b6b97667d0987fb1dd123ef0fbb91bc9c9 100644 (file)
@@ -294,29 +294,26 @@ impl ChannelMonitor {
                        }
                }
 
-               let mut waste_hash_state : Vec<[u8;32]> = Vec::new();
-               {
-                       let local_signed_commitment_tx = &self.current_local_signed_commitment_tx;
-                       let remote_hash_commitment_number = &self.remote_hash_commitment_number;
-                       let min_idx = self.get_min_seen_secret();
-                       self.payment_preimages.retain(|&k, _| {
-                                       for &(ref htlc, _s1, _s2) in &local_signed_commitment_tx.as_ref().expect("Channel needs at least an initial commitment tx !").htlc_outputs {
-                                               if k == htlc.payment_hash {
-                                                       return true
-                                               }
-                                       }
-                                       if let Some(cn) = remote_hash_commitment_number.get(&k) {
-                                               if *cn < min_idx {
-                                                       return true
-                                               }
-                                       }
-                                       waste_hash_state.push(k);
-                                       false
-                               });
-               }
-               for h in waste_hash_state {
-                       self.remote_hash_commitment_number.remove(&h);
-               }
+               let local_signed_commitment_tx = &self.current_local_signed_commitment_tx;
+               let min_idx = self.get_min_seen_secret();
+               let remote_hash_commitment_number = &mut self.remote_hash_commitment_number;
+               self.payment_preimages.retain(|&k, _| {
+                       for &(ref htlc, _s1, _s2) in &local_signed_commitment_tx.as_ref().expect("Channel needs at least an initial commitment tx !").htlc_outputs {
+                               if k == htlc.payment_hash {
+                                       return true
+                               }
+                       }
+                       let contains = if let Some(cn) = remote_hash_commitment_number.get(&k) {
+                               if *cn < min_idx {
+                                       return true
+                               }
+                               true
+                       } else { false };
+                       if contains {
+                               remote_hash_commitment_number.remove(&k);
+                       }
+                       false
+               });
 
                Ok(())
        }