Prefer fully-specified paths in test macros
[rust-lightning] / lightning / src / chain / chainmonitor.rs
index 13a4ac3786cee28f682d2be049abf1b049a388ee..3c8f9bb561b2456c7c3822f123efdd0f6539b67f 100644 (file)
@@ -92,10 +92,12 @@ impl MonitorUpdateId {
 ///    closed without broadcasting the latest state. See
 ///    [`ChannelMonitorUpdateErr::PermanentFailure`] for more details.
 pub trait Persist<ChannelSigner: Sign> {
-       /// Persist a new channel's data. The data can be stored any way you want, but the identifier
-       /// provided by LDK is the channel's outpoint (and it is up to you to maintain a correct
-       /// mapping between the outpoint and the stored channel data). Note that you **must** persist
-       /// every new monitor to disk.
+       /// Persist a new channel's data in response to a [`chain::Watch::watch_channel`] call. This is
+       /// called by [`ChannelManager`] for new channels, or may be called directly, e.g. on startup.
+       ///
+       /// The data can be stored any way you want, but the identifier provided by LDK is the
+       /// channel's outpoint (and it is up to you to maintain a correct mapping between the outpoint
+       /// and the stored channel data). Note that you **must** persist every new monitor to disk.
        ///
        /// The `update_id` is used to identify this call to [`ChainMonitor::channel_monitor_updated`],
        /// if you return [`ChannelMonitorUpdateErr::TemporaryFailure`].
@@ -103,6 +105,7 @@ pub trait Persist<ChannelSigner: Sign> {
        /// See [`Writeable::write`] on [`ChannelMonitor`] for writing out a `ChannelMonitor`
        /// and [`ChannelMonitorUpdateErr`] for requirements when returning errors.
        ///
+       /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
        /// [`Writeable::write`]: crate::util::ser::Writeable::write
        fn persist_new_channel(&self, channel_id: OutPoint, data: &ChannelMonitor<ChannelSigner>, update_id: MonitorUpdateId) -> Result<(), ChannelMonitorUpdateErr>;
 
@@ -589,24 +592,22 @@ where C::Target: chain::Filter,
                                return Err(ChannelMonitorUpdateErr::PermanentFailure)},
                        hash_map::Entry::Vacant(e) => e,
                };
+               log_trace!(self.logger, "Got new ChannelMonitor for channel {}", log_funding_info!(monitor));
                let update_id = MonitorUpdateId::from_new_monitor(&monitor);
                let mut pending_monitor_updates = Vec::new();
                let persist_res = self.persister.persist_new_channel(funding_outpoint, &monitor, update_id);
                if persist_res.is_err() {
-                       log_error!(self.logger, "Failed to persist new channel data: {:?}", persist_res);
+                       log_error!(self.logger, "Failed to persist new ChannelMonitor for channel {}: {:?}", log_funding_info!(monitor), persist_res);
+               } else {
+                       log_trace!(self.logger, "Finished persisting new ChannelMonitor for channel {}", log_funding_info!(monitor));
                }
                if persist_res == Err(ChannelMonitorUpdateErr::PermanentFailure) {
                        return persist_res;
                } else if persist_res.is_err() {
                        pending_monitor_updates.push(update_id);
                }
-               {
-                       let funding_txo = monitor.get_funding_txo();
-                       log_trace!(self.logger, "Got new Channel Monitor for channel {}", log_bytes!(funding_txo.0.to_channel_id()[..]));
-
-                       if let Some(ref chain_source) = self.chain_source {
-                               monitor.load_outputs_to_watch(chain_source);
-                       }
+               if let Some(ref chain_source) = self.chain_source {
+                       monitor.load_outputs_to_watch(chain_source);
                }
                entry.insert(MonitorHolder {
                        monitor,
@@ -636,10 +637,10 @@ where C::Target: chain::Filter,
                        },
                        Some(monitor_state) => {
                                let monitor = &monitor_state.monitor;
-                               log_trace!(self.logger, "Updating Channel Monitor for channel {}", log_funding_info!(monitor));
+                               log_trace!(self.logger, "Updating ChannelMonitor for channel {}", log_funding_info!(monitor));
                                let update_res = monitor.update_monitor(&update, &self.broadcaster, &self.fee_estimator, &self.logger);
                                if let Err(e) = &update_res {
-                                       log_error!(self.logger, "Failed to update channel monitor: {:?}", e);
+                                       log_error!(self.logger, "Failed to update ChannelMonitor for channel {}: {:?}", log_funding_info!(monitor), e);
                                }
                                // Even if updating the monitor returns an error, the monitor's state will
                                // still be changed. So, persist the updated monitor despite the error.
@@ -652,7 +653,9 @@ where C::Target: chain::Filter,
                                        } else {
                                                monitor_state.channel_perm_failed.store(true, Ordering::Release);
                                        }
-                                       log_error!(self.logger, "Failed to persist channel monitor update: {:?}", e);
+                                       log_error!(self.logger, "Failed to persist ChannelMonitor update for channel {}: {:?}", log_funding_info!(monitor), e);
+                               } else {
+                                       log_trace!(self.logger, "Finished persisting ChannelMonitor update for channel {}", log_funding_info!(monitor));
                                }
                                if update_res.is_err() {
                                        Err(ChannelMonitorUpdateErr::PermanentFailure)