Merge pull request #2964 from jbesraa/prune-stale-chanmonitor
[rust-lightning] / lightning / src / util / test_utils.rs
index a340d95a745a66196af98270ad4477382f95f783..95bc2a7c661982ea9062497f1647af434111dcd6 100644 (file)
@@ -504,6 +504,10 @@ impl<Signer: sign::ecdsa::WriteableEcdsaChannelSigner> chainmonitor::Persist<Sig
                }
                res
        }
+
+       fn archive_persisted_channel(&self, funding_txo: OutPoint) {
+               <TestPersister as chainmonitor::Persist<TestChannelSigner>>::archive_persisted_channel(&self.persister, funding_txo);
+       }
 }
 
 pub struct TestPersister {
@@ -552,6 +556,18 @@ impl<Signer: sign::ecdsa::WriteableEcdsaChannelSigner> chainmonitor::Persist<Sig
                }
                ret
        }
+
+       fn archive_persisted_channel(&self, funding_txo: OutPoint) { 
+               // remove the channel from the offchain_monitor_updates map
+               match self.offchain_monitor_updates.lock().unwrap().remove(&funding_txo) {
+                       Some(_) => {},
+                       None => {
+                               // If the channel was not in the offchain_monitor_updates map, it should be in the
+                               // chain_sync_monitor_persistences map.
+                               assert!(self.chain_sync_monitor_persistences.lock().unwrap().remove(&funding_txo).is_some());
+                       }
+               };
+       }
 }
 
 pub struct TestStore {
@@ -1366,6 +1382,10 @@ impl TestChainSource {
                        watched_outputs: Mutex::new(new_hash_set()),
                }
        }
+       pub fn remove_watched_txn_and_outputs(&self, outpoint: OutPoint, script_pubkey: ScriptBuf) {
+               self.watched_outputs.lock().unwrap().remove(&(outpoint, script_pubkey.clone())); 
+               self.watched_txn.lock().unwrap().remove(&(outpoint.txid, script_pubkey));
+       }
 }
 
 impl UtxoLookup for TestChainSource {