@@ -223,7 +223,7 @@ mod sealed {
223
223
/// useful for manipulating feature flags.
224
224
macro_rules! define_feature {
225
225
( $odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr, $optional_setter: ident,
226
- $required_setter: ident) => {
226
+ $required_setter: ident, $supported_getter : ident ) => {
227
227
#[ doc = $doc]
228
228
///
229
229
/// See [BOLT #9] for details.
@@ -320,6 +320,11 @@ mod sealed {
320
320
<T as $feature>:: set_required_bit( & mut self . flags) ;
321
321
self
322
322
}
323
+
324
+ /// Checks if this feature is supported.
325
+ pub fn $supported_getter( & self ) -> bool {
326
+ <T as $feature>:: supports_feature( & self . flags)
327
+ }
323
328
}
324
329
325
330
$(
@@ -331,41 +336,57 @@ mod sealed {
331
336
const ASSERT_ODD_BIT_PARITY : usize = ( <Self as $feature>:: ODD_BIT % 2 ) - 1 ;
332
337
}
333
338
) *
334
-
339
+ } ;
340
+ ( $odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr, $optional_setter: ident,
341
+ $required_setter: ident, $supported_getter: ident, $required_getter: ident) => {
342
+ define_feature!( $odd_bit, $feature, [ $( $context) ,+] , $doc, $optional_setter, $required_setter, $supported_getter) ;
343
+ impl <T : $feature> Features <T > {
344
+ /// Checks if this feature is required.
345
+ pub fn $required_getter( & self ) -> bool {
346
+ <T as $feature>:: requires_feature( & self . flags)
347
+ }
348
+ }
335
349
}
336
350
}
337
351
338
352
define_feature ! ( 1 , DataLossProtect , [ InitContext , NodeContext ] ,
339
353
"Feature flags for `option_data_loss_protect`." , set_data_loss_protect_optional,
340
- set_data_loss_protect_required) ;
354
+ set_data_loss_protect_required, supports_data_loss_protect , requires_data_loss_protect ) ;
341
355
// NOTE: Per Bolt #9, initial_routing_sync has no even bit.
342
356
define_feature ! ( 3 , InitialRoutingSync , [ InitContext ] , "Feature flags for `initial_routing_sync`." ,
343
- set_initial_routing_sync_optional, set_initial_routing_sync_required) ;
357
+ set_initial_routing_sync_optional, set_initial_routing_sync_required,
358
+ initial_routing_sync) ;
344
359
define_feature ! ( 5 , UpfrontShutdownScript , [ InitContext , NodeContext ] ,
345
360
"Feature flags for `option_upfront_shutdown_script`." , set_upfront_shutdown_script_optional,
346
- set_upfront_shutdown_script_required) ;
361
+ set_upfront_shutdown_script_required, supports_upfront_shutdown_script,
362
+ requires_upfront_shutdown_script) ;
347
363
define_feature ! ( 7 , GossipQueries , [ InitContext , NodeContext ] ,
348
- "Feature flags for `gossip_queries`." , set_gossip_queries_optional, set_gossip_queries_required) ;
364
+ "Feature flags for `gossip_queries`." , set_gossip_queries_optional, set_gossip_queries_required,
365
+ supports_gossip_queries, requires_gossip_queries) ;
349
366
define_feature ! ( 9 , VariableLengthOnion , [ InitContext , NodeContext , InvoiceContext ] ,
350
367
"Feature flags for `var_onion_optin`." , set_variable_length_onion_optional,
351
- set_variable_length_onion_required) ;
368
+ set_variable_length_onion_required, supports_variable_length_onion,
369
+ requires_variable_length_onion) ;
352
370
define_feature ! ( 13 , StaticRemoteKey , [ InitContext , NodeContext , ChannelTypeContext ] ,
353
371
"Feature flags for `option_static_remotekey`." , set_static_remote_key_optional,
354
- set_static_remote_key_required) ;
372
+ set_static_remote_key_required, supports_static_remote_key , requires_static_remote_key ) ;
355
373
define_feature ! ( 15 , PaymentSecret , [ InitContext , NodeContext , InvoiceContext ] ,
356
- "Feature flags for `payment_secret`." , set_payment_secret_optional, set_payment_secret_required) ;
374
+ "Feature flags for `payment_secret`." , set_payment_secret_optional, set_payment_secret_required,
375
+ supports_payment_secret, requires_payment_secret) ;
357
376
define_feature ! ( 17 , BasicMPP , [ InitContext , NodeContext , InvoiceContext ] ,
358
- "Feature flags for `basic_mpp`." , set_basic_mpp_optional, set_basic_mpp_required) ;
377
+ "Feature flags for `basic_mpp`." , set_basic_mpp_optional, set_basic_mpp_required,
378
+ supports_basic_mpp, requires_basic_mpp) ;
359
379
define_feature ! ( 27 , ShutdownAnySegwit , [ InitContext , NodeContext ] ,
360
380
"Feature flags for `opt_shutdown_anysegwit`." , set_shutdown_any_segwit_optional,
361
- set_shutdown_any_segwit_required) ;
381
+ set_shutdown_any_segwit_required, supports_shutdown_anysegwit , requires_shutdown_anysegwit ) ;
362
382
define_feature ! ( 55 , Keysend , [ NodeContext ] ,
363
- "Feature flags for keysend payments." , set_keysend_optional, set_keysend_required) ;
383
+ "Feature flags for keysend payments." , set_keysend_optional, set_keysend_required,
384
+ supports_keysend, requires_keysend) ;
364
385
365
386
#[ cfg( test) ]
366
387
define_feature ! ( 123456789 , UnknownFeature , [ NodeContext , ChannelContext , InvoiceContext ] ,
367
388
"Feature flags for an unknown feature used in testing." , set_unknown_feature_optional,
368
- set_unknown_feature_required) ;
389
+ set_unknown_feature_required, supports_unknown_test_feature , requires_unknown_test_feature ) ;
369
390
}
370
391
371
392
/// Tracks the set of features which a node implements, templated by the context in which it
@@ -662,25 +683,7 @@ impl<T: sealed::Context> Features<T> {
662
683
}
663
684
}
664
685
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
686
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
687
#[ cfg( test) ]
685
688
pub ( crate ) fn clear_upfront_shutdown_script ( mut self ) -> Self {
686
689
<T as sealed:: UpfrontShutdownScript >:: clear_bits ( & mut self . flags ) ;
@@ -690,44 +693,14 @@ impl<T: sealed::UpfrontShutdownScript> Features<T> {
690
693
691
694
692
695
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
696
#[ cfg( test) ]
701
697
pub ( crate ) fn clear_gossip_queries ( mut self ) -> Self {
702
698
<T as sealed:: GossipQueries >:: clear_bits ( & mut self . flags ) ;
703
699
self
704
700
}
705
701
}
706
702
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
703
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
704
// We are no longer setting initial_routing_sync now that gossip_queries
732
705
// is enabled. This feature is ignored by a peer when gossip_queries has
733
706
// been negotiated.
@@ -737,32 +710,7 @@ impl<T: sealed::InitialRoutingSync> Features<T> {
737
710
}
738
711
}
739
712
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
713
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
714
#[ cfg( test) ]
767
715
pub ( crate ) fn clear_shutdown_anysegwit ( mut self ) -> Self {
768
716
<T as sealed:: ShutdownAnySegwit >:: clear_bits ( & mut self . flags ) ;
0 commit comments