39
39
//! (see [BOLT-4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md) for more information).
40
40
//! - `BasicMPP` - requires/supports that a node can receive basic multi-part payments
41
41
//! (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).
42
44
//! - `ShutdownAnySegwit` - requires/supports that future segwit versions are allowed in `shutdown`
43
45
//! (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
44
49
//! - `ChannelType` - node supports the channel_type field in open/accept
45
50
//! (see [BOLT-2](https://github.com/lightning/bolts/blob/master/02-peer-protocol.md) for more information).
46
51
//! - `SCIDPrivacy` - supply channel aliases for routing
@@ -164,7 +169,8 @@ mod sealed {
164
169
] ,
165
170
optional_features: [
166
171
// 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.
168
174
// Byte 0
169
175
DataLossProtect | InitialRoutingSync | UpfrontShutdownScript | GossipQueries ,
170
176
// Byte 1
@@ -174,7 +180,7 @@ mod sealed {
174
180
// Byte 3
175
181
ShutdownAnySegwit ,
176
182
// Byte 4
177
- ,
183
+ OnionMessages ,
178
184
// Byte 5
179
185
ChannelType | SCIDPrivacy ,
180
186
// Byte 6
@@ -208,7 +214,7 @@ mod sealed {
208
214
// Byte 3
209
215
ShutdownAnySegwit ,
210
216
// Byte 4
211
- ,
217
+ OnionMessages ,
212
218
// Byte 5
213
219
ChannelType | SCIDPrivacy ,
214
220
// Byte 6
@@ -435,8 +441,6 @@ mod sealed {
435
441
define_feature ! ( 27 , ShutdownAnySegwit , [ InitContext , NodeContext ] ,
436
442
"Feature flags for `opt_shutdown_anysegwit`." , set_shutdown_any_segwit_optional,
437
443
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.
440
444
define_feature ! ( 39 , OnionMessages , [ InitContext , NodeContext ] ,
441
445
"Feature flags for `option_onion_messages`." , set_onion_messages_optional,
442
446
set_onion_messages_required, supports_onion_messages, requires_onion_messages) ;
@@ -470,6 +474,17 @@ pub struct Features<T: sealed::Context> {
470
474
mark : PhantomData < T > ,
471
475
}
472
476
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
+
473
488
impl < T : sealed:: Context > Clone for Features < T > {
474
489
fn clone ( & self ) -> Self {
475
490
Self {
@@ -532,16 +547,6 @@ impl InitFeatures {
532
547
Ok ( ( ) )
533
548
}
534
549
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
-
545
550
/// Converts `InitFeatures` to `Features<C>`. Only known `InitFeatures` relevant to context `C`
546
551
/// are included in the result.
547
552
pub ( crate ) fn to_context < C : sealed:: Context > ( & self ) -> Features < C > {
@@ -554,6 +559,16 @@ impl InitFeatures {
554
559
Self :: known ( )
555
560
. clear_initial_routing_sync ( )
556
561
. 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 ( )
557
572
}
558
573
}
559
574
@@ -787,6 +802,13 @@ impl<T: sealed::InitialRoutingSync> Features<T> {
787
802
}
788
803
}
789
804
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
+
790
812
impl < T : sealed:: ShutdownAnySegwit > Features < T > {
791
813
#[ cfg( test) ]
792
814
pub ( crate ) fn clear_shutdown_anysegwit ( mut self ) -> Self {
@@ -913,6 +935,11 @@ mod tests {
913
935
assert ! ( !InitFeatures :: known( ) . requires_wumbo( ) ) ;
914
936
assert ! ( !NodeFeatures :: known( ) . requires_wumbo( ) ) ;
915
937
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
+
916
943
assert ! ( InitFeatures :: known( ) . supports_zero_conf( ) ) ;
917
944
assert ! ( !InitFeatures :: known( ) . requires_zero_conf( ) ) ;
918
945
assert ! ( NodeFeatures :: known( ) . supports_zero_conf( ) ) ;
@@ -957,15 +984,15 @@ mod tests {
957
984
// - var_onion_optin (req) | static_remote_key (req) | payment_secret(req)
958
985
// - basic_mpp | wumbo
959
986
// - opt_shutdown_anysegwit
960
- // -
987
+ // - onion_messages
961
988
// - option_channel_type | option_scid_alias
962
989
// - option_zeroconf
963
990
assert_eq ! ( node_features. flags. len( ) , 7 ) ;
964
991
assert_eq ! ( node_features. flags[ 0 ] , 0b00000010 ) ;
965
992
assert_eq ! ( node_features. flags[ 1 ] , 0b01010001 ) ;
966
993
assert_eq ! ( node_features. flags[ 2 ] , 0b00001010 ) ;
967
994
assert_eq ! ( node_features. flags[ 3 ] , 0b00001000 ) ;
968
- assert_eq ! ( node_features. flags[ 4 ] , 0b00000000 ) ;
995
+ assert_eq ! ( node_features. flags[ 4 ] , 0b10000000 ) ;
969
996
assert_eq ! ( node_features. flags[ 5 ] , 0b10100000 ) ;
970
997
assert_eq ! ( node_features. flags[ 6 ] , 0b00001000 ) ;
971
998
}
0 commit comments