@@ -771,15 +771,7 @@ impl<T: sealed::Context> Features<T> {
771
771
// unknown features.
772
772
self . flags . iter ( ) . enumerate ( ) . any ( |( i, & byte) | {
773
773
const REQUIRED_FEATURES : u8 = 0b01_01_01_01 ;
774
- const OPTIONAL_FEATURES : u8 = 0b10_10_10_10 ;
775
- let unknown_features = if i < other. flags . len ( ) {
776
- // Form a mask similar to !T::KNOWN_FEATURE_MASK only for `other`
777
- !( other. flags [ i]
778
- | ( ( other. flags [ i] >> 1 ) & REQUIRED_FEATURES )
779
- | ( ( other. flags [ i] << 1 ) & OPTIONAL_FEATURES ) )
780
- } else {
781
- 0b11_11_11_11
782
- } ;
774
+ let unknown_features = unset_features_mask_at_position ( other, i) ;
783
775
( byte & ( REQUIRED_FEATURES & unknown_features) ) != 0
784
776
} )
785
777
}
@@ -790,17 +782,7 @@ impl<T: sealed::Context> Features<T> {
790
782
// Bitwise AND-ing with all even bits set except for known features will select required
791
783
// unknown features.
792
784
self . flags . iter ( ) . enumerate ( ) . for_each ( |( i, & byte) | {
793
- const REQUIRED_FEATURES : u8 = 0b01_01_01_01 ;
794
- const OPTIONAL_FEATURES : u8 = 0b10_10_10_10 ;
795
- let unknown_features = if i < other. flags . len ( ) {
796
- // Form a mask similar to !T::KNOWN_FEATURE_MASK only for `other`
797
- !( other. flags [ i]
798
- | ( ( other. flags [ i] >> 1 ) & REQUIRED_FEATURES )
799
- | ( ( other. flags [ i] << 1 ) & OPTIONAL_FEATURES ) )
800
- } else {
801
- 0b11_11_11_11
802
- } ;
803
-
785
+ let unknown_features = unset_features_mask_at_position ( other, i) ;
804
786
if byte & unknown_features != 0 {
805
787
for bit in ( 0 ..8 ) . step_by ( 2 ) {
806
788
if ( ( byte & unknown_features) >> bit) & 1 == 1 {
@@ -1047,6 +1029,19 @@ impl<T: sealed::Context> Readable for WithoutLength<Features<T>> {
1047
1029
}
1048
1030
}
1049
1031
1032
+ pub ( crate ) fn unset_features_mask_at_position < T : sealed:: Context > ( other : & Features < T > , index : usize ) -> u8 {
1033
+ const REQUIRED_FEATURES : u8 = 0b01_01_01_01 ;
1034
+ const OPTIONAL_FEATURES : u8 = 0b10_10_10_10 ;
1035
+ if index < other. flags . len ( ) {
1036
+ // Form a mask similar to !T::KNOWN_FEATURE_MASK only for `other`
1037
+ !( other. flags [ index]
1038
+ | ( ( other. flags [ index] >> 1 ) & REQUIRED_FEATURES )
1039
+ | ( ( other. flags [ index] << 1 ) & OPTIONAL_FEATURES ) )
1040
+ } else {
1041
+ 0b11_11_11_11
1042
+ }
1043
+ }
1044
+
1050
1045
#[ cfg( test) ]
1051
1046
mod tests {
1052
1047
use super :: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , Bolt11InvoiceFeatures , NodeFeatures , OfferFeatures , sealed} ;
0 commit comments