Handle Persister returning TemporaryFailure for new channels
authorMatt Corallo <git@bluematt.me>
Fri, 8 Oct 2021 20:40:34 +0000 (20:40 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 14 Oct 2021 00:19:12 +0000 (00:19 +0000)
Previously, if a Persister returned a TemporaryFailure error when
we tried to persist a new channel, the ChainMonitor wouldn't track
the new ChannelMonitor at all, generating a PermanentFailure later
when the updating is restored.

This fixes that by correctly storing the ChannelMonitor on
TemporaryFailures, allowing later update restoration to happen
normally.

This is (indirectly) tested in the next commit where we use
Persister to return all monitor-update errors.

lightning/src/chain/chainmonitor.rs

index 2de5540059c38e630919a3db76bb3215b6a5399f..f1ce0f79ae9cd99860283ec72c00df49430c87a3 100644 (file)
@@ -372,9 +372,12 @@ where C::Target: chain::Filter,
                                return Err(ChannelMonitorUpdateErr::PermanentFailure)},
                        hash_map::Entry::Vacant(e) => e,
                };
-               if let Err(e) = self.persister.persist_new_channel(funding_outpoint, &monitor) {
-                       log_error!(self.logger, "Failed to persist new channel data");
-                       return Err(e);
+               let persist_res = self.persister.persist_new_channel(funding_outpoint, &monitor);
+               if persist_res.is_err() {
+                       log_error!(self.logger, "Failed to persist new channel data: {:?}", persist_res);
+               }
+               if persist_res == Err(ChannelMonitorUpdateErr::PermanentFailure) {
+                       return persist_res;
                }
                {
                        let funding_txo = monitor.get_funding_txo();
@@ -385,7 +388,7 @@ where C::Target: chain::Filter,
                        }
                }
                entry.insert(MonitorHolder { monitor });
-               Ok(())
+               persist_res
        }
 
        /// Note that we persist the given `ChannelMonitor` update while holding the