@@ -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_processed_later !($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
@@ -3666,6 +3666,7 @@ macro_rules! handle_post_close_monitor_update {
3666
3666
idx,
3667
3667
_internal_outer,
3668
3668
{
3669
+ // If we get a monitor update for a closed channel
3669
3670
let _ = in_flight_updates.remove(idx);
3670
3671
if in_flight_updates.is_empty() {
3671
3672
let update_actions = $peer_state
@@ -3683,6 +3684,42 @@ macro_rules! handle_post_close_monitor_update {
3683
3684
}};
3684
3685
}
3685
3686
3687
+ /// Handles a new monitor update without dropping peer_state locks and calling
3688
+ /// [`ChannelManager::handle_monitor_update_completion_actions`] if the monitor update completed
3689
+ /// synchronously.
3690
+ ///
3691
+ /// Useful because monitor updates need to be handled in the same mutex where the channel generated
3692
+ /// them (otherwise they can end up getting applied out-of-order) but it's not always possible to
3693
+ /// drop the aforementioned peer state locks at a given callsite. In this situation, use this macro
3694
+ /// to apply the monitor update immediately and handle the monitor update completion actions at a
3695
+ /// later time.
3696
+ macro_rules! handle_new_monitor_update_actions_processed_later {
3697
+ (
3698
+ $self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $chan_context: expr
3699
+ ) => {{
3700
+ let logger = WithChannelContext::from(&$self.logger, &$chan_context, None);
3701
+ let chan_id = $chan_context.channel_id();
3702
+ let counterparty_node_id = $chan_context.get_counterparty_node_id();
3703
+ let in_flight_updates;
3704
+ let idx;
3705
+ handle_new_monitor_update!(
3706
+ $self,
3707
+ $funding_txo,
3708
+ $update,
3709
+ $peer_state,
3710
+ logger,
3711
+ chan_id,
3712
+ counterparty_node_id,
3713
+ in_flight_updates,
3714
+ idx,
3715
+ _internal_outer,
3716
+ {
3717
+ let _ = in_flight_updates.remove(idx);
3718
+ }
3719
+ )
3720
+ }};
3721
+ }
3722
+
3686
3723
macro_rules! handle_new_monitor_update {
3687
3724
(
3688
3725
$self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $logger: expr,
@@ -3732,31 +3769,6 @@ macro_rules! handle_new_monitor_update {
3732
3769
false
3733
3770
}
3734
3771
}};
3735
- (
3736
- $self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $chan_context: expr,
3737
- REMAIN_LOCKED_UPDATE_ACTIONS_PROCESSED_LATER
3738
- ) => {{
3739
- let logger = WithChannelContext::from(&$self.logger, &$chan_context, None);
3740
- let chan_id = $chan_context.channel_id();
3741
- let counterparty_node_id = $chan_context.get_counterparty_node_id();
3742
- let in_flight_updates;
3743
- let idx;
3744
- handle_new_monitor_update!(
3745
- $self,
3746
- $funding_txo,
3747
- $update,
3748
- $peer_state,
3749
- logger,
3750
- chan_id,
3751
- counterparty_node_id,
3752
- in_flight_updates,
3753
- idx,
3754
- _internal_outer,
3755
- {
3756
- let _ = in_flight_updates.remove(idx);
3757
- }
3758
- )
3759
- }};
3760
3772
(
3761
3773
$self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr,
3762
3774
$per_peer_state_lock: expr, $chan: expr
@@ -14039,13 +14051,12 @@ where
14039
14051
insert_short_channel_id!(short_to_chan_info, funded_channel);
14040
14052
14041
14053
if let Some(monitor_update) = monitor_update_opt {
14042
- handle_new_monitor_update !(
14054
+ handle_new_monitor_update_actions_processed_later !(
14043
14055
self,
14044
14056
funding_txo,
14045
14057
monitor_update,
14046
14058
peer_state,
14047
- funded_channel.context,
14048
- REMAIN_LOCKED_UPDATE_ACTIONS_PROCESSED_LATER
14059
+ funded_channel.context
14049
14060
);
14050
14061
to_process_monitor_update_actions.push((
14051
14062
counterparty_node_id, channel_id
0 commit comments