3939//! (see [BOLT-4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md) for more information).
4040//! - `BasicMPP` - requires/supports that a node can receive basic multi-part payments
4141//! (see [BOLT-4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md#basic-multi-part-payments) for more information).
42+ //! - `Wumbo` - requires/supports that a node create large channels. Called `option_support_large_channel` in the spec.
43+ //! (see [BOLT-2](https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel-message) for more information).
4244//! - `ShutdownAnySegwit` - requires/supports that future segwit versions are allowed in `shutdown`
4345//! (see [BOLT-2](https://github.com/lightning/bolts/blob/master/02-peer-protocol.md) for more information).
46+ //! - `OnionMessages` - requires/supports forwarding onion messages
47+ //! (see [BOLT-7](https://github.com/lightning/bolts/pull/759/files) for more information).
48+ //! TODO: update link
4449//! - `ChannelType` - node supports the channel_type field in open/accept
4550//! (see [BOLT-2](https://github.com/lightning/bolts/blob/master/02-peer-protocol.md) for more information).
4651//! - `SCIDPrivacy` - supply channel aliases for routing
@@ -164,7 +169,8 @@ mod sealed {
164169 ] ,
165170 optional_features: [
166171 // Note that if new "non-channel-related" flags are added here they should be
167- // explicitly cleared in InitFeatures::known_channel_features.
172+ // explicitly cleared in InitFeatures::known_channel_features and
173+ // NodeFeatures::known_channel_features.
168174 // Byte 0
169175 DataLossProtect | InitialRoutingSync | UpfrontShutdownScript | GossipQueries ,
170176 // Byte 1
@@ -174,7 +180,7 @@ mod sealed {
174180 // Byte 3
175181 ShutdownAnySegwit ,
176182 // Byte 4
177- ,
183+ OnionMessages ,
178184 // Byte 5
179185 ChannelType | SCIDPrivacy ,
180186 // Byte 6
@@ -208,7 +214,7 @@ mod sealed {
208214 // Byte 3
209215 ShutdownAnySegwit ,
210216 // Byte 4
211- ,
217+ OnionMessages ,
212218 // Byte 5
213219 ChannelType | SCIDPrivacy ,
214220 // Byte 6
@@ -435,8 +441,6 @@ mod sealed {
435441 define_feature ! ( 27 , ShutdownAnySegwit , [ InitContext , NodeContext ] ,
436442 "Feature flags for `opt_shutdown_anysegwit`." , set_shutdown_any_segwit_optional,
437443 set_shutdown_any_segwit_required, supports_shutdown_anysegwit, requires_shutdown_anysegwit) ;
438- // We do not yet advertise the onion messages feature bit, but we need to detect when peers
439- // support it.
440444 define_feature ! ( 39 , OnionMessages , [ InitContext , NodeContext ] ,
441445 "Feature flags for `option_onion_messages`." , set_onion_messages_optional,
442446 set_onion_messages_required, supports_onion_messages, requires_onion_messages) ;
@@ -470,6 +474,17 @@ pub struct Features<T: sealed::Context> {
470474 mark : PhantomData < T > ,
471475}
472476
477+ impl < T : sealed:: Context > Features < T > {
478+ pub ( crate ) fn or ( mut self , o : Self ) -> Self {
479+ let total_feature_len = cmp:: max ( self . flags . len ( ) , o. flags . len ( ) ) ;
480+ self . flags . resize ( total_feature_len, 0u8 ) ;
481+ for ( byte, o_byte) in self . flags . iter_mut ( ) . zip ( o. flags . iter ( ) ) {
482+ * byte |= * o_byte;
483+ }
484+ self
485+ }
486+ }
487+
473488impl < T : sealed:: Context > Clone for Features < T > {
474489 fn clone ( & self ) -> Self {
475490 Self {
@@ -532,16 +547,6 @@ impl InitFeatures {
532547 Ok ( ( ) )
533548 }
534549
535- /// or's another InitFeatures into this one.
536- pub ( crate ) fn or ( mut self , o : InitFeatures ) -> InitFeatures {
537- let total_feature_len = cmp:: max ( self . flags . len ( ) , o. flags . len ( ) ) ;
538- self . flags . resize ( total_feature_len, 0u8 ) ;
539- for ( byte, o_byte) in self . flags . iter_mut ( ) . zip ( o. flags . iter ( ) ) {
540- * byte |= * o_byte;
541- }
542- self
543- }
544-
545550 /// Converts `InitFeatures` to `Features<C>`. Only known `InitFeatures` relevant to context `C`
546551 /// are included in the result.
547552 pub ( crate ) fn to_context < C : sealed:: Context > ( & self ) -> Features < C > {
@@ -554,6 +559,16 @@ impl InitFeatures {
554559 Self :: known ( )
555560 . clear_initial_routing_sync ( )
556561 . clear_gossip_queries ( )
562+ . clear_onion_messages ( )
563+ }
564+ }
565+
566+ impl NodeFeatures {
567+ /// Returns the set of known node features that are related to channels.
568+ pub fn known_channel_features ( ) -> NodeFeatures {
569+ Self :: known ( )
570+ . clear_gossip_queries ( )
571+ . clear_onion_messages ( )
557572 }
558573}
559574
@@ -787,6 +802,13 @@ impl<T: sealed::InitialRoutingSync> Features<T> {
787802 }
788803}
789804
805+ impl < T : sealed:: OnionMessages > Features < T > {
806+ pub ( crate ) fn clear_onion_messages ( mut self ) -> Self {
807+ <T as sealed:: OnionMessages >:: clear_bits ( & mut self . flags ) ;
808+ self
809+ }
810+ }
811+
790812impl < T : sealed:: ShutdownAnySegwit > Features < T > {
791813 #[ cfg( test) ]
792814 pub ( crate ) fn clear_shutdown_anysegwit ( mut self ) -> Self {
@@ -913,6 +935,11 @@ mod tests {
913935 assert ! ( !InitFeatures :: known( ) . requires_wumbo( ) ) ;
914936 assert ! ( !NodeFeatures :: known( ) . requires_wumbo( ) ) ;
915937
938+ assert ! ( InitFeatures :: known( ) . supports_onion_messages( ) ) ;
939+ assert ! ( NodeFeatures :: known( ) . supports_onion_messages( ) ) ;
940+ assert ! ( !InitFeatures :: known( ) . requires_onion_messages( ) ) ;
941+ assert ! ( !NodeFeatures :: known( ) . requires_onion_messages( ) ) ;
942+
916943 assert ! ( InitFeatures :: known( ) . supports_zero_conf( ) ) ;
917944 assert ! ( !InitFeatures :: known( ) . requires_zero_conf( ) ) ;
918945 assert ! ( NodeFeatures :: known( ) . supports_zero_conf( ) ) ;
@@ -957,15 +984,15 @@ mod tests {
957984 // - var_onion_optin (req) | static_remote_key (req) | payment_secret(req)
958985 // - basic_mpp | wumbo
959986 // - opt_shutdown_anysegwit
960- // -
987+ // - onion_messages
961988 // - option_channel_type | option_scid_alias
962989 // - option_zeroconf
963990 assert_eq ! ( node_features. flags. len( ) , 7 ) ;
964991 assert_eq ! ( node_features. flags[ 0 ] , 0b00000010 ) ;
965992 assert_eq ! ( node_features. flags[ 1 ] , 0b01010001 ) ;
966993 assert_eq ! ( node_features. flags[ 2 ] , 0b00001010 ) ;
967994 assert_eq ! ( node_features. flags[ 3 ] , 0b00001000 ) ;
968- assert_eq ! ( node_features. flags[ 4 ] , 0b00000000 ) ;
995+ assert_eq ! ( node_features. flags[ 4 ] , 0b10000000 ) ;
969996 assert_eq ! ( node_features. flags[ 5 ] , 0b10100000 ) ;
970997 assert_eq ! ( node_features. flags[ 6 ] , 0b00001000 ) ;
971998 }
0 commit comments