@@ -3957,11 +3957,10 @@ where
3957
3957
}
3958
3958
3959
3959
/// Applies a [`ChannelMonitorUpdate`] which may or may not be for a channel which is closed.
3960
- #[must_use]
3961
3960
fn apply_post_close_monitor_update(
3962
3961
&self, counterparty_node_id: PublicKey, channel_id: ChannelId, funding_txo: OutPoint,
3963
3962
monitor_update: ChannelMonitorUpdate,
3964
- ) -> ChannelMonitorUpdateStatus {
3963
+ ) {
3965
3964
// Note that there may be some post-close updates which need to be well-ordered with
3966
3965
// respect to the `update_id`, so we hold the `peer_state` lock here.
3967
3966
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -3972,16 +3971,21 @@ where
3972
3971
match peer_state.channel_by_id.entry(channel_id) {
3973
3972
hash_map::Entry::Occupied(mut chan_phase) => {
3974
3973
if let ChannelPhase::Funded(chan) = chan_phase.get_mut() {
3975
- let in_flight = handle_new_monitor_update!(self, funding_txo,
3974
+ handle_new_monitor_update!(self, funding_txo,
3976
3975
monitor_update, peer_state_lock, peer_state, per_peer_state, chan);
3977
- return if in_flight { ChannelMonitorUpdateStatus::InProgress } else { ChannelMonitorUpdateStatus::Completed } ;
3976
+ return;
3978
3977
} else {
3979
3978
debug_assert!(false, "We shouldn't have an update for a non-funded channel");
3980
3979
}
3981
3980
},
3982
3981
hash_map::Entry::Vacant(_) => {},
3983
3982
}
3984
- self.chain_monitor.update_channel(funding_txo, &monitor_update)
3983
+ let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(channel_id), None);
3984
+
3985
+ handle_new_monitor_update!(
3986
+ self, funding_txo, monitor_update, peer_state_lock, peer_state, per_peer_state,
3987
+ logger, channel_id, POST_CHANNEL_CLOSE
3988
+ );
3985
3989
}
3986
3990
3987
3991
/// When a channel is removed, two things need to happen:
@@ -4010,7 +4014,7 @@ where
4010
4014
}
4011
4015
if let Some((_, funding_txo, _channel_id, monitor_update)) = shutdown_res.monitor_update {
4012
4016
debug_assert!(false, "This should have been handled in `locked_close_channel`");
4013
- let _ = self.apply_post_close_monitor_update(shutdown_res.counterparty_node_id, shutdown_res.channel_id, funding_txo, monitor_update);
4017
+ self.apply_post_close_monitor_update(shutdown_res.counterparty_node_id, shutdown_res.channel_id, funding_txo, monitor_update);
4014
4018
}
4015
4019
if self.background_events_processed_since_startup.load(Ordering::Acquire) {
4016
4020
// If a `ChannelMonitorUpdate` was applied (i.e. any time we have a funding txo and are
@@ -6359,9 +6363,7 @@ where
6359
6363
let _ = self.chain_monitor.update_channel(funding_txo, &update);
6360
6364
},
6361
6365
BackgroundEvent::MonitorUpdateRegeneratedOnStartup { counterparty_node_id, funding_txo, channel_id, update } => {
6362
- // The monitor update will be replayed on startup if it doesnt complete, so no
6363
- // use bothering to care about the monitor update completing.
6364
- let _ = self.apply_post_close_monitor_update(counterparty_node_id, channel_id, funding_txo, update);
6366
+ self.apply_post_close_monitor_update(counterparty_node_id, channel_id, funding_txo, update);
6365
6367
},
6366
6368
BackgroundEvent::MonitorUpdatesComplete { counterparty_node_id, channel_id } => {
6367
6369
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -7305,32 +7307,31 @@ where
7305
7307
let payment_hash = payment_preimage.into();
7306
7308
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(chan_id), Some(payment_hash));
7307
7309
7308
- if !during_init {
7309
- if let Some(action) = action_opt {
7310
- log_trace!(logger, "Tracking monitor update completion action for closed channel {}: {:?}",
7311
- chan_id, action);
7312
- peer_state.monitor_update_blocked_actions.entry(chan_id).or_insert(Vec::new()).push(action);
7313
- }
7310
+ if let Some(action) = action_opt {
7311
+ log_trace!(logger, "Tracking monitor update completion action for closed channel {}: {:?}",
7312
+ chan_id, action);
7313
+ peer_state.monitor_update_blocked_actions.entry(chan_id).or_insert(Vec::new()).push(action);
7314
+ }
7314
7315
7316
+ if !during_init {
7315
7317
handle_new_monitor_update!(self, prev_hop.funding_txo, preimage_update, peer_state, peer_state, per_peer_state, logger, chan_id, POST_CHANNEL_CLOSE);
7316
7318
} else {
7317
7319
// If we're running during init we cannot update a monitor directly - they probably
7318
7320
// haven't actually been loaded yet. Instead, push the monitor update as a background
7319
7321
// event.
7320
- // TODO: Track this update as pending and only complete the completion action when it
7321
- // finishes.
7322
+
7323
+ let in_flight_updates = peer_state.in_flight_monitor_updates
7324
+ .entry(prev_hop.funding_txo)
7325
+ .or_insert_with(Vec::new);
7326
+ in_flight_updates.push(preimage_update.clone());
7327
+
7322
7328
let event = BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
7323
7329
counterparty_node_id,
7324
7330
funding_txo: prev_hop.funding_txo,
7325
7331
channel_id: prev_hop.channel_id,
7326
7332
update: preimage_update,
7327
7333
};
7328
7334
self.pending_background_events.lock().unwrap().push(event);
7329
-
7330
- mem::drop(peer_state);
7331
- mem::drop(per_peer_state);
7332
-
7333
- self.handle_monitor_update_completion_actions(action_opt);
7334
7335
}
7335
7336
}
7336
7337
0 commit comments