]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Send channel_update messages to direct peers on private channels
authorMatt Corallo <git@bluematt.me>
Sat, 12 Jun 2021 21:58:50 +0000 (21:58 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 12 Jun 2021 21:58:50 +0000 (21:58 +0000)
If we are a public node and have a private channel, our
counterparty needs to know the fees which we will charge to forward
payments to them. Without sending them a channel_update, they have
no way to learn that information, resulting in the channel being
effectively useless for outbound-from-us payments.

This commit fixes our lack of channel_update messages to private
channel counterparties, ensuring we always send them a
channel_update after the channel funding is confirmed.

lightning/src/ln/channelmanager.rs
lightning/src/ln/peer_handler.rs
lightning/src/util/events.rs

index 530f610cf250fe389468e69ba572d7654f42ef91..bc659be2cee7791bf344451a4cb8fe877aeb2c7f 100644 (file)
@@ -947,6 +947,11 @@ macro_rules! handle_chan_restoration_locked {
                                                node_id: counterparty_node_id,
                                                msg: announcement_sigs,
                                        });
+                               } else if $channel_entry.get().is_usable() {
+                                       $channel_state.pending_msg_events.push(events::MessageSendEvent::SendChannelUpdate {
+                                               node_id: counterparty_node_id,
+                                               msg: $self.get_channel_update_for_unicast($channel_entry.get()).unwrap(),
+                                       });
                                }
                                $channel_state.short_to_id.insert($channel_entry.get().get_short_channel_id().unwrap(), $channel_entry.get().channel_id());
                        }
@@ -2961,6 +2966,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                                                node_id: counterparty_node_id.clone(),
                                                msg: announcement_sigs,
                                        });
+                               } else if chan.get().is_usable() {
+                                       channel_state.pending_msg_events.push(events::MessageSendEvent::SendChannelUpdate {
+                                               node_id: counterparty_node_id.clone(),
+                                               msg: self.get_channel_update_for_unicast(chan.get()).unwrap(),
+                                       });
                                }
                                Ok(())
                        },
@@ -3954,6 +3964,12 @@ where
                                                                node_id: channel.get_counterparty_node_id(),
                                                                msg: announcement_sigs,
                                                        });
+                                               } else if channel.is_usable() {
+                                                       log_trace!(self.logger, "Sending funding_locked WITHOUT announcement_signatures but with channel_update for {}", log_bytes!(channel.channel_id()));
+                                                       pending_msg_events.push(events::MessageSendEvent::SendChannelUpdate {
+                                                               node_id: channel.get_counterparty_node_id(),
+                                                               msg: self.get_channel_update_for_unicast(channel).unwrap(),
+                                                       });
                                                } else {
                                                        log_trace!(self.logger, "Sending funding_locked WITHOUT announcement_signatures for {}", log_bytes!(channel.channel_id()));
                                                }
@@ -4188,6 +4204,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
                                        &events::MessageSendEvent::BroadcastChannelAnnouncement { .. } => true,
                                        &events::MessageSendEvent::BroadcastNodeAnnouncement { .. } => true,
                                        &events::MessageSendEvent::BroadcastChannelUpdate { .. } => true,
+                                       &events::MessageSendEvent::SendChannelUpdate { ref node_id, .. } => node_id != counterparty_node_id,
                                        &events::MessageSendEvent::HandleError { ref node_id, .. } => node_id != counterparty_node_id,
                                        &events::MessageSendEvent::PaymentFailureNetworkUpdate { .. } => true,
                                        &events::MessageSendEvent::SendChannelRangeQuery { .. } => false,
index dd3955c190fb2dc5e0e436eced5fddd9361d583b..e1cf14548624cfc06d344a45787e245cef4b3a28 100644 (file)
@@ -1237,6 +1237,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
                                                        self.forward_broadcast_msg(peers, &wire::Message::ChannelUpdate(msg), None);
                                                }
                                        },
+                                       MessageSendEvent::SendChannelUpdate { ref node_id, ref msg } => {
+                                               log_trace!(self.logger, "Handling SendChannelUpdate event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id), msg.contents.short_channel_id);
+                                               let (_, peer) = get_peer_for_forwarding!(node_id);
+                                               peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg)));
+                                       },
                                        MessageSendEvent::PaymentFailureNetworkUpdate { ref update } => {
                                                self.message_handler.route_handler.handle_htlc_fail_channel_update(update);
                                        },
index c8c7ad496e4dd3a62ec6e02ee046d89cf03a62f5..f989ff307ff90f317056c786a9b6bdf1b74dfc39 100644 (file)
@@ -392,6 +392,15 @@ pub enum MessageSendEvent {
                /// The channel_update which should be sent.
                msg: msgs::ChannelUpdate,
        },
+       /// Used to indicate that a channel_update should be sent to a single peer.
+       /// This is used, in contrast to [`Self::BroadcastChannelUpdate`], when the channel is a
+       /// private channel and we shouldn't be informing all of our peers of channel parameters.
+       SendChannelUpdate {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The channel_update which should be sent.
+               msg: msgs::ChannelUpdate,
+       },
        /// Broadcast an error downstream to be handled
        HandleError {
                /// The node_id of the node which should receive this message