Skip to content

Commit 67e31ea

Browse files
committed
Debug-log monitor update starts and completions in ChainMonitor
When a `ChannelMonitor[Update]` persistence completes, we rely on logging in `ChannelManager` to hear about it. However, this won't happen at all if there's still pending updates as no `MonitorEvent` will be generated. Thus, here, we add logging directly in `ChainMonitor`, ensuring we can deduce when individual updates completed from debug logs.
1 parent 10480f0 commit 67e31ea

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ where C::Target: chain::Filter,
526526
pending_monitor_updates.retain(|update_id| *update_id != completed_update_id);
527527

528528
match completed_update_id {
529-
MonitorUpdateId { contents: UpdateOrigin::OffChain(_) } => {
529+
MonitorUpdateId { contents: UpdateOrigin::OffChain(completed_update_id) } => {
530530
// Note that we only check for `UpdateOrigin::OffChain` failures here - if
531531
// we're being told that a `UpdateOrigin::OffChain` monitor update completed,
532532
// we only care about ensuring we don't tell the `ChannelManager` to restore
@@ -537,6 +537,14 @@ where C::Target: chain::Filter,
537537
// `MonitorEvent`s from the monitor back to the `ChannelManager` until they
538538
// complete.
539539
let monitor_is_pending_updates = monitor_data.has_pending_offchain_updates(&pending_monitor_updates);
540+
log_debug!(self.logger, "Completed off-chain monitor update {} for channel with funding outpoint {:?}, {}",
541+
completed_update_id,
542+
funding_txo,
543+
if monitor_is_pending_updates {
544+
"still have pending off-chain updates"
545+
} else {
546+
"all off-chain updates complete, returning a MonitorEvent"
547+
});
540548
if monitor_is_pending_updates {
541549
// If there are still monitor updates pending, we cannot yet construct a
542550
// Completed event.
@@ -548,7 +556,16 @@ where C::Target: chain::Filter,
548556
}], monitor_data.monitor.get_counterparty_node_id()));
549557
},
550558
MonitorUpdateId { contents: UpdateOrigin::ChainSync(_) } => {
551-
if !monitor_data.has_pending_chainsync_updates(&pending_monitor_updates) {
559+
let monitor_has_pending_updates =
560+
monitor_data.has_pending_chainsync_updates(&pending_monitor_updates);
561+
log_debug!(self.logger, "Completed chain sync monitor update for channel with funding outpoint {:?}, {}",
562+
funding_txo,
563+
if monitor_has_pending_updates {
564+
"still have pending chain sync updates"
565+
} else {
566+
"all chain sync updates complete, releasing pending MonitorEvents"
567+
});
568+
if !monitor_has_pending_updates {
552569
monitor_data.last_chain_persist_height.store(self.highest_chain_height.load(Ordering::Acquire), Ordering::Release);
553570
// The next time release_pending_monitor_events is called, any events for this
554571
// ChannelMonitor will be returned.
@@ -771,7 +788,7 @@ where C::Target: chain::Filter,
771788
Some(monitor_state) => {
772789
let monitor = &monitor_state.monitor;
773790
let logger = WithChannelMonitor::from(&self.logger, &monitor);
774-
log_trace!(logger, "Updating ChannelMonitor for channel {}", log_funding_info!(monitor));
791+
log_trace!(logger, "Updating ChannelMonitor to id {} for channel {}", update.update_id, log_funding_info!(monitor));
775792
let update_res = monitor.update_monitor(update, &self.broadcaster, &self.fee_estimator, &self.logger);
776793

777794
let update_id = MonitorUpdateId::from_monitor_update(update);

0 commit comments

Comments
 (0)