@@ -3245,18 +3245,17 @@ macro_rules! handle_monitor_update_completion {
32453245}
32463246
32473247macro_rules! handle_new_monitor_update {
3248- ($self: ident, $update_res: expr, $chan : expr, _internal, $completed: expr) => { {
3248+ ($self: ident, $update_res: expr, $logger: expr, $channel_id : expr, _internal, $completed: expr) => { {
32493249 debug_assert!($self.background_events_processed_since_startup.load(Ordering::Acquire));
3250- let logger = WithChannelContext::from(&$self.logger, &$chan.context, None);
32513250 match $update_res {
32523251 ChannelMonitorUpdateStatus::UnrecoverableError => {
32533252 let err_str = "ChannelMonitor[Update] persistence failed unrecoverably. This indicates we cannot continue normal operation and must shut down.";
3254- log_error!(logger, "{}", err_str);
3253+ log_error!($ logger, "{}", err_str);
32553254 panic!("{}", err_str);
32563255 },
32573256 ChannelMonitorUpdateStatus::InProgress => {
3258- log_debug!(logger, "ChannelMonitor update for {} in flight, holding messages until the update completes.",
3259- &$chan.context. channel_id() );
3257+ log_debug!($ logger, "ChannelMonitor update for {} in flight, holding messages until the update completes.",
3258+ $ channel_id);
32603259 false
32613260 },
32623261 ChannelMonitorUpdateStatus::Completed => {
@@ -3266,22 +3265,52 @@ macro_rules! handle_new_monitor_update {
32663265 }
32673266 } };
32683267 ($self: ident, $update_res: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr, INITIAL_MONITOR) => {
3269- handle_new_monitor_update!($self, $update_res, $chan, _internal,
3268+ let logger = WithChannelContext::from(&$self.logger, &$chan.context, None);
3269+ handle_new_monitor_update!($self, $update_res, logger, $chan.context.channel_id(), _internal,
32703270 handle_monitor_update_completion!($self, $peer_state_lock, $peer_state, $per_peer_state_lock, $chan))
32713271 };
3272- ($self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr) => { {
3273- let in_flight_updates = $peer_state.in_flight_monitor_updates.entry($funding_txo)
3272+ (
3273+ $self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $logger: expr,
3274+ $chan_id: expr, $in_flight_updates: ident, $update_idx: ident, _internal_outer,
3275+ $completed: expr
3276+ ) => { {
3277+ $in_flight_updates = $peer_state.in_flight_monitor_updates.entry($funding_txo)
32743278 .or_insert_with(Vec::new);
32753279 // During startup, we push monitor updates as background events through to here in
32763280 // order to replay updates that were in-flight when we shut down. Thus, we have to
32773281 // filter for uniqueness here.
3278- let idx = in_flight_updates.iter().position(|upd| upd == &$update)
3282+ $update_idx = $ in_flight_updates.iter().position(|upd| upd == &$update)
32793283 .unwrap_or_else(|| {
3280- in_flight_updates.push($update);
3281- in_flight_updates.len() - 1
3284+ $ in_flight_updates.push($update);
3285+ $ in_flight_updates.len() - 1
32823286 });
3283- let update_res = $self.chain_monitor.update_channel($funding_txo, &in_flight_updates[idx]);
3284- handle_new_monitor_update!($self, update_res, $chan, _internal,
3287+ let update_res = $self.chain_monitor.update_channel($funding_txo, &$in_flight_updates[$update_idx]);
3288+ handle_new_monitor_update!($self, update_res, $logger, $chan_id, _internal, $completed)
3289+ } };
3290+ (
3291+ $self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $chan_context: expr,
3292+ REMAIN_LOCKED_UPDATE_ACTIONS_PROCESSED_LATER
3293+ ) => { {
3294+ let logger = WithChannelContext::from(&$self.logger, &$chan_context, None);
3295+ let chan_id = $chan_context.channel_id();
3296+ let in_flight_updates;
3297+ let idx;
3298+ handle_new_monitor_update!($self, $funding_txo, $update, $peer_state, logger, chan_id,
3299+ in_flight_updates, idx, _internal_outer,
3300+ {
3301+ let _ = in_flight_updates.remove(idx);
3302+ })
3303+ } };
3304+ (
3305+ $self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr,
3306+ $per_peer_state_lock: expr, $chan: expr
3307+ ) => { {
3308+ let logger = WithChannelContext::from(&$self.logger, &$chan.context, None);
3309+ let chan_id = $chan.context.channel_id();
3310+ let in_flight_updates;
3311+ let idx;
3312+ handle_new_monitor_update!($self, $funding_txo, $update, $peer_state, logger, chan_id,
3313+ in_flight_updates, idx, _internal_outer,
32853314 {
32863315 let _ = in_flight_updates.remove(idx);
32873316 if in_flight_updates.is_empty() && $chan.blocked_monitor_updates_pending() == 0 {
0 commit comments