@@ -666,14 +666,6 @@ impl<T: sealed::Context> Features<T> {
666666 }
667667 }
668668
669- /// Creates a Features with the bits set which are known by the implementation
670- pub fn known ( ) -> Self {
671- Self {
672- flags : T :: KNOWN_FEATURE_FLAGS . to_vec ( ) ,
673- mark : PhantomData ,
674- }
675- }
676-
677669 /// Converts `Features<T>` to `Features<C>`. Only known `T` features relevant to context `C` are
678670 /// included in the result.
679671 fn to_context_internal < C : sealed:: Context > ( & self ) -> Features < C > {
@@ -836,97 +828,9 @@ impl Readable for ChannelTypeFeatures {
836828
837829#[ cfg( test) ]
838830mod tests {
839- use super :: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , InvoiceFeatures , NodeFeatures } ;
831+ use super :: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , InvoiceFeatures , NodeFeatures , sealed } ;
840832 use bitcoin:: bech32:: { Base32Len , FromBase32 , ToBase32 , u5} ;
841833
842- #[ test]
843- fn sanity_test_known_features ( ) {
844- assert ! ( !ChannelFeatures :: known( ) . requires_unknown_bits( ) ) ;
845- assert ! ( !ChannelFeatures :: known( ) . supports_unknown_bits( ) ) ;
846- assert ! ( !InitFeatures :: known( ) . requires_unknown_bits( ) ) ;
847- assert ! ( !InitFeatures :: known( ) . supports_unknown_bits( ) ) ;
848- assert ! ( !NodeFeatures :: known( ) . requires_unknown_bits( ) ) ;
849- assert ! ( !NodeFeatures :: known( ) . supports_unknown_bits( ) ) ;
850-
851- assert ! ( InitFeatures :: known( ) . supports_upfront_shutdown_script( ) ) ;
852- assert ! ( NodeFeatures :: known( ) . supports_upfront_shutdown_script( ) ) ;
853- assert ! ( !InitFeatures :: known( ) . requires_upfront_shutdown_script( ) ) ;
854- assert ! ( !NodeFeatures :: known( ) . requires_upfront_shutdown_script( ) ) ;
855-
856- assert ! ( InitFeatures :: known( ) . supports_gossip_queries( ) ) ;
857- assert ! ( NodeFeatures :: known( ) . supports_gossip_queries( ) ) ;
858- assert ! ( !InitFeatures :: known( ) . requires_gossip_queries( ) ) ;
859- assert ! ( !NodeFeatures :: known( ) . requires_gossip_queries( ) ) ;
860-
861- assert ! ( InitFeatures :: known( ) . supports_data_loss_protect( ) ) ;
862- assert ! ( NodeFeatures :: known( ) . supports_data_loss_protect( ) ) ;
863- assert ! ( !InitFeatures :: known( ) . requires_data_loss_protect( ) ) ;
864- assert ! ( !NodeFeatures :: known( ) . requires_data_loss_protect( ) ) ;
865-
866- assert ! ( InitFeatures :: known( ) . supports_variable_length_onion( ) ) ;
867- assert ! ( NodeFeatures :: known( ) . supports_variable_length_onion( ) ) ;
868- assert ! ( InvoiceFeatures :: known( ) . supports_variable_length_onion( ) ) ;
869- assert ! ( InitFeatures :: known( ) . requires_variable_length_onion( ) ) ;
870- assert ! ( NodeFeatures :: known( ) . requires_variable_length_onion( ) ) ;
871- assert ! ( InvoiceFeatures :: known( ) . requires_variable_length_onion( ) ) ;
872-
873- assert ! ( InitFeatures :: known( ) . supports_static_remote_key( ) ) ;
874- assert ! ( NodeFeatures :: known( ) . supports_static_remote_key( ) ) ;
875- assert ! ( InitFeatures :: known( ) . requires_static_remote_key( ) ) ;
876- assert ! ( NodeFeatures :: known( ) . requires_static_remote_key( ) ) ;
877-
878- assert ! ( InitFeatures :: known( ) . supports_payment_secret( ) ) ;
879- assert ! ( NodeFeatures :: known( ) . supports_payment_secret( ) ) ;
880- assert ! ( InvoiceFeatures :: known( ) . supports_payment_secret( ) ) ;
881- assert ! ( InitFeatures :: known( ) . requires_payment_secret( ) ) ;
882- assert ! ( NodeFeatures :: known( ) . requires_payment_secret( ) ) ;
883- assert ! ( InvoiceFeatures :: known( ) . requires_payment_secret( ) ) ;
884-
885- assert ! ( InitFeatures :: known( ) . supports_basic_mpp( ) ) ;
886- assert ! ( NodeFeatures :: known( ) . supports_basic_mpp( ) ) ;
887- assert ! ( InvoiceFeatures :: known( ) . supports_basic_mpp( ) ) ;
888- assert ! ( !InitFeatures :: known( ) . requires_basic_mpp( ) ) ;
889- assert ! ( !NodeFeatures :: known( ) . requires_basic_mpp( ) ) ;
890- assert ! ( !InvoiceFeatures :: known( ) . requires_basic_mpp( ) ) ;
891-
892- assert ! ( InitFeatures :: known( ) . supports_channel_type( ) ) ;
893- assert ! ( NodeFeatures :: known( ) . supports_channel_type( ) ) ;
894- assert ! ( !InitFeatures :: known( ) . requires_channel_type( ) ) ;
895- assert ! ( !NodeFeatures :: known( ) . requires_channel_type( ) ) ;
896-
897- assert ! ( InitFeatures :: known( ) . supports_shutdown_anysegwit( ) ) ;
898- assert ! ( NodeFeatures :: known( ) . supports_shutdown_anysegwit( ) ) ;
899-
900- assert ! ( InitFeatures :: known( ) . supports_scid_privacy( ) ) ;
901- assert ! ( NodeFeatures :: known( ) . supports_scid_privacy( ) ) ;
902- assert ! ( ChannelTypeFeatures :: known( ) . supports_scid_privacy( ) ) ;
903- assert ! ( !InitFeatures :: known( ) . requires_scid_privacy( ) ) ;
904- assert ! ( !NodeFeatures :: known( ) . requires_scid_privacy( ) ) ;
905- assert ! ( ChannelTypeFeatures :: known( ) . requires_scid_privacy( ) ) ;
906-
907- assert ! ( InitFeatures :: known( ) . supports_wumbo( ) ) ;
908- assert ! ( NodeFeatures :: known( ) . supports_wumbo( ) ) ;
909- assert ! ( !InitFeatures :: known( ) . requires_wumbo( ) ) ;
910- assert ! ( !NodeFeatures :: known( ) . requires_wumbo( ) ) ;
911-
912- assert ! ( InitFeatures :: known( ) . supports_onion_messages( ) ) ;
913- assert ! ( NodeFeatures :: known( ) . supports_onion_messages( ) ) ;
914- assert ! ( !InitFeatures :: known( ) . requires_onion_messages( ) ) ;
915- assert ! ( !NodeFeatures :: known( ) . requires_onion_messages( ) ) ;
916-
917- assert ! ( InitFeatures :: known( ) . supports_zero_conf( ) ) ;
918- assert ! ( !InitFeatures :: known( ) . requires_zero_conf( ) ) ;
919- assert ! ( NodeFeatures :: known( ) . supports_zero_conf( ) ) ;
920- assert ! ( !NodeFeatures :: known( ) . requires_zero_conf( ) ) ;
921- assert ! ( ChannelTypeFeatures :: known( ) . supports_zero_conf( ) ) ;
922- assert ! ( ChannelTypeFeatures :: known( ) . requires_zero_conf( ) ) ;
923-
924- let mut init_features = InitFeatures :: known ( ) ;
925- assert ! ( init_features. initial_routing_sync( ) ) ;
926- init_features = init_features. clear_initial_routing_sync ( ) ;
927- assert ! ( !init_features. initial_routing_sync( ) ) ;
928- }
929-
930834 #[ test]
931835 fn sanity_test_unknown_bits ( ) {
932836 let features = ChannelFeatures :: empty ( ) ;
@@ -946,7 +850,21 @@ mod tests {
946850
947851 #[ test]
948852 fn convert_to_context_with_relevant_flags ( ) {
949- let init_features = InitFeatures :: known ( ) . clear_upfront_shutdown_script ( ) . clear_gossip_queries ( ) ;
853+ let mut init_features = InitFeatures :: empty ( ) ;
854+ // Set a bunch of features we use, plus initial_routing_sync_required (which shouldn't get
855+ // converted as its only relevant in an init context).
856+ init_features. set_initial_routing_sync_required ( ) ;
857+ init_features. set_data_loss_protect_optional ( ) ;
858+ init_features. set_variable_length_onion_required ( ) ;
859+ init_features. set_static_remote_key_required ( ) ;
860+ init_features. set_payment_secret_required ( ) ;
861+ init_features. set_basic_mpp_optional ( ) ;
862+ init_features. set_wumbo_optional ( ) ;
863+ init_features. set_shutdown_any_segwit_optional ( ) ;
864+ init_features. set_channel_type_optional ( ) ;
865+ init_features. set_scid_privacy_optional ( ) ;
866+ init_features. set_zero_conf_optional ( ) ;
867+
950868 assert ! ( init_features. initial_routing_sync( ) ) ;
951869 assert ! ( !init_features. supports_upfront_shutdown_script( ) ) ;
952870 assert ! ( !init_features. supports_gossip_queries( ) ) ;
@@ -984,8 +902,9 @@ mod tests {
984902 #[ test]
985903 fn convert_to_context_with_unknown_flags ( ) {
986904 // Ensure the `from` context has fewer known feature bytes than the `to` context.
987- assert ! ( InvoiceFeatures :: known( ) . flags. len( ) < NodeFeatures :: known( ) . flags. len( ) ) ;
988- let mut invoice_features = InvoiceFeatures :: known ( ) ;
905+ assert ! ( <sealed:: InvoiceContext as sealed:: Context >:: KNOWN_FEATURE_MASK . len( ) <
906+ <sealed:: NodeContext as sealed:: Context >:: KNOWN_FEATURE_MASK . len( ) ) ;
907+ let mut invoice_features = InvoiceFeatures :: empty ( ) ;
989908 invoice_features. set_unknown_feature_optional ( ) ;
990909 assert ! ( invoice_features. supports_unknown_bits( ) ) ;
991910 let node_features: NodeFeatures = invoice_features. to_context ( ) ;
0 commit comments