Skip to content

Commit 47e6dae

Browse files
committed
Persist full monitor if there is an error while applying monitor_update
Motivation: When there is an error while applying monitor_update to a channel_monitor, we don't want to persist a 'monitor_update' which results in a failure to apply later while reading 'channel_monitor' with updates from storage. Instead, we should persist the entire 'channel_monitor' here.
1 parent db41b87 commit 47e6dae

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,14 +752,20 @@ where C::Target: chain::Filter,
752752
let monitor = &monitor_state.monitor;
753753
log_trace!(self.logger, "Updating ChannelMonitor for channel {}", log_funding_info!(monitor));
754754
let update_res = monitor.update_monitor(update, &self.broadcaster, &*self.fee_estimator, &self.logger);
755-
if update_res.is_err() {
756-
log_error!(self.logger, "Failed to update ChannelMonitor for channel {}.", log_funding_info!(monitor));
757-
}
758-
// Even if updating the monitor returns an error, the monitor's state will
759-
// still be changed. So, persist the updated monitor despite the error.
755+
760756
let update_id = MonitorUpdateId::from_monitor_update(update);
761757
let mut pending_monitor_updates = monitor_state.pending_monitor_updates.lock().unwrap();
762-
let persist_res = self.persister.update_persisted_channel(funding_txo, Some(update), monitor, update_id);
758+
let persist_res = if update_res.is_err() {
759+
// Even if updating the monitor returns an error, the monitor's state will
760+
// still be changed. Therefore, we should persist the updated monitor despite the error.
761+
// We don't want to persist a `monitor_update` which results in a failure to apply later
762+
// while reading `channel_monitor` with updates from storage. Instead, we should persist
763+
// the entire `channel_monitor` here.
764+
log_warn!(self.logger, "Failed to update ChannelMonitor for channel {}. Going ahead and persisting the entire ChannelMonitor", log_funding_info!(monitor));
765+
self.persister.update_persisted_channel(funding_txo, None, monitor, update_id)
766+
} else {
767+
self.persister.update_persisted_channel(funding_txo, Some(update), monitor, update_id)
768+
};
763769
match persist_res {
764770
ChannelMonitorUpdateStatus::InProgress => {
765771
pending_monitor_updates.push(update_id);

0 commit comments

Comments
 (0)