@@ -3703,8 +3703,6 @@ macro_rules! handle_post_close_monitor_update {
37033703 ) => {{
37043704 let logger =
37053705 WithContext::from(&$self.logger, Some($counterparty_node_id), Some($channel_id), None);
3706- let in_flight_updates;
3707- let idx;
37083706 handle_new_monitor_update_internal!(
37093707 $self,
37103708 $funding_txo,
@@ -3713,21 +3711,16 @@ macro_rules! handle_post_close_monitor_update {
37133711 logger,
37143712 $channel_id,
37153713 $counterparty_node_id,
3716- in_flight_updates,
3717- idx,
37183714 {
3719- let _ = in_flight_updates.remove(idx);
3720- if in_flight_updates.is_empty() {
3721- let update_actions = $peer_state
3722- .monitor_update_blocked_actions
3723- .remove(&$channel_id)
3724- .unwrap_or(Vec::new());
3715+ let update_actions = $peer_state
3716+ .monitor_update_blocked_actions
3717+ .remove(&$channel_id)
3718+ .unwrap_or(Vec::new());
37253719
3726- mem::drop($peer_state_lock);
3727- mem::drop($per_peer_state_lock);
3720+ mem::drop($peer_state_lock);
3721+ mem::drop($per_peer_state_lock);
37283722
3729- $self.handle_monitor_update_completion_actions(update_actions);
3730- }
3723+ $self.handle_monitor_update_completion_actions(update_actions);
37313724 }
37323725 )
37333726 }};
@@ -3749,8 +3742,6 @@ macro_rules! handle_new_monitor_update_locked_actions_handled_by_caller {
37493742 let logger = WithChannelContext::from(&$self.logger, &$chan_context, None);
37503743 let chan_id = $chan_context.channel_id();
37513744 let counterparty_node_id = $chan_context.get_counterparty_node_id();
3752- let in_flight_updates;
3753- let idx;
37543745 handle_new_monitor_update_internal!(
37553746 $self,
37563747 $funding_txo,
@@ -3759,40 +3750,38 @@ macro_rules! handle_new_monitor_update_locked_actions_handled_by_caller {
37593750 logger,
37603751 chan_id,
37613752 counterparty_node_id,
3762- in_flight_updates,
3763- idx,
3764- {
3765- let _ = in_flight_updates.remove(idx);
3766- }
3753+ {}
37673754 )
37683755 }};
37693756}
37703757
37713758macro_rules! handle_new_monitor_update_internal {
37723759 (
37733760 $self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $logger: expr,
3774- $chan_id: expr, $counterparty_node_id: expr, $in_flight_updates: ident, $update_idx: ident,
3775- $completed: expr
3761+ $chan_id: expr, $counterparty_node_id: expr, $all_completed: expr
37763762 ) => {{
3777- $ in_flight_updates = &mut $peer_state
3763+ let in_flight_updates = &mut $peer_state
37783764 .in_flight_monitor_updates
37793765 .entry($chan_id)
37803766 .or_insert_with(|| ($funding_txo, Vec::new()))
37813767 .1;
37823768 // During startup, we push monitor updates as background events through to here in
37833769 // order to replay updates that were in-flight when we shut down. Thus, we have to
37843770 // filter for uniqueness here.
3785- $ update_idx =
3786- $ in_flight_updates.iter().position(|upd| upd == &$update).unwrap_or_else(|| {
3787- $ in_flight_updates.push($update);
3788- $ in_flight_updates.len() - 1
3771+ let update_idx =
3772+ in_flight_updates.iter().position(|upd| upd == &$update).unwrap_or_else(|| {
3773+ in_flight_updates.push($update);
3774+ in_flight_updates.len() - 1
37893775 });
37903776 if $self.background_events_processed_since_startup.load(Ordering::Acquire) {
37913777 let update_res =
3792- $self.chain_monitor.update_channel($chan_id, &$ in_flight_updates[$ update_idx]);
3778+ $self.chain_monitor.update_channel($chan_id, &in_flight_updates[update_idx]);
37933779 let update_completed = handle_monitor_update_res($self, update_res, $chan_id, $logger);
37943780 if update_completed {
3795- $completed;
3781+ let _ = in_flight_updates.remove(update_idx);
3782+ if in_flight_updates.is_empty() {
3783+ $all_completed;
3784+ }
37963785 }
37973786 update_completed
37983787 } else {
@@ -3803,7 +3792,7 @@ macro_rules! handle_new_monitor_update_internal {
38033792 counterparty_node_id: $counterparty_node_id,
38043793 funding_txo: $funding_txo,
38053794 channel_id: $chan_id,
3806- update: $ in_flight_updates[$ update_idx].clone(),
3795+ update: in_flight_updates[update_idx].clone(),
38073796 };
38083797 // We want to track the in-flight update both in `in_flight_monitor_updates` and in
38093798 // `pending_background_events` to avoid a race condition during
@@ -3827,8 +3816,6 @@ macro_rules! handle_new_monitor_update {
38273816 let logger = WithChannelContext::from(&$self.logger, &$chan.context, None);
38283817 let chan_id = $chan.context.channel_id();
38293818 let counterparty_node_id = $chan.context.get_counterparty_node_id();
3830- let in_flight_updates;
3831- let idx;
38323819 handle_new_monitor_update_internal!(
38333820 $self,
38343821 $funding_txo,
@@ -3837,11 +3824,8 @@ macro_rules! handle_new_monitor_update {
38373824 logger,
38383825 chan_id,
38393826 counterparty_node_id,
3840- in_flight_updates,
3841- idx,
38423827 {
3843- let _ = in_flight_updates.remove(idx);
3844- if in_flight_updates.is_empty() && $chan.blocked_monitor_updates_pending() == 0 {
3828+ if $chan.blocked_monitor_updates_pending() == 0 {
38453829 handle_monitor_update_completion!(
38463830 $self,
38473831 $peer_state_lock,
0 commit comments