Skip to content

Commit fab768a

Browse files
committed
Assert that all defined features are in the known features set
Now that the features contexts track the full set of all known features, rather than the set of supported features, all defined features should be listed in the context definition macro. This adds a compile-time assertion to check that all bits for known features are set in the context known set.
1 parent 0b47c15 commit fab768a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lightning/src/ln/features.rs

+12
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ mod sealed {
203203
/// [`ODD_BIT`]: #associatedconstant.ODD_BIT
204204
const ASSERT_ODD_BIT_PARITY: usize;
205205

206+
/// Assertion that the bits are set in the context's [`KNOWN_FEATURE_MASK`].
207+
///
208+
/// [`KNOWN_FEATURE_MASK`]: Context::KNOWN_FEATURE_MASK
209+
#[cfg(not(test))] // We violate this constraint with `UnknownFeature`
210+
const ASSERT_BITS_IN_MASK: u8;
211+
206212
/// The byte where the feature is set.
207213
const BYTE_OFFSET: usize = Self::EVEN_BIT / 8;
208214

@@ -289,6 +295,12 @@ mod sealed {
289295

290296
// ODD_BIT % 2 == 1
291297
const ASSERT_ODD_BIT_PARITY: usize = (<Self as $feature>::ODD_BIT % 2) - 1;
298+
299+
// (byte & (REQUIRED_MASK | OPTIONAL_MASK)) >> (EVEN_BIT % 8) == 3
300+
#[cfg(not(test))] // We violate this constraint with `UnknownFeature`
301+
const ASSERT_BITS_IN_MASK: u8 =
302+
((<$context>::KNOWN_FEATURE_MASK[<Self as $feature>::BYTE_OFFSET] & (<Self as $feature>::REQUIRED_MASK | <Self as $feature>::OPTIONAL_MASK))
303+
>> (<Self as $feature>::EVEN_BIT % 8)) - 3;
292304
}
293305
)*
294306
};

0 commit comments

Comments
 (0)