Skip to content

Commit 1087e93

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 cd735a2 commit 1087e93

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lightning/src/ln/features.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ mod sealed {
123123
// Byte 3
124124
ShutdownAnySegwit,
125125
// Byte 4
126-
,
126+
OnionMessages,
127127
// Byte 5
128128
ChannelType | SCIDPrivacy,
129129
// Byte 6
@@ -139,7 +139,7 @@ mod sealed {
139139
// Byte 3
140140
ShutdownAnySegwit,
141141
// Byte 4
142-
,
142+
OnionMessages,
143143
// Byte 5
144144
ChannelType | SCIDPrivacy,
145145
// Byte 6
@@ -200,6 +200,11 @@ mod sealed {
200200
/// [`ODD_BIT`]: #associatedconstant.ODD_BIT
201201
const ASSERT_ODD_BIT_PARITY: usize;
202202

203+
/// Assertion that the bits are set in the context's [`KNOWN_FEATURE_MASK`].
204+
///
205+
/// [`KNOWN_FEATURE_MASK`]: Context::KNOWN_FEATURE_MASK
206+
const ASSERT_BITS_IN_MASK: u8;
207+
203208
/// The byte where the feature is set.
204209
const BYTE_OFFSET: usize = Self::EVEN_BIT / 8;
205210

@@ -286,6 +291,11 @@ mod sealed {
286291

287292
// ODD_BIT % 2 == 1
288293
const ASSERT_ODD_BIT_PARITY: usize = (<Self as $feature>::ODD_BIT % 2) - 1;
294+
295+
// (byte & (REQUIRED_MASK | OPTIONAL_MASK)) >> (EVEN_BIT % 8) == 3
296+
const ASSERT_BITS_IN_MASK: u8 =
297+
((<$context>::KNOWN_FEATURE_MASK[<Self as $feature>::BYTE_OFFSET] & (<Self as $feature>::REQUIRED_MASK | <Self as $feature>::OPTIONAL_MASK))
298+
>> (<Self as $feature>::EVEN_BIT % 8)) - 3;
289299
}
290300
)*
291301
};

0 commit comments

Comments
 (0)