]> git.bitcoin.ninja Git - rust-lightning/commitdiff
OR NodeFeatures from both Channel and Routing message handlers
authorValentine Wallace <vwallace@protonmail.com>
Fri, 9 Sep 2022 16:12:50 +0000 (12:12 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Fri, 9 Sep 2022 19:58:20 +0000 (15:58 -0400)
When we broadcast a node announcement, the features we support are really a
combination of all the various features our different handlers support. This
commit captures this concept by OR'ing our NodeFeatures across both our channel
and routing message handlers.

lightning-net-tokio/src/lib.rs
lightning/src/ln/msgs.rs
lightning/src/ln/peer_handler.rs
lightning/src/routing/gossip.rs
lightning/src/util/test_utils.rs

index c50e3e69bd272083d8ceed17015a62d311f7f32c..d5feb9936527ce156b2bec62ccec6c2f241245eb 100644 (file)
@@ -582,6 +582,7 @@ mod tests {
                fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: ReplyShortChannelIdsEnd) -> Result<(), LightningError> { Ok(()) }
                fn handle_query_channel_range(&self, _their_node_id: &PublicKey, _msg: QueryChannelRange) -> Result<(), LightningError> { Ok(()) }
                fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: QueryShortChannelIds) -> Result<(), LightningError> { Ok(()) }
+               fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::known() }
                fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { InitFeatures::known() }
        }
        impl ChannelMessageHandler for MsgHandler {
index e063c31464fc89a7f93b57c16e18f6f3dc62b8eb..a6d096bffb93bce56a399b071e2314eff67ee61b 100644 (file)
@@ -958,6 +958,10 @@ pub trait RoutingMessageHandler : MessageSendEventsProvider {
        fn handle_query_short_channel_ids(&self, their_node_id: &PublicKey, msg: QueryShortChannelIds) -> Result<(), LightningError>;
 
        // 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.
index 417b14d15b2c9637d64d78997cbae2d2b56de201..5e69389933e26d7648d624b0f2441bde6501f864 100644 (file)
@@ -77,6 +77,7 @@ impl RoutingMessageHandler for IgnoringMessageHandler {
        fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyShortChannelIdsEnd) -> Result<(), LightningError> { Ok(()) }
        fn handle_query_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::QueryChannelRange) -> Result<(), LightningError> { Ok(()) }
        fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: msgs::QueryShortChannelIds) -> Result<(), LightningError> { Ok(()) }
+       fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() }
        fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures {
                InitFeatures::empty()
        }
@@ -1969,8 +1970,10 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                // addresses be sorted for future compatibility.
                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());
                let announcement = msgs::UnsignedNodeAnnouncement {
-                       features: self.message_handler.chan_handler.provided_node_features(),
+                       features,
                        timestamp: self.last_node_announcement_serial.fetch_add(1, Ordering::AcqRel) as u32,
                        node_id: PublicKey::from_secret_key(&self.secp_ctx, &self.our_node_secret),
                        rgb, alias, addresses,
index 92a0e479a3de6a2d12266e8f67cd049243d6ca0c..d439245c61e080cd34e344924735b13374a9ef7d 100644 (file)
@@ -571,6 +571,12 @@ where C::Target: chain::Access, L::Target: Logger
                })
        }
 
+       fn provided_node_features(&self) -> NodeFeatures {
+               let mut features = NodeFeatures::empty();
+               features.set_gossip_queries_optional();
+               features
+       }
+
        fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures {
                let mut features = InitFeatures::empty();
                features.set_gossip_queries_optional();
index 7c7aeb5d44f03da527b549f6d816c0ae1a3fce3b..abeb874b3d6ddcaa582a82f066b564f85949d31f 100644 (file)
@@ -511,6 +511,12 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler {
                Ok(())
        }
 
+       fn provided_node_features(&self) -> NodeFeatures {
+               let mut features = NodeFeatures::empty();
+               features.set_gossip_queries_optional();
+               features
+       }
+
        fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
                let mut features = InitFeatures::empty();
                features.set_gossip_queries_optional();