Skip to content

Commit 5f8d3cc

Browse files
Add methods to set features in Features objects.
1 parent 2cb655b commit 5f8d3cc

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

lightning/src/ln/features.rs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use ln::msgs::DecodeError;
3232
use util::ser::{Readable, Writeable, Writer};
3333

3434
mod sealed {
35+
use ln::features::Features;
3536
/// The context in which [`Features`] are applicable. Defines which features are required and
3637
/// which are optional for the context.
3738
///
@@ -146,7 +147,8 @@ mod sealed {
146147
///
147148
/// [`Context`]: trait.Context.html
148149
macro_rules! define_feature {
149-
($odd_bit: expr, $feature: ident, [$($context: ty),+], $doc: expr) => {
150+
($odd_bit: expr, $feature: ident, [$($context: ty),+], $doc: expr, $supports_setter: ident,
151+
$requires_setter: ident) => {
150152
#[doc = $doc]
151153
///
152154
/// See [BOLT #9] for details.
@@ -231,6 +233,16 @@ mod sealed {
231233
}
232234
}
233235

236+
impl <T: $feature> Features<T> {
237+
pub fn $supports_setter(&mut self) {
238+
<T as $feature>::set_optional_bit(&mut self.flags);
239+
}
240+
241+
pub fn $requires_setter(&mut self) {
242+
<T as $feature>::set_required_bit(&mut self.flags);
243+
}
244+
}
245+
234246
$(
235247
impl $feature for $context {
236248
// EVEN_BIT % 2 == 0
@@ -240,28 +252,34 @@ mod sealed {
240252
const ASSERT_ODD_BIT_PARITY: usize = (<Self as $feature>::ODD_BIT % 2) - 1;
241253
}
242254
)*
255+
243256
}
244257
}
245258

246259
define_feature!(1, DataLossProtect, [InitContext, NodeContext],
247-
"Feature flags for `option_data_loss_protect`.");
260+
"Feature flags for `option_data_loss_protect`.", set_supports_data_loss_protect,
261+
set_requires_data_loss_protect);
248262
// NOTE: Per Bolt #9, initial_routing_sync has no even bit.
249-
define_feature!(3, InitialRoutingSync, [InitContext],
250-
"Feature flags for `initial_routing_sync`.");
263+
define_feature!(3, InitialRoutingSync, [InitContext], "Feature flags for `initial_routing_sync`.",
264+
set_supports_initial_routing_sync, set_requires_initial_routing_sync);
251265
define_feature!(5, UpfrontShutdownScript, [InitContext, NodeContext],
252-
"Feature flags for `option_upfront_shutdown_script`.");
266+
"Feature flags for `option_upfront_shutdown_script`.", set_supports_upfront_shutdown_script,
267+
set_requires_upfront_shutdown_script);
253268
define_feature!(7, GossipQueries, [InitContext, NodeContext],
254-
"Feature flags for `gossip_queries`.");
269+
"Feature flags for `gossip_queries`.", set_supports_gossip_queries, set_requires_gossip_queries);
255270
define_feature!(9, VariableLengthOnion, [InitContext, NodeContext],
256-
"Feature flags for `var_onion_optin`.");
271+
"Feature flags for `var_onion_optin`.", set_supports_variable_length_onion,
272+
set_requires_variable_length_onion);
257273
define_feature!(13, StaticRemoteKey, [InitContext, NodeContext],
258-
"Feature flags for `option_static_remotekey`.");
274+
"Feature flags for `option_static_remotekey`.", set_supports_static_remote_key,
275+
set_requires_static_remote_key);
259276
define_feature!(15, PaymentSecret, [InitContext, NodeContext],
260-
"Feature flags for `payment_secret`.");
277+
"Feature flags for `payment_secret`.", set_supports_payment_secret, set_requires_payment_secret);
261278
define_feature!(17, BasicMPP, [InitContext, NodeContext],
262-
"Feature flags for `basic_mpp`.");
279+
"Feature flags for `basic_mpp`.", set_supports_basic_mpp, set_requires_basic_mpp);
263280
define_feature!(27, ShutdownAnySegwit, [InitContext, NodeContext],
264-
"Feature flags for `opt_shutdown_anysegwit`.");
281+
"Feature flags for `opt_shutdown_anysegwit`.", set_supports_shutdown_any_segwit,
282+
set_requires_shutdown_any_segwit);
265283

266284
#[cfg(test)]
267285
define_context!(TestingContext {
@@ -285,7 +303,8 @@ mod sealed {
285303

286304
#[cfg(test)]
287305
define_feature!(23, UnknownFeature, [TestingContext],
288-
"Feature flags for an unknown feature used in testing.");
306+
"Feature flags for an unknown feature used in testing.", set_supports_unknown_feature,
307+
set_requires_unknown_feature);
289308
}
290309

291310
/// Tracks the set of features which a node implements, templated by the context in which it

0 commit comments

Comments
 (0)