From: Matt Corallo Date: Fri, 9 Sep 2022 04:38:14 +0000 (+0000) Subject: Assert that all defined features are in the known features set X-Git-Tag: v0.0.112~37^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=9170804ca467cf624b87737752aedb0866d7fc49;p=rust-lightning 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. --- diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 4425a78e0..b372e6af6 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -203,6 +203,12 @@ mod sealed { /// [`ODD_BIT`]: #associatedconstant.ODD_BIT const ASSERT_ODD_BIT_PARITY: usize; + /// Assertion that the bits are set in the context's [`KNOWN_FEATURE_MASK`]. + /// + /// [`KNOWN_FEATURE_MASK`]: Context::KNOWN_FEATURE_MASK + #[cfg(not(test))] // We violate this constraint with `UnknownFeature` + const ASSERT_BITS_IN_MASK: u8; + /// The byte where the feature is set. const BYTE_OFFSET: usize = Self::EVEN_BIT / 8; @@ -289,6 +295,12 @@ mod sealed { // ODD_BIT % 2 == 1 const ASSERT_ODD_BIT_PARITY: usize = (::ODD_BIT % 2) - 1; + + // (byte & (REQUIRED_MASK | OPTIONAL_MASK)) >> (EVEN_BIT % 8) == 3 + #[cfg(not(test))] // We violate this constraint with `UnknownFeature` + const ASSERT_BITS_IN_MASK: u8 = + ((<$context>::KNOWN_FEATURE_MASK[::BYTE_OFFSET] & (::REQUIRED_MASK | ::OPTIONAL_MASK)) + >> (::EVEN_BIT % 8)) - 3; } )* };