]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Also avoid pruning preimages for previous local tx in ChannelMonitor
authorMatt Corallo <git@bluematt.me>
Fri, 29 Jun 2018 20:37:45 +0000 (16:37 -0400)
committerMatt Corallo <git@bluematt.me>
Fri, 29 Jun 2018 20:44:19 +0000 (16:44 -0400)
src/ln/channelmonitor.rs

index eefe51f3ee6581f2bc1f028f2d3d8fbbf3e25cb2..6c372c9be4bd0edd7bd91e6e6dfb854f84c84774 100644 (file)
@@ -294,26 +294,37 @@ impl ChannelMonitor {
                        }
                }
 
-               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
+               if !self.payment_preimages.is_empty() {
+                       let local_signed_commitment_tx = self.current_local_signed_commitment_tx.as_ref().expect("Channel needs at least an initial commitment tx !");
+                       let prev_local_signed_commitment_tx = self.prev_local_signed_commitment_tx.as_ref();
+                       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, _, _) in &local_signed_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
+                               if let Some(prev_local_commitment_tx) = prev_local_signed_commitment_tx {
+                                       for &(ref htlc, _, _) in prev_local_commitment_tx.htlc_outputs.iter() {
+                                               if k == htlc.payment_hash {
+                                                       return true
+                                               }
+                                       }
                                }
-                               true
-                       } else { false };
-                       if contains {
-                               remote_hash_commitment_number.remove(&k);
-                       }
-                       false
-               });
+                               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(())
        }