Convert send_channel_ready macro to method
What changed, and why it matters
This commit is a simple code cleanup: it turns an internal macro (a reusable code snippet) into a regular Rust method. The actual behavior of the program does not change. There is no security fix or vulnerability here.
No action needed; this is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors send_channel_ready!, a macro_rules! macro, into a private send_channel_ready method on ChannelManager. The logic inside is preserved verbatim: it checks if the channel is connected, pushes a SendChannelReady event, inserts the outbound SCID alias into short_to_chan_info, asserts no collisions, and calls insert_short_channel_id!. All call sites are updated from macro invocation syntax to method call syntax. No functional changes are present in the diff.
Changed components
lightning/src/ln/channelmanager.rsInspect captured patch +28 / −23
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 87f42a9..bfaf1e6 100644
--- a/lightning/src/ln/channelmanager.rs
+++ b/lightning/src/ln/channelmanager.rs
@@ -3201,24 +3201,6 @@ pub struct PhantomRouteHints {
pub real_node_pubkey: PublicKey,
}
-macro_rules! send_channel_ready {
- ($self: ident, $pending_msg_events: expr, $channel: expr, $channel_ready_msg: expr) => {{
- if $channel.context.is_connected() {
- $pending_msg_events.push(MessageSendEvent::SendChannelReady {
- node_id: $channel.context.get_counterparty_node_id(),
- msg: $channel_ready_msg,
- });
- }
- // Note that we may send a `channel_ready` multiple times for a channel if we reconnect, so
- // we allow collisions, but we shouldn't ever be updating the channel ID pointed to.
- let mut short_to_chan_info = $self.short_to_chan_info.write().unwrap();
- let outbound_alias_insert = short_to_chan_info.insert($channel.context.outbound_scid_alias(), ($channel.context.get_counterparty_node_id(), $channel.context.channel_id()));
- assert!(outbound_alias_insert.is_none() || outbound_alias_insert.unwrap() == ($channel.context.get_counterparty_node_id(), $channel.context.channel_id()),
- "SCIDs should never collide - ensure you weren't behind the chain tip by a full month when creating channels");
- insert_short_channel_id!(short_to_chan_info, $channel);
- }}
-}
-
macro_rules! insert_short_channel_id {
($short_to_chan_info: ident, $channel: expr) => {{
if let Some(real_scid) = $channel.funding.get_short_channel_id() {
@@ -4091,6 +4073,29 @@ where
}
}
+ fn send_channel_ready(
+ &self, pending_msg_events: &mut Vec<MessageSendEvent>, channel: &FundedChannel<SP>,
+ channel_ready_msg: msgs::ChannelReady,
+ ) {
+ let counterparty_node_id = channel.context.get_counterparty_node_id();
+ if channel.context.is_connected() {
+ pending_msg_events.push(MessageSendEvent::SendChannelReady {
+ node_id: counterparty_node_id,
+ msg: channel_ready_msg,
+ });
+ }
+ // Note that we may send a `channel_ready` multiple times for a channel if we reconnect, so
+ // we allow collisions, but we shouldn't ever be updating the channel ID pointed to.
+ let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
+ let outbound_alias_insert = short_to_chan_info.insert(
+ channel.context.outbound_scid_alias(),
+ (counterparty_node_id, channel.context.channel_id()),
+ );
+ assert!(outbound_alias_insert.is_none() || outbound_alias_insert.unwrap() == (counterparty_node_id, channel.context.channel_id()),
+ "SCIDs should never collide - ensure you weren't behind the chain tip by a full month when creating channels");
+ insert_short_channel_id!(short_to_chan_info, channel);
+ }
+
/// Gets the current [`UserConfig`] which controls some global behavior and includes the
/// default configuration applied to all new channels.
pub fn get_current_config(&self) -> UserConfig {
@@ -9832,7 +9837,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
if channel.context.is_connected() {
if let ChannelReadyOrder::ChannelReadyFirst = channel_ready_order {
if let Some(msg) = &channel_ready {
- send_channel_ready!(self, pending_msg_events, channel, msg.clone());
+ self.send_channel_ready(pending_msg_events, channel, msg.clone());
}
if let Some(msg) = &announcement_sigs {
@@ -9887,7 +9892,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
if let ChannelReadyOrder::SignaturesFirst = channel_ready_order {
if let Some(msg) = channel_ready {
- send_channel_ready!(self, pending_msg_events, channel, msg);
+ self.send_channel_ready(pending_msg_events, channel, msg);
}
if let Some(msg) = announcement_sigs {
@@ -9898,7 +9903,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
}
}
} else if let Some(msg) = channel_ready {
- send_channel_ready!(self, pending_msg_events, channel, msg);
+ self.send_channel_ready(pending_msg_events, channel, msg);
}
if let Some(tx) = funding_broadcastable {
@@ -12598,7 +12603,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
}
if let Some(funded_chan) = chan.as_funded() {
if let Some(msg) = msgs.channel_ready {
- send_channel_ready!(self, pending_msg_events, funded_chan, msg);
+ self.send_channel_ready(pending_msg_events, funded_chan, msg);
}
if let Some(broadcast_tx) = msgs.signed_closing_tx {
log_info!(logger, "Broadcasting closing tx {}", log_tx!(broadcast_tx));
@@ -14740,7 +14745,7 @@ where
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
match funding_confirmed_opt {
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
- send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
+ self.send_channel_ready(pending_msg_events, funded_channel, channel_ready);
if funded_channel.context.is_usable() && peer_state.is_connected {
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty");
if let Ok((msg, _, _)) = self.get_channel_update_for_unicast(funded_channel) {
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.