@@ -25,19 +25,29 @@ mod sealed { // You should just use the type aliases instead.
25
25
///
26
26
/// [`Context`]: trait.Context.html
27
27
macro_rules! define_feature {
28
- ( $even_bit : expr , $ odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr) => {
28
+ ( $odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr) => {
29
29
#[ doc = $doc]
30
30
///
31
31
/// See [BOLT #9] for details.
32
32
///
33
33
/// [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md
34
34
pub trait $feature: Context {
35
35
/// The bit used to signify that the feature is required.
36
- const EVEN_BIT : usize = $even_bit ;
36
+ const EVEN_BIT : usize = $odd_bit - 1 ;
37
37
38
38
/// The bit used to signify that the feature is optional.
39
39
const ODD_BIT : usize = $odd_bit;
40
40
41
+ /// Assertion that [`EVEN_BIT`] is actually even.
42
+ ///
43
+ /// [`EVEN_BIT`]: #associatedconstant.EVEN_BIT
44
+ const ASSERT_EVEN_BIT_PARITY : usize ;
45
+
46
+ /// Assertion that [`ODD_BIT`] is actually odd.
47
+ ///
48
+ /// [`ODD_BIT`]: #associatedconstant.ODD_BIT
49
+ const ASSERT_ODD_BIT_PARITY : usize ;
50
+
41
51
/// The byte where the feature is set.
42
52
const BYTE_OFFSET : usize = Self :: EVEN_BIT / 8 ;
43
53
@@ -78,23 +88,29 @@ mod sealed { // You should just use the type aliases instead.
78
88
}
79
89
80
90
$(
81
- impl $feature for $context { }
91
+ impl $feature for $context {
92
+ // EVEN_BIT % 2 == 0
93
+ const ASSERT_EVEN_BIT_PARITY : usize = 0 - ( <Self as $feature>:: EVEN_BIT % 2 ) ;
94
+
95
+ // ODD_BIT % 2 == 1
96
+ const ASSERT_ODD_BIT_PARITY : usize = ( <Self as $feature>:: ODD_BIT % 2 ) - 1 ;
97
+ }
82
98
) *
83
99
}
84
100
}
85
101
86
- define_feature ! ( 0 , 1 , DataLossProtect , [ InitContext , NodeContext ] ,
102
+ define_feature ! ( 1 , DataLossProtect , [ InitContext , NodeContext ] ,
87
103
"Feature flags for `option_data_loss_protect`." ) ;
88
104
// NOTE: Per Bolt #9, initial_routing_sync has no even bit.
89
- define_feature ! ( 3 , 3 , InitialRoutingSync , [ InitContext ] ,
105
+ define_feature ! ( 3 , InitialRoutingSync , [ InitContext ] ,
90
106
"Feature flags for `initial_routing_sync`." ) ;
91
- define_feature ! ( 4 , 5 , UpfrontShutdownScript , [ InitContext , NodeContext ] ,
107
+ define_feature ! ( 5 , UpfrontShutdownScript , [ InitContext , NodeContext ] ,
92
108
"Feature flags for `option_upfront_shutdown_script`." ) ;
93
- define_feature ! ( 8 , 9 , VariableLengthOnion , [ InitContext , NodeContext ] ,
109
+ define_feature ! ( 9 , VariableLengthOnion , [ InitContext , NodeContext ] ,
94
110
"Feature flags for `var_onion_optin`." ) ;
95
- define_feature ! ( 14 , 15 , PaymentSecret , [ InitContext , NodeContext ] ,
111
+ define_feature ! ( 15 , PaymentSecret , [ InitContext , NodeContext ] ,
96
112
"Feature flags for `payment_secret`." ) ;
97
- define_feature ! ( 16 , 17 , BasicMPP , [ InitContext , NodeContext ] ,
113
+ define_feature ! ( 17 , BasicMPP , [ InitContext , NodeContext ] ,
98
114
"Feature flags for `basic_mpp`." ) ;
99
115
100
116
/// Generates a feature flag byte with the given features set as optional. Useful for initializing
0 commit comments