@@ -115,19 +115,29 @@ mod sealed {
115
115
///
116
116
/// [`Context`]: trait.Context.html
117
117
macro_rules! define_feature {
118
- ( $even_bit : expr , $ odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr) => {
118
+ ( $odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr) => {
119
119
#[ doc = $doc]
120
120
///
121
121
/// See [BOLT #9] for details.
122
122
///
123
123
/// [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md
124
124
pub trait $feature: Context {
125
125
/// The bit used to signify that the feature is required.
126
- const EVEN_BIT : usize = $even_bit ;
126
+ const EVEN_BIT : usize = $odd_bit - 1 ;
127
127
128
128
/// The bit used to signify that the feature is optional.
129
129
const ODD_BIT : usize = $odd_bit;
130
130
131
+ /// Assertion that [`EVEN_BIT`] is actually even.
132
+ ///
133
+ /// [`EVEN_BIT`]: #associatedconstant.EVEN_BIT
134
+ const ASSERT_EVEN_BIT_PARITY : usize ;
135
+
136
+ /// Assertion that [`ODD_BIT`] is actually odd.
137
+ ///
138
+ /// [`ODD_BIT`]: #associatedconstant.ODD_BIT
139
+ const ASSERT_ODD_BIT_PARITY : usize ;
140
+
131
141
/// The byte where the feature is set.
132
142
const BYTE_OFFSET : usize = Self :: EVEN_BIT / 8 ;
133
143
@@ -170,23 +180,29 @@ mod sealed {
170
180
}
171
181
172
182
$(
173
- impl $feature for $context { }
183
+ impl $feature for $context {
184
+ // EVEN_BIT % 2 == 0
185
+ const ASSERT_EVEN_BIT_PARITY : usize = 0 - ( <Self as $feature>:: EVEN_BIT % 2 ) ;
186
+
187
+ // ODD_BIT % 2 == 1
188
+ const ASSERT_ODD_BIT_PARITY : usize = ( <Self as $feature>:: ODD_BIT % 2 ) - 1 ;
189
+ }
174
190
) *
175
191
}
176
192
}
177
193
178
- define_feature ! ( 0 , 1 , DataLossProtect , [ InitContext , NodeContext ] ,
194
+ define_feature ! ( 1 , DataLossProtect , [ InitContext , NodeContext ] ,
179
195
"Feature flags for `option_data_loss_protect`." ) ;
180
196
// NOTE: Per Bolt #9, initial_routing_sync has no even bit.
181
- define_feature ! ( 3 , 3 , InitialRoutingSync , [ InitContext ] ,
197
+ define_feature ! ( 3 , InitialRoutingSync , [ InitContext ] ,
182
198
"Feature flags for `initial_routing_sync`." ) ;
183
- define_feature ! ( 4 , 5 , UpfrontShutdownScript , [ InitContext , NodeContext ] ,
199
+ define_feature ! ( 5 , UpfrontShutdownScript , [ InitContext , NodeContext ] ,
184
200
"Feature flags for `option_upfront_shutdown_script`." ) ;
185
- define_feature ! ( 8 , 9 , VariableLengthOnion , [ InitContext , NodeContext ] ,
201
+ define_feature ! ( 9 , VariableLengthOnion , [ InitContext , NodeContext ] ,
186
202
"Feature flags for `var_onion_optin`." ) ;
187
- define_feature ! ( 14 , 15 , PaymentSecret , [ InitContext , NodeContext ] ,
203
+ define_feature ! ( 15 , PaymentSecret , [ InitContext , NodeContext ] ,
188
204
"Feature flags for `payment_secret`." ) ;
189
- define_feature ! ( 16 , 17 , BasicMPP , [ InitContext , NodeContext ] ,
205
+ define_feature ! ( 17 , BasicMPP , [ InitContext , NodeContext ] ,
190
206
"Feature flags for `basic_mpp`." ) ;
191
207
}
192
208
0 commit comments