@@ -3271,8 +3271,8 @@ macro_rules! locked_close_channel {
3271
3271
}};
3272
3272
($self: ident, $peer_state: expr, $funded_chan: expr, $shutdown_res_mut: expr, FUNDED) => {{
3273
3273
if let Some((_, funding_txo, _, update)) = $shutdown_res_mut.monitor_update.take() {
3274
- handle_new_monitor_update !($self, funding_txo, update, $peer_state,
3275
- $funded_chan.context, REMAIN_LOCKED_UPDATE_ACTIONS_PROCESSED_LATER );
3274
+ handle_new_monitor_update_actions_deferred !($self, funding_txo, update, $peer_state,
3275
+ $funded_chan.context);
3276
3276
}
3277
3277
// If there's a possibility that we need to generate further monitor updates for this
3278
3278
// channel, we need to store the last update_id of it. However, we don't want to insert
@@ -3713,6 +3713,42 @@ macro_rules! handle_post_close_monitor_update {
3713
3713
}};
3714
3714
}
3715
3715
3716
+ /// Handles a new monitor update without dropping peer_state locks and calling
3717
+ /// [`ChannelManager::handle_monitor_update_completion_actions`] if the monitor update completed
3718
+ /// synchronously.
3719
+ ///
3720
+ /// Useful because monitor updates need to be handled in the same mutex where the channel generated
3721
+ /// them (otherwise they can end up getting applied out-of-order) but it's not always possible to
3722
+ /// drop the aforementioned peer state locks at a given callsite. In this situation, use this macro
3723
+ /// to apply the monitor update immediately and handle the monitor update completion actions at a
3724
+ /// later time.
3725
+ macro_rules! handle_new_monitor_update_actions_deferred {
3726
+ (
3727
+ $self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $chan_context: expr
3728
+ ) => {{
3729
+ let logger = WithChannelContext::from(&$self.logger, &$chan_context, None);
3730
+ let chan_id = $chan_context.channel_id();
3731
+ let counterparty_node_id = $chan_context.get_counterparty_node_id();
3732
+ let in_flight_updates;
3733
+ let idx;
3734
+ handle_new_monitor_update!(
3735
+ $self,
3736
+ $funding_txo,
3737
+ $update,
3738
+ $peer_state,
3739
+ logger,
3740
+ chan_id,
3741
+ counterparty_node_id,
3742
+ in_flight_updates,
3743
+ idx,
3744
+ _internal_outer,
3745
+ {
3746
+ let _ = in_flight_updates.remove(idx);
3747
+ }
3748
+ )
3749
+ }};
3750
+ }
3751
+
3716
3752
macro_rules! handle_new_monitor_update {
3717
3753
(
3718
3754
$self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $logger: expr,
@@ -3762,31 +3798,6 @@ macro_rules! handle_new_monitor_update {
3762
3798
false
3763
3799
}
3764
3800
}};
3765
- (
3766
- $self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $chan_context: expr,
3767
- REMAIN_LOCKED_UPDATE_ACTIONS_PROCESSED_LATER
3768
- ) => {{
3769
- let logger = WithChannelContext::from(&$self.logger, &$chan_context, None);
3770
- let chan_id = $chan_context.channel_id();
3771
- let counterparty_node_id = $chan_context.get_counterparty_node_id();
3772
- let in_flight_updates;
3773
- let idx;
3774
- handle_new_monitor_update!(
3775
- $self,
3776
- $funding_txo,
3777
- $update,
3778
- $peer_state,
3779
- logger,
3780
- chan_id,
3781
- counterparty_node_id,
3782
- in_flight_updates,
3783
- idx,
3784
- _internal_outer,
3785
- {
3786
- let _ = in_flight_updates.remove(idx);
3787
- }
3788
- )
3789
- }};
3790
3801
(
3791
3802
$self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr,
3792
3803
$per_peer_state_lock: expr, $chan: expr
@@ -14039,13 +14050,12 @@ where
14039
14050
insert_short_channel_id!(short_to_chan_info, funded_channel);
14040
14051
14041
14052
if let Some(monitor_update) = monitor_update_opt {
14042
- handle_new_monitor_update !(
14053
+ handle_new_monitor_update_actions_deferred !(
14043
14054
self,
14044
14055
funding_txo,
14045
14056
monitor_update,
14046
14057
peer_state,
14047
- funded_channel.context,
14048
- REMAIN_LOCKED_UPDATE_ACTIONS_PROCESSED_LATER
14058
+ funded_channel.context
14049
14059
);
14050
14060
to_process_monitor_update_actions.push((
14051
14061
counterparty_node_id, channel_id
0 commit comments