@@ -662,14 +662,6 @@ impl<T: sealed::Context> Features<T> {
662
662
}
663
663
}
664
664
665
- /// Creates a Features with the bits set which are known by the implementation
666
- pub fn known ( ) -> Self {
667
- Self {
668
- flags : T :: KNOWN_FEATURE_FLAGS . to_vec ( ) ,
669
- mark : PhantomData ,
670
- }
671
- }
672
-
673
665
/// Converts `Features<T>` to `Features<C>`. Only known `T` features relevant to context `C` are
674
666
/// included in the result.
675
667
fn to_context_internal < C : sealed:: Context > ( & self ) -> Features < C > {
@@ -814,92 +806,9 @@ impl Readable for ChannelTypeFeatures {
814
806
815
807
#[ cfg( test) ]
816
808
mod tests {
817
- use super :: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , InvoiceFeatures , NodeFeatures } ;
809
+ use super :: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , InvoiceFeatures , NodeFeatures , sealed } ;
818
810
use bitcoin:: bech32:: { Base32Len , FromBase32 , ToBase32 , u5} ;
819
811
820
- #[ test]
821
- fn sanity_test_known_features ( ) {
822
- assert ! ( !ChannelFeatures :: known( ) . requires_unknown_bits( ) ) ;
823
- assert ! ( !ChannelFeatures :: known( ) . supports_unknown_bits( ) ) ;
824
- assert ! ( !InitFeatures :: known( ) . requires_unknown_bits( ) ) ;
825
- assert ! ( !InitFeatures :: known( ) . supports_unknown_bits( ) ) ;
826
- assert ! ( !NodeFeatures :: known( ) . requires_unknown_bits( ) ) ;
827
- assert ! ( !NodeFeatures :: known( ) . supports_unknown_bits( ) ) ;
828
-
829
- assert ! ( InitFeatures :: known( ) . supports_upfront_shutdown_script( ) ) ;
830
- assert ! ( NodeFeatures :: known( ) . supports_upfront_shutdown_script( ) ) ;
831
- assert ! ( !InitFeatures :: known( ) . requires_upfront_shutdown_script( ) ) ;
832
- assert ! ( !NodeFeatures :: known( ) . requires_upfront_shutdown_script( ) ) ;
833
-
834
- assert ! ( InitFeatures :: known( ) . supports_gossip_queries( ) ) ;
835
- assert ! ( NodeFeatures :: known( ) . supports_gossip_queries( ) ) ;
836
- assert ! ( !InitFeatures :: known( ) . requires_gossip_queries( ) ) ;
837
- assert ! ( !NodeFeatures :: known( ) . requires_gossip_queries( ) ) ;
838
-
839
- assert ! ( InitFeatures :: known( ) . supports_data_loss_protect( ) ) ;
840
- assert ! ( NodeFeatures :: known( ) . supports_data_loss_protect( ) ) ;
841
- assert ! ( !InitFeatures :: known( ) . requires_data_loss_protect( ) ) ;
842
- assert ! ( !NodeFeatures :: known( ) . requires_data_loss_protect( ) ) ;
843
-
844
- assert ! ( InitFeatures :: known( ) . supports_variable_length_onion( ) ) ;
845
- assert ! ( NodeFeatures :: known( ) . supports_variable_length_onion( ) ) ;
846
- assert ! ( InvoiceFeatures :: known( ) . supports_variable_length_onion( ) ) ;
847
- assert ! ( InitFeatures :: known( ) . requires_variable_length_onion( ) ) ;
848
- assert ! ( NodeFeatures :: known( ) . requires_variable_length_onion( ) ) ;
849
- assert ! ( InvoiceFeatures :: known( ) . requires_variable_length_onion( ) ) ;
850
-
851
- assert ! ( InitFeatures :: known( ) . supports_static_remote_key( ) ) ;
852
- assert ! ( NodeFeatures :: known( ) . supports_static_remote_key( ) ) ;
853
- assert ! ( InitFeatures :: known( ) . requires_static_remote_key( ) ) ;
854
- assert ! ( NodeFeatures :: known( ) . requires_static_remote_key( ) ) ;
855
-
856
- assert ! ( InitFeatures :: known( ) . supports_payment_secret( ) ) ;
857
- assert ! ( NodeFeatures :: known( ) . supports_payment_secret( ) ) ;
858
- assert ! ( InvoiceFeatures :: known( ) . supports_payment_secret( ) ) ;
859
- assert ! ( InitFeatures :: known( ) . requires_payment_secret( ) ) ;
860
- assert ! ( NodeFeatures :: known( ) . requires_payment_secret( ) ) ;
861
- assert ! ( InvoiceFeatures :: known( ) . requires_payment_secret( ) ) ;
862
-
863
- assert ! ( InitFeatures :: known( ) . supports_basic_mpp( ) ) ;
864
- assert ! ( NodeFeatures :: known( ) . supports_basic_mpp( ) ) ;
865
- assert ! ( InvoiceFeatures :: known( ) . supports_basic_mpp( ) ) ;
866
- assert ! ( !InitFeatures :: known( ) . requires_basic_mpp( ) ) ;
867
- assert ! ( !NodeFeatures :: known( ) . requires_basic_mpp( ) ) ;
868
- assert ! ( !InvoiceFeatures :: known( ) . requires_basic_mpp( ) ) ;
869
-
870
- assert ! ( InitFeatures :: known( ) . supports_channel_type( ) ) ;
871
- assert ! ( NodeFeatures :: known( ) . supports_channel_type( ) ) ;
872
- assert ! ( !InitFeatures :: known( ) . requires_channel_type( ) ) ;
873
- assert ! ( !NodeFeatures :: known( ) . requires_channel_type( ) ) ;
874
-
875
- assert ! ( InitFeatures :: known( ) . supports_shutdown_anysegwit( ) ) ;
876
- assert ! ( NodeFeatures :: known( ) . supports_shutdown_anysegwit( ) ) ;
877
-
878
- assert ! ( InitFeatures :: known( ) . supports_scid_privacy( ) ) ;
879
- assert ! ( NodeFeatures :: known( ) . supports_scid_privacy( ) ) ;
880
- assert ! ( ChannelTypeFeatures :: known( ) . supports_scid_privacy( ) ) ;
881
- assert ! ( !InitFeatures :: known( ) . requires_scid_privacy( ) ) ;
882
- assert ! ( !NodeFeatures :: known( ) . requires_scid_privacy( ) ) ;
883
- assert ! ( ChannelTypeFeatures :: known( ) . requires_scid_privacy( ) ) ;
884
-
885
- assert ! ( InitFeatures :: known( ) . supports_wumbo( ) ) ;
886
- assert ! ( NodeFeatures :: known( ) . supports_wumbo( ) ) ;
887
- assert ! ( !InitFeatures :: known( ) . requires_wumbo( ) ) ;
888
- assert ! ( !NodeFeatures :: known( ) . requires_wumbo( ) ) ;
889
-
890
- assert ! ( InitFeatures :: known( ) . supports_zero_conf( ) ) ;
891
- assert ! ( !InitFeatures :: known( ) . requires_zero_conf( ) ) ;
892
- assert ! ( NodeFeatures :: known( ) . supports_zero_conf( ) ) ;
893
- assert ! ( !NodeFeatures :: known( ) . requires_zero_conf( ) ) ;
894
- assert ! ( ChannelTypeFeatures :: known( ) . supports_zero_conf( ) ) ;
895
- assert ! ( ChannelTypeFeatures :: known( ) . requires_zero_conf( ) ) ;
896
-
897
- let mut init_features = InitFeatures :: known ( ) ;
898
- assert ! ( init_features. initial_routing_sync( ) ) ;
899
- init_features = init_features. clear_initial_routing_sync ( ) ;
900
- assert ! ( !init_features. initial_routing_sync( ) ) ;
901
- }
902
-
903
812
#[ test]
904
813
fn sanity_test_unknown_bits ( ) {
905
814
let features = ChannelFeatures :: empty ( ) ;
@@ -919,7 +828,21 @@ mod tests {
919
828
920
829
#[ test]
921
830
fn convert_to_context_with_relevant_flags ( ) {
922
- let init_features = InitFeatures :: known ( ) . clear_upfront_shutdown_script ( ) . clear_gossip_queries ( ) ;
831
+ let mut init_features = InitFeatures :: empty ( ) ;
832
+ // Set a bunch of features we use, plus initial_routing_sync_required (which shouldn't get
833
+ // converted as its only relevant in an init context).
834
+ init_features. set_initial_routing_sync_required ( ) ;
835
+ init_features. set_data_loss_protect_optional ( ) ;
836
+ init_features. set_variable_length_onion_required ( ) ;
837
+ init_features. set_static_remote_key_required ( ) ;
838
+ init_features. set_payment_secret_required ( ) ;
839
+ init_features. set_basic_mpp_optional ( ) ;
840
+ init_features. set_wumbo_optional ( ) ;
841
+ init_features. set_shutdown_any_segwit_optional ( ) ;
842
+ init_features. set_channel_type_optional ( ) ;
843
+ init_features. set_scid_privacy_optional ( ) ;
844
+ init_features. set_zero_conf_optional ( ) ;
845
+
923
846
assert ! ( init_features. initial_routing_sync( ) ) ;
924
847
assert ! ( !init_features. supports_upfront_shutdown_script( ) ) ;
925
848
assert ! ( !init_features. supports_gossip_queries( ) ) ;
@@ -957,8 +880,9 @@ mod tests {
957
880
#[ test]
958
881
fn convert_to_context_with_unknown_flags ( ) {
959
882
// Ensure the `from` context has fewer known feature bytes than the `to` context.
960
- assert ! ( InvoiceFeatures :: known( ) . flags. len( ) < NodeFeatures :: known( ) . flags. len( ) ) ;
961
- let mut invoice_features = InvoiceFeatures :: known ( ) ;
883
+ assert ! ( <sealed:: InvoiceContext as sealed:: Context >:: KNOWN_FEATURE_MASK . len( ) <
884
+ <sealed:: NodeContext as sealed:: Context >:: KNOWN_FEATURE_MASK . len( ) ) ;
885
+ let mut invoice_features = InvoiceFeatures :: empty ( ) ;
962
886
invoice_features. set_unknown_feature_optional ( ) ;
963
887
assert ! ( invoice_features. supports_unknown_bits( ) ) ;
964
888
let node_features: NodeFeatures = invoice_features. to_context ( ) ;
0 commit comments