@@ -3972,11 +3972,10 @@ where
39723972 }
39733973
39743974 /// Applies a [`ChannelMonitorUpdate`] which may or may not be for a channel which is closed.
3975- #[must_use]
39763975 fn apply_post_close_monitor_update(
39773976 &self, counterparty_node_id: PublicKey, channel_id: ChannelId, funding_txo: OutPoint,
39783977 monitor_update: ChannelMonitorUpdate,
3979- ) -> ChannelMonitorUpdateStatus {
3978+ ) {
39803979 // Note that there may be some post-close updates which need to be well-ordered with
39813980 // respect to the `update_id`, so we hold the `peer_state` lock here.
39823981 let per_peer_state = self.per_peer_state.read().unwrap();
@@ -3987,16 +3986,21 @@ where
39873986 match peer_state.channel_by_id.entry(channel_id) {
39883987 hash_map::Entry::Occupied(mut chan_phase) => {
39893988 if let ChannelPhase::Funded(chan) = chan_phase.get_mut() {
3990- let in_flight = handle_new_monitor_update!(self, funding_txo,
3989+ handle_new_monitor_update!(self, funding_txo,
39913990 monitor_update, peer_state_lock, peer_state, per_peer_state, chan);
3992- return if in_flight { ChannelMonitorUpdateStatus::InProgress } else { ChannelMonitorUpdateStatus::Completed } ;
3991+ return;
39933992 } else {
39943993 debug_assert!(false, "We shouldn't have an update for a non-funded channel");
39953994 }
39963995 },
39973996 hash_map::Entry::Vacant(_) => {},
39983997 }
3999- self.chain_monitor.update_channel(funding_txo, &monitor_update)
3998+ let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(channel_id), None);
3999+
4000+ handle_new_monitor_update!(
4001+ self, funding_txo, monitor_update, peer_state_lock, peer_state, per_peer_state,
4002+ logger, channel_id, POST_CHANNEL_CLOSE
4003+ );
40004004 }
40014005
40024006 /// When a channel is removed, two things need to happen:
@@ -4025,7 +4029,7 @@ where
40254029 }
40264030 if let Some((_, funding_txo, _channel_id, monitor_update)) = shutdown_res.monitor_update {
40274031 debug_assert!(false, "This should have been handled in `locked_close_channel`");
4028- let _ = self.apply_post_close_monitor_update(shutdown_res.counterparty_node_id, shutdown_res.channel_id, funding_txo, monitor_update);
4032+ self.apply_post_close_monitor_update(shutdown_res.counterparty_node_id, shutdown_res.channel_id, funding_txo, monitor_update);
40294033 }
40304034 if self.background_events_processed_since_startup.load(Ordering::Acquire) {
40314035 // If a `ChannelMonitorUpdate` was applied (i.e. any time we have a funding txo and are
@@ -6342,9 +6346,7 @@ where
63426346 let _ = self.chain_monitor.update_channel(funding_txo, &update);
63436347 },
63446348 BackgroundEvent::MonitorUpdateRegeneratedOnStartup { counterparty_node_id, funding_txo, channel_id, update } => {
6345- // The monitor update will be replayed on startup if it doesnt complete, so no
6346- // use bothering to care about the monitor update completing.
6347- let _ = self.apply_post_close_monitor_update(counterparty_node_id, channel_id, funding_txo, update);
6349+ self.apply_post_close_monitor_update(counterparty_node_id, channel_id, funding_txo, update);
63486350 },
63496351 BackgroundEvent::MonitorUpdatesComplete { counterparty_node_id, channel_id } => {
63506352 let per_peer_state = self.per_peer_state.read().unwrap();
@@ -7265,32 +7267,31 @@ where
72657267 let payment_hash = payment_preimage.into();
72667268 let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(chan_id), Some(payment_hash));
72677269
7268- if !during_init {
7269- if let Some(action) = action_opt {
7270- log_trace!(logger, "Tracking monitor update completion action for closed channel {}: {:?}",
7271- chan_id, action);
7272- peer_state.monitor_update_blocked_actions.entry(chan_id).or_insert(Vec::new()).push(action);
7273- }
7270+ if let Some(action) = action_opt {
7271+ log_trace!(logger, "Tracking monitor update completion action for closed channel {}: {:?}",
7272+ chan_id, action);
7273+ peer_state.monitor_update_blocked_actions.entry(chan_id).or_insert(Vec::new()).push(action);
7274+ }
72747275
7276+ if !during_init {
72757277 handle_new_monitor_update!(self, prev_hop.funding_txo, preimage_update, peer_state, peer_state, per_peer_state, logger, chan_id, POST_CHANNEL_CLOSE);
72767278 } else {
72777279 // If we're running during init we cannot update a monitor directly - they probably
72787280 // haven't actually been loaded yet. Instead, push the monitor update as a background
72797281 // event.
7280- // TODO: Track this update as pending and only complete the completion action when it
7281- // finishes.
7282+
7283+ let in_flight_updates = peer_state.in_flight_monitor_updates
7284+ .entry(prev_hop.funding_txo)
7285+ .or_insert_with(Vec::new);
7286+ in_flight_updates.push(preimage_update.clone());
7287+
72827288 let event = BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
72837289 counterparty_node_id,
72847290 funding_txo: prev_hop.funding_txo,
72857291 channel_id: prev_hop.channel_id,
72867292 update: preimage_update,
72877293 };
72887294 self.pending_background_events.lock().unwrap().push(event);
7289-
7290- mem::drop(peer_state);
7291- mem::drop(per_peer_state);
7292-
7293- self.handle_monitor_update_completion_actions(action_opt);
72947295 }
72957296 }
72967297
0 commit comments