Skip to content

Commit d3f0fa4

Browse files
committed
Add additional variants to handle_new_monitor_update!
In the coming commits we'll start handling `ChannelMonitorUpdate`s during channel closure in-line rather than after dropping locks via `finish_close_channel`. In order to make that easy, here we add a new `REMAIN_LOCKED_UPDATE_ACTIONS_PROCESSED_LATER` variant to `handle_new_monitor_update!` which can attempt to apply an update without dropping the locks and processing `MonitorUpdateCompletionAction`s immediately.
1 parent 9cdc9c1 commit d3f0fa4

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,18 +3232,17 @@ macro_rules! handle_monitor_update_completion {
32323232
}
32333233

32343234
macro_rules! handle_new_monitor_update {
3235-
($self: ident, $update_res: expr, $chan: expr, _internal, $completed: expr) => { {
3235+
($self: ident, $update_res: expr, $logger: expr, $channel_id: expr, _internal, $completed: expr) => { {
32363236
debug_assert!($self.background_events_processed_since_startup.load(Ordering::Acquire));
3237-
let logger = WithChannelContext::from(&$self.logger, &$chan.context, None);
32383237
match $update_res {
32393238
ChannelMonitorUpdateStatus::UnrecoverableError => {
32403239
let err_str = "ChannelMonitor[Update] persistence failed unrecoverably. This indicates we cannot continue normal operation and must shut down.";
3241-
log_error!(logger, "{}", err_str);
3240+
log_error!($logger, "{}", err_str);
32423241
panic!("{}", err_str);
32433242
},
32443243
ChannelMonitorUpdateStatus::InProgress => {
3245-
log_debug!(logger, "ChannelMonitor update for {} in flight, holding messages until the update completes.",
3246-
&$chan.context.channel_id());
3244+
log_debug!($logger, "ChannelMonitor update for {} in flight, holding messages until the update completes.",
3245+
$channel_id);
32473246
false
32483247
},
32493248
ChannelMonitorUpdateStatus::Completed => {
@@ -3253,22 +3252,52 @@ macro_rules! handle_new_monitor_update {
32533252
}
32543253
} };
32553254
($self: ident, $update_res: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr, INITIAL_MONITOR) => {
3256-
handle_new_monitor_update!($self, $update_res, $chan, _internal,
3255+
let logger = WithChannelContext::from(&$self.logger, &$chan.context, None);
3256+
handle_new_monitor_update!($self, $update_res, logger, $chan.context.channel_id(), _internal,
32573257
handle_monitor_update_completion!($self, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan))
32583258
};
3259-
($self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr) => { {
3260-
let in_flight_updates = $peer_state.in_flight_monitor_updates.entry($funding_txo)
3259+
(
3260+
$self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $logger: expr,
3261+
$chan_id: expr, $in_flight_updates: ident, $update_idx: ident, _internal_outer,
3262+
$completed: expr
3263+
) => { {
3264+
$in_flight_updates = $peer_state.in_flight_monitor_updates.entry($funding_txo)
32613265
.or_insert_with(Vec::new);
32623266
// During startup, we push monitor updates as background events through to here in
32633267
// order to replay updates that were in-flight when we shut down. Thus, we have to
32643268
// filter for uniqueness here.
3265-
let idx = in_flight_updates.iter().position(|upd| upd == &$update)
3269+
$update_idx = $in_flight_updates.iter().position(|upd| upd == &$update)
32663270
.unwrap_or_else(|| {
3267-
in_flight_updates.push($update);
3268-
in_flight_updates.len() - 1
3271+
$in_flight_updates.push($update);
3272+
$in_flight_updates.len() - 1
32693273
});
3270-
let update_res = $self.chain_monitor.update_channel($funding_txo, &in_flight_updates[idx]);
3271-
handle_new_monitor_update!($self, update_res, $chan, _internal,
3274+
let update_res = $self.chain_monitor.update_channel($funding_txo, &$in_flight_updates[$update_idx]);
3275+
handle_new_monitor_update!($self, update_res, $logger, $chan_id, _internal, $completed)
3276+
} };
3277+
(
3278+
$self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $chan_context: expr,
3279+
REMAIN_LOCKED_UPDATE_ACTIONS_PROCESSED_LATER
3280+
) => { {
3281+
let logger = WithChannelContext::from(&$self.logger, &$chan_context, None);
3282+
let chan_id = $chan_context.channel_id();
3283+
let in_flight_updates;
3284+
let idx;
3285+
handle_new_monitor_update!($self, $funding_txo, $update, $peer_state, logger, chan_id,
3286+
in_flight_updates, idx, _internal_outer,
3287+
{
3288+
let _ = in_flight_updates.remove(idx);
3289+
})
3290+
} };
3291+
(
3292+
$self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr,
3293+
$per_peer_state_lock: expr, $chan: expr
3294+
) => { {
3295+
let logger = WithChannelContext::from(&$self.logger, &$chan.context, None);
3296+
let chan_id = $chan.context.channel_id();
3297+
let in_flight_updates;
3298+
let idx;
3299+
handle_new_monitor_update!($self, $funding_txo, $update, $peer_state, logger, chan_id,
3300+
in_flight_updates, idx, _internal_outer,
32723301
{
32733302
let _ = in_flight_updates.remove(idx);
32743303
if in_flight_updates.is_empty() && $chan.blocked_monitor_updates_pending() == 0 {

0 commit comments

Comments
 (0)