Skip to content

Commit 49d2caa

Browse files
Add a new NodeFeatures constructor to capture the types of flags
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.
1 parent 9952362 commit 49d2caa

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6122,7 +6122,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
61226122
}
61236123

61246124
fn provided_node_features(&self) -> NodeFeatures {
6125-
NodeFeatures::known()
6125+
NodeFeatures::known_channel_features()
61266126
}
61276127

61286128
fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {

lightning/src/ln/features.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ mod sealed {
164164
],
165165
optional_features: [
166166
// Note that if new "non-channel-related" flags are added here they should be
167-
// explicitly cleared in InitFeatures::known_channel_features.
167+
// explicitly cleared in InitFeatures::known_channel_features and
168+
// NodeFeatures::known_channel_features.
168169
// Byte 0
169170
DataLossProtect | InitialRoutingSync | UpfrontShutdownScript | GossipQueries,
170171
// Byte 1
@@ -558,6 +559,14 @@ impl InitFeatures {
558559
}
559560
}
560561

562+
impl NodeFeatures {
563+
/// Returns the set of known node features that are related to channels. At least some of
564+
/// these features are likely required for peers to talk to us.
565+
pub fn known_channel_features() -> NodeFeatures {
566+
Self::known().clear_gossip_queries()
567+
}
568+
}
569+
561570
impl InvoiceFeatures {
562571
/// Converts `InvoiceFeatures` to `Features<C>`. Only known `InvoiceFeatures` relevant to
563572
/// context `C` are included in the result.

lightning/src/util/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler {
358358
self.received_msg(wire::Message::Error(msg.clone()));
359359
}
360360
fn provided_node_features(&self) -> NodeFeatures {
361-
NodeFeatures::empty()
361+
NodeFeatures::known_channel_features()
362362
}
363363
fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
364364
InitFeatures::known_channel_features()

0 commit comments

Comments
 (0)