Skip to content

Commit c5ea569

Browse files
Track recent monitor updates in TestChainMonitor
And log them in check_added_monitors if it fails.
1 parent 9fba5f1 commit c5ea569

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

lightning/src/ln/functional_test_utils.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,20 @@ pub fn check_added_monitors<CM: AChannelManager, H: NodeHolder<CM = CM>>(node: &
12741274
if let Some(chain_monitor) = node.chain_monitor() {
12751275
let mut added_monitors = chain_monitor.added_monitors.lock().unwrap();
12761276
let n = added_monitors.len();
1277-
assert_eq!(n, count, "expected {} monitors to be added, not {}", count, n);
1277+
if n != count {
1278+
let recent = chain_monitor.recent_monitor_updates.lock().unwrap();
1279+
let mut desc = String::new();
1280+
for (i, (chan_id, update)) in recent.iter().take(n).enumerate() {
1281+
desc += &format!(
1282+
"\n [{}] chan={} update_id={} steps={:?}",
1283+
i, chan_id, update.update_id, update.updates
1284+
);
1285+
}
1286+
panic!(
1287+
"expected {} monitors to be added, not {}. Last {} updates (most recent first):{}",
1288+
count, n, n, desc
1289+
);
1290+
}
12781291
added_monitors.clear();
12791292
}
12801293
}

lightning/src/util/test_utils.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ pub struct TestChainMonitor<'a> {
521521
/// deferred operations. This allows tests to control exactly when queued monitor updates
522522
/// are applied to the in-memory monitor.
523523
pub pause_flush: AtomicBool,
524+
/// Buffer of the last 20 monitor updates, most recent first.
525+
pub recent_monitor_updates: Mutex<Vec<(ChannelId, ChannelMonitorUpdate)>>,
524526
}
525527
impl<'a> TestChainMonitor<'a> {
526528
pub fn new(
@@ -581,6 +583,7 @@ impl<'a> TestChainMonitor<'a> {
581583
#[cfg(feature = "std")]
582584
write_blocker: Mutex::new(None),
583585
pause_flush: AtomicBool::new(false),
586+
recent_monitor_updates: Mutex::new(Vec::new()),
584587
}
585588
}
586589

@@ -679,6 +682,12 @@ impl<'a> chain::Watch<TestChannelSigner> for TestChainMonitor<'a> {
679682
.or_insert(Vec::new())
680683
.push(update.clone());
681684

685+
{
686+
let mut recent = self.recent_monitor_updates.lock().unwrap();
687+
recent.insert(0, (channel_id, update.clone()));
688+
recent.truncate(20);
689+
}
690+
682691
if let Some(exp) = self.expect_channel_force_closed.lock().unwrap().take() {
683692
assert_eq!(channel_id, exp.0);
684693
assert_eq!(update.updates.len(), 1);

0 commit comments

Comments
 (0)