Extract post-close monitor update macro
What changed, and why it matters
This commit is a pure code cleanup: it pulls one specialized branch of a large Rust macro out into its own named macro and updates the three call sites to use the new name. No behavior, logic, or security properties change.
No security action needed; treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extracts the POST_CHANNEL_CLOSE arm of the handle_new_monitor_update! macro into a new handle_post_close_monitor_update! macro. The new macro simply forwards to handle_new_monitor_update! with the same closure body that was previously inline. The three existing call sites are updated from handle_new_monitor_update!(…, POST_CHANNEL_CLOSE) to handle_post_close_monitor_update!(…). Token-level semantics are preserved; this is a refactor for readability.
Changed components
lightning/src/ln/channelmanager.rsInspect captured patch +44 / −43
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 6b3bd5c..f0e0005 100644
--- a/lightning/src/ln/channelmanager.rs
+++ b/lightning/src/ln/channelmanager.rs
@@ -3675,6 +3675,44 @@ macro_rules! handle_initial_monitor {
};
}
+macro_rules! handle_post_close_monitor_update {
+ (
+ $self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr,
+ $per_peer_state_lock: expr, $counterparty_node_id: expr, $channel_id: expr
+ ) => {{
+ let logger =
+ WithContext::from(&$self.logger, Some($counterparty_node_id), Some($channel_id), None);
+ let in_flight_updates;
+ let idx;
+ handle_new_monitor_update!(
+ $self,
+ $funding_txo,
+ $update,
+ $peer_state,
+ logger,
+ $channel_id,
+ $counterparty_node_id,
+ in_flight_updates,
+ idx,
+ _internal_outer,
+ {
+ let _ = in_flight_updates.remove(idx);
+ if in_flight_updates.is_empty() {
+ let update_actions = $peer_state
+ .monitor_update_blocked_actions
+ .remove(&$channel_id)
+ .unwrap_or(Vec::new());
+
+ mem::drop($peer_state_lock);
+ mem::drop($per_peer_state_lock);
+
+ $self.handle_monitor_update_completion_actions(update_actions);
+ }
+ }
+ )
+ }};
+}
+
macro_rules! handle_new_monitor_update {
(
$self: ident, $funding_txo: expr, $update: expr, $peer_state: expr, $logger: expr,
@@ -3749,41 +3787,6 @@ macro_rules! handle_new_monitor_update {
}
)
}};
- (
- $self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr,
- $per_peer_state_lock: expr, $counterparty_node_id: expr, $channel_id: expr, POST_CHANNEL_CLOSE
- ) => {{
- let logger =
- WithContext::from(&$self.logger, Some($counterparty_node_id), Some($channel_id), None);
- let in_flight_updates;
- let idx;
- handle_new_monitor_update!(
- $self,
- $funding_txo,
- $update,
- $peer_state,
- logger,
- $channel_id,
- $counterparty_node_id,
- in_flight_updates,
- idx,
- _internal_outer,
- {
- let _ = in_flight_updates.remove(idx);
- if in_flight_updates.is_empty() {
- let update_actions = $peer_state
- .monitor_update_blocked_actions
- .remove(&$channel_id)
- .unwrap_or(Vec::new());
-
- mem::drop($peer_state_lock);
- mem::drop($per_peer_state_lock);
-
- $self.handle_monitor_update_completion_actions(update_actions);
- }
- }
- )
- }};
(
$self: ident, $funding_txo: expr, $update: expr, $peer_state_lock: expr, $peer_state: expr,
$per_peer_state_lock: expr, $chan: expr
@@ -4494,9 +4497,9 @@ where
hash_map::Entry::Vacant(_) => {},
}
- handle_new_monitor_update!(
+ handle_post_close_monitor_update!(
self, funding_txo, monitor_update, peer_state_lock, peer_state, per_peer_state,
- counterparty_node_id, channel_id, POST_CHANNEL_CLOSE
+ counterparty_node_id, channel_id
);
}
@@ -8955,7 +8958,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
.push(action);
}
- handle_new_monitor_update!(
+ handle_post_close_monitor_update!(
self,
prev_hop.funding_txo,
preimage_update,
@@ -8963,8 +8966,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
peer_state,
per_peer_state,
prev_hop.counterparty_node_id,
- chan_id,
- POST_CHANNEL_CLOSE
+ chan_id
);
}
@@ -13345,7 +13347,7 @@ where
};
self.pending_background_events.lock().unwrap().push(event);
} else {
- handle_new_monitor_update!(
+ handle_post_close_monitor_update!(
self,
channel_funding_outpoint,
update,
@@ -13353,8 +13355,7 @@ where
peer_state,
per_peer_state,
counterparty_node_id,
- channel_id,
- POST_CHANNEL_CLOSE
+ channel_id
);
}
},
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.