Update BOLT4 onion test vectors
[rust-lightning] / lightning / src / ln / features.rs
index 4425a78e03f9ad406fe885e9f65d91a00d866115..e8a3e6d26facd524c3ae3036ed87ec54a08b8937 100644 (file)
 //! [BOLT #9]: https://github.com/lightning/bolts/blob/master/09-features.md
 //! [messages]: crate::ln::msgs
 
-use {io, io_extras};
-use prelude::*;
+use crate::{io, io_extras};
+use crate::prelude::*;
 use core::{cmp, fmt};
 use core::hash::{Hash, Hasher};
 use core::marker::PhantomData;
 
 use bitcoin::bech32;
 use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, u5, WriteBase32};
-use ln::msgs::DecodeError;
-use util::ser::{Readable, Writeable, Writer};
+use crate::ln::msgs::DecodeError;
+use crate::util::ser::{Readable, Writeable, Writer};
 
 mod sealed {
-       use prelude::*;
-       use ln::features::Features;
+       use crate::prelude::*;
+       use crate::ln::features::Features;
 
        /// The context in which [`Features`] are applicable. Defines which features are known to the
        /// implementation, though specification of them as required or optional is up to the code
@@ -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 = (<Self as $feature>::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[<Self as $feature>::BYTE_OFFSET] & (<Self as $feature>::REQUIRED_MASK | <Self as $feature>::OPTIONAL_MASK))
+                                                >> (<Self as $feature>::EVEN_BIT % 8)) - 3;
                                }
                        )*
                };