- orig_monitor.update_monitor(update, &self.broadcaster, &self.logger)
- },
- None => Err(MonitorUpdateError("No such monitor registered"))
- }
- }
-}
-
-impl<ChanSigner: ChannelKeys, C: Deref + Sync + Send, T: Deref + Sync + Send, F: Deref + Sync + Send, L: Deref + Sync + Send> chain::Watch for ChainMonitor<ChanSigner, C, T, F, L>
- where C::Target: chain::Filter,
- T::Target: BroadcasterInterface,
- F::Target: FeeEstimator,
- L::Target: Logger,
-{
- type Keys = ChanSigner;
-
- fn watch_channel(&self, funding_txo: OutPoint, monitor: ChannelMonitor<ChanSigner>) -> Result<(), ChannelMonitorUpdateErr> {
- match self.add_monitor(funding_txo, monitor) {
- Ok(_) => Ok(()),
- Err(_) => Err(ChannelMonitorUpdateErr::PermanentFailure),
- }
- }
-
- fn update_channel(&self, funding_txo: OutPoint, update: ChannelMonitorUpdate) -> Result<(), ChannelMonitorUpdateErr> {
- match self.update_monitor(funding_txo, update) {
- Ok(_) => Ok(()),
- Err(_) => Err(ChannelMonitorUpdateErr::PermanentFailure),
+ let update_res = orig_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);
+ }
+ // Even if updating the monitor returns an error, the monitor's state will
+ // still be changed. So, persist the updated monitor despite the error.
+ let persist_res = self.persister.update_persisted_channel(funding_txo, &update, orig_monitor);
+ if let Err(ref e) = persist_res {
+ log_error!(self.logger, "Failed to persist channel monitor update: {:?}", e);
+ }
+ if update_res.is_err() {
+ Err(ChannelMonitorUpdateErr::PermanentFailure)
+ } else {
+ persist_res
+ }
+ }