@@ -126,6 +126,10 @@ mod sealed {
126
126
,
127
127
// Byte 3
128
128
,
129
+ // Byte 4
130
+ ,
131
+ // Byte 5
132
+ ,
129
133
] ,
130
134
optional_features: [
131
135
// Byte 0
@@ -136,6 +140,10 @@ mod sealed {
136
140
BasicMPP ,
137
141
// Byte 3
138
142
ShutdownAnySegwit ,
143
+ // Byte 4
144
+ ,
145
+ // Byte 5
146
+ ChannelType ,
139
147
] ,
140
148
} ) ;
141
149
define_context ! ( NodeContext {
@@ -167,7 +175,7 @@ mod sealed {
167
175
// Byte 4
168
176
,
169
177
// Byte 5
170
- ,
178
+ ChannelType ,
171
179
// Byte 6
172
180
Keysend ,
173
181
] ,
@@ -223,7 +231,7 @@ mod sealed {
223
231
/// useful for manipulating feature flags.
224
232
macro_rules! define_feature {
225
233
( $odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr, $optional_setter: ident,
226
- $required_setter: ident) => {
234
+ $required_setter: ident, $supported_getter : ident ) => {
227
235
#[ doc = $doc]
228
236
///
229
237
/// See [BOLT #9] for details.
@@ -320,6 +328,11 @@ mod sealed {
320
328
<T as $feature>:: set_required_bit( & mut self . flags) ;
321
329
self
322
330
}
331
+
332
+ /// Checks if this feature is supported.
333
+ pub fn $supported_getter( & self ) -> bool {
334
+ <T as $feature>:: supports_feature( & self . flags)
335
+ }
323
336
}
324
337
325
338
$(
@@ -331,41 +344,60 @@ mod sealed {
331
344
const ASSERT_ODD_BIT_PARITY : usize = ( <Self as $feature>:: ODD_BIT % 2 ) - 1 ;
332
345
}
333
346
) *
334
-
347
+ } ;
348
+ ( $odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr, $optional_setter: ident,
349
+ $required_setter: ident, $supported_getter: ident, $required_getter: ident) => {
350
+ define_feature!( $odd_bit, $feature, [ $( $context) ,+] , $doc, $optional_setter, $required_setter, $supported_getter) ;
351
+ impl <T : $feature> Features <T > {
352
+ /// Checks if this feature is required.
353
+ pub fn $required_getter( & self ) -> bool {
354
+ <T as $feature>:: requires_feature( & self . flags)
355
+ }
356
+ }
335
357
}
336
358
}
337
359
338
360
define_feature ! ( 1 , DataLossProtect , [ InitContext , NodeContext ] ,
339
361
"Feature flags for `option_data_loss_protect`." , set_data_loss_protect_optional,
340
- set_data_loss_protect_required) ;
362
+ set_data_loss_protect_required, supports_data_loss_protect , requires_data_loss_protect ) ;
341
363
// NOTE: Per Bolt #9, initial_routing_sync has no even bit.
342
364
define_feature ! ( 3 , InitialRoutingSync , [ InitContext ] , "Feature flags for `initial_routing_sync`." ,
343
- set_initial_routing_sync_optional, set_initial_routing_sync_required) ;
365
+ set_initial_routing_sync_optional, set_initial_routing_sync_required,
366
+ initial_routing_sync) ;
344
367
define_feature ! ( 5 , UpfrontShutdownScript , [ InitContext , NodeContext ] ,
345
368
"Feature flags for `option_upfront_shutdown_script`." , set_upfront_shutdown_script_optional,
346
- set_upfront_shutdown_script_required) ;
369
+ set_upfront_shutdown_script_required, supports_upfront_shutdown_script,
370
+ requires_upfront_shutdown_script) ;
347
371
define_feature ! ( 7 , GossipQueries , [ InitContext , NodeContext ] ,
348
- "Feature flags for `gossip_queries`." , set_gossip_queries_optional, set_gossip_queries_required) ;
372
+ "Feature flags for `gossip_queries`." , set_gossip_queries_optional, set_gossip_queries_required,
373
+ supports_gossip_queries, requires_gossip_queries) ;
349
374
define_feature ! ( 9 , VariableLengthOnion , [ InitContext , NodeContext , InvoiceContext ] ,
350
375
"Feature flags for `var_onion_optin`." , set_variable_length_onion_optional,
351
- set_variable_length_onion_required) ;
376
+ set_variable_length_onion_required, supports_variable_length_onion,
377
+ requires_variable_length_onion) ;
352
378
define_feature ! ( 13 , StaticRemoteKey , [ InitContext , NodeContext , ChannelTypeContext ] ,
353
379
"Feature flags for `option_static_remotekey`." , set_static_remote_key_optional,
354
- set_static_remote_key_required) ;
380
+ set_static_remote_key_required, supports_static_remote_key , requires_static_remote_key ) ;
355
381
define_feature ! ( 15 , PaymentSecret , [ InitContext , NodeContext , InvoiceContext ] ,
356
- "Feature flags for `payment_secret`." , set_payment_secret_optional, set_payment_secret_required) ;
382
+ "Feature flags for `payment_secret`." , set_payment_secret_optional, set_payment_secret_required,
383
+ supports_payment_secret, requires_payment_secret) ;
357
384
define_feature ! ( 17 , BasicMPP , [ InitContext , NodeContext , InvoiceContext ] ,
358
- "Feature flags for `basic_mpp`." , set_basic_mpp_optional, set_basic_mpp_required) ;
385
+ "Feature flags for `basic_mpp`." , set_basic_mpp_optional, set_basic_mpp_required,
386
+ supports_basic_mpp, requires_basic_mpp) ;
359
387
define_feature ! ( 27 , ShutdownAnySegwit , [ InitContext , NodeContext ] ,
360
388
"Feature flags for `opt_shutdown_anysegwit`." , set_shutdown_any_segwit_optional,
361
- set_shutdown_any_segwit_required) ;
389
+ set_shutdown_any_segwit_required, supports_shutdown_anysegwit, requires_shutdown_anysegwit) ;
390
+ define_feature ! ( 45 , ChannelType , [ InitContext , NodeContext ] ,
391
+ "Feature flags for `option_channel_type`." , set_channel_type_optional,
392
+ set_channel_type_required, supports_channel_type, requires_channel_type) ;
362
393
define_feature ! ( 55 , Keysend , [ NodeContext ] ,
363
- "Feature flags for keysend payments." , set_keysend_optional, set_keysend_required) ;
394
+ "Feature flags for keysend payments." , set_keysend_optional, set_keysend_required,
395
+ supports_keysend, requires_keysend) ;
364
396
365
397
#[ cfg( test) ]
366
398
define_feature ! ( 123456789 , UnknownFeature , [ NodeContext , ChannelContext , InvoiceContext ] ,
367
399
"Feature flags for an unknown feature used in testing." , set_unknown_feature_optional,
368
- set_unknown_feature_required) ;
400
+ set_unknown_feature_required, supports_unknown_test_feature , requires_unknown_test_feature ) ;
369
401
}
370
402
371
403
/// Tracks the set of features which a node implements, templated by the context in which it
@@ -662,25 +694,7 @@ impl<T: sealed::Context> Features<T> {
662
694
}
663
695
}
664
696
665
- impl < T : sealed:: DataLossProtect > Features < T > {
666
- #[ cfg( test) ]
667
- pub ( crate ) fn requires_data_loss_protect ( & self ) -> bool {
668
- <T as sealed:: DataLossProtect >:: requires_feature ( & self . flags )
669
- }
670
- #[ cfg( test) ]
671
- pub ( crate ) fn supports_data_loss_protect ( & self ) -> bool {
672
- <T as sealed:: DataLossProtect >:: supports_feature ( & self . flags )
673
- }
674
- }
675
-
676
697
impl < T : sealed:: UpfrontShutdownScript > Features < T > {
677
- #[ cfg( test) ]
678
- pub ( crate ) fn requires_upfront_shutdown_script ( & self ) -> bool {
679
- <T as sealed:: UpfrontShutdownScript >:: requires_feature ( & self . flags )
680
- }
681
- pub ( crate ) fn supports_upfront_shutdown_script ( & self ) -> bool {
682
- <T as sealed:: UpfrontShutdownScript >:: supports_feature ( & self . flags )
683
- }
684
698
#[ cfg( test) ]
685
699
pub ( crate ) fn clear_upfront_shutdown_script ( mut self ) -> Self {
686
700
<T as sealed:: UpfrontShutdownScript >:: clear_bits ( & mut self . flags ) ;
@@ -690,44 +704,14 @@ impl<T: sealed::UpfrontShutdownScript> Features<T> {
690
704
691
705
692
706
impl < T : sealed:: GossipQueries > Features < T > {
693
- #[ cfg( test) ]
694
- pub ( crate ) fn requires_gossip_queries ( & self ) -> bool {
695
- <T as sealed:: GossipQueries >:: requires_feature ( & self . flags )
696
- }
697
- pub ( crate ) fn supports_gossip_queries ( & self ) -> bool {
698
- <T as sealed:: GossipQueries >:: supports_feature ( & self . flags )
699
- }
700
707
#[ cfg( test) ]
701
708
pub ( crate ) fn clear_gossip_queries ( mut self ) -> Self {
702
709
<T as sealed:: GossipQueries >:: clear_bits ( & mut self . flags ) ;
703
710
self
704
711
}
705
712
}
706
713
707
- impl < T : sealed:: VariableLengthOnion > Features < T > {
708
- #[ cfg( test) ]
709
- pub ( crate ) fn requires_variable_length_onion ( & self ) -> bool {
710
- <T as sealed:: VariableLengthOnion >:: requires_feature ( & self . flags )
711
- }
712
- pub ( crate ) fn supports_variable_length_onion ( & self ) -> bool {
713
- <T as sealed:: VariableLengthOnion >:: supports_feature ( & self . flags )
714
- }
715
- }
716
-
717
- impl < T : sealed:: StaticRemoteKey > Features < T > {
718
- pub ( crate ) fn supports_static_remote_key ( & self ) -> bool {
719
- <T as sealed:: StaticRemoteKey >:: supports_feature ( & self . flags )
720
- }
721
- #[ cfg( test) ]
722
- pub ( crate ) fn requires_static_remote_key ( & self ) -> bool {
723
- <T as sealed:: StaticRemoteKey >:: requires_feature ( & self . flags )
724
- }
725
- }
726
-
727
714
impl < T : sealed:: InitialRoutingSync > Features < T > {
728
- pub ( crate ) fn initial_routing_sync ( & self ) -> bool {
729
- <T as sealed:: InitialRoutingSync >:: supports_feature ( & self . flags )
730
- }
731
715
// We are no longer setting initial_routing_sync now that gossip_queries
732
716
// is enabled. This feature is ignored by a peer when gossip_queries has
733
717
// been negotiated.
@@ -737,32 +721,7 @@ impl<T: sealed::InitialRoutingSync> Features<T> {
737
721
}
738
722
}
739
723
740
- impl < T : sealed:: PaymentSecret > Features < T > {
741
- #[ cfg( test) ]
742
- pub ( crate ) fn requires_payment_secret ( & self ) -> bool {
743
- <T as sealed:: PaymentSecret >:: requires_feature ( & self . flags )
744
- }
745
- /// Returns whether the `payment_secret` feature is supported.
746
- pub fn supports_payment_secret ( & self ) -> bool {
747
- <T as sealed:: PaymentSecret >:: supports_feature ( & self . flags )
748
- }
749
- }
750
-
751
- impl < T : sealed:: BasicMPP > Features < T > {
752
- #[ cfg( test) ]
753
- pub ( crate ) fn requires_basic_mpp ( & self ) -> bool {
754
- <T as sealed:: BasicMPP >:: requires_feature ( & self . flags )
755
- }
756
- // We currently never test for this since we don't actually *generate* multipath routes.
757
- pub ( crate ) fn supports_basic_mpp ( & self ) -> bool {
758
- <T as sealed:: BasicMPP >:: supports_feature ( & self . flags )
759
- }
760
- }
761
-
762
724
impl < T : sealed:: ShutdownAnySegwit > Features < T > {
763
- pub ( crate ) fn supports_shutdown_anysegwit ( & self ) -> bool {
764
- <T as sealed:: ShutdownAnySegwit >:: supports_feature ( & self . flags )
765
- }
766
725
#[ cfg( test) ]
767
726
pub ( crate ) fn clear_shutdown_anysegwit ( mut self ) -> Self {
768
727
<T as sealed:: ShutdownAnySegwit >:: clear_bits ( & mut self . flags ) ;
@@ -859,6 +818,11 @@ mod tests {
859
818
assert ! ( !NodeFeatures :: known( ) . requires_basic_mpp( ) ) ;
860
819
assert ! ( !InvoiceFeatures :: known( ) . requires_basic_mpp( ) ) ;
861
820
821
+ assert ! ( InitFeatures :: known( ) . supports_channel_type( ) ) ;
822
+ assert ! ( NodeFeatures :: known( ) . supports_channel_type( ) ) ;
823
+ assert ! ( !InitFeatures :: known( ) . requires_channel_type( ) ) ;
824
+ assert ! ( !NodeFeatures :: known( ) . requires_channel_type( ) ) ;
825
+
862
826
assert ! ( InitFeatures :: known( ) . supports_shutdown_anysegwit( ) ) ;
863
827
assert ! ( NodeFeatures :: known( ) . supports_shutdown_anysegwit( ) ) ;
864
828
@@ -897,11 +861,15 @@ mod tests {
897
861
// - var_onion_optin (req) | static_remote_key (req) | payment_secret(req)
898
862
// - basic_mpp
899
863
// - opt_shutdown_anysegwit
900
- assert_eq ! ( node_features. flags. len( ) , 4 ) ;
864
+ // -
865
+ // - option_channel_type
866
+ assert_eq ! ( node_features. flags. len( ) , 6 ) ;
901
867
assert_eq ! ( node_features. flags[ 0 ] , 0b00000010 ) ;
902
868
assert_eq ! ( node_features. flags[ 1 ] , 0b01010001 ) ;
903
869
assert_eq ! ( node_features. flags[ 2 ] , 0b00000010 ) ;
904
870
assert_eq ! ( node_features. flags[ 3 ] , 0b00001000 ) ;
871
+ assert_eq ! ( node_features. flags[ 4 ] , 0b00000000 ) ;
872
+ assert_eq ! ( node_features. flags[ 5 ] , 0b00100000 ) ;
905
873
}
906
874
907
875
// Check that cleared flags are kept blank when converting back:
0 commit comments