]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add a new NodeFeatures constructor to capture the types of flags
authorValentine Wallace <vwallace@protonmail.com>
Fri, 9 Sep 2022 16:17:33 +0000 (12:17 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Fri, 9 Sep 2022 19:58:24 +0000 (15:58 -0400)
When ChannelMessageHandler implementations wish to return a NodeFeatures which
contain all the known flags that are relevant to channel handling, but not
gossip  handling, they currently need to do so by manually constructing a
NodeFeatures with all known flags and then clearing the ones they don't want.

Instead of spreading this logic across the codebase, this consolidates such
construction into one place in features.rs.

lightning/src/ln/channelmanager.rs
lightning/src/ln/features.rs
lightning/src/util/test_utils.rs

index 7d09a5b81a839241d13003f2f4d9a947cf44b808..7495af879c7719aa59fba83418823e90255666f3 100644 (file)
@@ -6122,7 +6122,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
        }
 
        fn provided_node_features(&self) -> NodeFeatures {
-               NodeFeatures::known()
+               NodeFeatures::known_channel_features()
        }
 
        fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
index a680d0184e7601502763dcdb68824ad97342e545..ceb78a4a0d23678ecb26f3aef1da4b42bffe3da9 100644 (file)
@@ -164,7 +164,8 @@ mod sealed {
                ],
                optional_features: [
                        // Note that if new "non-channel-related" flags are added here they should be
-                       // explicitly cleared in InitFeatures::known_channel_features.
+                       // explicitly cleared in InitFeatures::known_channel_features and
+                       // NodeFeatures::known_channel_features.
                        // Byte 0
                        DataLossProtect | InitialRoutingSync | UpfrontShutdownScript | GossipQueries,
                        // Byte 1
@@ -558,6 +559,13 @@ impl InitFeatures {
        }
 }
 
+impl NodeFeatures {
+       /// Returns the set of known node features that are related to channels.
+       pub fn known_channel_features() -> NodeFeatures {
+               Self::known().clear_gossip_queries()
+       }
+}
+
 impl InvoiceFeatures {
        /// Converts `InvoiceFeatures` to `Features<C>`. Only known `InvoiceFeatures` relevant to
        /// context `C` are included in the result.
index abeb874b3d6ddcaa582a82f066b564f85949d31f..b0f9ba0a98ebf0efffbfa6ee5ee1b6a00fa7ab75 100644 (file)
@@ -358,7 +358,7 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler {
                self.received_msg(wire::Message::Error(msg.clone()));
        }
        fn provided_node_features(&self) -> NodeFeatures {
-               NodeFeatures::empty()
+               NodeFeatures::known_channel_features()
        }
        fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
                InitFeatures::known_channel_features()