From 37c6c18789151b2a8c7c3b7e4c1d98f7f86e906a Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 17 Oct 2021 21:26:04 +0000 Subject: [PATCH] Continue after a single failure in `ChannelMonitor::update_monitor` `ChannelMonitorUpdate`s may contain multiple updates, including, eg a payment preimage after a commitment transaction update. While such updates are generally not generated today, we shouldn't return early out of the update loop, causing us to miss any updates after an earlier update fails. --- lightning/src/chain/channelmonitor.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 1699e4827..dd33e7d0d 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -1886,12 +1886,17 @@ impl ChannelMonitorImpl { } else if self.latest_update_id + 1 != updates.update_id { panic!("Attempted to apply ChannelMonitorUpdates out of order, check the update_id before passing an update to update_monitor!"); } + let mut ret = Ok(()); for update in updates.updates.iter() { match update { ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs } => { log_trace!(logger, "Updating ChannelMonitor with latest holder commitment transaction info"); if self.lockdown_from_offchain { panic!(); } - self.provide_latest_holder_commitment_tx(commitment_tx.clone(), htlc_outputs.clone())? + if let Err(e) = self.provide_latest_holder_commitment_tx(commitment_tx.clone(), htlc_outputs.clone()) { + log_error!(logger, "Providing latest holder commitment transaction failed/was refused:"); + log_error!(logger, " {}", e.0); + ret = Err(e); + } } ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo { commitment_txid, htlc_outputs, commitment_number, their_revocation_point } => { log_trace!(logger, "Updating ChannelMonitor with latest counterparty commitment transaction info"); @@ -1903,7 +1908,11 @@ impl ChannelMonitorImpl { }, ChannelMonitorUpdateStep::CommitmentSecret { idx, secret } => { log_trace!(logger, "Updating ChannelMonitor with commitment secret"); - self.provide_secret(*idx, *secret)? + if let Err(e) = self.provide_secret(*idx, *secret) { + log_error!(logger, "Providing latest counterparty commitment secret failed/was refused:"); + log_error!(logger, " {}", e.0); + ret = Err(e); + } }, ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast } => { log_trace!(logger, "Updating ChannelMonitor: channel force closed, should broadcast: {}", should_broadcast); @@ -1928,7 +1937,7 @@ impl ChannelMonitorImpl { } } self.latest_update_id = updates.update_id; - Ok(()) + ret } pub fn get_latest_update_id(&self) -> u64 { -- 2.39.5