@@ -3974,11 +3974,10 @@ where
3974
3974
}
3975
3975
3976
3976
/// Applies a [`ChannelMonitorUpdate`] which may or may not be for a channel which is closed.
3977
- #[must_use]
3978
3977
fn apply_post_close_monitor_update(
3979
3978
&self, counterparty_node_id: PublicKey, channel_id: ChannelId, funding_txo: OutPoint,
3980
3979
monitor_update: ChannelMonitorUpdate,
3981
- ) -> ChannelMonitorUpdateStatus {
3980
+ ) {
3982
3981
// Note that there may be some post-close updates which need to be well-ordered with
3983
3982
// respect to the `update_id`, so we hold the `peer_state` lock here.
3984
3983
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -3989,16 +3988,21 @@ where
3989
3988
match peer_state.channel_by_id.entry(channel_id) {
3990
3989
hash_map::Entry::Occupied(mut chan_phase) => {
3991
3990
if let ChannelPhase::Funded(chan) = chan_phase.get_mut() {
3992
- let in_flight = handle_new_monitor_update!(self, funding_txo,
3991
+ handle_new_monitor_update!(self, funding_txo,
3993
3992
monitor_update, peer_state_lock, peer_state, per_peer_state, chan);
3994
- return if in_flight { ChannelMonitorUpdateStatus::InProgress } else { ChannelMonitorUpdateStatus::Completed } ;
3993
+ return;
3995
3994
} else {
3996
3995
debug_assert!(false, "We shouldn't have an update for a non-funded channel");
3997
3996
}
3998
3997
},
3999
3998
hash_map::Entry::Vacant(_) => {},
4000
3999
}
4001
- self.chain_monitor.update_channel(funding_txo, &monitor_update)
4000
+ let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(channel_id), None);
4001
+
4002
+ handle_new_monitor_update!(
4003
+ self, funding_txo, monitor_update, peer_state_lock, peer_state, per_peer_state,
4004
+ logger, channel_id, POST_CHANNEL_CLOSE
4005
+ );
4002
4006
}
4003
4007
4004
4008
/// When a channel is removed, two things need to happen:
@@ -4027,7 +4031,7 @@ where
4027
4031
}
4028
4032
if let Some((_, funding_txo, _channel_id, monitor_update)) = shutdown_res.monitor_update {
4029
4033
debug_assert!(false, "This should have been handled in `locked_close_channel`");
4030
- let _ = self.apply_post_close_monitor_update(shutdown_res.counterparty_node_id, shutdown_res.channel_id, funding_txo, monitor_update);
4034
+ self.apply_post_close_monitor_update(shutdown_res.counterparty_node_id, shutdown_res.channel_id, funding_txo, monitor_update);
4031
4035
}
4032
4036
if self.background_events_processed_since_startup.load(Ordering::Acquire) {
4033
4037
// If a `ChannelMonitorUpdate` was applied (i.e. any time we have a funding txo and are
@@ -6378,9 +6382,7 @@ where
6378
6382
let _ = self.chain_monitor.update_channel(funding_txo, &update);
6379
6383
},
6380
6384
BackgroundEvent::MonitorUpdateRegeneratedOnStartup { counterparty_node_id, funding_txo, channel_id, update } => {
6381
- // The monitor update will be replayed on startup if it doesnt complete, so no
6382
- // use bothering to care about the monitor update completing.
6383
- let _ = self.apply_post_close_monitor_update(counterparty_node_id, channel_id, funding_txo, update);
6385
+ self.apply_post_close_monitor_update(counterparty_node_id, channel_id, funding_txo, update);
6384
6386
},
6385
6387
BackgroundEvent::MonitorUpdatesComplete { counterparty_node_id, channel_id } => {
6386
6388
let per_peer_state = self.per_peer_state.read().unwrap();
@@ -7324,32 +7326,31 @@ where
7324
7326
let payment_hash = payment_preimage.into();
7325
7327
let logger = WithContext::from(&self.logger, Some(counterparty_node_id), Some(chan_id), Some(payment_hash));
7326
7328
7327
- if !during_init {
7328
- if let Some(action) = action_opt {
7329
- log_trace!(logger, "Tracking monitor update completion action for closed channel {}: {:?}",
7330
- chan_id, action);
7331
- peer_state.monitor_update_blocked_actions.entry(chan_id).or_insert(Vec::new()).push(action);
7332
- }
7329
+ if let Some(action) = action_opt {
7330
+ log_trace!(logger, "Tracking monitor update completion action for closed channel {}: {:?}",
7331
+ chan_id, action);
7332
+ peer_state.monitor_update_blocked_actions.entry(chan_id).or_insert(Vec::new()).push(action);
7333
+ }
7333
7334
7335
+ if !during_init {
7334
7336
handle_new_monitor_update!(self, prev_hop.funding_txo, preimage_update, peer_state, peer_state, per_peer_state, logger, chan_id, POST_CHANNEL_CLOSE);
7335
7337
} else {
7336
7338
// If we're running during init we cannot update a monitor directly - they probably
7337
7339
// haven't actually been loaded yet. Instead, push the monitor update as a background
7338
7340
// event.
7339
- // TODO: Track this update as pending and only complete the completion action when it
7340
- // finishes.
7341
+
7342
+ let in_flight_updates = peer_state.in_flight_monitor_updates
7343
+ .entry(prev_hop.funding_txo)
7344
+ .or_insert_with(Vec::new);
7345
+ in_flight_updates.push(preimage_update.clone());
7346
+
7341
7347
let event = BackgroundEvent::MonitorUpdateRegeneratedOnStartup {
7342
7348
counterparty_node_id,
7343
7349
funding_txo: prev_hop.funding_txo,
7344
7350
channel_id: prev_hop.channel_id,
7345
7351
update: preimage_update,
7346
7352
};
7347
7353
self.pending_background_events.lock().unwrap().push(event);
7348
-
7349
- mem::drop(peer_state);
7350
- mem::drop(per_peer_state);
7351
-
7352
- self.handle_monitor_update_completion_actions(action_opt);
7353
7354
}
7354
7355
}
7355
7356
0 commit comments