Skip to content

Commit

Permalink
Handle Persister returning TemporaryFailure for new channels
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheBlueMatt committed Oct 8, 2021
1 parent a389b8b commit 954bb6e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lightning/src/chain/chainmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,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 update_res = self.persister.persist_new_channel(funding_outpoint, &monitor);
if update_res.is_err() {
log_error!(self.logger, "Failed to persist new channel data: {:?}", update_res);
}
if update_res == Err(ChannelMonitorUpdateErr::PermanentFailure) {
return update_res;
}
{
let funding_txo = monitor.get_funding_txo();
Expand All @@ -380,7 +383,7 @@ where C::Target: chain::Filter,
}
}
entry.insert(MonitorHolder { monitor });
Ok(())
update_res
}

/// Note that we persist the given `ChannelMonitor` update while holding the
Expand Down

0 comments on commit 954bb6e

Please sign in to comment.