@@ -187,8 +187,14 @@ impl<T: sealed::Context> Features<T> {
187187 pub ( crate ) fn requires_unknown_bits ( & self ) -> bool {
188188 self . flags . iter ( ) . enumerate ( ) . any ( |( idx, & byte) | {
189189 ( match idx {
190- 0 => ( byte & 0b00010100 ) ,
190+ // Unknown bits are even bits which we don't understand, we list ones which we do
191+ // here:
192+ // unknown, upfront_shutdown_script, unknown (actually initial_routing_sync, but it
193+ // is only valid as an optional feature), and data_loss_protect:
194+ 0 => ( byte & 0b01000100 ) ,
195+ // unknown, unknown, unknown, var_onion_optin:
191196 1 => ( byte & 0b01010100 ) ,
197+ // fallback, all even bits set:
192198 _ => ( byte & 0b01010101 ) ,
193199 } ) != 0
194200 } )
@@ -197,7 +203,10 @@ impl<T: sealed::Context> Features<T> {
197203 pub ( crate ) fn supports_unknown_bits ( & self ) -> bool {
198204 self . flags . iter ( ) . enumerate ( ) . any ( |( idx, & byte) | {
199205 ( match idx {
206+ // unknown, upfront_shutdown_script, initial_routing_sync (is only valid as an
207+ // optional feature), and data_loss_protect:
200208 0 => ( byte & 0b11000100 ) ,
209+ // unknown, unknown, unknown, var_onion_optin:
201210 1 => ( byte & 0b11111100 ) ,
202211 _ => byte,
203212 } ) != 0
@@ -284,3 +293,41 @@ impl<R: ::std::io::Read, T: sealed::Context> Readable<R> for Features<T> {
284293 } )
285294 }
286295}
296+
297+ #[ cfg( test) ]
298+ mod tests {
299+ use super :: { ChannelFeatures , InitFeatures , NodeFeatures } ;
300+
301+ #[ test]
302+ fn sanity_test_our_features ( ) {
303+ assert ! ( !ChannelFeatures :: supported( ) . requires_unknown_bits( ) ) ;
304+ assert ! ( !ChannelFeatures :: supported( ) . supports_unknown_bits( ) ) ;
305+ assert ! ( !InitFeatures :: supported( ) . requires_unknown_bits( ) ) ;
306+ assert ! ( !InitFeatures :: supported( ) . supports_unknown_bits( ) ) ;
307+ assert ! ( !NodeFeatures :: supported( ) . requires_unknown_bits( ) ) ;
308+ assert ! ( !NodeFeatures :: supported( ) . supports_unknown_bits( ) ) ;
309+
310+ assert ! ( InitFeatures :: supported( ) . supports_upfront_shutdown_script( ) ) ;
311+ assert ! ( NodeFeatures :: supported( ) . supports_upfront_shutdown_script( ) ) ;
312+
313+ assert ! ( InitFeatures :: supported( ) . supports_data_loss_protect( ) ) ;
314+ assert ! ( NodeFeatures :: supported( ) . supports_data_loss_protect( ) ) ;
315+
316+ assert ! ( InitFeatures :: supported( ) . supports_variable_length_onion( ) ) ;
317+ assert ! ( NodeFeatures :: supported( ) . supports_variable_length_onion( ) ) ;
318+
319+ let mut init_features = InitFeatures :: supported ( ) ;
320+ init_features. set_initial_routing_sync ( ) ;
321+ assert ! ( !init_features. requires_unknown_bits( ) ) ;
322+ assert ! ( !init_features. supports_unknown_bits( ) ) ;
323+ }
324+
325+ #[ test]
326+ fn sanity_test_unkown_bits_testing ( ) {
327+ let mut features = ChannelFeatures :: supported ( ) ;
328+ features. set_require_unknown_bits ( ) ;
329+ assert ! ( features. requires_unknown_bits( ) ) ;
330+ features. clear_require_unknown_bits ( ) ;
331+ assert ! ( !features. requires_unknown_bits( ) ) ;
332+ }
333+ }
0 commit comments