]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Fetch our `InitFeatures` from `ChannelMessageHandler`
authorMatt Corallo <git@bluematt.me>
Wed, 7 Sep 2022 17:51:16 +0000 (17:51 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 9 Sep 2022 15:36:46 +0000 (15:36 +0000)
Like we now do for `NodeFeatures`, this converts to asking our
registered `ChannelMessageHandler` for our `InitFeatures` instead
of hard-coding them to the global LDK known set.

This allows handlers to set different feature bits based on what
our configuration actually supports rather than what LDK supports
in aggregate.

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

index 022b67fca0c3d021a919e98027a197324594fadb..fafa9ef8a4948b2aa9cd67e1fc4fb81ef639832d 100644 (file)
@@ -614,6 +614,7 @@ mod tests {
                fn handle_channel_reestablish(&self, _their_node_id: &PublicKey, _msg: &ChannelReestablish) {}
                fn handle_error(&self, _their_node_id: &PublicKey, _msg: &ErrorMessage) {}
                fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::known() }
+               fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { InitFeatures::known() }
        }
        impl MessageSendEventsProvider for MsgHandler {
                fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
index afbd040b61c30d8a1543050f20c1739ef1aab29c..20fd5a38bd7ae38057fbbcbea8fcddeb70a6226f 100644 (file)
@@ -6124,6 +6124,10 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
        fn provided_node_features(&self) -> NodeFeatures {
                NodeFeatures::known()
        }
+
+       fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
+               InitFeatures::known()
+       }
 }
 
 const SERIALIZATION_VERSION: u8 = 1;
index a810731c691f40c58a12272b2784a4dd48722245..fdcf5b05ff76e7191439d3738870275b3f932586 100644 (file)
@@ -902,6 +902,13 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
        /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`]
        /// which are broadcasted in our node_announcement 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;
 }
 
 /// A trait to describe an object which can receive routing messages.
index 9d3b7aca807688b6ce8caf8d900702ccfee9a8e0..02c9749d19d21fed17fc8f2f672e6e68cb079154 100644 (file)
@@ -203,6 +203,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
        fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &msgs::Init) {}
        fn handle_error(&self, _their_node_id: &PublicKey, _msg: &msgs::ErrorMessage) {}
        fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() }
+       fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { InitFeatures::known() }
 }
 impl Deref for ErroringMessageHandler {
        type Target = ErroringMessageHandler;
@@ -1052,7 +1053,7 @@ 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 = InitFeatures::known();
+                                                               let features = self.message_handler.chan_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;
@@ -1064,7 +1065,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                                                peer.pending_read_is_header = true;
                                                                peer.their_node_id = Some(their_node_id);
                                                                insert_node_id!();
-                                                               let features = InitFeatures::known();
+                                                               let features = self.message_handler.chan_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;
index 42ac228c144d8317a0bca0d3804f576e1539b9b7..0ef05b7d1bd87c87c925dbc852bbbb83e793a45d 100644 (file)
@@ -360,6 +360,9 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler {
        fn provided_node_features(&self) -> NodeFeatures {
                NodeFeatures::empty()
        }
+       fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
+               InitFeatures::known()
+       }
 }
 
 impl events::MessageSendEventsProvider for TestChannelMessageHandler {