@@ -3941,11 +3941,10 @@ where
3941
3941
}
3942
3942
3943
3943
/// Applies a [`ChannelMonitorUpdate`] which may or may not be for a channel which is closed.
3944
- #[must_use]
3945
3944
fn apply_post_close_monitor_update(
3946
3945
&self, counterparty_node_id: PublicKey, channel_id: ChannelId, funding_txo: OutPoint,
3947
3946
monitor_update: ChannelMonitorUpdate,
3948
- ) -> ChannelMonitorUpdateStatus {
3947
+ ) {
3949
3948
// Note that there may be some post-close updates which need to be well-ordered with
3950
3949
// respect to the `update_id`, so we hold the `peer_state` lock here.
3951
3950
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -3956,16 +3955,21 @@ where
3956
3955
match peer_state.channel_by_id.entry(channel_id) {
3957
3956
hash_map::Entry::Occupied(mut chan_phase) => {
3958
3957
if let ChannelPhase::Funded(chan) = chan_phase.get_mut() {
3959
- let in_flight = handle_new_monitor_update!(self, funding_txo,
3958
+ handle_new_monitor_update!(self, funding_txo,
3960
3959
monitor_update, peer_state_lock, peer_state, per_peer_state, chan);
3961
- return if in_flight { ChannelMonitorUpdateStatus::InProgress } else { ChannelMonitorUpdateStatus::Completed } ;
3960
+ return;
3962
3961
} else {
3963
3962
debug_assert!(false, "We shouldn't have an update for a non-funded channel");
3964
3963
}
3965
3964
},
3966
3965
hash_map::Entry::Vacant(_) => {},
3967
3966
}
3968
- self.chain_monitor.update_channel(funding_txo, &monitor_update)
3967
+ let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(channel_id), None);
3968
+
3969
+ handle_new_monitor_update!(
3970
+ self, funding_txo, monitor_update, peer_state_lock, peer_state, per_peer_state,
3971
+ logger, channel_id, POST_CHANNEL_CLOSE
3972
+ );
3969
3973
}
3970
3974
3971
3975
/// When a channel is removed, two things need to happen:
@@ -3994,7 +3998,7 @@ where
3994
3998
}
3995
3999
if let Some((_, funding_txo, _channel_id, monitor_update)) = shutdown_res.monitor_update {
3996
4000
debug_assert!(false, "This should have been handled in `locked_close_channel`");
3997
- let _ = self.apply_post_close_monitor_update(shutdown_res.counterparty_node_id, shutdown_res.channel_id, funding_txo, monitor_update);
4001
+ self.apply_post_close_monitor_update(shutdown_res.counterparty_node_id, shutdown_res.channel_id, funding_txo, monitor_update);
3998
4002
}
3999
4003
if self.background_events_processed_since_startup.load(Ordering::Acquire) {
4000
4004
// If a `ChannelMonitorUpdate` was applied (i.e. any time we have a funding txo and are
@@ -6348,9 +6352,7 @@ where
6348
6352
let _ = self.chain_monitor.update_channel(funding_txo, &update);
6349
6353
},
6350
6354
BackgroundEvent::MonitorUpdateRegeneratedOnStartup { counterparty_node_id, funding_txo, channel_id, update } => {
6351
- // The monitor update will be replayed on startup if it doesnt complete, so no
6352
- // use bothering to care about the monitor update completing.
6353
- let _ = self.apply_post_close_monitor_update(counterparty_node_id, channel_id, funding_txo, update);
6355
+ self.apply_post_close_monitor_update(counterparty_node_id, channel_id, funding_txo, update);
6354
6356
},
6355
6357
BackgroundEvent::MonitorUpdatesComplete { counterparty_node_id, channel_id } => {
6356
6358
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -7296,32 +7298,31 @@ where
7296
7298
let payment_hash = payment_preimage.into();
7297
7299
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(chan_id), Some(payment_hash));
7298
7300
7299
- if !during_init {
7300
- if let Some(action) = action_opt {
7301
- log_trace!(logger, "Tracking monitor update completion action for closed channel {}: {:?}",
7302
- chan_id, action);
7303
- peer_state.monitor_update_blocked_actions.entry(chan_id).or_insert(Vec::new()).push(action);
7304
- }
7301
+ if let Some(action) = action_opt {
7302
+ log_trace!(logger, "Tracking monitor update completion action for closed channel {}: {:?}",
7303
+ chan_id, action);
7304
+ peer_state.monitor_update_blocked_actions.entry(chan_id).or_insert(Vec::new()).push(action);
7305
+ }
7305
7306
7307
+ if !during_init {
7306
7308
handle_new_monitor_update!(self, prev_hop.funding_txo, preimage_update, peer_state, peer_state, per_peer_state, logger, chan_id, POST_CHANNEL_CLOSE);
7307
7309
} else {
7308
7310
// If we're running during init we cannot update a monitor directly - they probably
7309
7311
// haven't actually been loaded yet. Instead, push the monitor update as a background
7310
7312
// event.
7311
- // TODO: Track this update as pending and only complete the completion action when it
7312
- // finishes.
7313
+
7314
+ let in_flight_updates = peer_state.in_flight_monitor_updates
7315
+ .entry(prev_hop.funding_txo)
7316
+ .or_insert_with(Vec::new);
7317
+ in_flight_updates.push(preimage_update.clone());
7318
+
7313
7319
let event = BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
7314
7320
counterparty_node_id,
7315
7321
funding_txo: prev_hop.funding_txo,
7316
7322
channel_id: prev_hop.channel_id,
7317
7323
update: preimage_update,
7318
7324
};
7319
7325
self.pending_background_events.lock().unwrap().push(event);
7320
-
7321
- mem::drop(peer_state);
7322
- mem::drop(per_peer_state);
7323
-
7324
- self.handle_monitor_update_completion_actions(action_opt);
7325
7326
}
7326
7327
}
7327
7328
0 commit comments