Skip to content

Commit f0de03a

Browse files
Extract post-close monitor update macro
Makes handle_new_monitor_update more readable.
1 parent cd9bb85 commit f0de03a

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3675,6 +3675,44 @@ macro_rules! handle_initial_monitor {
36753675
};
36763676
}
36773677

3678+
macro_rules! handle_post_close_monitor_update {
3679+
(
3680+
$self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr,
3681+
$per_peer_state_lock: expr, $counterparty_node_id: expr, $channel_id: expr
3682+
) => {{
3683+
let logger =
3684+
WithContext::from(&$self.logger, Some($counterparty_node_id), Some($channel_id), None);
3685+
let in_flight_updates;
3686+
let idx;
3687+
handle_new_monitor_update!(
3688+
$self,
3689+
$funding_txo,
3690+
$update,
3691+
$peer_state,
3692+
logger,
3693+
$channel_id,
3694+
$counterparty_node_id,
3695+
in_flight_updates,
3696+
idx,
3697+
_internal_outer,
3698+
{
3699+
let _ = in_flight_updates.remove(idx);
3700+
if in_flight_updates.is_empty() {
3701+
let update_actions = $peer_state
3702+
.monitor_update_blocked_actions
3703+
.remove(&$channel_id)
3704+
.unwrap_or(Vec::new());
3705+
3706+
mem::drop($peer_state_lock);
3707+
mem::drop($per_peer_state_lock);
3708+
3709+
$self.handle_monitor_update_completion_actions(update_actions);
3710+
}
3711+
}
3712+
)
3713+
}};
3714+
}
3715+
36783716
macro_rules! handle_new_monitor_update {
36793717
(
36803718
$self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $logger: expr,
@@ -3749,41 +3787,6 @@ macro_rules! handle_new_monitor_update {
37493787
}
37503788
)
37513789
}};
3752-
(
3753-
$self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr,
3754-
$per_peer_state_lock: expr, $counterparty_node_id: expr, $channel_id: expr, POST_CHANNEL_CLOSE
3755-
) => {{
3756-
let logger =
3757-
WithContext::from(&$self.logger, Some($counterparty_node_id), Some($channel_id), None);
3758-
let in_flight_updates;
3759-
let idx;
3760-
handle_new_monitor_update!(
3761-
$self,
3762-
$funding_txo,
3763-
$update,
3764-
$peer_state,
3765-
logger,
3766-
$channel_id,
3767-
$counterparty_node_id,
3768-
in_flight_updates,
3769-
idx,
3770-
_internal_outer,
3771-
{
3772-
let _ = in_flight_updates.remove(idx);
3773-
if in_flight_updates.is_empty() {
3774-
let update_actions = $peer_state
3775-
.monitor_update_blocked_actions
3776-
.remove(&$channel_id)
3777-
.unwrap_or(Vec::new());
3778-
3779-
mem::drop($peer_state_lock);
3780-
mem::drop($per_peer_state_lock);
3781-
3782-
$self.handle_monitor_update_completion_actions(update_actions);
3783-
}
3784-
}
3785-
)
3786-
}};
37873790
(
37883791
$self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr,
37893792
$per_peer_state_lock: expr, $chan: expr
@@ -4494,9 +4497,9 @@ where
44944497
hash_map::Entry::Vacant(_) => {},
44954498
}
44964499

4497-
handle_new_monitor_update!(
4500+
handle_post_close_monitor_update!(
44984501
self, funding_txo, monitor_update, peer_state_lock, peer_state, per_peer_state,
4499-
counterparty_node_id, channel_id, POST_CHANNEL_CLOSE
4502+
counterparty_node_id, channel_id
45004503
);
45014504
}
45024505

@@ -8955,16 +8958,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89558958
.push(action);
89568959
}
89578960

8958-
handle_new_monitor_update!(
8961+
handle_post_close_monitor_update!(
89598962
self,
89608963
prev_hop.funding_txo,
89618964
preimage_update,
89628965
peer_state_lock,
89638966
peer_state,
89648967
per_peer_state,
89658968
prev_hop.counterparty_node_id,
8966-
chan_id,
8967-
POST_CHANNEL_CLOSE
8969+
chan_id
89688970
);
89698971
}
89708972

@@ -13345,16 +13347,15 @@ where
1334513347
};
1334613348
self.pending_background_events.lock().unwrap().push(event);
1334713349
} else {
13348-
handle_new_monitor_update!(
13350+
handle_post_close_monitor_update!(
1334913351
self,
1335013352
channel_funding_outpoint,
1335113353
update,
1335213354
peer_state,
1335313355
peer_state,
1335413356
per_peer_state,
1335513357
counterparty_node_id,
13356-
channel_id,
13357-
POST_CHANNEL_CLOSE
13358+
channel_id
1335813359
);
1335913360
}
1336013361
},

0 commit comments

Comments
 (0)