Merge pull request #1766 from tee8z/event-node-received
[rust-lightning] / lightning / src / chain / channelmonitor.rs
index bee2bfd012e0ff3efc628b4954883804f5d6a0c7..92f1a8df45d8e88bb75e9db80c7974fa89a430ec 100644 (file)
@@ -3150,10 +3150,24 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
                F::Target: FeeEstimator,
                L::Target: Logger,
        {
-               self.onchain_events_awaiting_threshold_conf.retain(|ref entry| if entry.txid == *txid {
-                       log_info!(logger, "Removing onchain event with txid {}", txid);
-                       false
-               } else { true });
+               let mut removed_height = None;
+               for entry in self.onchain_events_awaiting_threshold_conf.iter() {
+                       if entry.txid == *txid {
+                               removed_height = Some(entry.height);
+                               break;
+                       }
+               }
+
+               if let Some(removed_height) = removed_height {
+                       log_info!(logger, "transaction_unconfirmed of txid {} implies height {} was reorg'd out", txid, removed_height);
+                       self.onchain_events_awaiting_threshold_conf.retain(|ref entry| if entry.height >= removed_height {
+                               log_info!(logger, "Transaction {} reorg'd out", entry.txid);
+                               false
+                       } else { true });
+               }
+
+               debug_assert!(!self.onchain_events_awaiting_threshold_conf.iter().any(|ref entry| entry.txid == *txid));
+
                self.onchain_tx_handler.transaction_unconfirmed(txid, broadcaster, fee_estimator, logger);
        }
 
@@ -4072,7 +4086,7 @@ mod tests {
                        SecretKey::from_slice(&[41; 32]).unwrap(),
                        [41; 32],
                        0,
-                       [0; 32]
+                       [0; 32],
                );
 
                let counterparty_pubkeys = ChannelPublicKeys {
@@ -4093,6 +4107,7 @@ mod tests {
                        }),
                        funding_outpoint: Some(funding_outpoint),
                        opt_anchors: None,
+                       opt_non_zero_fee_anchors: None,
                };
                // Prune with one old state and a holder commitment tx holding a few overlaps with the
                // old state.