Skip to content

Commit 9f74638

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 1895f5d commit 9f74638

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lightning/src/ln/features.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ 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+
#[cfg(not(test))] // We violate this constraint with `UnknownFeature`
212+
const ASSERT_BITS_IN_MASK: u8;
213+
208214
/// The byte where the feature is set.
209215
const BYTE_OFFSET: usize = Self::EVEN_BIT / 8;
210216

@@ -291,6 +297,12 @@ mod sealed {
291297

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

0 commit comments

Comments
 (0)