Skip to content

Commit bc64c82

Browse files
Extract macro for new monitor upd, process actions later
Makes handle_new_monitor_update more readable. Also documents the variant and why someone may want to use it.
1 parent 672ad17 commit bc64c82

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,8 +3271,8 @@ macro_rules! locked_close_channel {
32713271
}};
32723272
($self: ident, $peer_state: expr, $funded_chan: expr, $shutdown_res_mut: expr, FUNDED) => {{
32733273
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);
32763276
}
32773277
// If there's a possibility that we need to generate further monitor updates for this
32783278
// channel, we need to store the last update_id of it. However, we don't want to insert
@@ -3683,6 +3683,42 @@ macro_rules! handle_post_close_monitor_update {
36833683
}};
36843684
}
36853685

3686+
/// Handles a new monitor update without dropping peer_state locks and calling
3687+
/// [`ChannelManager::handle_monitor_update_completion_actions`] if the monitor update completed
3688+
/// synchronously.
3689+
///
3690+
/// Useful because monitor updates need to be handled in the same mutex where the channel generated
3691+
/// them (otherwise they can end up getting applied out-of-order) but it's not always possible to
3692+
/// drop the aforementioned peer state locks at a given callsite. In this situation, use this macro
3693+
/// to apply the monitor update immediately and handle the monitor update completion actions at a
3694+
/// later time.
3695+
macro_rules! handle_new_monitor_update_actions_processed_later {
3696+
(
3697+
$self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $chan_context: expr
3698+
) => {{
3699+
let logger = WithChannelContext::from(&$self.logger, &$chan_context, None);
3700+
let chan_id = $chan_context.channel_id();
3701+
let counterparty_node_id = $chan_context.get_counterparty_node_id();
3702+
let in_flight_updates;
3703+
let idx;
3704+
handle_new_monitor_update!(
3705+
$self,
3706+
$funding_txo,
3707+
$update,
3708+
$peer_state,
3709+
logger,
3710+
chan_id,
3711+
counterparty_node_id,
3712+
in_flight_updates,
3713+
idx,
3714+
_internal_outer,
3715+
{
3716+
let _ = in_flight_updates.remove(idx);
3717+
}
3718+
)
3719+
}};
3720+
}
3721+
36863722
macro_rules! handle_new_monitor_update {
36873723
(
36883724
$self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $logger: expr,
@@ -3732,31 +3768,6 @@ macro_rules! handle_new_monitor_update {
37323768
false
37333769
}
37343770
}};
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-
}};
37603771
(
37613772
$self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr,
37623773
$per_peer_state_lock: expr, $chan: expr
@@ -14039,13 +14050,12 @@ where
1403914050
insert_short_channel_id!(short_to_chan_info, funded_channel);
1404014051

1404114052
if let Some(monitor_update) = monitor_update_opt {
14042-
handle_new_monitor_update!(
14053+
handle_new_monitor_update_actions_processed_later!(
1404314054
self,
1404414055
funding_txo,
1404514056
monitor_update,
1404614057
peer_state,
14047-
funded_channel.context,
14048-
REMAIN_LOCKED_UPDATE_ACTIONS_PROCESSED_LATER
14058+
funded_channel.context
1404914059
);
1405014060
to_process_monitor_update_actions.push((
1405114061
counterparty_node_id, channel_id

0 commit comments

Comments
 (0)