@@ -3972,11 +3972,10 @@ where
3972
3972
}
3973
3973
3974
3974
/// Applies a [`ChannelMonitorUpdate`] which may or may not be for a channel which is closed.
3975
- #[must_use]
3976
3975
fn apply_post_close_monitor_update(
3977
3976
&self, counterparty_node_id: PublicKey, channel_id: ChannelId, funding_txo: OutPoint,
3978
3977
monitor_update: ChannelMonitorUpdate,
3979
- ) -> ChannelMonitorUpdateStatus {
3978
+ ) {
3980
3979
// Note that there may be some post-close updates which need to be well-ordered with
3981
3980
// respect to the `update_id`, so we hold the `peer_state` lock here.
3982
3981
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -3987,16 +3986,21 @@ where
3987
3986
match peer_state.channel_by_id.entry(channel_id) {
3988
3987
hash_map::Entry::Occupied(mut chan_phase) => {
3989
3988
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,
3991
3990
monitor_update, peer_state_lock, peer_state, per_peer_state, chan);
3992
- return if in_flight { ChannelMonitorUpdateStatus::InProgress } else { ChannelMonitorUpdateStatus::Completed } ;
3991
+ return;
3993
3992
} else {
3994
3993
debug_assert!(false, "We shouldn't have an update for a non-funded channel");
3995
3994
}
3996
3995
},
3997
3996
hash_map::Entry::Vacant(_) => {},
3998
3997
}
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
+ );
4000
4004
}
4001
4005
4002
4006
/// When a channel is removed, two things need to happen:
@@ -4025,7 +4029,7 @@ where
4025
4029
}
4026
4030
if let Some((_, funding_txo, _channel_id, monitor_update)) = shutdown_res.monitor_update {
4027
4031
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);
4029
4033
}
4030
4034
if self.background_events_processed_since_startup.load(Ordering::Acquire) {
4031
4035
// If a `ChannelMonitorUpdate` was applied (i.e. any time we have a funding txo and are
@@ -6342,9 +6346,7 @@ where
6342
6346
let _ = self.chain_monitor.update_channel(funding_txo, &update);
6343
6347
},
6344
6348
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);
6348
6350
},
6349
6351
BackgroundEvent::MonitorUpdatesComplete { counterparty_node_id, channel_id } => {
6350
6352
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -7265,32 +7267,31 @@ where
7265
7267
let payment_hash = payment_preimage.into();
7266
7268
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(chan_id), Some(payment_hash));
7267
7269
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
+ }
7274
7275
7276
+ if !during_init {
7275
7277
handle_new_monitor_update!(self, prev_hop.funding_txo, preimage_update, peer_state, peer_state, per_peer_state, logger, chan_id, POST_CHANNEL_CLOSE);
7276
7278
} else {
7277
7279
// If we're running during init we cannot update a monitor directly - they probably
7278
7280
// haven't actually been loaded yet. Instead, push the monitor update as a background
7279
7281
// 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
+
7282
7288
let event = BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
7283
7289
counterparty_node_id,
7284
7290
funding_txo: prev_hop.funding_txo,
7285
7291
channel_id: prev_hop.channel_id,
7286
7292
update: preimage_update,
7287
7293
};
7288
7294
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);
7294
7295
}
7295
7296
}
7296
7297
0 commit comments