OR InitFeatures and NodeFeatures from onion message handler
authorValentine Wallace <vwallace@protonmail.com>
Fri, 9 Sep 2022 16:29:13 +0000 (12:29 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Fri, 9 Sep 2022 20:00:21 +0000 (16:00 -0400)
Similar to how we OR our InitFeaures and NodeFeatures across both our channel
and routing message handlers, we also want to OR the features of our onion
message handler.

lightning/src/ln/msgs.rs
lightning/src/ln/peer_handler.rs
lightning/src/onion_message/messenger.rs

index a6d096bffb93bce56a399b071e2314eff67ee61b..a43156965cc71dafe22cdb159e16fc672f18bd3c 100644 (file)
@@ -980,6 +980,19 @@ pub trait OnionMessageHandler : OnionMessageProvider {
        /// Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to
        /// drop and refuse to forward onion messages to this peer.
        fn peer_disconnected(&self, their_node_id: &PublicKey, no_connection_possible: bool);
+
+       // Handler information:
+       /// Gets the node feature flags which this handler itself supports. All available handlers are
+       /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
+       /// which are broadcasted in our [`NodeAnnouncement`] message.
+       fn provided_node_features(&self) -> NodeFeatures;
+
+       /// Gets the init feature flags which should be sent to the given peer. All available handlers
+       /// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`]
+       /// which are sent in our [`Init`] message.
+       ///
+       /// Note that this method is called before [`Self::peer_connected`].
+       fn provided_init_features(&self, their_node_id: &PublicKey) -> InitFeatures;
 }
 
 mod fuzzy_internal_msgs {
index 5e69389933e26d7648d624b0f2441bde6501f864..838927cb2367ac0e0af1fab435edb7a1170e27da 100644 (file)
@@ -89,6 +89,10 @@ impl OnionMessageHandler for IgnoringMessageHandler {
        fn handle_onion_message(&self, _their_node_id: &PublicKey, _msg: &msgs::OnionMessage) {}
        fn peer_connected(&self, _their_node_id: &PublicKey, _init: &msgs::Init) {}
        fn peer_disconnected(&self, _their_node_id: &PublicKey, _no_connection_possible: bool) {}
+       fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() }
+       fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures {
+               InitFeatures::empty()
+       }
 }
 impl Deref for IgnoringMessageHandler {
        type Target = IgnoringMessageHandler;
@@ -1062,7 +1066,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                                                peer.their_node_id = Some(their_node_id);
                                                                insert_node_id!();
                                                                let features = self.message_handler.chan_handler.provided_init_features(&their_node_id)
-                                                                       .or(self.message_handler.route_handler.provided_init_features(&their_node_id));
+                                                                       .or(self.message_handler.route_handler.provided_init_features(&their_node_id))
+                                                                       .or(self.message_handler.onion_message_handler.provided_init_features(&their_node_id));
                                                                let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
                                                                self.enqueue_message(peer, &resp);
                                                                peer.awaiting_pong_timer_tick_intervals = 0;
@@ -1075,7 +1080,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                                                peer.their_node_id = Some(their_node_id);
                                                                insert_node_id!();
                                                                let features = self.message_handler.chan_handler.provided_init_features(&their_node_id)
-                                                                       .or(self.message_handler.route_handler.provided_init_features(&their_node_id));
+                                                                       .or(self.message_handler.route_handler.provided_init_features(&their_node_id))
+                                                                       .or(self.message_handler.onion_message_handler.provided_init_features(&their_node_id));
                                                                let resp = msgs::Init { features, remote_network_address: filter_addresses(peer.their_net_address.clone()) };
                                                                self.enqueue_message(peer, &resp);
                                                                peer.awaiting_pong_timer_tick_intervals = 0;
@@ -1971,7 +1977,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                addresses.sort_by_key(|addr| addr.get_id());
 
                let features = self.message_handler.chan_handler.provided_node_features()
-                       .or(self.message_handler.route_handler.provided_node_features());
+                       .or(self.message_handler.route_handler.provided_node_features())
+                       .or(self.message_handler.onion_message_handler.provided_node_features());
                let announcement = msgs::UnsignedNodeAnnouncement {
                        features,
                        timestamp: self.last_node_announcement_serial.fetch_add(1, Ordering::AcqRel) as u32,
index e38a0d10f6aef42a840c9781beaa2bc540775133..2df01c2ba103dc118d644779aabbcf45489d6ba2 100644 (file)
@@ -16,6 +16,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};
 
 use chain::keysinterface::{InMemorySigner, KeysInterface, KeysManager, Recipient, Sign};
+use ln::features::{InitFeatures, NodeFeatures};
 use ln::msgs::{self, OnionMessageHandler};
 use ln::onion_utils;
 use super::blinded_route::{BlindedRoute, ForwardTlvs, ReceiveTlvs};
@@ -345,6 +346,18 @@ impl<Signer: Sign, K: Deref, L: Deref> OnionMessageHandler for OnionMessenger<Si
                let mut pending_msgs = self.pending_messages.lock().unwrap();
                pending_msgs.remove(their_node_id);
        }
+
+       fn provided_node_features(&self) -> NodeFeatures {
+               let mut features = NodeFeatures::empty();
+               features.set_onion_messages_optional();
+               features
+       }
+
+       fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures {
+               let mut features = InitFeatures::empty();
+               features.set_onion_messages_optional();
+               features
+       }
 }
 
 impl<Signer: Sign, K: Deref, L: Deref> OnionMessageProvider for OnionMessenger<Signer, K, L>