mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-13 14:52:21 +01:00
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.
This commit is contained in:
parent
6836fc4cd8
commit
f4c2a011f2
1 changed files with 41 additions and 47 deletions
|
@ -251,7 +251,7 @@ mod sealed {
|
|||
/// useful for manipulating feature flags.
|
||||
macro_rules! define_feature {
|
||||
($odd_bit: expr, $feature: ident, [$($context: ty),+], $doc: expr, $optional_setter: ident,
|
||||
$required_setter: ident, $supported_getter: ident) => {
|
||||
$required_setter: ident, $clear: ident, $supported_getter: ident) => {
|
||||
#[doc = $doc]
|
||||
///
|
||||
/// See [BOLT #9] for details.
|
||||
|
@ -354,6 +354,11 @@ mod sealed {
|
|||
<T as $feature>::set_required_bit(&mut self.flags);
|
||||
}
|
||||
|
||||
/// Unsets this feature.
|
||||
pub fn $clear(&mut self) {
|
||||
<T as $feature>::clear_bits(&mut self.flags);
|
||||
}
|
||||
|
||||
/// Checks if this feature is supported.
|
||||
pub fn $supported_getter(&self) -> bool {
|
||||
<T as $feature>::supports_feature(&self.flags)
|
||||
|
@ -377,8 +382,8 @@ mod sealed {
|
|||
)*
|
||||
};
|
||||
($odd_bit: expr, $feature: ident, [$($context: ty),+], $doc: expr, $optional_setter: ident,
|
||||
$required_setter: ident, $supported_getter: ident, $required_getter: ident) => {
|
||||
define_feature!($odd_bit, $feature, [$($context),+], $doc, $optional_setter, $required_setter, $supported_getter);
|
||||
$required_setter: ident, $clear: ident, $supported_getter: ident, $required_getter: ident) => {
|
||||
define_feature!($odd_bit, $feature, [$($context),+], $doc, $optional_setter, $required_setter, $clear, $supported_getter);
|
||||
impl <T: $feature> Features<T> {
|
||||
/// Checks if this feature is required.
|
||||
pub fn $required_getter(&self) -> bool {
|
||||
|
@ -395,6 +400,7 @@ mod sealed {
|
|||
"Feature flags for `option_data_loss_protect`.",
|
||||
set_data_loss_protect_optional,
|
||||
set_data_loss_protect_required,
|
||||
clear_data_loss_protect,
|
||||
supports_data_loss_protect,
|
||||
requires_data_loss_protect
|
||||
);
|
||||
|
@ -406,6 +412,7 @@ mod sealed {
|
|||
"Feature flags for `initial_routing_sync`.",
|
||||
set_initial_routing_sync_optional,
|
||||
set_initial_routing_sync_required,
|
||||
clear_initial_routing_sync,
|
||||
initial_routing_sync
|
||||
);
|
||||
define_feature!(
|
||||
|
@ -415,6 +422,7 @@ mod sealed {
|
|||
"Feature flags for `option_upfront_shutdown_script`.",
|
||||
set_upfront_shutdown_script_optional,
|
||||
set_upfront_shutdown_script_required,
|
||||
clear_upfront_shutdown_script,
|
||||
supports_upfront_shutdown_script,
|
||||
requires_upfront_shutdown_script
|
||||
);
|
||||
|
@ -425,6 +433,7 @@ mod sealed {
|
|||
"Feature flags for `gossip_queries`.",
|
||||
set_gossip_queries_optional,
|
||||
set_gossip_queries_required,
|
||||
clear_gossip_queries,
|
||||
supports_gossip_queries,
|
||||
requires_gossip_queries
|
||||
);
|
||||
|
@ -435,6 +444,7 @@ mod sealed {
|
|||
"Feature flags for `var_onion_optin`.",
|
||||
set_variable_length_onion_optional,
|
||||
set_variable_length_onion_required,
|
||||
clear_variable_length_onion,
|
||||
supports_variable_length_onion,
|
||||
requires_variable_length_onion
|
||||
);
|
||||
|
@ -445,6 +455,7 @@ mod sealed {
|
|||
"Feature flags for `option_static_remotekey`.",
|
||||
set_static_remote_key_optional,
|
||||
set_static_remote_key_required,
|
||||
clear_static_remote_key,
|
||||
supports_static_remote_key,
|
||||
requires_static_remote_key
|
||||
);
|
||||
|
@ -455,6 +466,7 @@ mod sealed {
|
|||
"Feature flags for `payment_secret`.",
|
||||
set_payment_secret_optional,
|
||||
set_payment_secret_required,
|
||||
clear_payment_secret,
|
||||
supports_payment_secret,
|
||||
requires_payment_secret
|
||||
);
|
||||
|
@ -465,6 +477,7 @@ mod sealed {
|
|||
"Feature flags for `basic_mpp`.",
|
||||
set_basic_mpp_optional,
|
||||
set_basic_mpp_required,
|
||||
clear_basic_mpp,
|
||||
supports_basic_mpp,
|
||||
requires_basic_mpp
|
||||
);
|
||||
|
@ -475,6 +488,7 @@ mod sealed {
|
|||
"Feature flags for `option_support_large_channel` (aka wumbo channels).",
|
||||
set_wumbo_optional,
|
||||
set_wumbo_required,
|
||||
clear_wumbo,
|
||||
supports_wumbo,
|
||||
requires_wumbo
|
||||
);
|
||||
|
@ -485,6 +499,7 @@ mod sealed {
|
|||
"Feature flags for `option_anchors_nonzero_fee_htlc_tx`.",
|
||||
set_anchors_nonzero_fee_htlc_tx_optional,
|
||||
set_anchors_nonzero_fee_htlc_tx_required,
|
||||
clear_anchors_nonzero_fee_htlc_tx,
|
||||
supports_anchors_nonzero_fee_htlc_tx,
|
||||
requires_anchors_nonzero_fee_htlc_tx
|
||||
);
|
||||
|
@ -495,6 +510,7 @@ mod sealed {
|
|||
"Feature flags for `option_anchors_zero_fee_htlc_tx`.",
|
||||
set_anchors_zero_fee_htlc_tx_optional,
|
||||
set_anchors_zero_fee_htlc_tx_required,
|
||||
clear_anchors_zero_fee_htlc_tx,
|
||||
supports_anchors_zero_fee_htlc_tx,
|
||||
requires_anchors_zero_fee_htlc_tx
|
||||
);
|
||||
|
@ -505,6 +521,7 @@ mod sealed {
|
|||
"Feature flags for `option_route_blinding`.",
|
||||
set_route_blinding_optional,
|
||||
set_route_blinding_required,
|
||||
clear_route_blinding,
|
||||
supports_route_blinding,
|
||||
requires_route_blinding
|
||||
);
|
||||
|
@ -515,6 +532,7 @@ mod sealed {
|
|||
"Feature flags for `opt_shutdown_anysegwit`.",
|
||||
set_shutdown_any_segwit_optional,
|
||||
set_shutdown_any_segwit_required,
|
||||
clear_shutdown_anysegwit,
|
||||
supports_shutdown_anysegwit,
|
||||
requires_shutdown_anysegwit
|
||||
);
|
||||
|
@ -525,6 +543,7 @@ mod sealed {
|
|||
"Feature flags for `option_dual_fund`.",
|
||||
set_dual_fund_optional,
|
||||
set_dual_fund_required,
|
||||
clear_dual_fund,
|
||||
supports_dual_fund,
|
||||
requires_dual_fund
|
||||
);
|
||||
|
@ -535,6 +554,7 @@ mod sealed {
|
|||
"Feature flags for `option_taproot`.",
|
||||
set_taproot_optional,
|
||||
set_taproot_required,
|
||||
clear_taproot,
|
||||
supports_taproot,
|
||||
requires_taproot
|
||||
);
|
||||
|
@ -545,6 +565,7 @@ mod sealed {
|
|||
"Feature flags for `option_quiesce`.",
|
||||
set_quiescence_optional,
|
||||
set_quiescence_required,
|
||||
clear_quiescence,
|
||||
supports_quiescence,
|
||||
requires_quiescence
|
||||
);
|
||||
|
@ -555,6 +576,7 @@ mod sealed {
|
|||
"Feature flags for `option_onion_messages`.",
|
||||
set_onion_messages_optional,
|
||||
set_onion_messages_required,
|
||||
clear_onion_messages,
|
||||
supports_onion_messages,
|
||||
requires_onion_messages
|
||||
);
|
||||
|
@ -565,6 +587,7 @@ mod sealed {
|
|||
"Feature flags for `option_provide_storage`.",
|
||||
set_provide_storage_optional,
|
||||
set_provide_storage_required,
|
||||
clear_provide_storage,
|
||||
supports_provide_storage,
|
||||
requires_provide_storage
|
||||
);
|
||||
|
@ -575,12 +598,20 @@ mod sealed {
|
|||
"Feature flags for `option_channel_type`.",
|
||||
set_channel_type_optional,
|
||||
set_channel_type_required,
|
||||
clear_channel_type,
|
||||
supports_channel_type,
|
||||
requires_channel_type
|
||||
);
|
||||
define_feature!(47, SCIDPrivacy, [InitContext, NodeContext, ChannelTypeContext],
|
||||
define_feature!(47,
|
||||
SCIDPrivacy,
|
||||
[InitContext, NodeContext, ChannelTypeContext],
|
||||
"Feature flags for only forwarding with SCID aliasing. Called `option_scid_alias` in the BOLTs",
|
||||
set_scid_privacy_optional, set_scid_privacy_required, supports_scid_privacy, requires_scid_privacy);
|
||||
set_scid_privacy_optional,
|
||||
set_scid_privacy_required,
|
||||
clear_scid_privacy,
|
||||
supports_scid_privacy,
|
||||
requires_scid_privacy
|
||||
);
|
||||
define_feature!(
|
||||
49,
|
||||
PaymentMetadata,
|
||||
|
@ -588,6 +619,7 @@ mod sealed {
|
|||
"Feature flags for payment metadata in invoices.",
|
||||
set_payment_metadata_optional,
|
||||
set_payment_metadata_required,
|
||||
clear_payment_metadata,
|
||||
supports_payment_metadata,
|
||||
requires_payment_metadata
|
||||
);
|
||||
|
@ -601,6 +633,7 @@ mod sealed {
|
|||
"Feature flags for keysend payments.",
|
||||
set_keysend_optional,
|
||||
set_keysend_required,
|
||||
clear_keysend,
|
||||
supports_keysend,
|
||||
requires_keysend
|
||||
);
|
||||
|
@ -611,6 +644,7 @@ mod sealed {
|
|||
"Feature flags for Trampoline routing.",
|
||||
set_trampoline_routing_optional,
|
||||
set_trampoline_routing_required,
|
||||
clear_trampoline_routing,
|
||||
supports_trampoline_routing,
|
||||
requires_trampoline_routing
|
||||
);
|
||||
|
@ -621,6 +655,7 @@ mod sealed {
|
|||
"Feature flags for DNS resolving.",
|
||||
set_dns_resolution_optional,
|
||||
set_dns_resolution_required,
|
||||
clear_dns_resolution,
|
||||
supports_dns_resolution,
|
||||
requires_dns_resolution
|
||||
);
|
||||
|
@ -643,6 +678,7 @@ mod sealed {
|
|||
"Feature flags for an unknown feature used in testing.",
|
||||
set_unknown_feature_optional,
|
||||
set_unknown_feature_required,
|
||||
clear_unknown_feature,
|
||||
supports_unknown_test_feature,
|
||||
requires_unknown_test_feature
|
||||
);
|
||||
|
@ -1038,48 +1074,6 @@ impl<T: sealed::Context> Features<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: sealed::UpfrontShutdownScript> Features<T> {
|
||||
/// Unsets the `upfront_shutdown_script` feature
|
||||
pub fn clear_upfront_shutdown_script(&mut self) {
|
||||
<T as sealed::UpfrontShutdownScript>::clear_bits(&mut self.flags);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: sealed::ShutdownAnySegwit> Features<T> {
|
||||
/// Unsets the `shutdown_anysegwit` feature
|
||||
pub fn clear_shutdown_anysegwit(&mut self) {
|
||||
<T as sealed::ShutdownAnySegwit>::clear_bits(&mut self.flags);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: sealed::Wumbo> Features<T> {
|
||||
/// Unsets the `wumbo` feature
|
||||
pub fn clear_wumbo(&mut self) {
|
||||
<T as sealed::Wumbo>::clear_bits(&mut self.flags);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: sealed::SCIDPrivacy> Features<T> {
|
||||
/// Unsets the `scid_privacy` feature
|
||||
pub fn clear_scid_privacy(&mut self) {
|
||||
<T as sealed::SCIDPrivacy>::clear_bits(&mut self.flags);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: sealed::AnchorsZeroFeeHtlcTx> Features<T> {
|
||||
/// Unsets the `anchors_zero_fee_htlc_tx` feature
|
||||
pub fn clear_anchors_zero_fee_htlc_tx(&mut self) {
|
||||
<T as sealed::AnchorsZeroFeeHtlcTx>::clear_bits(&mut self.flags);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: sealed::RouteBlinding> Features<T> {
|
||||
/// Unsets the `route_blinding` feature
|
||||
pub fn clear_route_blinding(&mut self) {
|
||||
<T as sealed::RouteBlinding>::clear_bits(&mut self.flags);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "_test_utils"))]
|
||||
impl<T: sealed::UnknownFeature> Features<T> {
|
||||
/// Sets an unknown feature for testing
|
||||
|
|
Loading…
Add table
Reference in a new issue