Skip to content

Commit d25d55a

Browse files
authored
Merge pull request #2990 from TheBlueMatt/2024-04-log-in-flights
Log pending in-flight updates when we are missing a monitor
2 parents 6ee8d81 + 93e7763 commit d25d55a

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

lightning/src/chain/chainmonitor.rs

+42-9
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,9 @@ where C::Target: chain::Filter,
368368
let mut txn_outputs;
369369
{
370370
txn_outputs = process(monitor, txdata);
371+
let chain_sync_update_id = self.sync_persistence_id.get_increment();
371372
let update_id = MonitorUpdateId {
372-
contents: UpdateOrigin::ChainSync(self.sync_persistence_id.get_increment()),
373+
contents: UpdateOrigin::ChainSync(chain_sync_update_id),
373374
};
374375
let mut pending_monitor_updates = monitor_state.pending_monitor_updates.lock().unwrap();
375376
if let Some(height) = best_height {
@@ -381,10 +382,16 @@ where C::Target: chain::Filter,
381382
}
382383
}
383384

384-
log_trace!(logger, "Syncing Channel Monitor for channel {}", log_funding_info!(monitor));
385+
log_trace!(logger, "Syncing Channel Monitor for channel {} for block-data update_id {}",
386+
log_funding_info!(monitor),
387+
chain_sync_update_id
388+
);
385389
match self.persister.update_persisted_channel(*funding_outpoint, None, monitor, update_id) {
386390
ChannelMonitorUpdateStatus::Completed =>
387-
log_trace!(logger, "Finished syncing Channel Monitor for channel {}", log_funding_info!(monitor)),
391+
log_trace!(logger, "Finished syncing Channel Monitor for channel {} for block-data update_id {}",
392+
log_funding_info!(monitor),
393+
chain_sync_update_id
394+
),
388395
ChannelMonitorUpdateStatus::InProgress => {
389396
log_debug!(logger, "Channel Monitor sync for channel {} in progress, holding events until completion!", log_funding_info!(monitor));
390397
pending_monitor_updates.push(update_id);
@@ -534,7 +541,7 @@ where C::Target: chain::Filter,
534541
pending_monitor_updates.retain(|update_id| *update_id != completed_update_id);
535542

536543
match completed_update_id {
537-
MonitorUpdateId { contents: UpdateOrigin::OffChain(_) } => {
544+
MonitorUpdateId { contents: UpdateOrigin::OffChain(completed_update_id) } => {
538545
// Note that we only check for `UpdateOrigin::OffChain` failures here - if
539546
// we're being told that a `UpdateOrigin::OffChain` monitor update completed,
540547
// we only care about ensuring we don't tell the `ChannelManager` to restore
@@ -545,6 +552,14 @@ where C::Target: chain::Filter,
545552
// `MonitorEvent`s from the monitor back to the `ChannelManager` until they
546553
// complete.
547554
let monitor_is_pending_updates = monitor_data.has_pending_offchain_updates(&pending_monitor_updates);
555+
log_debug!(self.logger, "Completed off-chain monitor update {} for channel with funding outpoint {:?}, {}",
556+
completed_update_id,
557+
funding_txo,
558+
if monitor_is_pending_updates {
559+
"still have pending off-chain updates"
560+
} else {
561+
"all off-chain updates complete, returning a MonitorEvent"
562+
});
548563
if monitor_is_pending_updates {
549564
// If there are still monitor updates pending, we cannot yet construct a
550565
// Completed event.
@@ -556,8 +571,18 @@ where C::Target: chain::Filter,
556571
monitor_update_id: monitor_data.monitor.get_latest_update_id(),
557572
}], monitor_data.monitor.get_counterparty_node_id()));
558573
},
559-
MonitorUpdateId { contents: UpdateOrigin::ChainSync(_) } => {
560-
if !monitor_data.has_pending_chainsync_updates(&pending_monitor_updates) {
574+
MonitorUpdateId { contents: UpdateOrigin::ChainSync(completed_update_id) } => {
575+
let monitor_has_pending_updates =
576+
monitor_data.has_pending_chainsync_updates(&pending_monitor_updates);
577+
log_debug!(self.logger, "Completed chain sync monitor update {} for channel with funding outpoint {:?}, {}",
578+
completed_update_id,
579+
funding_txo,
580+
if monitor_has_pending_updates {
581+
"still have pending chain sync updates"
582+
} else {
583+
"all chain sync updates complete, releasing pending MonitorEvents"
584+
});
585+
if !monitor_has_pending_updates {
561586
monitor_data.last_chain_persist_height.store(self.highest_chain_height.load(Ordering::Acquire), Ordering::Release);
562587
// The next time release_pending_monitor_events is called, any events for this
563588
// ChannelMonitor will be returned.
@@ -844,7 +869,7 @@ where C::Target: chain::Filter,
844869
Some(monitor_state) => {
845870
let monitor = &monitor_state.monitor;
846871
let logger = WithChannelMonitor::from(&self.logger, &monitor);
847-
log_trace!(logger, "Updating ChannelMonitor for channel {}", log_funding_info!(monitor));
872+
log_trace!(logger, "Updating ChannelMonitor to id {} for channel {}", update.update_id, log_funding_info!(monitor));
848873
let update_res = monitor.update_monitor(update, &self.broadcaster, &self.fee_estimator, &self.logger);
849874

850875
let update_id = MonitorUpdateId::from_monitor_update(update);
@@ -863,10 +888,18 @@ where C::Target: chain::Filter,
863888
match persist_res {
864889
ChannelMonitorUpdateStatus::InProgress => {
865890
pending_monitor_updates.push(update_id);
866-
log_debug!(logger, "Persistence of ChannelMonitorUpdate for channel {} in progress", log_funding_info!(monitor));
891+
log_debug!(logger,
892+
"Persistence of ChannelMonitorUpdate id {:?} for channel {} in progress",
893+
update_id,
894+
log_funding_info!(monitor)
895+
);
867896
},
868897
ChannelMonitorUpdateStatus::Completed => {
869-
log_debug!(logger, "Persistence of ChannelMonitorUpdate for channel {} completed", log_funding_info!(monitor));
898+
log_debug!(logger,
899+
"Persistence of ChannelMonitorUpdate id {:?} for channel {} completed",
900+
update_id,
901+
log_funding_info!(monitor)
902+
);
870903
},
871904
ChannelMonitorUpdateStatus::UnrecoverableError => {
872905
// Take the monitors lock for writing so that we poison it and any future

lightning/src/ln/channelmanager.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11888,6 +11888,7 @@ where
1188811888
log_error!(logger, " client applications must ensure that ChannelMonitor data is always available and the latest to avoid funds loss!");
1188911889
log_error!(logger, " Without the latest ChannelMonitor we cannot continue without risking funds.");
1189011890
log_error!(logger, " Please ensure the chain::Watch API requirements are met and file a bug report at https://github.com/lightningdevkit/rust-lightning");
11891+
log_error!(logger, " Pending in-flight updates are: {:?}", chan_in_flight_updates);
1189111892
return Err(DecodeError::InvalidValue);
1189211893
}
1189311894
}

0 commit comments

Comments
 (0)