From: Matt Corallo Date: Wed, 7 Sep 2022 17:51:16 +0000 (+0000) Subject: Fetch our `InitFeatures` from `ChannelMessageHandler` X-Git-Tag: v0.0.111~9^2~3 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=950ccc434046adb8527c9d3c066da482219b924a;p=rust-lightning Fetch our `InitFeatures` from `ChannelMessageHandler` 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. --- diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 022b67fca..fafa9ef8a 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -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 { diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index afbd040b6..20fd5a38b 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -6124,6 +6124,10 @@ impl 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; diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index a810731c6..fdcf5b05f 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -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. diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 9d3b7aca8..02c9749d1 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -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 NodeFeatures { NodeFeatures::empty() } + fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures { + InitFeatures::known() + } } impl events::MessageSendEventsProvider for TestChannelMessageHandler {