@@ -32,6 +32,7 @@ use ln::msgs::DecodeError;
32
32
use util:: ser:: { Readable , Writeable , Writer } ;
33
33
34
34
mod sealed {
35
+ use ln:: features:: Features ;
35
36
/// The context in which [`Features`] are applicable. Defines which features are required and
36
37
/// which are optional for the context.
37
38
///
@@ -157,7 +158,8 @@ mod sealed {
157
158
///
158
159
/// [`Context`]: trait.Context.html
159
160
macro_rules! define_feature {
160
- ( $odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr) => {
161
+ ( $odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr, $supports_setter: ident,
162
+ $requires_setter: ident) => {
161
163
#[ doc = $doc]
162
164
///
163
165
/// See [BOLT #9] for details.
@@ -242,6 +244,16 @@ mod sealed {
242
244
}
243
245
}
244
246
247
+ impl <T : $feature> Features <T > {
248
+ pub fn $supports_setter( & mut self ) {
249
+ <T as $feature>:: set_optional_bit( & mut self . flags) ;
250
+ }
251
+
252
+ pub fn $requires_setter( & mut self ) {
253
+ <T as $feature>:: set_required_bit( & mut self . flags) ;
254
+ }
255
+ }
256
+
245
257
$(
246
258
impl $feature for $context {
247
259
// EVEN_BIT % 2 == 0
@@ -251,28 +263,34 @@ mod sealed {
251
263
const ASSERT_ODD_BIT_PARITY : usize = ( <Self as $feature>:: ODD_BIT % 2 ) - 1 ;
252
264
}
253
265
) *
266
+
254
267
}
255
268
}
256
269
257
270
define_feature ! ( 1 , DataLossProtect , [ InitContext , NodeContext ] ,
258
- "Feature flags for `option_data_loss_protect`." ) ;
271
+ "Feature flags for `option_data_loss_protect`." , set_supports_data_loss_protect,
272
+ set_requires_data_loss_protect) ;
259
273
// NOTE: Per Bolt #9, initial_routing_sync has no even bit.
260
- define_feature ! ( 3 , InitialRoutingSync , [ InitContext ] ,
261
- "Feature flags for `initial_routing_sync`." ) ;
274
+ define_feature ! ( 3 , InitialRoutingSync , [ InitContext ] , "Feature flags for `initial_routing_sync`." ,
275
+ set_supports_initial_routing_sync , set_requires_initial_routing_sync ) ;
262
276
define_feature ! ( 5 , UpfrontShutdownScript , [ InitContext , NodeContext ] ,
263
- "Feature flags for `option_upfront_shutdown_script`." ) ;
277
+ "Feature flags for `option_upfront_shutdown_script`." , set_supports_upfront_shutdown_script,
278
+ set_requires_upfront_shutdown_script) ;
264
279
define_feature ! ( 7 , GossipQueries , [ InitContext , NodeContext ] ,
265
- "Feature flags for `gossip_queries`." ) ;
280
+ "Feature flags for `gossip_queries`." , set_supports_gossip_queries , set_requires_gossip_queries ) ;
266
281
define_feature ! ( 9 , VariableLengthOnion , [ InitContext , NodeContext , InvoiceContext ] ,
267
- "Feature flags for `var_onion_optin`." ) ;
282
+ "Feature flags for `var_onion_optin`." , set_supports_variable_length_onion,
283
+ set_requires_variable_length_onion) ;
268
284
define_feature ! ( 13 , StaticRemoteKey , [ InitContext , NodeContext ] ,
269
- "Feature flags for `option_static_remotekey`." ) ;
285
+ "Feature flags for `option_static_remotekey`." , set_supports_static_remote_key,
286
+ set_requires_static_remote_key) ;
270
287
define_feature ! ( 15 , PaymentSecret , [ InitContext , NodeContext , InvoiceContext ] ,
271
- "Feature flags for `payment_secret`." ) ;
288
+ "Feature flags for `payment_secret`." , set_supports_payment_secret , set_requires_payment_secret ) ;
272
289
define_feature ! ( 17 , BasicMPP , [ InitContext , NodeContext , InvoiceContext ] ,
273
- "Feature flags for `basic_mpp`." ) ;
290
+ "Feature flags for `basic_mpp`." , set_supports_basic_mpp , set_requires_basic_mpp ) ;
274
291
define_feature ! ( 27 , ShutdownAnySegwit , [ InitContext , NodeContext ] ,
275
- "Feature flags for `opt_shutdown_anysegwit`." ) ;
292
+ "Feature flags for `opt_shutdown_anysegwit`." , set_supports_shutdown_any_segwit,
293
+ set_requires_shutdown_any_segwit) ;
276
294
277
295
#[ cfg( test) ]
278
296
define_context ! ( TestingContext {
@@ -296,7 +314,8 @@ mod sealed {
296
314
297
315
#[ cfg( test) ]
298
316
define_feature ! ( 23 , UnknownFeature , [ TestingContext ] ,
299
- "Feature flags for an unknown feature used in testing." ) ;
317
+ "Feature flags for an unknown feature used in testing." , set_supports_unknown_feature,
318
+ set_requires_unknown_feature) ;
300
319
}
301
320
302
321
/// Tracks the set of features which a node implements, templated by the context in which it
0 commit comments