Skip to content

Commit 9ea2de6

Browse files
committed
f Assertion checks for bit parity and proximity
1 parent 3c06e95 commit 9ea2de6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lightning/src/ln/features.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ mod sealed { // You should just use the type aliases instead.
3838
/// The bit used to signify that the feature is optional.
3939
const ODD_BIT: usize = $odd_bit;
4040

41+
/// Assertion that [`ODD_BIT`] is actually odd.
42+
const ASSERT_BIT_PARITY: usize;
43+
44+
/// Assertion that [`ODD_BIT`] is at most `EVEN_BIT + 1`. Allows for special cases
45+
/// where a feature only has one bit and thus `EVEN_BIT == ODD_BIT`.
46+
const ASSERT_BIT_PROXIMITY: usize;
47+
4148
/// The byte where the feature is set.
4249
const BYTE_OFFSET: usize = Self::EVEN_BIT / 8;
4350

@@ -78,7 +85,14 @@ mod sealed { // You should just use the type aliases instead.
7885
}
7986

8087
$(
81-
impl $feature for $context {}
88+
impl $feature for $context {
89+
// ODD_BIT % 2 == 1
90+
const ASSERT_BIT_PARITY: usize = (<Self as $feature>::ODD_BIT % 2) - 1;
91+
92+
// ODD_BIT == EVEN_BIT + 1 || ODD_BIT == EVEN_BIT
93+
const ASSERT_BIT_PROXIMITY: usize =
94+
1 - (<Self as $feature>::ODD_BIT - <Self as $feature>::EVEN_BIT);
95+
}
8296
)*
8397
}
8498
}

0 commit comments

Comments
 (0)