From 06cb48afd46c71b10dfd96bdac1c0f509605cf6b Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 7 Sep 2022 17:35:50 +0000 Subject: [PATCH] OR InitFeatures from both Channel and Routing message handlers When we go to send an Init message to new peers, 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 InitFeatures across both our Channel and Routing handlers. Note that this also disables setting the `initial_routing_sync` flag in init messages, as was intended in e742894492c55802b241eebc585bbd28aa16481b, per the comment added on `clear_initial_routing_sync`, though this should not be a behavior change in practice as nodes which support gossip queries ignore the initial routing sync flag. --- lightning-net-tokio/src/lib.rs | 1 + lightning/src/ln/msgs.rs | 8 ++++++++ lightning/src/ln/peer_handler.rs | 9 +++++++-- lightning/src/routing/gossip.rs | 8 +++++++- lightning/src/util/test_utils.rs | 6 ++++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index fafa9ef8a..c50e3e69b 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_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { InitFeatures::known() } } impl ChannelMessageHandler for MsgHandler { fn handle_open_channel(&self, _their_node_id: &PublicKey, _their_features: InitFeatures, _msg: &OpenChannel) {} diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index fdcf5b05f..e063c3146 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -956,6 +956,14 @@ pub trait RoutingMessageHandler : MessageSendEventsProvider { /// Handles when a peer asks us to send routing gossip messages for a /// list of short_channel_ids. fn handle_query_short_channel_ids(&self, their_node_id: &PublicKey, msg: QueryShortChannelIds) -> Result<(), LightningError>; + + // Handler information: + /// 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; } /// A trait to describe an object that can receive onion messages. diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 02c9749d1..4c83c8cf4 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -77,6 +77,9 @@ 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_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { + InitFeatures::empty() + } } impl OnionMessageProvider for IgnoringMessageHandler { fn next_onion_message_for_peer(&self, _peer_node_id: PublicKey) -> Option { None } @@ -1053,7 +1056,8 @@ impl InitFeatures { + let mut features = InitFeatures::empty(); + features.set_gossip_queries_optional(); + features + } } impl>, C: Deref, L: Deref> MessageSendEventsProvider for P2PGossipSync diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 0ef05b7d1..a5389f92b 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -510,6 +510,12 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: msgs::QueryShortChannelIds) -> Result<(), msgs::LightningError> { Ok(()) } + + fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures { + let mut features = InitFeatures::empty(); + features.set_gossip_queries_optional(); + features + } } impl events::MessageSendEventsProvider for TestRoutingMessageHandler { -- 2.39.5