From 1912d8df01997c27ebe73323473ec6b1d45c1f1c Mon Sep 17 00:00:00 2001 From: G8XSU <3442979+G8XSU@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:55:39 -0700 Subject: [PATCH] Start tracking chain_sync_monitor_persistences in TestPersister It is helpful to assert that chain-sync did trigger a monitor persist. --- lightning/src/util/test_utils.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index f6616a8e5..2d0084477 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -545,12 +545,16 @@ pub struct TestPersister { /// /// [`ChannelMonitor`]: channelmonitor::ChannelMonitor pub offchain_monitor_updates: Mutex>>, + /// When we get an update_persisted_channel call with no ChannelMonitorUpdate, we insert the + /// monitor's funding outpoint here. + pub chain_sync_monitor_persistences: Mutex> } impl TestPersister { pub fn new() -> Self { Self { update_rets: Mutex::new(VecDeque::new()), offchain_monitor_updates: Mutex::new(new_hash_map()), + chain_sync_monitor_persistences: Mutex::new(VecDeque::new()) } } @@ -573,15 +577,18 @@ impl chainmonitor::Persist for ret = update_ret; } - if let Some(update) = update { + if let Some(update) = update { self.offchain_monitor_updates.lock().unwrap().entry(funding_txo).or_insert(new_hash_set()).insert(update.update_id); + } else { + self.chain_sync_monitor_persistences.lock().unwrap().push_back(funding_txo); } ret } fn archive_persisted_channel(&self, funding_txo: OutPoint) { - // remove the channel from the offchain_monitor_updates map + // remove the channel from the offchain_monitor_updates and chain_sync_monitor_persistences. self.offchain_monitor_updates.lock().unwrap().remove(&funding_txo); + self.chain_sync_monitor_persistences.lock().unwrap().retain(|x| x != &funding_txo); } } -- 2.39.5