Skip to content

Commit 184d221

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 e2c8efe commit 184d221

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lightning/src/ln/features.rs

+10
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ mod sealed {
205205
/// [`ODD_BIT`]: #associatedconstant.ODD_BIT
206206
const ASSERT_ODD_BIT_PARITY: usize;
207207

208+
/// Assertion that the bits are set in the context's [`KNOWN_FEATURE_MASK`].
209+
///
210+
/// [`KNOWN_FEATURE_MASK`]: Context::KNOWN_FEATURE_MASK
211+
const ASSERT_BITS_IN_MASK: u8;
212+
208213
/// The byte where the feature is set.
209214
const BYTE_OFFSET: usize = Self::EVEN_BIT / 8;
210215

@@ -291,6 +296,11 @@ mod sealed {
291296

292297
// ODD_BIT % 2 == 1
293298
const ASSERT_ODD_BIT_PARITY: usize = (<Self as $feature>::ODD_BIT % 2) - 1;
299+
300+
// (byte & (REQUIRED_MASK | OPTIONAL_MASK)) >> (EVEN_BIT % 8) == 3
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;
294304
}
295305
)*
296306
};

0 commit comments

Comments
 (0)