Skip to content

Commit 593d6aa

Browse files
authored
Merge pull request #4279 from elnosh/remove-send-channel-ready
Convert send_channel_ready macro to method
2 parents 18cebae + 3247fad commit 593d6aa

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,24 +3201,6 @@ pub struct PhantomRouteHints {
32013201
pub real_node_pubkey: PublicKey,
32023202
}
32033203

3204-
macro_rules! send_channel_ready {
3205-
($self: ident, $pending_msg_events: expr, $channel: expr, $channel_ready_msg: expr) => {{
3206-
if $channel.context.is_connected() {
3207-
$pending_msg_events.push(MessageSendEvent::SendChannelReady {
3208-
node_id: $channel.context.get_counterparty_node_id(),
3209-
msg: $channel_ready_msg,
3210-
});
3211-
}
3212-
// Note that we may send a `channel_ready` multiple times for a channel if we reconnect, so
3213-
// we allow collisions, but we shouldn't ever be updating the channel ID pointed to.
3214-
let mut short_to_chan_info = $self.short_to_chan_info.write().unwrap();
3215-
let outbound_alias_insert = short_to_chan_info.insert($channel.context.outbound_scid_alias(), ($channel.context.get_counterparty_node_id(), $channel.context.channel_id()));
3216-
assert!(outbound_alias_insert.is_none() || outbound_alias_insert.unwrap() == ($channel.context.get_counterparty_node_id(), $channel.context.channel_id()),
3217-
"SCIDs should never collide - ensure you weren't behind the chain tip by a full month when creating channels");
3218-
insert_short_channel_id!(short_to_chan_info, $channel);
3219-
}}
3220-
}
3221-
32223204
macro_rules! insert_short_channel_id {
32233205
($short_to_chan_info: ident, $channel: expr) => {{
32243206
if let Some(real_scid) = $channel.funding.get_short_channel_id() {
@@ -4091,6 +4073,29 @@ where
40914073
}
40924074
}
40934075

4076+
fn send_channel_ready(
4077+
&self, pending_msg_events: &mut Vec<MessageSendEvent>, channel: &FundedChannel<SP>,
4078+
channel_ready_msg: msgs::ChannelReady,
4079+
) {
4080+
let counterparty_node_id = channel.context.get_counterparty_node_id();
4081+
if channel.context.is_connected() {
4082+
pending_msg_events.push(MessageSendEvent::SendChannelReady {
4083+
node_id: counterparty_node_id,
4084+
msg: channel_ready_msg,
4085+
});
4086+
}
4087+
// Note that we may send a `channel_ready` multiple times for a channel if we reconnect, so
4088+
// we allow collisions, but we shouldn't ever be updating the channel ID pointed to.
4089+
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap();
4090+
let outbound_alias_insert = short_to_chan_info.insert(
4091+
channel.context.outbound_scid_alias(),
4092+
(counterparty_node_id, channel.context.channel_id()),
4093+
);
4094+
assert!(outbound_alias_insert.is_none() || outbound_alias_insert.unwrap() == (counterparty_node_id, channel.context.channel_id()),
4095+
"SCIDs should never collide - ensure you weren't behind the chain tip by a full month when creating channels");
4096+
insert_short_channel_id!(short_to_chan_info, channel);
4097+
}
4098+
40944099
/// Gets the current [`UserConfig`] which controls some global behavior and includes the
40954100
/// default configuration applied to all new channels.
40964101
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/
98329837
if channel.context.is_connected() {
98339838
if let ChannelReadyOrder::ChannelReadyFirst = channel_ready_order {
98349839
if let Some(msg) = &channel_ready {
9835-
send_channel_ready!(self, pending_msg_events, channel, msg.clone());
9840+
self.send_channel_ready(pending_msg_events, channel, msg.clone());
98369841
}
98379842

98389843
if let Some(msg) = &announcement_sigs {
@@ -9887,7 +9892,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
98879892

98889893
if let ChannelReadyOrder::SignaturesFirst = channel_ready_order {
98899894
if let Some(msg) = channel_ready {
9890-
send_channel_ready!(self, pending_msg_events, channel, msg);
9895+
self.send_channel_ready(pending_msg_events, channel, msg);
98919896
}
98929897

98939898
if let Some(msg) = announcement_sigs {
@@ -9898,7 +9903,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
98989903
}
98999904
}
99009905
} else if let Some(msg) = channel_ready {
9901-
send_channel_ready!(self, pending_msg_events, channel, msg);
9906+
self.send_channel_ready(pending_msg_events, channel, msg);
99029907
}
99039908

99049909
if let Some(tx) = funding_broadcastable {
@@ -12598,7 +12603,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1259812603
}
1259912604
if let Some(funded_chan) = chan.as_funded() {
1260012605
if let Some(msg) = msgs.channel_ready {
12601-
send_channel_ready!(self, pending_msg_events, funded_chan, msg);
12606+
self.send_channel_ready(pending_msg_events, funded_chan, msg);
1260212607
}
1260312608
if let Some(broadcast_tx) = msgs.signed_closing_tx {
1260412609
log_info!(logger, "Broadcasting closing tx {}", log_tx!(broadcast_tx));
@@ -14740,7 +14745,7 @@ where
1474014745
let logger = WithChannelContext::from(&self.logger, &funded_channel.context, None);
1474114746
match funding_confirmed_opt {
1474214747
Some(FundingConfirmedMessage::Establishment(channel_ready)) => {
14743-
send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
14748+
self.send_channel_ready(pending_msg_events, funded_channel, channel_ready);
1474414749
if funded_channel.context.is_usable() && peer_state.is_connected {
1474514750
log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty");
1474614751
if let Ok((msg, _, _)) = self.get_channel_update_for_unicast(funded_channel) {

0 commit comments

Comments
 (0)