Skip to content

Commit bec8bf1

Browse files
committed
Remove the *Features::known constructor
As we move towards specify supported/required feature bits in the module(s) where they are supported, the global `known` feature set constructors no longer make sense. Here we (finally) remove the `known` constructor entirely, modifying tests in the `features` module as required.
1 parent b93fe32 commit bec8bf1

File tree

1 file changed

+20
-118
lines changed

1 file changed

+20
-118
lines changed

lightning/src/ln/features.rs

Lines changed: 20 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -666,14 +666,6 @@ impl<T: sealed::Context> Features<T> {
666666
}
667667
}
668668

669-
/// Creates a Features with the bits set which are known by the implementation
670-
pub fn known() -> Self {
671-
Self {
672-
flags: T::KNOWN_FEATURE_FLAGS.to_vec(),
673-
mark: PhantomData,
674-
}
675-
}
676-
677669
/// Converts `Features<T>` to `Features<C>`. Only known `T` features relevant to context `C` are
678670
/// included in the result.
679671
fn to_context_internal<C: sealed::Context>(&self) -> Features<C> {
@@ -765,24 +757,6 @@ impl<T: sealed::UpfrontShutdownScript> Features<T> {
765757
}
766758
}
767759

768-
769-
impl<T: sealed::GossipQueries> Features<T> {
770-
#[cfg(test)]
771-
pub(crate) fn clear_gossip_queries(mut self) -> Self {
772-
<T as sealed::GossipQueries>::clear_bits(&mut self.flags);
773-
self
774-
}
775-
}
776-
777-
impl<T: sealed::InitialRoutingSync> Features<T> {
778-
// Note that initial_routing_sync is ignored if gossip_queries is set.
779-
#[cfg(test)]
780-
pub(crate) fn clear_initial_routing_sync(mut self) -> Self {
781-
<T as sealed::InitialRoutingSync>::clear_bits(&mut self.flags);
782-
self
783-
}
784-
}
785-
786760
impl<T: sealed::ShutdownAnySegwit> Features<T> {
787761
#[cfg(test)]
788762
pub(crate) fn clear_shutdown_anysegwit(mut self) -> Self {
@@ -836,97 +810,9 @@ impl Readable for ChannelTypeFeatures {
836810

837811
#[cfg(test)]
838812
mod tests {
839-
use super::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, InvoiceFeatures, NodeFeatures};
813+
use super::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, InvoiceFeatures, NodeFeatures, sealed};
840814
use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, u5};
841815

842-
#[test]
843-
fn sanity_test_known_features() {
844-
assert!(!ChannelFeatures::known().requires_unknown_bits());
845-
assert!(!ChannelFeatures::known().supports_unknown_bits());
846-
assert!(!InitFeatures::known().requires_unknown_bits());
847-
assert!(!InitFeatures::known().supports_unknown_bits());
848-
assert!(!NodeFeatures::known().requires_unknown_bits());
849-
assert!(!NodeFeatures::known().supports_unknown_bits());
850-
851-
assert!(InitFeatures::known().supports_upfront_shutdown_script());
852-
assert!(NodeFeatures::known().supports_upfront_shutdown_script());
853-
assert!(!InitFeatures::known().requires_upfront_shutdown_script());
854-
assert!(!NodeFeatures::known().requires_upfront_shutdown_script());
855-
856-
assert!(InitFeatures::known().supports_gossip_queries());
857-
assert!(NodeFeatures::known().supports_gossip_queries());
858-
assert!(!InitFeatures::known().requires_gossip_queries());
859-
assert!(!NodeFeatures::known().requires_gossip_queries());
860-
861-
assert!(InitFeatures::known().supports_data_loss_protect());
862-
assert!(NodeFeatures::known().supports_data_loss_protect());
863-
assert!(!InitFeatures::known().requires_data_loss_protect());
864-
assert!(!NodeFeatures::known().requires_data_loss_protect());
865-
866-
assert!(InitFeatures::known().supports_variable_length_onion());
867-
assert!(NodeFeatures::known().supports_variable_length_onion());
868-
assert!(InvoiceFeatures::known().supports_variable_length_onion());
869-
assert!(InitFeatures::known().requires_variable_length_onion());
870-
assert!(NodeFeatures::known().requires_variable_length_onion());
871-
assert!(InvoiceFeatures::known().requires_variable_length_onion());
872-
873-
assert!(InitFeatures::known().supports_static_remote_key());
874-
assert!(NodeFeatures::known().supports_static_remote_key());
875-
assert!(InitFeatures::known().requires_static_remote_key());
876-
assert!(NodeFeatures::known().requires_static_remote_key());
877-
878-
assert!(InitFeatures::known().supports_payment_secret());
879-
assert!(NodeFeatures::known().supports_payment_secret());
880-
assert!(InvoiceFeatures::known().supports_payment_secret());
881-
assert!(InitFeatures::known().requires_payment_secret());
882-
assert!(NodeFeatures::known().requires_payment_secret());
883-
assert!(InvoiceFeatures::known().requires_payment_secret());
884-
885-
assert!(InitFeatures::known().supports_basic_mpp());
886-
assert!(NodeFeatures::known().supports_basic_mpp());
887-
assert!(InvoiceFeatures::known().supports_basic_mpp());
888-
assert!(!InitFeatures::known().requires_basic_mpp());
889-
assert!(!NodeFeatures::known().requires_basic_mpp());
890-
assert!(!InvoiceFeatures::known().requires_basic_mpp());
891-
892-
assert!(InitFeatures::known().supports_channel_type());
893-
assert!(NodeFeatures::known().supports_channel_type());
894-
assert!(!InitFeatures::known().requires_channel_type());
895-
assert!(!NodeFeatures::known().requires_channel_type());
896-
897-
assert!(InitFeatures::known().supports_shutdown_anysegwit());
898-
assert!(NodeFeatures::known().supports_shutdown_anysegwit());
899-
900-
assert!(InitFeatures::known().supports_scid_privacy());
901-
assert!(NodeFeatures::known().supports_scid_privacy());
902-
assert!(ChannelTypeFeatures::known().supports_scid_privacy());
903-
assert!(!InitFeatures::known().requires_scid_privacy());
904-
assert!(!NodeFeatures::known().requires_scid_privacy());
905-
assert!(ChannelTypeFeatures::known().requires_scid_privacy());
906-
907-
assert!(InitFeatures::known().supports_wumbo());
908-
assert!(NodeFeatures::known().supports_wumbo());
909-
assert!(!InitFeatures::known().requires_wumbo());
910-
assert!(!NodeFeatures::known().requires_wumbo());
911-
912-
assert!(InitFeatures::known().supports_onion_messages());
913-
assert!(NodeFeatures::known().supports_onion_messages());
914-
assert!(!InitFeatures::known().requires_onion_messages());
915-
assert!(!NodeFeatures::known().requires_onion_messages());
916-
917-
assert!(InitFeatures::known().supports_zero_conf());
918-
assert!(!InitFeatures::known().requires_zero_conf());
919-
assert!(NodeFeatures::known().supports_zero_conf());
920-
assert!(!NodeFeatures::known().requires_zero_conf());
921-
assert!(ChannelTypeFeatures::known().supports_zero_conf());
922-
assert!(ChannelTypeFeatures::known().requires_zero_conf());
923-
924-
let mut init_features = InitFeatures::known();
925-
assert!(init_features.initial_routing_sync());
926-
init_features = init_features.clear_initial_routing_sync();
927-
assert!(!init_features.initial_routing_sync());
928-
}
929-
930816
#[test]
931817
fn sanity_test_unknown_bits() {
932818
let features = ChannelFeatures::empty();
@@ -946,7 +832,22 @@ mod tests {
946832

947833
#[test]
948834
fn convert_to_context_with_relevant_flags() {
949-
let init_features = InitFeatures::known().clear_upfront_shutdown_script().clear_gossip_queries();
835+
let mut init_features = InitFeatures::empty();
836+
// Set a bunch of features we use, plus initial_routing_sync_required (which shouldn't get
837+
// converted as it's only relevant in an init context).
838+
init_features.set_initial_routing_sync_required();
839+
init_features.set_data_loss_protect_optional();
840+
init_features.set_variable_length_onion_required();
841+
init_features.set_static_remote_key_required();
842+
init_features.set_payment_secret_required();
843+
init_features.set_basic_mpp_optional();
844+
init_features.set_wumbo_optional();
845+
init_features.set_shutdown_any_segwit_optional();
846+
init_features.set_onion_messages_optional();
847+
init_features.set_channel_type_optional();
848+
init_features.set_scid_privacy_optional();
849+
init_features.set_zero_conf_optional();
850+
950851
assert!(init_features.initial_routing_sync());
951852
assert!(!init_features.supports_upfront_shutdown_script());
952853
assert!(!init_features.supports_gossip_queries());
@@ -984,8 +885,9 @@ mod tests {
984885
#[test]
985886
fn convert_to_context_with_unknown_flags() {
986887
// Ensure the `from` context has fewer known feature bytes than the `to` context.
987-
assert!(InvoiceFeatures::known().flags.len() < NodeFeatures::known().flags.len());
988-
let mut invoice_features = InvoiceFeatures::known();
888+
assert!(<sealed::InvoiceContext as sealed::Context>::KNOWN_FEATURE_MASK.len() <
889+
<sealed::NodeContext as sealed::Context>::KNOWN_FEATURE_MASK.len());
890+
let mut invoice_features = InvoiceFeatures::empty();
989891
invoice_features.set_unknown_feature_optional();
990892
assert!(invoice_features.supports_unknown_bits());
991893
let node_features: NodeFeatures = invoice_features.to_context();

0 commit comments

Comments
 (0)