From 9878edeebaae6a33f08c609896d78c1d471a7577 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Thu, 4 May 2023 15:16:17 -0700 Subject: [PATCH] Prevent ChannelForceClosed monitor update error after detecting spend If we detected a spend for a channel onchain prior to handling its `ChannelForceClosed` monitor update, we'd log a concerning error message and return an error unnecessarily. The channel has already been closed, so handling the `ChannelForceClosed` monitor update at this point should be a no-op. --- lightning/src/chain/channelmonitor.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 7d1a325c7..bf3008774 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -2457,7 +2457,9 @@ impl ChannelMonitorImpl { self.latest_update_id = updates.update_id; - if ret.is_ok() && self.funding_spend_seen { + // Refuse updates after we've detected a spend onchain, but only if we haven't processed a + // force closed monitor update yet. + if ret.is_ok() && self.funding_spend_seen && self.latest_update_id != CLOSED_CHANNEL_UPDATE_ID { log_error!(logger, "Refusing Channel Monitor Update as counterparty attempted to update commitment after funding was spent"); Err(()) } else { ret } -- 2.39.5