From c106d4ff9f60a9225f662ab68cb054f416ce8361 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Fri, 9 Sep 2022 12:12:50 -0400 Subject: [PATCH] OR NodeFeatures from both Channel and Routing message handlers 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 | 1 + lightning/src/ln/msgs.rs | 4 ++++ lightning/src/ln/peer_handler.rs | 5 ++++- lightning/src/routing/gossip.rs | 6 ++++++ lightning/src/util/test_utils.rs | 6 ++++++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index c50e3e69b..d5feb9936 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -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 { diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index e063c3146..a6d096bff 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -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. diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 417b14d15..5e6938993 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -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 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(); diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 7c7aeb5d4..abeb874b3 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -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(); -- 2.39.5