Skip to content

Commit 7c4dfad

Browse files
authored
Merge pull request #1105 from TheBlueMatt/2021-10-log-persist-time
Log before+after ChannelMonitor/Manager updates for visibility
2 parents 6f053e4 + 8e96f6b commit 7c4dfad

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ impl BackgroundProcessor {
217217
let updates_available =
218218
channel_manager.await_persistable_update_timeout(Duration::from_millis(100));
219219
if updates_available {
220+
log_trace!(logger, "Persisting ChannelManager...");
220221
persister.persist_manager(&*channel_manager)?;
222+
log_trace!(logger, "Done persisting ChannelManager.");
221223
}
222224
// Exit the loop if the background processor was requested to stop.
223225
if stop_thread.load(Ordering::Acquire) == true {

lightning/src/chain/chainmonitor.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -592,24 +592,22 @@ where C::Target: chain::Filter,
592592
return Err(ChannelMonitorUpdateErr::PermanentFailure)},
593593
hash_map::Entry::Vacant(e) => e,
594594
};
595+
log_trace!(self.logger, "Got new ChannelMonitor for channel {}", log_funding_info!(monitor));
595596
let update_id = MonitorUpdateId::from_new_monitor(&monitor);
596597
let mut pending_monitor_updates = Vec::new();
597598
let persist_res = self.persister.persist_new_channel(funding_outpoint, &monitor, update_id);
598599
if persist_res.is_err() {
599-
log_error!(self.logger, "Failed to persist new channel data: {:?}", persist_res);
600+
log_error!(self.logger, "Failed to persist new ChannelMonitor for channel {}: {:?}", log_funding_info!(monitor), persist_res);
601+
} else {
602+
log_trace!(self.logger, "Finished persisting new ChannelMonitor for channel {}", log_funding_info!(monitor));
600603
}
601604
if persist_res == Err(ChannelMonitorUpdateErr::PermanentFailure) {
602605
return persist_res;
603606
} else if persist_res.is_err() {
604607
pending_monitor_updates.push(update_id);
605608
}
606-
{
607-
let funding_txo = monitor.get_funding_txo();
608-
log_trace!(self.logger, "Got new Channel Monitor for channel {}", log_bytes!(funding_txo.0.to_channel_id()[..]));
609-
610-
if let Some(ref chain_source) = self.chain_source {
611-
monitor.load_outputs_to_watch(chain_source);
612-
}
609+
if let Some(ref chain_source) = self.chain_source {
610+
monitor.load_outputs_to_watch(chain_source);
613611
}
614612
entry.insert(MonitorHolder {
615613
monitor,
@@ -639,10 +637,10 @@ where C::Target: chain::Filter,
639637
},
640638
Some(monitor_state) => {
641639
let monitor = &monitor_state.monitor;
642-
log_trace!(self.logger, "Updating Channel Monitor for channel {}", log_funding_info!(monitor));
640+
log_trace!(self.logger, "Updating ChannelMonitor for channel {}", log_funding_info!(monitor));
643641
let update_res = monitor.update_monitor(&update, &self.broadcaster, &self.fee_estimator, &self.logger);
644642
if let Err(e) = &update_res {
645-
log_error!(self.logger, "Failed to update channel monitor: {:?}", e);
643+
log_error!(self.logger, "Failed to update ChannelMonitor for channel {}: {:?}", log_funding_info!(monitor), e);
646644
}
647645
// Even if updating the monitor returns an error, the monitor's state will
648646
// still be changed. So, persist the updated monitor despite the error.
@@ -655,7 +653,9 @@ where C::Target: chain::Filter,
655653
} else {
656654
monitor_state.channel_perm_failed.store(true, Ordering::Release);
657655
}
658-
log_error!(self.logger, "Failed to persist channel monitor update: {:?}", e);
656+
log_error!(self.logger, "Failed to persist ChannelMonitor update for channel {}: {:?}", log_funding_info!(monitor), e);
657+
} else {
658+
log_trace!(self.logger, "Finished persisting ChannelMonitor update for channel {}", log_funding_info!(monitor));
659659
}
660660
if update_res.is_err() {
661661
Err(ChannelMonitorUpdateErr::PermanentFailure)

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fn test_monitor_and_persister_update_fail() {
137137
// because the update is bogus, ultimately the error that's returned
138138
// should be a PermanentFailure.
139139
if let Err(ChannelMonitorUpdateErr::PermanentFailure) = chain_mon.chain_monitor.update_channel(outpoint, update.clone()) {} else { panic!("Expected monitor error to be permanent"); }
140-
logger.assert_log_contains("lightning::chain::chainmonitor".to_string(), "Failed to persist channel monitor update: TemporaryFailure".to_string(), 1);
140+
logger.assert_log_regex("lightning::chain::chainmonitor".to_string(), regex::Regex::new("Failed to persist ChannelMonitor update for channel [0-9a-f]*: TemporaryFailure").unwrap(), 1);
141141
if let Ok(_) = nodes[0].chain_monitor.update_channel(outpoint, update) {} else { assert!(false); }
142142
} else { assert!(false); }
143143
} else { assert!(false); };

0 commit comments

Comments
 (0)