From b7fd436d880391b69ccf317ef9f20c99b2e816d6 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 11 Aug 2020 13:58:28 -0400 Subject: [PATCH] Test + fuzz that Channel{,Monitor} would_broadcast are identical --- fuzz/src/chanmon_consistency.rs | 4 ++++ lightning/src/ln/channelmanager.rs | 9 +++++++++ lightning/src/ln/channelmonitor.rs | 10 ++++++++++ lightning/src/util/test_utils.rs | 4 ++++ 4 files changed, 27 insertions(+) diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 9749361fd..7d8ee6ae9 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -135,6 +135,10 @@ impl channelmonitor::ManyChannelMonitor for TestChannelMonitor { self.update_ret.lock().unwrap().clone() } + fn get_monitor_would_broadcast(&self, funding_txo: &OutPoint, height: u32) -> bool { + self.simple_monitor.get_monitor_would_broadcast(funding_txo, height) + } + fn get_and_clear_pending_htlcs_updated(&self) -> Vec { return self.simple_monitor.get_and_clear_pending_htlcs_updated(); } diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 748053595..11eabb6b5 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -3104,6 +3104,15 @@ impl bool { + self.monitors.lock().unwrap().get(funding_txo).unwrap().would_broadcast_at_height(height, &self.logger) + } + fn get_and_clear_pending_htlcs_updated(&self) -> Vec { let mut pending_htlcs_updated = Vec::new(); for chan in self.monitors.lock().unwrap().values_mut() { @@ -877,6 +882,11 @@ pub trait ManyChannelMonitor: Send + Sync { /// ChannelMonitors via block_connected may result in FUNDS LOSS. fn update_monitor(&self, funding_txo: OutPoint, monitor: ChannelMonitorUpdate) -> Result<(), ChannelMonitorUpdateErr>; + #[cfg(any(test, feature = "fuzztarget"))] + /// Calls would_broadcast_at_height() on the given monitor. Used in testing to check that the + /// ChannelMonitor copy can never get out of sync with the Channel copy. + fn get_monitor_would_broadcast(&self, funding_txo: &OutPoint, height: u32) -> bool; + /// Used by ChannelManager to get list of HTLC resolved onchain and which needed to be updated /// with success or failure. /// diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index d684e9c07..35ad11348 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -129,6 +129,10 @@ impl<'a> channelmonitor::ManyChannelMonitor for TestChannelMonitor<'a> { ret } + fn get_monitor_would_broadcast(&self, funding_txo: &OutPoint, height: u32) -> bool { + self.simple_monitor.get_monitor_would_broadcast(funding_txo, height) + } + fn get_and_clear_pending_htlcs_updated(&self) -> Vec { return self.simple_monitor.get_and_clear_pending_htlcs_updated(); } -- 2.39.5