From 55b712ee355762ea030a8a05157b79f932a615f8 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 24 Nov 2024 14:51:56 +0000 Subject: [PATCH] f clean up flow --- lightning/src/ln/channelmanager.rs | 41 +++++++++++++++--------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index d5a173bfb8a..c89f1c8e8eb 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -7663,30 +7663,29 @@ where pending.len() } else { 0 }; - let channel = - if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get_mut(channel_id) { - chan - } else { - if remaining_in_flight != 0 { - return; - } - - let update_actions = peer_state.monitor_update_blocked_actions - .remove(channel_id).unwrap_or(Vec::new()); - mem::drop(peer_state_lock); - mem::drop(per_peer_state); - self.handle_monitor_update_completion_actions(update_actions); - return; - }; + let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(*channel_id), None); + log_trace!(logger, "ChannelMonitor updated to {}. {} pending in-flight updates.", + highest_applied_update_id, remaining_in_flight); - let logger = WithChannelContext::from(&self.logger, &channel.context, None); - log_trace!(logger, "ChannelMonitor updated to {}. Current highest is {}. {} pending in-flight updates.", - highest_applied_update_id, channel.context.get_latest_monitor_update_id(), - remaining_in_flight); - if remaining_in_flight != 0 || !channel.is_awaiting_monitor_update() { + if remaining_in_flight != 0 { return; } - handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel); + + if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get_mut(channel_id) { + if chan.is_awaiting_monitor_update() { + log_trace!(logger, "Channel is open and awaiting update, resuming it"); + handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, chan); + } else { + log_trace!(logger, "Channel is open but not awaiting update"); + } + } else { + let update_actions = peer_state.monitor_update_blocked_actions + .remove(channel_id).unwrap_or(Vec::new()); + log_trace!(logger, "Channel is closed, applying {} post-update actions", update_actions.len()); + mem::drop(peer_state_lock); + mem::drop(per_peer_state); + self.handle_monitor_update_completion_actions(update_actions); + } } /// Accepts a request to open a channel after a [`Event::OpenChannelRequest`].