Skip to content

Commit f4c2a01

Browse files
committed
Expose a feature-clearing method for all feature flags
We've ad-hoc exposed feature-clearing methods for various feature flags over the years, but there's not a lot of reason to not just do it for all the flags, so we go ahead and do that here.
1 parent 6836fc4 commit f4c2a01

File tree

1 file changed

+41
-47
lines changed

1 file changed

+41
-47
lines changed

lightning-types/src/features.rs

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ mod sealed {
251251
/// useful for manipulating feature flags.
252252
macro_rules! define_feature {
253253
($odd_bit: expr, $feature: ident, [$($context: ty),+], $doc: expr, $optional_setter: ident,
254-
$required_setter: ident, $supported_getter: ident) => {
254+
$required_setter: ident, $clear: ident, $supported_getter: ident) => {
255255
#[doc = $doc]
256256
///
257257
/// See [BOLT #9] for details.
@@ -354,6 +354,11 @@ mod sealed {
354354
<T as $feature>::set_required_bit(&mut self.flags);
355355
}
356356

357+
/// Unsets this feature.
358+
pub fn $clear(&mut self) {
359+
<T as $feature>::clear_bits(&mut self.flags);
360+
}
361+
357362
/// Checks if this feature is supported.
358363
pub fn $supported_getter(&self) -> bool {
359364
<T as $feature>::supports_feature(&self.flags)
@@ -377,8 +382,8 @@ mod sealed {
377382
)*
378383
};
379384
($odd_bit: expr, $feature: ident, [$($context: ty),+], $doc: expr, $optional_setter: ident,
380-
$required_setter: ident, $supported_getter: ident, $required_getter: ident) => {
381-
define_feature!($odd_bit, $feature, [$($context),+], $doc, $optional_setter, $required_setter, $supported_getter);
385+
$required_setter: ident, $clear: ident, $supported_getter: ident, $required_getter: ident) => {
386+
define_feature!($odd_bit, $feature, [$($context),+], $doc, $optional_setter, $required_setter, $clear, $supported_getter);
382387
impl <T: $feature> Features<T> {
383388
/// Checks if this feature is required.
384389
pub fn $required_getter(&self) -> bool {
@@ -395,6 +400,7 @@ mod sealed {
395400
"Feature flags for `option_data_loss_protect`.",
396401
set_data_loss_protect_optional,
397402
set_data_loss_protect_required,
403+
clear_data_loss_protect,
398404
supports_data_loss_protect,
399405
requires_data_loss_protect
400406
);
@@ -406,6 +412,7 @@ mod sealed {
406412
"Feature flags for `initial_routing_sync`.",
407413
set_initial_routing_sync_optional,
408414
set_initial_routing_sync_required,
415+
clear_initial_routing_sync,
409416
initial_routing_sync
410417
);
411418
define_feature!(
@@ -415,6 +422,7 @@ mod sealed {
415422
"Feature flags for `option_upfront_shutdown_script`.",
416423
set_upfront_shutdown_script_optional,
417424
set_upfront_shutdown_script_required,
425+
clear_upfront_shutdown_script,
418426
supports_upfront_shutdown_script,
419427
requires_upfront_shutdown_script
420428
);
@@ -425,6 +433,7 @@ mod sealed {
425433
"Feature flags for `gossip_queries`.",
426434
set_gossip_queries_optional,
427435
set_gossip_queries_required,
436+
clear_gossip_queries,
428437
supports_gossip_queries,
429438
requires_gossip_queries
430439
);
@@ -435,6 +444,7 @@ mod sealed {
435444
"Feature flags for `var_onion_optin`.",
436445
set_variable_length_onion_optional,
437446
set_variable_length_onion_required,
447+
clear_variable_length_onion,
438448
supports_variable_length_onion,
439449
requires_variable_length_onion
440450
);
@@ -445,6 +455,7 @@ mod sealed {
445455
"Feature flags for `option_static_remotekey`.",
446456
set_static_remote_key_optional,
447457
set_static_remote_key_required,
458+
clear_static_remote_key,
448459
supports_static_remote_key,
449460
requires_static_remote_key
450461
);
@@ -455,6 +466,7 @@ mod sealed {
455466
"Feature flags for `payment_secret`.",
456467
set_payment_secret_optional,
457468
set_payment_secret_required,
469+
clear_payment_secret,
458470
supports_payment_secret,
459471
requires_payment_secret
460472
);
@@ -465,6 +477,7 @@ mod sealed {
465477
"Feature flags for `basic_mpp`.",
466478
set_basic_mpp_optional,
467479
set_basic_mpp_required,
480+
clear_basic_mpp,
468481
supports_basic_mpp,
469482
requires_basic_mpp
470483
);
@@ -475,6 +488,7 @@ mod sealed {
475488
"Feature flags for `option_support_large_channel` (aka wumbo channels).",
476489
set_wumbo_optional,
477490
set_wumbo_required,
491+
clear_wumbo,
478492
supports_wumbo,
479493
requires_wumbo
480494
);
@@ -485,6 +499,7 @@ mod sealed {
485499
"Feature flags for `option_anchors_nonzero_fee_htlc_tx`.",
486500
set_anchors_nonzero_fee_htlc_tx_optional,
487501
set_anchors_nonzero_fee_htlc_tx_required,
502+
clear_anchors_nonzero_fee_htlc_tx,
488503
supports_anchors_nonzero_fee_htlc_tx,
489504
requires_anchors_nonzero_fee_htlc_tx
490505
);
@@ -495,6 +510,7 @@ mod sealed {
495510
"Feature flags for `option_anchors_zero_fee_htlc_tx`.",
496511
set_anchors_zero_fee_htlc_tx_optional,
497512
set_anchors_zero_fee_htlc_tx_required,
513+
clear_anchors_zero_fee_htlc_tx,
498514
supports_anchors_zero_fee_htlc_tx,
499515
requires_anchors_zero_fee_htlc_tx
500516
);
@@ -505,6 +521,7 @@ mod sealed {
505521
"Feature flags for `option_route_blinding`.",
506522
set_route_blinding_optional,
507523
set_route_blinding_required,
524+
clear_route_blinding,
508525
supports_route_blinding,
509526
requires_route_blinding
510527
);
@@ -515,6 +532,7 @@ mod sealed {
515532
"Feature flags for `opt_shutdown_anysegwit`.",
516533
set_shutdown_any_segwit_optional,
517534
set_shutdown_any_segwit_required,
535+
clear_shutdown_anysegwit,
518536
supports_shutdown_anysegwit,
519537
requires_shutdown_anysegwit
520538
);
@@ -525,6 +543,7 @@ mod sealed {
525543
"Feature flags for `option_dual_fund`.",
526544
set_dual_fund_optional,
527545
set_dual_fund_required,
546+
clear_dual_fund,
528547
supports_dual_fund,
529548
requires_dual_fund
530549
);
@@ -535,6 +554,7 @@ mod sealed {
535554
"Feature flags for `option_taproot`.",
536555
set_taproot_optional,
537556
set_taproot_required,
557+
clear_taproot,
538558
supports_taproot,
539559
requires_taproot
540560
);
@@ -545,6 +565,7 @@ mod sealed {
545565
"Feature flags for `option_quiesce`.",
546566
set_quiescence_optional,
547567
set_quiescence_required,
568+
clear_quiescence,
548569
supports_quiescence,
549570
requires_quiescence
550571
);
@@ -555,6 +576,7 @@ mod sealed {
555576
"Feature flags for `option_onion_messages`.",
556577
set_onion_messages_optional,
557578
set_onion_messages_required,
579+
clear_onion_messages,
558580
supports_onion_messages,
559581
requires_onion_messages
560582
);
@@ -565,6 +587,7 @@ mod sealed {
565587
"Feature flags for `option_provide_storage`.",
566588
set_provide_storage_optional,
567589
set_provide_storage_required,
590+
clear_provide_storage,
568591
supports_provide_storage,
569592
requires_provide_storage
570593
);
@@ -575,19 +598,28 @@ mod sealed {
575598
"Feature flags for `option_channel_type`.",
576599
set_channel_type_optional,
577600
set_channel_type_required,
601+
clear_channel_type,
578602
supports_channel_type,
579603
requires_channel_type
580604
);
581-
define_feature!(47, SCIDPrivacy, [InitContext, NodeContext, ChannelTypeContext],
605+
define_feature!(47,
606+
SCIDPrivacy,
607+
[InitContext, NodeContext, ChannelTypeContext],
582608
"Feature flags for only forwarding with SCID aliasing. Called `option_scid_alias` in the BOLTs",
583-
set_scid_privacy_optional, set_scid_privacy_required, supports_scid_privacy, requires_scid_privacy);
609+
set_scid_privacy_optional,
610+
set_scid_privacy_required,
611+
clear_scid_privacy,
612+
supports_scid_privacy,
613+
requires_scid_privacy
614+
);
584615
define_feature!(
585616
49,
586617
PaymentMetadata,
587618
[Bolt11InvoiceContext],
588619
"Feature flags for payment metadata in invoices.",
589620
set_payment_metadata_optional,
590621
set_payment_metadata_required,
622+
clear_payment_metadata,
591623
supports_payment_metadata,
592624
requires_payment_metadata
593625
);
@@ -601,6 +633,7 @@ mod sealed {
601633
"Feature flags for keysend payments.",
602634
set_keysend_optional,
603635
set_keysend_required,
636+
clear_keysend,
604637
supports_keysend,
605638
requires_keysend
606639
);
@@ -611,6 +644,7 @@ mod sealed {
611644
"Feature flags for Trampoline routing.",
612645
set_trampoline_routing_optional,
613646
set_trampoline_routing_required,
647+
clear_trampoline_routing,
614648
supports_trampoline_routing,
615649
requires_trampoline_routing
616650
);
@@ -621,6 +655,7 @@ mod sealed {
621655
"Feature flags for DNS resolving.",
622656
set_dns_resolution_optional,
623657
set_dns_resolution_required,
658+
clear_dns_resolution,
624659
supports_dns_resolution,
625660
requires_dns_resolution
626661
);
@@ -643,6 +678,7 @@ mod sealed {
643678
"Feature flags for an unknown feature used in testing.",
644679
set_unknown_feature_optional,
645680
set_unknown_feature_required,
681+
clear_unknown_feature,
646682
supports_unknown_test_feature,
647683
requires_unknown_test_feature
648684
);
@@ -1038,48 +1074,6 @@ impl<T: sealed::Context> Features<T> {
10381074
}
10391075
}
10401076

1041-
impl<T: sealed::UpfrontShutdownScript> Features<T> {
1042-
/// Unsets the `upfront_shutdown_script` feature
1043-
pub fn clear_upfront_shutdown_script(&mut self) {
1044-
<T as sealed::UpfrontShutdownScript>::clear_bits(&mut self.flags);
1045-
}
1046-
}
1047-
1048-
impl<T: sealed::ShutdownAnySegwit> Features<T> {
1049-
/// Unsets the `shutdown_anysegwit` feature
1050-
pub fn clear_shutdown_anysegwit(&mut self) {
1051-
<T as sealed::ShutdownAnySegwit>::clear_bits(&mut self.flags);
1052-
}
1053-
}
1054-
1055-
impl<T: sealed::Wumbo> Features<T> {
1056-
/// Unsets the `wumbo` feature
1057-
pub fn clear_wumbo(&mut self) {
1058-
<T as sealed::Wumbo>::clear_bits(&mut self.flags);
1059-
}
1060-
}
1061-
1062-
impl<T: sealed::SCIDPrivacy> Features<T> {
1063-
/// Unsets the `scid_privacy` feature
1064-
pub fn clear_scid_privacy(&mut self) {
1065-
<T as sealed::SCIDPrivacy>::clear_bits(&mut self.flags);
1066-
}
1067-
}
1068-
1069-
impl<T: sealed::AnchorsZeroFeeHtlcTx> Features<T> {
1070-
/// Unsets the `anchors_zero_fee_htlc_tx` feature
1071-
pub fn clear_anchors_zero_fee_htlc_tx(&mut self) {
1072-
<T as sealed::AnchorsZeroFeeHtlcTx>::clear_bits(&mut self.flags);
1073-
}
1074-
}
1075-
1076-
impl<T: sealed::RouteBlinding> Features<T> {
1077-
/// Unsets the `route_blinding` feature
1078-
pub fn clear_route_blinding(&mut self) {
1079-
<T as sealed::RouteBlinding>::clear_bits(&mut self.flags);
1080-
}
1081-
}
1082-
10831077
#[cfg(any(test, feature = "_test_utils"))]
10841078
impl<T: sealed::UnknownFeature> Features<T> {
10851079
/// Sets an unknown feature for testing

0 commit comments

Comments
 (0)