@@ -3923,6 +3923,34 @@ where
39233923 self.close_channel_internal(channel_id, counterparty_node_id, target_feerate_sats_per_1000_weight, shutdown_script)
39243924 }
39253925
3926+ /// Applies a [`ChannelMonitorUpdate`] which may or may not be for a channel which is closed.
3927+ #[must_use]
3928+ fn apply_post_close_monitor_update(
3929+ &self, counterparty_node_id: PublicKey, channel_id: ChannelId, funding_txo: OutPoint,
3930+ monitor_update: ChannelMonitorUpdate,
3931+ ) -> ChannelMonitorUpdateStatus {
3932+ // Note that there may be some post-close updates which need to be well-ordered with
3933+ // respect to the `update_id`, so we hold the `peer_state` lock here.
3934+ let per_peer_state = self.per_peer_state.read().unwrap();
3935+ let mut peer_state_lock = per_peer_state.get(&counterparty_node_id)
3936+ .expect("We must always have a peer entry for a peer with which we have channels that have ChannelMonitors")
3937+ .lock().unwrap();
3938+ let peer_state = &mut *peer_state_lock;
3939+ match peer_state.channel_by_id.entry(channel_id) {
3940+ hash_map::Entry::Occupied(mut chan_phase) => {
3941+ if let ChannelPhase::Funded(chan) = chan_phase.get_mut() {
3942+ let completed = handle_new_monitor_update!(self, funding_txo,
3943+ monitor_update, peer_state_lock, peer_state, per_peer_state, chan);
3944+ return if completed { ChannelMonitorUpdateStatus::Completed } else { ChannelMonitorUpdateStatus::InProgress };
3945+ } else {
3946+ debug_assert!(false, "We shouldn't have an update for a non-funded channel");
3947+ }
3948+ },
3949+ hash_map::Entry::Vacant(_) => {},
3950+ }
3951+ self.chain_monitor.update_channel(funding_txo, &monitor_update)
3952+ }
3953+
39263954 fn set_closed_chan_next_monitor_update_id(
39273955 peer_state: &mut PeerState<SP>, channel_id: ChannelId, monitor_update: &mut ChannelMonitorUpdate,
39283956 ) {
@@ -3956,34 +3984,6 @@ where
39563984 }
39573985 }
39583986
3959- /// Applies a [`ChannelMonitorUpdate`] which may or may not be for a channel which is closed.
3960- #[must_use]
3961- fn apply_post_close_monitor_update(
3962- &self, counterparty_node_id: PublicKey, channel_id: ChannelId, funding_txo: OutPoint,
3963- monitor_update: ChannelMonitorUpdate,
3964- ) -> ChannelMonitorUpdateStatus {
3965- // Note that there may be some post-close updates which need to be well-ordered with
3966- // respect to the `update_id`, so we hold the `peer_state` lock here.
3967- let per_peer_state = self.per_peer_state.read().unwrap();
3968- let mut peer_state_lock = per_peer_state.get(&counterparty_node_id)
3969- .expect("We must always have a peer entry for a peer with which we have channels that have ChannelMonitors")
3970- .lock().unwrap();
3971- let peer_state = &mut *peer_state_lock;
3972- match peer_state.channel_by_id.entry(channel_id) {
3973- hash_map::Entry::Occupied(mut chan_phase) => {
3974- if let ChannelPhase::Funded(chan) = chan_phase.get_mut() {
3975- let completed = handle_new_monitor_update!(self, funding_txo,
3976- monitor_update, peer_state_lock, peer_state, per_peer_state, chan);
3977- return if completed { ChannelMonitorUpdateStatus::Completed } else { ChannelMonitorUpdateStatus::InProgress };
3978- } else {
3979- debug_assert!(false, "We shouldn't have an update for a non-funded channel");
3980- }
3981- },
3982- hash_map::Entry::Vacant(_) => {},
3983- }
3984- self.chain_monitor.update_channel(funding_txo, &monitor_update)
3985- }
3986-
39873987 /// When a channel is removed, two things need to happen:
39883988 /// (a) [`locked_close_channel`] must be called in the same `per_peer_state` lock as
39893989 /// the channel-closing action,
0 commit comments