@@ -223,7 +223,7 @@ mod sealed {
223223 /// useful for manipulating feature flags.
224224 macro_rules! define_feature {
225225 ( $odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr, $optional_setter: ident,
226- $required_setter: ident) => {
226+ $required_setter: ident, $supported_getter : ident ) => {
227227 #[ doc = $doc]
228228 ///
229229 /// See [BOLT #9] for details.
@@ -320,6 +320,11 @@ mod sealed {
320320 <T as $feature>:: set_required_bit( & mut self . flags) ;
321321 self
322322 }
323+
324+ /// Checks if this feature is supported.
325+ pub fn $supported_getter( & self ) -> bool {
326+ <T as $feature>:: supports_feature( & self . flags)
327+ }
323328 }
324329
325330 $(
@@ -331,41 +336,57 @@ mod sealed {
331336 const ASSERT_ODD_BIT_PARITY : usize = ( <Self as $feature>:: ODD_BIT % 2 ) - 1 ;
332337 }
333338 ) *
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+ }
335349 }
336350 }
337351
338352 define_feature ! ( 1 , DataLossProtect , [ InitContext , NodeContext ] ,
339353 "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 ) ;
341355 // NOTE: Per Bolt #9, initial_routing_sync has no even bit.
342356 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) ;
344359 define_feature ! ( 5 , UpfrontShutdownScript , [ InitContext , NodeContext ] ,
345360 "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) ;
347363 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) ;
349366 define_feature ! ( 9 , VariableLengthOnion , [ InitContext , NodeContext , InvoiceContext ] ,
350367 "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) ;
352370 define_feature ! ( 13 , StaticRemoteKey , [ InitContext , NodeContext , ChannelTypeContext ] ,
353371 "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 ) ;
355373 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) ;
357376 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) ;
359379 define_feature ! ( 27 , ShutdownAnySegwit , [ InitContext , NodeContext ] ,
360380 "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 ) ;
362382 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) ;
364385
365386 #[ cfg( test) ]
366387 define_feature ! ( 123456789 , UnknownFeature , [ NodeContext , ChannelContext , InvoiceContext ] ,
367388 "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 ) ;
369390}
370391
371392/// 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> {
662683 }
663684}
664685
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-
676686impl < 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- }
684687 #[ cfg( test) ]
685688 pub ( crate ) fn clear_upfront_shutdown_script ( mut self ) -> Self {
686689 <T as sealed:: UpfrontShutdownScript >:: clear_bits ( & mut self . flags ) ;
@@ -690,44 +693,14 @@ impl<T: sealed::UpfrontShutdownScript> Features<T> {
690693
691694
692695impl < 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- }
700696 #[ cfg( test) ]
701697 pub ( crate ) fn clear_gossip_queries ( mut self ) -> Self {
702698 <T as sealed:: GossipQueries >:: clear_bits ( & mut self . flags ) ;
703699 self
704700 }
705701}
706702
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-
727703impl < T : sealed:: InitialRoutingSync > Features < T > {
728- pub ( crate ) fn initial_routing_sync ( & self ) -> bool {
729- <T as sealed:: InitialRoutingSync >:: supports_feature ( & self . flags )
730- }
731704 // We are no longer setting initial_routing_sync now that gossip_queries
732705 // is enabled. This feature is ignored by a peer when gossip_queries has
733706 // been negotiated.
@@ -737,32 +710,7 @@ impl<T: sealed::InitialRoutingSync> Features<T> {
737710 }
738711}
739712
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-
762713impl < T : sealed:: ShutdownAnySegwit > Features < T > {
763- pub ( crate ) fn supports_shutdown_anysegwit ( & self ) -> bool {
764- <T as sealed:: ShutdownAnySegwit >:: supports_feature ( & self . flags )
765- }
766714 #[ cfg( test) ]
767715 pub ( crate ) fn clear_shutdown_anysegwit ( mut self ) -> Self {
768716 <T as sealed:: ShutdownAnySegwit >:: clear_bits ( & mut self . flags ) ;
0 commit comments