Remove ChainWatchInterface from BlockNotifier
[rust-lightning] / lightning / src / ln / channelmonitor.rs
index 91f81fa573664d6d0ceb64380181ee2d4d5adc86..cca3c99f043b6dec7bb076d8bba98b43927573f8 100644 (file)
@@ -211,19 +211,26 @@ impl<Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys, T: Deref + Sync
              L::Target: Logger,
         C::Target: ChainWatchInterface,
 {
-       fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], _indexes_of_txn_matched: &[usize]) {
-               let block_hash = header.block_hash();
-               {
-                       let mut monitors = self.monitors.lock().unwrap();
-                       for monitor in monitors.values_mut() {
-                               let txn_outputs = monitor.block_connected(txn_matched, height, &block_hash, &*self.broadcaster, &*self.fee_estimator, &*self.logger);
-
-                               for (ref txid, ref outputs) in txn_outputs {
-                                       for (idx, output) in outputs.iter().enumerate() {
-                                               self.chain_monitor.install_watch_outpoint((txid.clone(), idx as u32), &output.script_pubkey);
+       fn block_connected(&self, header: &BlockHeader, txdata: &[(usize, &Transaction)], height: u32) {
+               let mut reentered = true;
+               while reentered {
+                       let matched_indexes = self.chain_monitor.filter_block(header, txdata);
+                       let matched_txn: Vec<_> = matched_indexes.iter().map(|index| txdata[*index].1).collect();
+                       let last_seen = self.chain_monitor.reentered();
+                       let block_hash = header.block_hash();
+                       {
+                               let mut monitors = self.monitors.lock().unwrap();
+                               for monitor in monitors.values_mut() {
+                                       let txn_outputs = monitor.block_connected(&matched_txn, height, &block_hash, &*self.broadcaster, &*self.fee_estimator, &*self.logger);
+
+                                       for (ref txid, ref outputs) in txn_outputs {
+                                               for (idx, output) in outputs.iter().enumerate() {
+                                                       self.chain_monitor.install_watch_outpoint((txid.clone(), idx as u32), &output.script_pubkey);
+                                               }
                                        }
                                }
                        }
+                       reentered = last_seen != self.chain_monitor.reentered();
                }
        }