@@ -111,6 +111,7 @@ use crate::onion_message::messenger::{
111111 MessageRouter, MessageSendInstructions, Responder, ResponseInstruction,
112112};
113113use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
114+ use crate::routing::gossip::NodeId;
114115use crate::routing::router::{
115116 BlindedTail, FixedRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route,
116117 RouteParameters, RouteParametersConfig, Router,
@@ -942,7 +943,7 @@ impl Into<LocalHTLCFailureReason> for FailureCode {
942943struct MsgHandleErrInternal {
943944 err: msgs::LightningError,
944945 closes_channel: bool,
945- shutdown_finish: Option<(ShutdownResult, Option<msgs::ChannelUpdate>)>,
946+ shutdown_finish: Option<(ShutdownResult, Option<( msgs::ChannelUpdate, NodeId, NodeId) >)>,
946947 tx_abort: Option<msgs::TxAbort>,
947948}
948949impl MsgHandleErrInternal {
@@ -966,7 +967,7 @@ impl MsgHandleErrInternal {
966967
967968 fn from_finish_shutdown(
968969 err: String, channel_id: ChannelId, shutdown_res: ShutdownResult,
969- channel_update: Option<msgs::ChannelUpdate>,
970+ channel_update: Option<( msgs::ChannelUpdate, NodeId, NodeId) >,
970971 ) -> Self {
971972 let err_msg = msgs::ErrorMessage { channel_id, data: err.clone() };
972973 let action = if shutdown_res.monitor_update.is_some() {
@@ -3244,10 +3245,10 @@ macro_rules! handle_error {
32443245 log_error!(logger, "Closing channel: {}", err.err);
32453246
32463247 $self.finish_close_channel(shutdown_res);
3247- if let Some(update) = update_option {
3248+ if let Some(( update, node_id_1, node_id_2) ) = update_option {
32483249 let mut pending_broadcast_messages = $self.pending_broadcast_messages.lock().unwrap();
32493250 pending_broadcast_messages.push(MessageSendEvent::BroadcastChannelUpdate {
3250- msg: update
3251+ msg: update, node_id_1, node_id_2
32513252 });
32523253 }
32533254 } else {
@@ -3574,7 +3575,7 @@ macro_rules! handle_monitor_update_completion {
35743575 // channel_update later through the announcement_signatures process for public
35753576 // channels, but there's no reason not to just inform our counterparty of our fees
35763577 // now.
3577- if let Ok(msg) = $self.get_channel_update_for_unicast($chan) {
3578+ if let Ok(( msg, _, _) ) = $self.get_channel_update_for_unicast($chan) {
35783579 Some(MessageSendEvent::SendChannelUpdate {
35793580 node_id: counterparty_node_id,
35803581 msg,
@@ -5137,7 +5138,7 @@ where
51375138 /// [`internal_closing_signed`]: Self::internal_closing_signed
51385139 fn get_channel_update_for_broadcast(
51395140 &self, chan: &FundedChannel<SP>,
5140- ) -> Result<msgs::ChannelUpdate, LightningError> {
5141+ ) -> Result<( msgs::ChannelUpdate, NodeId, NodeId) , LightningError> {
51415142 if !chan.context.should_announce() {
51425143 return Err(LightningError {
51435144 err: "Cannot broadcast a channel_update for a private channel".to_owned(),
@@ -5171,7 +5172,9 @@ where
51715172 /// [`channel_update`]: msgs::ChannelUpdate
51725173 /// [`internal_closing_signed`]: Self::internal_closing_signed
51735174 #[rustfmt::skip]
5174- fn get_channel_update_for_unicast(&self, chan: &FundedChannel<SP>) -> Result<msgs::ChannelUpdate, LightningError> {
5175+ fn get_channel_update_for_unicast(
5176+ &self, chan: &FundedChannel<SP>,
5177+ ) -> Result<(msgs::ChannelUpdate, NodeId, NodeId), LightningError> {
51755178 let logger = WithChannelContext::from(&self.logger, &chan.context, None);
51765179 log_trace!(logger, "Attempting to generate channel update for channel {}", chan.context.channel_id());
51775180 let short_channel_id = match chan.funding.get_short_channel_id().or(chan.context.latest_inbound_scid_alias()) {
@@ -5181,7 +5184,9 @@ where
51815184
51825185 let logger = WithChannelContext::from(&self.logger, &chan.context, None);
51835186 log_trace!(logger, "Generating channel update for channel {}", chan.context.channel_id());
5184- let were_node_one = self.our_network_pubkey.serialize()[..] < chan.context.get_counterparty_node_id().serialize()[..];
5187+ let our_node_id = NodeId::from_pubkey(&self.our_network_pubkey);
5188+ let their_node_id = NodeId::from_pubkey(&chan.context.get_counterparty_node_id());
5189+ let were_node_one = our_node_id < their_node_id;
51855190 let enabled = chan.context.is_enabled();
51865191
51875192 let unsigned = msgs::UnsignedChannelUpdate {
@@ -5203,10 +5208,14 @@ where
52035208 // channel.
52045209 let sig = self.node_signer.sign_gossip_message(msgs::UnsignedGossipMessage::ChannelUpdate(&unsigned)).unwrap();
52055210
5206- Ok(msgs::ChannelUpdate {
5207- signature: sig,
5208- contents: unsigned
5209- })
5211+ Ok((
5212+ msgs::ChannelUpdate {
5213+ signature: sig,
5214+ contents: unsigned
5215+ },
5216+ if were_node_one { our_node_id } else { their_node_id },
5217+ if were_node_one { their_node_id } else { our_node_id },
5218+ ))
52105219 }
52115220
52125221 #[cfg(any(test, feature = "_externalize_tests"))]
@@ -6649,11 +6658,11 @@ where
66496658 continue;
66506659 }
66516660 if let Some(channel) = channel.as_funded() {
6652- if let Ok(msg) = self.get_channel_update_for_broadcast(channel) {
6661+ if let Ok(( msg, node_id_1, node_id_2) ) = self.get_channel_update_for_broadcast(channel) {
66536662 let mut pending_broadcast_messages = self.pending_broadcast_messages.lock().unwrap();
6654- pending_broadcast_messages.push(MessageSendEvent::BroadcastChannelUpdate { msg });
6663+ pending_broadcast_messages.push(MessageSendEvent::BroadcastChannelUpdate { msg, node_id_1, node_id_2 });
66556664 } else if peer_state.is_connected {
6656- if let Ok(msg) = self.get_channel_update_for_unicast(channel) {
6665+ if let Ok(( msg, _, _) ) = self.get_channel_update_for_unicast(channel) {
66576666 peer_state.pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
66586667 node_id: channel.context.get_counterparty_node_id(),
66596668 msg,
@@ -8177,10 +8186,10 @@ where
81778186 n += 1;
81788187 if n >= DISABLE_GOSSIP_TICKS {
81798188 funded_chan.set_channel_update_status(ChannelUpdateStatus::Disabled);
8180- if let Ok(update) = self.get_channel_update_for_broadcast(&funded_chan) {
8189+ if let Ok(( update, node_id_1, node_id_2) ) = self.get_channel_update_for_broadcast(&funded_chan) {
81818190 let mut pending_broadcast_messages = self.pending_broadcast_messages.lock().unwrap();
81828191 pending_broadcast_messages.push(MessageSendEvent::BroadcastChannelUpdate {
8183- msg: update
8192+ msg: update, node_id_1, node_id_2
81848193 });
81858194 }
81868195 should_persist = NotifyOption::DoPersist;
@@ -8192,10 +8201,10 @@ where
81928201 n += 1;
81938202 if n >= ENABLE_GOSSIP_TICKS {
81948203 funded_chan.set_channel_update_status(ChannelUpdateStatus::Enabled);
8195- if let Ok(update) = self.get_channel_update_for_broadcast(&funded_chan) {
8204+ if let Ok(( update, node_id_1, node_id_2) ) = self.get_channel_update_for_broadcast(&funded_chan) {
81968205 let mut pending_broadcast_messages = self.pending_broadcast_messages.lock().unwrap();
81978206 pending_broadcast_messages.push(MessageSendEvent::BroadcastChannelUpdate {
8198- msg: update
8207+ msg: update, node_id_1, node_id_2
81998208 });
82008209 }
82018210 should_persist = NotifyOption::DoPersist;
@@ -10821,7 +10830,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1082110830 // channel_update here if the channel is not public, i.e. we're not sending an
1082210831 // announcement_signatures.
1082310832 log_trace!(logger, "Sending private initial channel_update for our counterparty on channel {}", chan.context.channel_id());
10824- if let Ok(msg) = self.get_channel_update_for_unicast(chan) {
10833+ if let Ok(( msg, _, _) ) = self.get_channel_update_for_unicast(chan) {
1082510834 peer_state.pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
1082610835 node_id: counterparty_node_id.clone(),
1082710836 msg,
@@ -11620,7 +11629,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1162011629 msg: try_channel_entry!(self, peer_state, res, chan_entry),
1162111630 // Note that announcement_signatures fails if the channel cannot be announced,
1162211631 // so get_channel_update_for_broadcast will never fail by the time we get here.
11623- update_msg: Some(self.get_channel_update_for_broadcast(chan).unwrap()),
11632+ update_msg: Some(self.get_channel_update_for_broadcast(chan).unwrap().0 ),
1162411633 });
1162511634 } else {
1162611635 return try_channel_entry!(self, peer_state, Err(ChannelError::close(
@@ -11729,7 +11738,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1172911738 // If the channel is in a usable state (ie the channel is not being shut
1173011739 // down), send a unicast channel_update to our counterparty to make sure
1173111740 // they have the latest channel parameters.
11732- if let Ok(msg) = self.get_channel_update_for_unicast(chan) {
11741+ if let Ok(( msg, _, _) ) = self.get_channel_update_for_unicast(chan) {
1173311742 channel_update = Some(MessageSendEvent::SendChannelUpdate {
1173411743 node_id: chan.context.get_counterparty_node_id(),
1173511744 msg,
@@ -14340,7 +14349,7 @@ where
1434014349 send_channel_ready!(self, pending_msg_events, funded_channel, channel_ready);
1434114350 if funded_channel.context.is_usable() && peer_state.is_connected {
1434214351 log_trace!(logger, "Sending channel_ready with private initial channel_update for our counterparty on channel {}", channel_id);
14343- if let Ok(msg) = self.get_channel_update_for_unicast(funded_channel) {
14352+ if let Ok(( msg, _, _) ) = self.get_channel_update_for_unicast(funded_channel) {
1434414353 pending_msg_events.push(MessageSendEvent::SendChannelUpdate {
1434514354 node_id: funded_channel.context.get_counterparty_node_id(),
1434614355 msg,
@@ -14433,7 +14442,7 @@ where
1443314442 // if the channel cannot be announced, so
1443414443 // get_channel_update_for_broadcast will never fail
1443514444 // by the time we get here.
14436- update_msg: Some(self.get_channel_update_for_broadcast(funded_channel).unwrap()),
14445+ update_msg: Some(self.get_channel_update_for_broadcast(funded_channel).unwrap().0 ),
1443714446 });
1443814447 }
1443914448 }
0 commit comments