@@ -96,7 +96,7 @@ use core::{cmp, fmt};
9696use alloc:: vec:: Vec ;
9797
9898mod sealed {
99- use super :: { FeatureFlags , Features } ;
99+ use super :: Features ;
100100
101101 /// The context in which [`Features`] are applicable. Defines which features are known to the
102102 /// implementation, though specification of them as required or optional is up to the code
@@ -310,54 +310,54 @@ mod sealed {
310310
311311 /// Sets the feature's required (even) bit in the given flags.
312312 #[ inline]
313- fn set_required_bit( flags : & mut FeatureFlags ) {
314- if flags. len( ) <= Self :: BYTE_OFFSET {
315- flags. resize( Self :: BYTE_OFFSET + 1 , 0u8 ) ;
313+ fn set_required_bit( obj : & mut Features < Self > ) {
314+ if obj . flags. len( ) <= Self :: BYTE_OFFSET {
315+ obj . flags. resize( Self :: BYTE_OFFSET + 1 , 0u8 ) ;
316316 }
317317
318- flags[ Self :: BYTE_OFFSET ] |= Self :: REQUIRED_MASK ;
319- flags[ Self :: BYTE_OFFSET ] &= !Self :: OPTIONAL_MASK ;
318+ obj . flags[ Self :: BYTE_OFFSET ] |= Self :: REQUIRED_MASK ;
319+ obj . flags[ Self :: BYTE_OFFSET ] &= !Self :: OPTIONAL_MASK ;
320320 }
321321
322322 /// Sets the feature's optional (odd) bit in the given flags.
323323 #[ inline]
324- fn set_optional_bit( flags : & mut FeatureFlags ) {
325- if flags. len( ) <= Self :: BYTE_OFFSET {
326- flags. resize( Self :: BYTE_OFFSET + 1 , 0u8 ) ;
324+ fn set_optional_bit( obj : & mut Features < Self > ) {
325+ if obj . flags. len( ) <= Self :: BYTE_OFFSET {
326+ obj . flags. resize( Self :: BYTE_OFFSET + 1 , 0u8 ) ;
327327 }
328328
329- flags[ Self :: BYTE_OFFSET ] |= Self :: OPTIONAL_MASK ;
329+ obj . flags[ Self :: BYTE_OFFSET ] |= Self :: OPTIONAL_MASK ;
330330 }
331331
332332 /// Clears the feature's required (even) and optional (odd) bits from the given
333333 /// flags.
334334 #[ inline]
335- fn clear_bits( flags : & mut FeatureFlags ) {
336- if flags. len( ) > Self :: BYTE_OFFSET {
337- flags[ Self :: BYTE_OFFSET ] &= !Self :: REQUIRED_MASK ;
338- flags[ Self :: BYTE_OFFSET ] &= !Self :: OPTIONAL_MASK ;
335+ fn clear_bits( obj : & mut Features < Self > ) {
336+ if obj . flags. len( ) > Self :: BYTE_OFFSET {
337+ obj . flags[ Self :: BYTE_OFFSET ] &= !Self :: REQUIRED_MASK ;
338+ obj . flags[ Self :: BYTE_OFFSET ] &= !Self :: OPTIONAL_MASK ;
339339 }
340340
341- let last_non_zero_byte = flags. iter( ) . rposition( |& byte| byte != 0 ) ;
341+ let last_non_zero_byte = obj . flags. iter( ) . rposition( |& byte| byte != 0 ) ;
342342 let size = if let Some ( offset) = last_non_zero_byte { offset + 1 } else { 0 } ;
343- flags. resize( size, 0u8 ) ;
343+ obj . flags. resize( size, 0u8 ) ;
344344 }
345345 }
346346
347347 impl <T : $feature> Features <T > {
348348 /// Set this feature as optional.
349349 pub fn $optional_setter( & mut self ) {
350- <T as $feature>:: set_optional_bit( & mut self . flags ) ;
350+ <T as $feature>:: set_optional_bit( self ) ;
351351 }
352352
353353 /// Set this feature as required.
354354 pub fn $required_setter( & mut self ) {
355- <T as $feature>:: set_required_bit( & mut self . flags ) ;
355+ <T as $feature>:: set_required_bit( self ) ;
356356 }
357357
358358 /// Unsets this feature.
359359 pub fn $clear( & mut self ) {
360- <T as $feature>:: clear_bits( & mut self . flags ) ;
360+ <T as $feature>:: clear_bits( self ) ;
361361 }
362362
363363 /// Checks if this feature is supported.
@@ -718,15 +718,20 @@ const DIRECT_ALLOC_BYTES: usize = if sealed::MIN_FEATURES_ALLOCATION_BYTES > 8 *
718718} ;
719719const _ASSERT: ( ) = assert ! ( DIRECT_ALLOC_BYTES <= u8 :: MAX as usize ) ;
720720
721- /// The internal storage for feature flags. Public only for the [`sealed`] feature flag traits but
722- /// generally should never be used directly.
721+ #[ cfg( fuzzing) ]
723722#[ derive( Clone , PartialEq , Eq ) ]
724- #[ doc( hidden) ]
725723pub enum FeatureFlags {
726724 Held { bytes : [ u8 ; DIRECT_ALLOC_BYTES ] , len : u8 } ,
727725 Heap ( Vec < u8 > ) ,
728726}
729727
728+ #[ cfg( not( fuzzing) ) ]
729+ #[ derive( Clone , PartialEq , Eq ) ]
730+ enum FeatureFlags {
731+ Held { bytes : [ u8 ; DIRECT_ALLOC_BYTES ] , len : u8 } ,
732+ Heap ( Vec < u8 > ) ,
733+ }
734+
730735impl FeatureFlags {
731736 fn empty ( ) -> Self {
732737 Self :: Held { bytes : [ 0 ; DIRECT_ALLOC_BYTES ] , len : 0 }
@@ -826,7 +831,7 @@ impl fmt::Debug for FeatureFlags {
826831///
827832/// This is not exported to bindings users as we map the concrete feature types below directly instead
828833#[ derive( Eq ) ]
829- pub struct Features < T : sealed:: Context > {
834+ pub struct Features < T : sealed:: Context + ? Sized > {
830835 /// Note that, for convenience, flags is LITTLE endian (despite being big-endian on the wire)
831836 flags : FeatureFlags ,
832837 mark : PhantomData < T > ,
@@ -865,7 +870,7 @@ impl<T: sealed::Context> Hash for Features<T> {
865870 nonzero_flags. hash ( hasher) ;
866871 }
867872}
868- impl < T : sealed:: Context > PartialEq for Features < T > {
873+ impl < T : sealed:: Context + ? Sized > PartialEq for Features < T > {
869874 fn eq ( & self , o : & Self ) -> bool {
870875 let mut o_iter = o. flags . iter ( ) ;
871876 let mut self_iter = self . flags . iter ( ) ;
@@ -1000,17 +1005,15 @@ impl ChannelTypeFeatures {
10001005 /// Constructs a ChannelTypeFeatures with only static_remotekey set
10011006 pub fn only_static_remote_key ( ) -> Self {
10021007 let mut ret = Self :: empty ( ) ;
1003- <sealed:: ChannelTypeContext as sealed:: StaticRemoteKey >:: set_required_bit ( & mut ret. flags ) ;
1008+ <sealed:: ChannelTypeContext as sealed:: StaticRemoteKey >:: set_required_bit ( & mut ret) ;
10041009 ret
10051010 }
10061011
10071012 /// Constructs a ChannelTypeFeatures with anchors support
10081013 pub fn anchors_zero_htlc_fee_and_dependencies ( ) -> Self {
10091014 let mut ret = Self :: empty ( ) ;
1010- <sealed:: ChannelTypeContext as sealed:: StaticRemoteKey >:: set_required_bit ( & mut ret. flags ) ;
1011- <sealed:: ChannelTypeContext as sealed:: AnchorsZeroFeeHtlcTx >:: set_required_bit (
1012- & mut ret. flags ,
1013- ) ;
1015+ <sealed:: ChannelTypeContext as sealed:: StaticRemoteKey >:: set_required_bit ( & mut ret) ;
1016+ <sealed:: ChannelTypeContext as sealed:: AnchorsZeroFeeHtlcTx >:: set_required_bit ( & mut ret) ;
10141017 ret
10151018 }
10161019}
0 commit comments