From c1db30d5be88e312e10efb47e26aade95413a01b Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 10 Apr 2020 11:36:47 -0700 Subject: [PATCH 1/9] Unset upfront_shutdown_script using bit clearing The test_upfront_shutdown_script functional test clears this feature flag. However, the method used to clear the flag is implemented by bit toggling. Thus, if the flag is not set the method would actually set it. Implement the method using bit clearing instead. --- lightning/src/ln/features.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 5eb1bd909e8..1e52268ac35 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -272,7 +272,7 @@ impl Features { } #[cfg(test)] pub(crate) fn unset_upfront_shutdown_script(&mut self) { - self.flags[0] ^= 1 << 5; + self.flags[0] &= !(1 << 5); } } From 07cea6bfeda1641c2a1440f4e4847c747507c4f0 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Thu, 23 Apr 2020 09:47:15 -0700 Subject: [PATCH 2/9] Set initial_routing_sync in InitFeatures The initial_routing_sync feature is set by peer_handler whenever a full sync of the network graph is desired. It is not explicitly set when creating features with InitFeatures::supported(). An upcoming refactor will change supported() to known(), which will return all features known by the implementation. Thus, the initial_routing_sync flag will need to be set by default. This commit makes the behavior change ahead of the refactor. --- lightning/src/ln/features.rs | 20 +++++------ lightning/src/ln/peer_handler.rs | 58 +++++++++++++++++++++++++++++--- lightning/src/util/test_utils.rs | 15 +++++++-- 3 files changed, 75 insertions(+), 18 deletions(-) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 1e52268ac35..f6912662497 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -81,7 +81,7 @@ impl InitFeatures { /// Create a Features with the features we support pub fn supported() -> InitFeatures { InitFeatures { - flags: vec![2 | 1 << 5, 1 << (9-8) | 1 << (15 - 8), 1 << (17 - 8*2)], + flags: vec![2 | 1 << 3 | 1 << 5, 1 << (9-8) | 1 << (15 - 8), 1 << (17 - 8*2)], mark: PhantomData, } } @@ -286,11 +286,9 @@ impl Features { pub(crate) fn initial_routing_sync(&self) -> bool { self.flags.len() > 0 && (self.flags[0] & (1 << 3)) != 0 } - pub(crate) fn set_initial_routing_sync(&mut self) { - if self.flags.len() == 0 { - self.flags.resize(1, 1 << 3); - } else { - self.flags[0] |= 1 << 3; + pub(crate) fn clear_initial_routing_sync(&mut self) { + if self.flags.len() > 0 { + self.flags[0] &= !(1 << 3); } } } @@ -364,9 +362,9 @@ mod tests { assert!(NodeFeatures::supported().supports_basic_mpp()); let mut init_features = InitFeatures::supported(); - init_features.set_initial_routing_sync(); - assert!(!init_features.requires_unknown_bits()); - assert!(!init_features.supports_unknown_bits()); + assert!(init_features.initial_routing_sync()); + init_features.clear_initial_routing_sync(); + assert!(!init_features.initial_routing_sync()); } #[test] @@ -381,8 +379,8 @@ mod tests { #[test] fn test_node_with_known_relevant_init_flags() { // Create an InitFeatures with initial_routing_sync supported. - let mut init_features = InitFeatures::supported(); - init_features.set_initial_routing_sync(); + let init_features = InitFeatures::supported(); + assert!(init_features.initial_routing_sync()); // Attempt to pull out non-node-context feature flags from these InitFeatures. let res = NodeFeatures::with_known_relevant_init_flags(&init_features); diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 15fa105d0c0..9399cfecf69 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -549,8 +549,8 @@ impl PeerManager where peer.their_node_id = Some(their_node_id); insert_node_id!(); let mut features = InitFeatures::supported(); - if self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) { - features.set_initial_routing_sync(); + if !self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) { + features.clear_initial_routing_sync(); } let resp = msgs::Init { features }; @@ -643,8 +643,8 @@ impl PeerManager where if !peer.outbound { let mut features = InitFeatures::supported(); - if self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) { - features.set_initial_routing_sync(); + if !self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) { + features.clear_initial_routing_sync(); } let resp = msgs::Init { features }; @@ -1247,6 +1247,13 @@ mod tests { (fd_a.clone(), fd_b.clone()) } + fn establish_connection_and_read_events<'a>(peer_a: &PeerManager, peer_b: &PeerManager) -> (FileDescriptor, FileDescriptor) { + let (mut fd_a, mut fd_b) = establish_connection(peer_a, peer_b); + assert_eq!(peer_b.read_event(&mut fd_b, &fd_a.outbound_data.lock().unwrap().split_off(0)).unwrap(), false); + assert_eq!(peer_a.read_event(&mut fd_a, &fd_b.outbound_data.lock().unwrap().split_off(0)).unwrap(), false); + (fd_a.clone(), fd_b.clone()) + } + #[test] fn test_disconnect_peer() { // Simple test which builds a network of PeerManager, connects and brings them to NoiseState::Finished and @@ -1421,4 +1428,47 @@ mod tests { assert_eq!(routing_handlers_concrete[1].clone().chan_upds_recvd.load(Ordering::Acquire), 100); assert_eq!(routing_handlers_concrete[1].clone().chan_anns_recvd.load(Ordering::Acquire), 50); } + + #[test] + fn limit_initial_routing_sync_requests() { + // Inbound peer 0 requests initial_routing_sync, but outbound peer 1 does not. + { + let chan_handlers = create_chan_handlers(2); + let routing_handlers: Vec> = vec![ + Arc::new(test_utils::TestRoutingMessageHandler::new().set_request_full_sync()), + Arc::new(test_utils::TestRoutingMessageHandler::new()), + ]; + let peers = create_network(2, &chan_handlers, Some(&routing_handlers)); + let (fd_0_to_1, fd_1_to_0) = establish_connection_and_read_events(&peers[0], &peers[1]); + + let peer_0 = peers[0].peers.lock().unwrap(); + let peer_1 = peers[1].peers.lock().unwrap(); + + let peer_0_features = peer_1.peers.get(&fd_1_to_0).unwrap().their_features.as_ref(); + let peer_1_features = peer_0.peers.get(&fd_0_to_1).unwrap().their_features.as_ref(); + + assert!(peer_0_features.unwrap().initial_routing_sync()); + assert!(!peer_1_features.unwrap().initial_routing_sync()); + } + + // Outbound peer 1 requests initial_routing_sync, but inbound peer 0 does not. + { + let chan_handlers = create_chan_handlers(2); + let routing_handlers: Vec> = vec![ + Arc::new(test_utils::TestRoutingMessageHandler::new()), + Arc::new(test_utils::TestRoutingMessageHandler::new().set_request_full_sync()), + ]; + let peers = create_network(2, &chan_handlers, Some(&routing_handlers)); + let (fd_0_to_1, fd_1_to_0) = establish_connection_and_read_events(&peers[0], &peers[1]); + + let peer_0 = peers[0].peers.lock().unwrap(); + let peer_1 = peers[1].peers.lock().unwrap(); + + let peer_0_features = peer_1.peers.get(&fd_1_to_0).unwrap().their_features.as_ref(); + let peer_1_features = peer_0.peers.get(&fd_0_to_1).unwrap().their_features.as_ref(); + + assert!(!peer_0_features.unwrap().initial_routing_sync()); + assert!(peer_1_features.unwrap().initial_routing_sync()); + } + } } diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 905a53e6648..8385c39c1db 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -170,11 +170,20 @@ impl events::MessageSendEventsProvider for TestChannelMessageHandler { } } -pub struct TestRoutingMessageHandler {} +pub struct TestRoutingMessageHandler { + request_full_sync: bool, +} impl TestRoutingMessageHandler { pub fn new() -> Self { - TestRoutingMessageHandler {} + TestRoutingMessageHandler { + request_full_sync: false, + } + } + + pub fn set_request_full_sync(mut self) -> Self { + self.request_full_sync = true; + self } } impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { @@ -195,7 +204,7 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { Vec::new() } fn should_request_full_sync(&self, _node_id: &PublicKey) -> bool { - true + self.request_full_sync } } From 491bbc56cfcfa5c62c79113d1af2d17c37fbb75d Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Thu, 9 Apr 2020 17:08:48 -0700 Subject: [PATCH 3/9] Encapsulate feature flag checking and manipulation Each feature is represented by two bits within Features' flags field. Working with these flags requires bitwise operations, which can be error prone. Rather than directly checking and manipulating bits, encapsulate the bits within each feature trait and provide mechanisms for doing so. This removes the need to comment on which features correspond to bitwise expressions since the expressions use feature trait identifiers instead. With this approach, byte literals and expressions can be evaluated at compile time still. However, for these cases, knowing which byte within the flags that a feature corresponds to still must be determined by the implementor. Remove the special case where initial_routing_sync has no even bit. Now, it (bit 2) is considered known by the implementation. --- lightning/src/ln/features.rs | 231 ++++++++++++++++++++++++++--------- 1 file changed, 175 insertions(+), 56 deletions(-) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index f6912662497..e9e12b35174 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -8,6 +8,7 @@ use std::marker::PhantomData; use ln::msgs::DecodeError; use util::ser::{Readable, Writeable, Writer}; +#[macro_use] mod sealed { // You should just use the type aliases instead. pub struct InitContext {} pub struct NodeContext {} @@ -19,28 +20,112 @@ mod sealed { // You should just use the type aliases instead. impl Context for NodeContext {} impl Context for ChannelContext {} - pub trait DataLossProtect: Context {} - impl DataLossProtect for InitContext {} - impl DataLossProtect for NodeContext {} - - pub trait InitialRoutingSync: Context {} - impl InitialRoutingSync for InitContext {} - - pub trait UpfrontShutdownScript: Context {} - impl UpfrontShutdownScript for InitContext {} - impl UpfrontShutdownScript for NodeContext {} + /// Defines a feature with the given bits for the specified [`Context`]s. The generated trait is + /// useful for manipulating feature flags. + /// + /// [`Context`]: trait.Context.html + macro_rules! define_feature { + ($odd_bit: expr, $feature: ident, [$($context: ty),+], $doc: expr) => { + #[doc = $doc] + /// + /// See [BOLT #9] for details. + /// + /// [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md + pub trait $feature: Context { + /// The bit used to signify that the feature is required. + const EVEN_BIT: usize = $odd_bit - 1; + + /// The bit used to signify that the feature is optional. + const ODD_BIT: usize = $odd_bit; + + /// Assertion that [`EVEN_BIT`] is actually even. + /// + /// [`EVEN_BIT`]: #associatedconstant.EVEN_BIT + const ASSERT_EVEN_BIT_PARITY: usize; + + /// Assertion that [`ODD_BIT`] is actually odd. + /// + /// [`ODD_BIT`]: #associatedconstant.ODD_BIT + const ASSERT_ODD_BIT_PARITY: usize; + + /// The byte where the feature is set. + const BYTE_OFFSET: usize = Self::EVEN_BIT / 8; + + /// The bitmask for the feature's required flag relative to the [`BYTE_OFFSET`]. + /// + /// [`BYTE_OFFSET`]: #associatedconstant.BYTE_OFFSET + const REQUIRED_MASK: u8 = 1 << (Self::EVEN_BIT - 8 * Self::BYTE_OFFSET); + + /// The bitmask for the feature's optional flag relative to the [`BYTE_OFFSET`]. + /// + /// [`BYTE_OFFSET`]: #associatedconstant.BYTE_OFFSET + const OPTIONAL_MASK: u8 = 1 << (Self::ODD_BIT - 8 * Self::BYTE_OFFSET); + + /// Returns whether the feature is supported by the given flags. + #[inline] + fn supports_feature(flags: &Vec) -> bool { + flags.len() > Self::BYTE_OFFSET && + (flags[Self::BYTE_OFFSET] & (Self::REQUIRED_MASK | Self::OPTIONAL_MASK)) != 0 + } + + /// Sets the feature's optional (odd) bit in the given flags. + #[inline] + fn set_optional_bit(flags: &mut Vec) { + if flags.len() <= Self::BYTE_OFFSET { + flags.resize(Self::BYTE_OFFSET + 1, 0u8); + } + + flags[Self::BYTE_OFFSET] |= Self::OPTIONAL_MASK; + } + + /// Clears the feature's optional (odd) bit from the given flags. + #[inline] + fn clear_optional_bit(flags: &mut Vec) { + if flags.len() > Self::BYTE_OFFSET { + flags[Self::BYTE_OFFSET] &= !Self::OPTIONAL_MASK; + } + } + } - pub trait VariableLengthOnion: Context {} - impl VariableLengthOnion for InitContext {} - impl VariableLengthOnion for NodeContext {} + $( + impl $feature for $context { + // EVEN_BIT % 2 == 0 + const ASSERT_EVEN_BIT_PARITY: usize = 0 - (::EVEN_BIT % 2); - pub trait PaymentSecret: Context {} - impl PaymentSecret for InitContext {} - impl PaymentSecret for NodeContext {} + // ODD_BIT % 2 == 1 + const ASSERT_ODD_BIT_PARITY: usize = (::ODD_BIT % 2) - 1; + } + )* + } + } - pub trait BasicMPP: Context {} - impl BasicMPP for InitContext {} - impl BasicMPP for NodeContext {} + define_feature!(1, DataLossProtect, [InitContext, NodeContext], + "Feature flags for `option_data_loss_protect`."); + // NOTE: Per Bolt #9, initial_routing_sync has no even bit. + define_feature!(3, InitialRoutingSync, [InitContext], + "Feature flags for `initial_routing_sync`."); + define_feature!(5, UpfrontShutdownScript, [InitContext, NodeContext], + "Feature flags for `option_upfront_shutdown_script`."); + define_feature!(9, VariableLengthOnion, [InitContext, NodeContext], + "Feature flags for `var_onion_optin`."); + define_feature!(15, PaymentSecret, [InitContext, NodeContext], + "Feature flags for `payment_secret`."); + define_feature!(17, BasicMPP, [InitContext, NodeContext], + "Feature flags for `basic_mpp`."); + + /// Generates a feature flag byte with the given features set as optional. Useful for initializing + /// the flags within [`Features`]. + /// + /// [`Features`]: struct.Features.html + macro_rules! feature_flags { + ($context: ty; $($feature: ident)|*) => { + (0b00_00_00_00 + $( + | <$context as sealed::$feature>::OPTIONAL_MASK + )* + ) + } + } } /// Tracks the set of features which a node implements, templated by the context in which it @@ -81,7 +166,11 @@ impl InitFeatures { /// Create a Features with the features we support pub fn supported() -> InitFeatures { InitFeatures { - flags: vec![2 | 1 << 3 | 1 << 5, 1 << (9-8) | 1 << (15 - 8), 1 << (17 - 8*2)], + flags: vec![ + feature_flags![sealed::InitContext; DataLossProtect | InitialRoutingSync | UpfrontShutdownScript], + feature_flags![sealed::InitContext; VariableLengthOnion | PaymentSecret], + feature_flags![sealed::InitContext; BasicMPP], + ], mark: PhantomData, } } @@ -144,14 +233,22 @@ impl NodeFeatures { #[cfg(not(feature = "fuzztarget"))] pub(crate) fn supported() -> NodeFeatures { NodeFeatures { - flags: vec![2 | 1 << 5, 1 << (9 - 8) | 1 << (15 - 8), 1 << (17 - 8*2)], + flags: vec![ + feature_flags![sealed::NodeContext; DataLossProtect | UpfrontShutdownScript], + feature_flags![sealed::NodeContext; VariableLengthOnion | PaymentSecret], + feature_flags![sealed::NodeContext; BasicMPP], + ], mark: PhantomData, } } #[cfg(feature = "fuzztarget")] pub fn supported() -> NodeFeatures { NodeFeatures { - flags: vec![2 | 1 << 5, 1 << (9 - 8) | 1 << (15 - 8), 1 << (17 - 8*2)], + flags: vec![ + feature_flags![sealed::NodeContext; DataLossProtect | UpfrontShutdownScript], + feature_flags![sealed::NodeContext; VariableLengthOnion | PaymentSecret], + feature_flags![sealed::NodeContext; BasicMPP], + ], mark: PhantomData, } } @@ -160,15 +257,25 @@ impl NodeFeatures { /// relevant in a node-context features and creates a node-context features from them. /// Be sure to blank out features that are unknown to us. pub(crate) fn with_known_relevant_init_flags(init_ctx: &InitFeatures) -> Self { + // Generates a bitmask with both even and odd bits set for the given features. Bitwise + // AND-ing it with a byte will select only common features. + macro_rules! features_including { + ($($feature: ident)|*) => { + (0b00_00_00_00 + $( + | ::REQUIRED_MASK + | ::OPTIONAL_MASK + )* + ) + } + } + let mut flags = Vec::new(); for (i, feature_byte)in init_ctx.flags.iter().enumerate() { match i { - // Blank out initial_routing_sync (feature bits 2/3), gossip_queries (6/7), - // gossip_queries_ex (10/11), option_static_remotekey (12/13), and - // option_support_large_channel (16/17) - 0 => flags.push(feature_byte & 0b00110011), - 1 => flags.push(feature_byte & 0b11000011), - 2 => flags.push(feature_byte & 0b00000011), + 0 => flags.push(feature_byte & features_including![DataLossProtect | UpfrontShutdownScript]), + 1 => flags.push(feature_byte & features_including![VariableLengthOnion | PaymentSecret]), + 2 => flags.push(feature_byte & features_including![BasicMPP]), _ => (), } } @@ -201,33 +308,47 @@ impl Features { } pub(crate) fn requires_unknown_bits(&self) -> bool { + // Generates a bitmask with all even bits set except for the given features. Bitwise + // AND-ing it with a byte will select unknown required features. + macro_rules! features_excluding { + ($($feature: ident)|*) => { + (0b01_01_01_01 + $( + & !(::REQUIRED_MASK) + )* + ) + } + } + self.flags.iter().enumerate().any(|(idx, &byte)| { (match idx { - // Unknown bits are even bits which we don't understand, we list ones which we do - // here: - // unknown, upfront_shutdown_script, unknown (actually initial_routing_sync, but it - // is only valid as an optional feature), and data_loss_protect: - 0 => (byte & 0b01000100), - // payment_secret, unknown, unknown, var_onion_optin: - 1 => (byte & 0b00010100), - // unknown, unknown, unknown, basic_mpp: - 2 => (byte & 0b01010100), - // fallback, all even bits set: - _ => (byte & 0b01010101), + 0 => (byte & features_excluding![DataLossProtect | InitialRoutingSync | UpfrontShutdownScript]), + 1 => (byte & features_excluding![VariableLengthOnion | PaymentSecret]), + 2 => (byte & features_excluding![BasicMPP]), + _ => (byte & features_excluding![]), }) != 0 }) } pub(crate) fn supports_unknown_bits(&self) -> bool { + // Generates a bitmask with all even and odd bits set except for the given features. Bitwise + // AND-ing it with a byte will select unknown supported features. + macro_rules! features_excluding { + ($($feature: ident)|*) => { + (0b11_11_11_11 + $( + & !(::REQUIRED_MASK) + & !(::OPTIONAL_MASK) + )* + ) + } + } + self.flags.iter().enumerate().any(|(idx, &byte)| { (match idx { - // unknown, upfront_shutdown_script, initial_routing_sync (is only valid as an - // optional feature), and data_loss_protect: - 0 => (byte & 0b11000100), - // payment_secret, unknown, unknown, var_onion_optin: - 1 => (byte & 0b00111100), - // unknown, unknown, unknown, basic_mpp: - 2 => (byte & 0b11111100), + 0 => (byte & features_excluding![DataLossProtect | InitialRoutingSync | UpfrontShutdownScript]), + 1 => (byte & features_excluding![VariableLengthOnion | PaymentSecret]), + 2 => (byte & features_excluding![BasicMPP]), _ => byte, }) != 0 }) @@ -262,34 +383,32 @@ impl Features { impl Features { pub(crate) fn supports_data_loss_protect(&self) -> bool { - self.flags.len() > 0 && (self.flags[0] & 3) != 0 + ::supports_feature(&self.flags) } } impl Features { pub(crate) fn supports_upfront_shutdown_script(&self) -> bool { - self.flags.len() > 0 && (self.flags[0] & (3 << 4)) != 0 + ::supports_feature(&self.flags) } #[cfg(test)] pub(crate) fn unset_upfront_shutdown_script(&mut self) { - self.flags[0] &= !(1 << 5); + ::clear_optional_bit(&mut self.flags) } } impl Features { pub(crate) fn supports_variable_length_onion(&self) -> bool { - self.flags.len() > 1 && (self.flags[1] & 3) != 0 + ::supports_feature(&self.flags) } } impl Features { pub(crate) fn initial_routing_sync(&self) -> bool { - self.flags.len() > 0 && (self.flags[0] & (1 << 3)) != 0 + ::supports_feature(&self.flags) } pub(crate) fn clear_initial_routing_sync(&mut self) { - if self.flags.len() > 0 { - self.flags[0] &= !(1 << 3); - } + ::clear_optional_bit(&mut self.flags) } } @@ -299,7 +418,7 @@ impl Features { // invoice provides a payment_secret, we assume that we can use it (ie that the recipient // supports payment_secret). pub(crate) fn supports_payment_secret(&self) -> bool { - self.flags.len() > 1 && (self.flags[1] & (3 << (14-8))) != 0 + ::supports_feature(&self.flags) } } @@ -307,7 +426,7 @@ impl Features { // We currently never test for this since we don't actually *generate* multipath routes. #[allow(dead_code)] pub(crate) fn supports_basic_mpp(&self) -> bool { - self.flags.len() > 2 && (self.flags[2] & (3 << (16-8*2))) != 0 + ::supports_feature(&self.flags) } } From 77b467c845792945a0caf19790e4aff883969258 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 13 Apr 2020 18:39:29 -0700 Subject: [PATCH 4/9] Improve features module documentation --- lightning/src/ln/features.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index e9e12b35174..3440354ec54 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -1,5 +1,15 @@ -//! Lightning exposes sets of supported operations through "feature flags". This module includes -//! types to store those feature flags and query for specific flags. +//! Feature flag definitions for the Lightning protocol according to [BOLT #9]. +//! +//! Lightning nodes advertise a supported set of operation through feature flags. Features are +//! applicable for a specific context as indicated in some [messages]. [`Features`] encapsulates +//! behavior for specifying and checking feature flags for a particular context. Each feature is +//! defined internally by a trait specifying the corresponding flags (i.e., even and odd bits). A +//! [`Context`] is used to parameterize [`Features`] and defines which features it can support. +//! +//! [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md +//! [messages]: ../msgs/index.html +//! [`Features`]: struct.Features.html +//! [`Context`]: sealed/trait.Context.html use std::{cmp, fmt}; use std::result::Result; @@ -131,7 +141,7 @@ mod sealed { // You should just use the type aliases instead. /// Tracks the set of features which a node implements, templated by the context in which it /// appears. pub struct Features { - /// Note that, for convinience, flags is LITTLE endian (despite being big-endian on the wire) + /// Note that, for convenience, flags is LITTLE endian (despite being big-endian on the wire) flags: Vec, mark: PhantomData, } @@ -155,11 +165,11 @@ impl fmt::Debug for Features { } } -/// A feature message as it appears in an init message +/// Features used within an `init` message. pub type InitFeatures = Features; -/// A feature message as it appears in a node_announcement message +/// Features used within a `node_announcement` message. pub type NodeFeatures = Features; -/// A feature message as it appears in a channel_announcement message +/// Features used within a `channel_announcement` message. pub type ChannelFeatures = Features; impl InitFeatures { From 9dd2be15e90d9fa7369e7f9757cabce81c293602 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Wed, 15 Apr 2020 17:16:45 -0700 Subject: [PATCH 5/9] Remove duplicate specification of features Features for a given context are duplicated throughout the features module. Use a macro for defining a Context and the applicable features such that features only need to be defined for a Context in one place. The Context provides bitmasks for selecting known and unknown feature flags. BOLT 1 and BOLT 9 refer to features as "known" if a peer understands them. They also use the term "supported" to mean either optional or required. Update the features module to use similar terminology. - Define contexts in terms of required and optional features rather than just supported features - Define known features as those that are optional or required - Rename supported() constructor to known() For completeness, clear_optional_bit for each feature is now called clear_bits and clears both optional and required bits. --- fuzz/src/chanmon_consistency.rs | 4 +- lightning/src/ln/chanmon_update_fail_tests.rs | 50 +-- lightning/src/ln/channel.rs | 6 +- lightning/src/ln/channelmanager.rs | 2 +- lightning/src/ln/features.rs | 326 +++++++++--------- lightning/src/ln/functional_tests.rs | 290 ++++++++-------- lightning/src/ln/msgs.rs | 2 +- lightning/src/ln/peer_handler.rs | 6 +- lightning/src/ln/reorg_tests.rs | 4 +- lightning/src/ln/router.rs | 10 +- 10 files changed, 357 insertions(+), 343 deletions(-) diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index fcc88454fe5..8603458e7ef 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -249,7 +249,7 @@ pub fn do_test(data: &[u8], out: Out) { } else { panic!("Wrong event type"); } }; - $dest.handle_open_channel(&$source.get_our_node_id(), InitFeatures::supported(), &open_channel); + $dest.handle_open_channel(&$source.get_our_node_id(), InitFeatures::known(), &open_channel); let accept_channel = { let events = $dest.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -258,7 +258,7 @@ pub fn do_test(data: &[u8], out: Out) { } else { panic!("Wrong event type"); } }; - $source.handle_accept_channel(&$dest.get_our_node_id(), InitFeatures::supported(), &accept_channel); + $source.handle_accept_channel(&$dest.get_our_node_id(), InitFeatures::known(), &accept_channel); let funding_output; { let events = $source.get_and_clear_pending_events(); diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 4cce9fcd2cd..739db729a19 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -24,7 +24,7 @@ fn test_simple_monitor_permanent_update_fail() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap(); let (_, payment_hash_1) = get_payment_preimage_hash!(&nodes[0]); @@ -57,7 +57,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).2; + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap(); let (payment_preimage_1, payment_hash_1) = get_payment_preimage_hash!(&nodes[0]); @@ -161,7 +161,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).2; + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000); @@ -493,7 +493,7 @@ fn test_monitor_update_fail_cs() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).2; + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap(); let (payment_preimage, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -578,7 +578,7 @@ fn test_monitor_update_fail_no_rebroadcast() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).2; + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap(); let (payment_preimage_1, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -624,7 +624,7 @@ fn test_monitor_update_raa_while_paused() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).2; + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; send_payment(&nodes[0], &[&nodes[1]], 5000000, 5_000_000); @@ -695,8 +695,8 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); // Rebalance a bit so that we can send backwards from 2 to 1. send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000); @@ -953,8 +953,8 @@ fn test_monitor_update_fail_reestablish() { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let (our_payment_preimage, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000); @@ -1035,7 +1035,7 @@ fn raa_no_response_awaiting_raa_state() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).2; + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap(); let (payment_preimage_1, payment_hash_1) = get_payment_preimage_hash!(nodes[0]); @@ -1152,7 +1152,7 @@ fn claim_while_disconnected_monitor_update_fail() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).2; + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; // Forward a payment for B to claim let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000); @@ -1272,7 +1272,7 @@ fn monitor_failed_no_reestablish_response() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).2; + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; // Route the payment and deliver the initial commitment_signed (with a monitor update failure // on receipt). @@ -1342,7 +1342,7 @@ fn first_message_on_recv_ordering() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).2; + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; // Route the first payment outbound, holding the last RAA for B until we are set up so that we // can deliver it and fail the monitor update. @@ -1432,8 +1432,8 @@ fn test_monitor_update_fail_claim() { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); // Rebalance a bit so that we can send backwards from 3 to 2. send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000); @@ -1509,8 +1509,8 @@ fn test_monitor_update_on_pending_forwards() { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); // Rebalance a bit so that we can send backwards from 3 to 1. send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 5000000, 5_000_000); @@ -1578,7 +1578,7 @@ fn monitor_update_claim_fail_no_response() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).2; + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; // Forward a payment for B to claim let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000); @@ -1640,8 +1640,8 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf: let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 43, None).unwrap(); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::supported(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::supported(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); + nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); + nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); let (temporary_channel_id, funding_tx, funding_output) = create_funding_transaction(&nodes[0], 100000, 43); @@ -1741,10 +1741,10 @@ fn test_path_paused_mpp() { let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]); let mut nodes = create_network(4, &node_cfgs, &node_chanmgrs); - let chan_1_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).0.contents.short_channel_id; - let (chan_2_ann, _, chan_2_id, _) = create_announced_chan_between_nodes(&nodes, 0, 2, InitFeatures::supported(), InitFeatures::supported()); - let chan_3_id = create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::supported(), InitFeatures::supported()).0.contents.short_channel_id; - let chan_4_id = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::supported(), InitFeatures::supported()).0.contents.short_channel_id; + let chan_1_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id; + let (chan_2_ann, _, chan_2_id, _) = create_announced_chan_between_nodes(&nodes, 0, 2, InitFeatures::known(), InitFeatures::known()); + let chan_3_id = create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id; + let chan_4_id = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id; let (payment_preimage, payment_hash) = get_payment_preimage_hash!(&nodes[0]); let payment_secret = PaymentSecret([0xdb; 32]); diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 35e688a0d76..98e515f0021 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -3446,7 +3446,7 @@ impl Channel { let our_bitcoin_key = PublicKey::from_secret_key(&self.secp_ctx, self.local_keys.funding_key()); let msg = msgs::UnsignedChannelAnnouncement { - features: ChannelFeatures::supported(), + features: ChannelFeatures::known(), chain_hash: chain_hash, short_channel_id: self.get_short_channel_id().unwrap(), node_id_1: if were_node_one { our_node_id } else { self.get_their_node_id() }, @@ -4383,11 +4383,11 @@ mod tests { // Create Node B's channel by receiving Node A's open_channel message let open_channel_msg = node_a_chan.get_open_channel(genesis_block(network).header.bitcoin_hash(), &&feeest); let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap()); - let mut node_b_chan = Channel::::new_from_req(&&feeest, &&keys_provider, node_b_node_id, InitFeatures::supported(), &open_channel_msg, 7, logger, &config).unwrap(); + let mut node_b_chan = Channel::::new_from_req(&&feeest, &&keys_provider, node_b_node_id, InitFeatures::known(), &open_channel_msg, 7, logger, &config).unwrap(); // Node B --> Node A: accept channel let accept_channel_msg = node_b_chan.get_accept_channel(); - node_a_chan.accept_channel(&accept_channel_msg, &config, InitFeatures::supported()).unwrap(); + node_a_chan.accept_channel(&accept_channel_msg, &config, InitFeatures::known()).unwrap(); // Node A --> Node B: funding created let output_script = node_a_chan.get_funding_redeemscript(); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index f347c279f5a..f9b0f70468a 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -1507,7 +1507,7 @@ impl ChannelMan } let announcement = msgs::UnsignedNodeAnnouncement { - features: NodeFeatures::supported(), + features: NodeFeatures::known(), timestamp: self.last_node_announcement_serial.fetch_add(1, Ordering::AcqRel) as u32, node_id: self.get_our_node_id(), rgb, alias, addresses, diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 3440354ec54..fc2526fe558 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -6,6 +6,11 @@ //! defined internally by a trait specifying the corresponding flags (i.e., even and odd bits). A //! [`Context`] is used to parameterize [`Features`] and defines which features it can support. //! +//! Whether a feature is considered "known" or "unknown" is relative to the implementation, whereas +//! the term "supports" is used in reference to a particular set of [`Features`]. That is, a node +//! supports a feature if it advertises the feature (as either required or optional) to its peers. +//! And the implementation can interpret a feature if the feature is known to it. +//! //! [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md //! [messages]: ../msgs/index.html //! [`Features`]: struct.Features.html @@ -18,17 +23,107 @@ use std::marker::PhantomData; use ln::msgs::DecodeError; use util::ser::{Readable, Writeable, Writer}; -#[macro_use] -mod sealed { // You should just use the type aliases instead. - pub struct InitContext {} - pub struct NodeContext {} - pub struct ChannelContext {} +mod sealed { + /// The context in which [`Features`] are applicable. Defines which features are required and + /// which are optional for the context. + /// + /// [`Features`]: ../struct.Features.html + pub trait Context { + /// Features that are known to the implementation, where a required feature is indicated by + /// its even bit and an optional feature is indicated by its odd bit. + const KNOWN_FEATURE_FLAGS: &'static [u8]; + + /// Bitmask for selecting features that are known to the implementation, regardless of + /// whether each feature is required or optional. + const KNOWN_FEATURE_MASK: &'static [u8]; + } - /// An internal trait capturing the various feature context types - pub trait Context {} - impl Context for InitContext {} - impl Context for NodeContext {} - impl Context for ChannelContext {} + /// Defines a [`Context`] by stating which features it requires and which are optional. Features + /// are specified as a comma-separated list of bytes where each byte is a pipe-delimited list of + /// feature identifiers. + /// + /// [`Context`]: trait.Context.html + macro_rules! define_context { + ($context: ident { + required_features: [$( $( $required_feature: ident )|*, )*], + optional_features: [$( $( $optional_feature: ident )|*, )*], + }) => { + pub struct $context {} + + impl Context for $context { + const KNOWN_FEATURE_FLAGS: &'static [u8] = &[ + // For each byte, use bitwise-OR to compute the applicable flags for known + // required features `r_i` and optional features `o_j` for all `i` and `j` such + // that the following slice is formed: + // + // [ + // `r_0` | `r_1` | ... | `o_0` | `o_1` | ..., + // ..., + // ] + $( + 0b00_00_00_00 $(| + ::REQUIRED_MASK)* + $(| + ::OPTIONAL_MASK)*, + )* + ]; + + const KNOWN_FEATURE_MASK: &'static [u8] = &[ + // Similar as above, but set both flags for each feature regardless of whether + // the feature is required or optional. + $( + 0b00_00_00_00 $(| + ::REQUIRED_MASK | + ::OPTIONAL_MASK)* + $(| + ::REQUIRED_MASK | + ::OPTIONAL_MASK)*, + )* + ]; + } + }; + } + + define_context!(InitContext { + required_features: [ + // Byte 0 + , + // Byte 1 + , + // Byte 2 + , + ], + optional_features: [ + // Byte 0 + DataLossProtect | InitialRoutingSync | UpfrontShutdownScript, + // Byte 1 + VariableLengthOnion | PaymentSecret, + // Byte 2 + BasicMPP, + ], + }); + define_context!(NodeContext { + required_features: [ + // Byte 0 + , + // Byte 1 + , + // Byte 2 + , + ], + optional_features: [ + // Byte 0 + DataLossProtect | UpfrontShutdownScript, + // Byte 1 + VariableLengthOnion | PaymentSecret, + // Byte 2 + BasicMPP, + ], + }); + define_context!(ChannelContext { + required_features: [], + optional_features: [], + }); /// Defines a feature with the given bits for the specified [`Context`]s. The generated trait is /// useful for manipulating feature flags. @@ -88,10 +183,12 @@ mod sealed { // You should just use the type aliases instead. flags[Self::BYTE_OFFSET] |= Self::OPTIONAL_MASK; } - /// Clears the feature's optional (odd) bit from the given flags. + /// Clears the feature's required (even) and optional (odd) bits from the given + /// flags. #[inline] - fn clear_optional_bit(flags: &mut Vec) { + fn clear_bits(flags: &mut Vec) { if flags.len() > Self::BYTE_OFFSET { + flags[Self::BYTE_OFFSET] &= !Self::REQUIRED_MASK; flags[Self::BYTE_OFFSET] &= !Self::OPTIONAL_MASK; } } @@ -122,20 +219,6 @@ mod sealed { // You should just use the type aliases instead. "Feature flags for `payment_secret`."); define_feature!(17, BasicMPP, [InitContext, NodeContext], "Feature flags for `basic_mpp`."); - - /// Generates a feature flag byte with the given features set as optional. Useful for initializing - /// the flags within [`Features`]. - /// - /// [`Features`]: struct.Features.html - macro_rules! feature_flags { - ($context: ty; $($feature: ident)|*) => { - (0b00_00_00_00 - $( - | <$context as sealed::$feature>::OPTIONAL_MASK - )* - ) - } - } } /// Tracks the set of features which a node implements, templated by the context in which it @@ -173,18 +256,6 @@ pub type NodeFeatures = Features; pub type ChannelFeatures = Features; impl InitFeatures { - /// Create a Features with the features we support - pub fn supported() -> InitFeatures { - InitFeatures { - flags: vec![ - feature_flags![sealed::InitContext; DataLossProtect | InitialRoutingSync | UpfrontShutdownScript], - feature_flags![sealed::InitContext; VariableLengthOnion | PaymentSecret], - feature_flags![sealed::InitContext; BasicMPP], - ], - mark: PhantomData, - } - } - /// Writes all features present up to, and including, 13. pub(crate) fn write_up_to_13(&self, w: &mut W) -> Result<(), ::std::io::Error> { let len = cmp::min(2, self.flags.len()); @@ -214,22 +285,6 @@ impl InitFeatures { } impl ChannelFeatures { - /// Create a Features with the features we support - #[cfg(not(feature = "fuzztarget"))] - pub(crate) fn supported() -> ChannelFeatures { - ChannelFeatures { - flags: Vec::new(), - mark: PhantomData, - } - } - #[cfg(feature = "fuzztarget")] - pub fn supported() -> ChannelFeatures { - ChannelFeatures { - flags: Vec::new(), - mark: PhantomData, - } - } - /// Takes the flags that we know how to interpret in an init-context features that are also /// relevant in a channel-context features and creates a channel-context features from them. pub(crate) fn with_known_relevant_init_flags(_init_ctx: &InitFeatures) -> Self { @@ -239,54 +294,17 @@ impl ChannelFeatures { } impl NodeFeatures { - /// Create a Features with the features we support - #[cfg(not(feature = "fuzztarget"))] - pub(crate) fn supported() -> NodeFeatures { - NodeFeatures { - flags: vec![ - feature_flags![sealed::NodeContext; DataLossProtect | UpfrontShutdownScript], - feature_flags![sealed::NodeContext; VariableLengthOnion | PaymentSecret], - feature_flags![sealed::NodeContext; BasicMPP], - ], - mark: PhantomData, - } - } - #[cfg(feature = "fuzztarget")] - pub fn supported() -> NodeFeatures { - NodeFeatures { - flags: vec![ - feature_flags![sealed::NodeContext; DataLossProtect | UpfrontShutdownScript], - feature_flags![sealed::NodeContext; VariableLengthOnion | PaymentSecret], - feature_flags![sealed::NodeContext; BasicMPP], - ], - mark: PhantomData, - } - } - /// Takes the flags that we know how to interpret in an init-context features that are also /// relevant in a node-context features and creates a node-context features from them. /// Be sure to blank out features that are unknown to us. pub(crate) fn with_known_relevant_init_flags(init_ctx: &InitFeatures) -> Self { - // Generates a bitmask with both even and odd bits set for the given features. Bitwise - // AND-ing it with a byte will select only common features. - macro_rules! features_including { - ($($feature: ident)|*) => { - (0b00_00_00_00 - $( - | ::REQUIRED_MASK - | ::OPTIONAL_MASK - )* - ) - } - } + use ln::features::sealed::Context; + let byte_count = sealed::NodeContext::KNOWN_FEATURE_MASK.len(); let mut flags = Vec::new(); - for (i, feature_byte)in init_ctx.flags.iter().enumerate() { - match i { - 0 => flags.push(feature_byte & features_including![DataLossProtect | UpfrontShutdownScript]), - 1 => flags.push(feature_byte & features_including![VariableLengthOnion | PaymentSecret]), - 2 => flags.push(feature_byte & features_including![BasicMPP]), - _ => (), + for (i, feature_byte) in init_ctx.flags.iter().enumerate() { + if i < byte_count { + flags.push(feature_byte & sealed::NodeContext::KNOWN_FEATURE_MASK[i]); } } Self { flags, mark: PhantomData, } @@ -302,6 +320,16 @@ impl Features { } } + /// Creates features known by the implementation as defined by [`T::KNOWN_FEATURE_FLAGS`]. + /// + /// [`T::KNOWN_FEATURE_FLAGS`]: sealed/trait.Context.html#associatedconstant.KNOWN_FEATURE_FLAGS + pub fn known() -> Features { + Self { + flags: T::KNOWN_FEATURE_FLAGS.to_vec(), + mark: PhantomData, + } + } + #[cfg(test)] /// Create a Features given a set of flags, in LE. pub fn from_le_bytes(flags: Vec) -> Features { @@ -318,49 +346,35 @@ impl Features { } pub(crate) fn requires_unknown_bits(&self) -> bool { - // Generates a bitmask with all even bits set except for the given features. Bitwise - // AND-ing it with a byte will select unknown required features. - macro_rules! features_excluding { - ($($feature: ident)|*) => { - (0b01_01_01_01 - $( - & !(::REQUIRED_MASK) - )* - ) - } - } - - self.flags.iter().enumerate().any(|(idx, &byte)| { - (match idx { - 0 => (byte & features_excluding![DataLossProtect | InitialRoutingSync | UpfrontShutdownScript]), - 1 => (byte & features_excluding![VariableLengthOnion | PaymentSecret]), - 2 => (byte & features_excluding![BasicMPP]), - _ => (byte & features_excluding![]), - }) != 0 + use ln::features::sealed::Context; + let byte_count = sealed::InitContext::KNOWN_FEATURE_MASK.len(); + + // Bitwise AND-ing with all even bits set except for known features will select unknown + // required features. + self.flags.iter().enumerate().any(|(i, &byte)| { + let required_features = 0b01_01_01_01; + let unknown_features = if i < byte_count { + !sealed::InitContext::KNOWN_FEATURE_MASK[i] + } else { + 0b11_11_11_11 + }; + (byte & (required_features & unknown_features)) != 0 }) } pub(crate) fn supports_unknown_bits(&self) -> bool { - // Generates a bitmask with all even and odd bits set except for the given features. Bitwise - // AND-ing it with a byte will select unknown supported features. - macro_rules! features_excluding { - ($($feature: ident)|*) => { - (0b11_11_11_11 - $( - & !(::REQUIRED_MASK) - & !(::OPTIONAL_MASK) - )* - ) - } - } - - self.flags.iter().enumerate().any(|(idx, &byte)| { - (match idx { - 0 => (byte & features_excluding![DataLossProtect | InitialRoutingSync | UpfrontShutdownScript]), - 1 => (byte & features_excluding![VariableLengthOnion | PaymentSecret]), - 2 => (byte & features_excluding![BasicMPP]), - _ => byte, - }) != 0 + use ln::features::sealed::Context; + let byte_count = sealed::InitContext::KNOWN_FEATURE_MASK.len(); + + // Bitwise AND-ing with all even and odd bits set except for known features will select + // unknown features. + self.flags.iter().enumerate().any(|(i, &byte)| { + let unknown_features = if i < byte_count { + !sealed::InitContext::KNOWN_FEATURE_MASK[i] + } else { + 0b11_11_11_11 + }; + (byte & unknown_features) != 0 }) } @@ -403,7 +417,7 @@ impl Features { } #[cfg(test)] pub(crate) fn unset_upfront_shutdown_script(&mut self) { - ::clear_optional_bit(&mut self.flags) + ::clear_bits(&mut self.flags) } } @@ -418,7 +432,7 @@ impl Features { ::supports_feature(&self.flags) } pub(crate) fn clear_initial_routing_sync(&mut self) { - ::clear_optional_bit(&mut self.flags) + ::clear_bits(&mut self.flags) } } @@ -468,29 +482,29 @@ mod tests { #[test] fn sanity_test_our_features() { - assert!(!ChannelFeatures::supported().requires_unknown_bits()); - assert!(!ChannelFeatures::supported().supports_unknown_bits()); - assert!(!InitFeatures::supported().requires_unknown_bits()); - assert!(!InitFeatures::supported().supports_unknown_bits()); - assert!(!NodeFeatures::supported().requires_unknown_bits()); - assert!(!NodeFeatures::supported().supports_unknown_bits()); + assert!(!ChannelFeatures::known().requires_unknown_bits()); + assert!(!ChannelFeatures::known().supports_unknown_bits()); + assert!(!InitFeatures::known().requires_unknown_bits()); + assert!(!InitFeatures::known().supports_unknown_bits()); + assert!(!NodeFeatures::known().requires_unknown_bits()); + assert!(!NodeFeatures::known().supports_unknown_bits()); - assert!(InitFeatures::supported().supports_upfront_shutdown_script()); - assert!(NodeFeatures::supported().supports_upfront_shutdown_script()); + assert!(InitFeatures::known().supports_upfront_shutdown_script()); + assert!(NodeFeatures::known().supports_upfront_shutdown_script()); - assert!(InitFeatures::supported().supports_data_loss_protect()); - assert!(NodeFeatures::supported().supports_data_loss_protect()); + assert!(InitFeatures::known().supports_data_loss_protect()); + assert!(NodeFeatures::known().supports_data_loss_protect()); - assert!(InitFeatures::supported().supports_variable_length_onion()); - assert!(NodeFeatures::supported().supports_variable_length_onion()); + assert!(InitFeatures::known().supports_variable_length_onion()); + assert!(NodeFeatures::known().supports_variable_length_onion()); - assert!(InitFeatures::supported().supports_payment_secret()); - assert!(NodeFeatures::supported().supports_payment_secret()); + assert!(InitFeatures::known().supports_payment_secret()); + assert!(NodeFeatures::known().supports_payment_secret()); - assert!(InitFeatures::supported().supports_basic_mpp()); - assert!(NodeFeatures::supported().supports_basic_mpp()); + assert!(InitFeatures::known().supports_basic_mpp()); + assert!(NodeFeatures::known().supports_basic_mpp()); - let mut init_features = InitFeatures::supported(); + let mut init_features = InitFeatures::known(); assert!(init_features.initial_routing_sync()); init_features.clear_initial_routing_sync(); assert!(!init_features.initial_routing_sync()); @@ -498,7 +512,7 @@ mod tests { #[test] fn sanity_test_unkown_bits_testing() { - let mut features = ChannelFeatures::supported(); + let mut features = ChannelFeatures::known(); features.set_require_unknown_bits(); assert!(features.requires_unknown_bits()); features.clear_require_unknown_bits(); @@ -508,7 +522,7 @@ mod tests { #[test] fn test_node_with_known_relevant_init_flags() { // Create an InitFeatures with initial_routing_sync supported. - let init_features = InitFeatures::supported(); + let init_features = InitFeatures::known(); assert!(init_features.initial_routing_sync()); // Attempt to pull out non-node-context feature flags from these InitFeatures. diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 267d4bbdc06..0a2d1b59002 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -75,7 +75,7 @@ fn test_insane_channel_opens() { // Test helper that asserts we get the correct error string given a mutator // that supposedly makes the channel open message insane let insane_open_helper = |expected_error_str: &str, message_mutator: fn(msgs::OpenChannel) -> msgs::OpenChannel| { - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::supported(), &message_mutator(open_channel_message.clone())); + nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &message_mutator(open_channel_message.clone())); let msg_events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 1); if let MessageSendEvent::HandleError { ref action, .. } = msg_events[0] { @@ -117,7 +117,7 @@ fn test_async_inbound_update_fee() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let channel_id = chan.2; // balancing @@ -230,7 +230,7 @@ fn test_update_fee_unordered_raa() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let channel_id = chan.2; // balancing @@ -283,7 +283,7 @@ fn test_multi_flight_update_fee() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let channel_id = chan.2; // A B @@ -401,7 +401,7 @@ fn test_1_conf_open() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(alice_config), Some(bob_config)]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 100000, 10001, InitFeatures::supported(), InitFeatures::supported()); + let tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 100000, 10001, InitFeatures::known(), InitFeatures::known()); assert!(nodes[0].chain_monitor.does_match_tx(&tx)); assert!(nodes[1].chain_monitor.does_match_tx(&tx)); @@ -442,11 +442,11 @@ fn do_test_sanity_on_in_flight_opens(steps: u8) { let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); if steps & 0x0f == 1 { return; } - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::supported(), &open_channel); + nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); if steps & 0x0f == 2 { return; } - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::supported(), &accept_channel); + nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_channel); let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], 100000, 42); @@ -520,7 +520,7 @@ fn test_update_fee_vanilla() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let channel_id = chan.2; let feerate = get_feerate!(nodes[0], channel_id); @@ -562,7 +562,7 @@ fn test_update_fee_that_funder_cannot_afford() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let channel_value = 1888; - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, channel_value, 700000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, channel_value, 700000, InitFeatures::known(), InitFeatures::known()); let channel_id = chan.2; let feerate = 260; @@ -611,7 +611,7 @@ fn test_update_fee_with_fundee_update_add_htlc() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let channel_id = chan.2; // balancing @@ -708,7 +708,7 @@ fn test_update_fee() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let channel_id = chan.2; // A B @@ -812,7 +812,7 @@ fn pre_funding_lock_shutdown_test() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 8000000, 0, InitFeatures::supported(), InitFeatures::supported()); + let tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 8000000, 0, InitFeatures::known(), InitFeatures::known()); let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 }; nodes[0].block_notifier.block_connected(&Block { header, txdata: vec![tx.clone()]}, 1); nodes[1].block_notifier.block_connected(&Block { header, txdata: vec![tx.clone()]}, 1); @@ -841,8 +841,8 @@ fn updates_shutdown_wait() { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let route_1 = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 100000, TEST_FINAL_CLTV).unwrap(); let route_2 = nodes[1].router.get_route(&nodes[0].node.get_our_node_id(), None, &[], 100000, TEST_FINAL_CLTV).unwrap(); @@ -914,8 +914,8 @@ fn htlc_fail_async_shutdown() { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[2].node.get_our_node_id(), None, &[], 100000, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -990,8 +990,8 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let (our_payment_preimage, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 100000); @@ -1155,9 +1155,9 @@ fn fake_network_test() { let nodes = create_network(4, &node_cfgs, &node_chanmgrs); // Create some initial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); - let chan_3 = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); + let chan_3 = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::known(), InitFeatures::known()); // Rebalance the network a bit by relaying one payment through all the channels... send_payment(&nodes[0], &vec!(&nodes[1], &nodes[2], &nodes[3])[..], 8000000, 8_000_000); @@ -1175,7 +1175,7 @@ fn fake_network_test() { fail_payment(&nodes[0], &vec!(&nodes[1], &nodes[2], &nodes[3])[..], payment_hash_1); // Add a new channel that skips 3 - let chan_4 = create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::supported(), InitFeatures::supported()); + let chan_4 = create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::known(), InitFeatures::known()); send_payment(&nodes[0], &vec!(&nodes[1], &nodes[3])[..], 1000000, 1_000_000); send_payment(&nodes[2], &vec!(&nodes[3])[..], 1000000, 1_000_000); @@ -1249,7 +1249,7 @@ fn fake_network_test() { claim_payment(&nodes[1], &vec!(&nodes[2], &nodes[3], &nodes[1])[..], payment_preimage_1, 1_000_000); // Add a duplicate new channel from 2 to 4 - let chan_5 = create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::supported(), InitFeatures::supported()); + let chan_5 = create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::known(), InitFeatures::known()); // Send some payments across both channels let payment_preimage_3 = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[3])[..], 3000000).0; @@ -1285,8 +1285,8 @@ fn holding_cell_htlc_counting() { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let mut payments = Vec::new(); for _ in 0..::ln::channel::OUR_MAX_HTLCS { @@ -1408,11 +1408,11 @@ fn duplicate_htlc_test() { let mut nodes = create_network(6, &node_cfgs, &node_chanmgrs); // Create some initial channels to route via 3 to 4/5 from 0/1/2 - create_announced_chan_between_nodes(&nodes, 0, 3, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 3, 4, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 3, 5, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 3, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 3, 4, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 3, 5, InitFeatures::known(), InitFeatures::known()); let (payment_preimage, payment_hash) = route_payment(&nodes[0], &vec!(&nodes[3], &nodes[4])[..], 1000000); @@ -1437,7 +1437,7 @@ fn test_duplicate_htlc_different_direction_onchain() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); // balancing send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000, 8_000_000); @@ -1505,8 +1505,8 @@ fn do_channel_reserve_test(test_recv: bool) { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - let chan_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1900, 1001, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1900, 1001, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1900, 1001, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1900, 1001, InitFeatures::known(), InitFeatures::known()); let mut stat01 = get_channel_value_stat!(nodes[0], chan_1.2); let mut stat11 = get_channel_value_stat!(nodes[1], chan_1.2); @@ -1785,7 +1785,7 @@ fn channel_reserve_in_flight_removes() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let b_chan_values = get_channel_value_stat!(nodes[1], chan_1.2); // Route the first two HTLCs. @@ -1917,10 +1917,10 @@ fn channel_monitor_network_test() { let nodes = create_network(5, &node_cfgs, &node_chanmgrs); // Create some initial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); - let chan_3 = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::supported(), InitFeatures::supported()); - let chan_4 = create_announced_chan_between_nodes(&nodes, 3, 4, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); + let chan_3 = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::known(), InitFeatures::known()); + let chan_4 = create_announced_chan_between_nodes(&nodes, 3, 4, InitFeatures::known(), InitFeatures::known()); // Rebalance the network a bit by relaying one payment through all the channels... send_payment(&nodes[0], &vec!(&nodes[1], &nodes[2], &nodes[3], &nodes[4])[..], 8000000, 8_000_000); @@ -2075,7 +2075,7 @@ fn test_justice_tx() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &user_cfgs); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Create some new channels: - let chan_5 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_5 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); // A pending HTLC which will be revoked: let payment_preimage_3 = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; @@ -2122,7 +2122,7 @@ fn test_justice_tx() { // We test justice_tx build by A on B's revoked HTLC-Success tx // Create some new channels: - let chan_6 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_6 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); { let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap(); node_txn.clear(); @@ -2172,7 +2172,7 @@ fn revoked_output_claim() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); // node[0] is gonna to revoke an old state thus node[1] should be able to claim the revoked output let revoked_local_txn = get_local_commitment_txn!(nodes[0], chan_1.2); assert_eq!(revoked_local_txn.len(), 1); @@ -2206,7 +2206,7 @@ fn claim_htlc_outputs_shared_tx() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Create some new channel: - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); // Rebalance the network to generate htlc in the two directions send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000, 8_000_000); @@ -2275,7 +2275,7 @@ fn claim_htlc_outputs_single_tx() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); // Rebalance the network to generate htlc in the two directions send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000, 8_000_000); @@ -2361,8 +2361,8 @@ fn test_htlc_on_chain_success() { let nodes = create_network(3, &node_cfgs, &node_chanmgrs); // Create some initial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); // Rebalance the network a bit by relaying one payment through all the channels... send_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 8000000, 8_000_000); @@ -2534,8 +2534,8 @@ fn test_htlc_on_chain_timeout() { let nodes = create_network(3, &node_cfgs, &node_chanmgrs); // Create some intial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); // Rebalance the network a bit by relaying one payment thorugh all the channels... send_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 8000000, 8_000_000); @@ -2644,8 +2644,8 @@ fn test_simple_commitment_revoked_fail_backward() { let nodes = create_network(3, &node_cfgs, &node_chanmgrs); // Create some initial channels - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let (payment_preimage, _payment_hash) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 3000000); // Get the will-be-revoked local txn from nodes[2] @@ -2710,8 +2710,8 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); // Create some initial channels - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let (payment_preimage, _payment_hash) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], if no_to_remote { 10_000 } else { 3_000_000 }); // Get the will-be-revoked local txn from nodes[2] @@ -2921,7 +2921,7 @@ fn fail_backward_pending_htlc_upon_channel_failure() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 500_000_000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 500_000_000, InitFeatures::known(), InitFeatures::known()); // Alice -> Bob: Route a payment but without Bob sending revoke_and_ack. { @@ -2993,7 +2993,7 @@ fn test_htlc_ignore_latest_remote_commitment() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); route_payment(&nodes[0], &[&nodes[1]], 10000000); nodes[0].node.force_close_channel(&nodes[0].node.list_channels()[0].channel_id); @@ -3020,8 +3020,8 @@ fn test_force_close_fail_back() { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[2].node.get_our_node_id(), None, &Vec::new(), 1000000, 42).unwrap(); @@ -3099,7 +3099,7 @@ fn test_unconf_chan() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let channel_state = nodes[0].node.channel_state.lock().unwrap(); assert_eq!(channel_state.by_id.len(), 1); @@ -3132,8 +3132,8 @@ fn test_simple_peer_disconnect() { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false); nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false); @@ -3189,10 +3189,10 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); if messages_delivered == 0 { - create_chan_between_nodes_with_value_a(&nodes[0], &nodes[1], 100000, 10001, InitFeatures::supported(), InitFeatures::supported()); + create_chan_between_nodes_with_value_a(&nodes[0], &nodes[1], 100000, 10001, InitFeatures::known(), InitFeatures::known()); // nodes[1] doesn't receive the funding_locked message (it'll be re-sent on reconnect) } else { - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); } let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), Some(&nodes[0].node.list_usable_channels()), &Vec::new(), 1000000, TEST_FINAL_CLTV).unwrap(); @@ -3398,7 +3398,7 @@ fn test_funding_peer_disconnect() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 100000, 10001, InitFeatures::supported(), InitFeatures::supported()); + let tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 100000, 10001, InitFeatures::known(), InitFeatures::known()); nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false); nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false); @@ -3483,7 +3483,7 @@ fn test_drop_messages_peer_disconnect_dual_htlc() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let (payment_preimage_1, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000); @@ -3626,7 +3626,7 @@ fn do_test_htlc_timeout(send_partial_mpp: bool) { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let our_payment_hash = if send_partial_mpp { let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), 100000, TEST_FINAL_CLTV).unwrap(); @@ -3684,8 +3684,8 @@ fn do_test_holding_cell_htlc_add_timeouts(forwarded_htlc: bool) { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); // Route a first payment to get the 1 -> 2 channel in awaiting_raa... let route = nodes[1].router.get_route(&nodes[2].node.get_our_node_id(), None, &Vec::new(), 100000, TEST_FINAL_CLTV).unwrap(); @@ -3764,7 +3764,7 @@ fn test_invalid_channel_announcement() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan_announcement = create_chan_between_nodes(&nodes[0], &nodes[1], InitFeatures::supported(), InitFeatures::supported()); + let chan_announcement = create_chan_between_nodes(&nodes[0], &nodes[1], InitFeatures::known(), InitFeatures::known()); let a_channel_lock = nodes[0].node.channel_state.lock().unwrap(); let b_channel_lock = nodes[1].node.channel_state.lock().unwrap(); @@ -3786,7 +3786,7 @@ fn test_invalid_channel_announcement() { macro_rules! dummy_unsigned_msg { () => { msgs::UnsignedChannelAnnouncement { - features: ChannelFeatures::supported(), + features: ChannelFeatures::known(), chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(), short_channel_id: as_chan.get_short_channel_id().unwrap(), node_id_1: if were_node_one { as_network_key } else { bs_network_key }, @@ -3843,7 +3843,7 @@ fn test_no_txn_manager_serialize_deserialize() { let nodes_0_deserialized: ChannelManager; let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 100000, 10001, InitFeatures::supported(), InitFeatures::supported()); + let tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 100000, 10001, InitFeatures::known(), InitFeatures::known()); nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false); @@ -3914,7 +3914,7 @@ fn test_simple_manager_serialize_deserialize() { let keys_manager: test_utils::TestKeysInterface; let nodes_0_deserialized: ChannelManager; let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let (our_payment_preimage, _) = route_payment(&nodes[0], &[&nodes[1]], 1000000); let (_, our_payment_hash) = route_payment(&nodes[0], &[&nodes[1]], 1000000); @@ -3971,9 +3971,9 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() { let keys_manager: test_utils::TestKeysInterface; let nodes_0_deserialized: ChannelManager; let mut nodes = create_network(4, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 2, 0, InitFeatures::supported(), InitFeatures::supported()); - let (_, _, channel_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 3, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 2, 0, InitFeatures::known(), InitFeatures::known()); + let (_, _, channel_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 3, InitFeatures::known(), InitFeatures::known()); let mut node_0_stale_monitors_serialized = Vec::new(); for monitor in nodes[0].chan_monitor.simple_monitor.monitors.lock().unwrap().iter() { @@ -4206,7 +4206,7 @@ fn test_claim_sizeable_push_msat() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 99000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 99000000, InitFeatures::known(), InitFeatures::known()); nodes[1].node.force_close_channel(&chan.2); check_closed_broadcast!(nodes[1], false); check_added_monitors!(nodes[1], 1); @@ -4233,7 +4233,7 @@ fn test_claim_on_remote_sizeable_push_msat() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 99000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 99000000, InitFeatures::known(), InitFeatures::known()); nodes[0].node.force_close_channel(&chan.2); check_closed_broadcast!(nodes[0], false); check_added_monitors!(nodes[0], 1); @@ -4265,7 +4265,7 @@ fn test_claim_on_remote_revoked_sizeable_push_msat() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 59000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 59000000, InitFeatures::known(), InitFeatures::known()); let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; let revoked_local_txn = get_local_commitment_txn!(nodes[0], chan.2); assert_eq!(revoked_local_txn[0].input.len(), 1); @@ -4297,7 +4297,7 @@ fn test_static_spendable_outputs_preimage_tx() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Create some initial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; @@ -4346,7 +4346,7 @@ fn test_static_spendable_outputs_timeout_tx() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Create some initial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); // Rebalance the network a bit by relaying one payment through all the channels ... send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000, 8_000_000); @@ -4393,7 +4393,7 @@ fn test_static_spendable_outputs_justice_tx_revoked_commitment_tx() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Create some initial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; let revoked_local_txn = get_local_commitment_txn!(nodes[0], chan_1.2); @@ -4429,7 +4429,7 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Create some initial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; let revoked_local_txn = get_local_commitment_txn!(nodes[0], chan_1.2); @@ -4485,7 +4485,7 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Create some initial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; let revoked_local_txn = get_local_commitment_txn!(nodes[1], chan_1.2); @@ -4546,8 +4546,8 @@ fn test_onchain_to_onchain_claim() { let nodes = create_network(3, &node_cfgs, &node_chanmgrs); // Create some initial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); // Rebalance the network a bit by relaying one payment through all the channels ... send_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 8000000, 8_000_000); @@ -4640,8 +4640,8 @@ fn test_duplicate_payment_hash_one_failure_one_success() { let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let (our_payment_preimage, duplicate_payment_hash) = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 900000); *nodes[0].network_payment_count.borrow_mut() -= 1; @@ -4756,7 +4756,7 @@ fn test_dynamic_spendable_outputs_local_htlc_success_tx() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Create some initial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 9000000).0; let local_txn = get_local_commitment_txn!(nodes[1], chan_1.2); @@ -4815,11 +4815,11 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]); let nodes = create_network(6, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 2, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); - let chan = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 3, 4, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 3, 5, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 2, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); + let chan = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 3, 4, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 3, 5, InitFeatures::known(), InitFeatures::known()); // Rebalance and check output sanity... send_payment(&nodes[0], &[&nodes[2], &nodes[3], &nodes[4]], 500000, 500_000); @@ -5058,7 +5058,7 @@ fn test_dynamic_spendable_outputs_local_htlc_timeout_tx() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Create some initial channels - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let (_, our_payment_hash) = route_payment(&nodes[0], &vec!(&nodes[1])[..], 9000000); let local_txn = get_local_commitment_txn!(nodes[0], chan_1.2); @@ -5099,7 +5099,7 @@ fn test_static_output_closing_tx() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000, 8_000_000); let closing_tx = close_channel(&nodes[0], &nodes[1], &chan.2, chan.3, true).2; @@ -5125,7 +5125,7 @@ fn do_htlc_claim_local_commitment_only(use_dust: bool) { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let (our_payment_preimage, _) = route_payment(&nodes[0], &[&nodes[1]], if use_dust { 50000 } else { 3000000 }); @@ -5166,7 +5166,7 @@ fn do_htlc_claim_current_remote_commitment_only(use_dust: bool) { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &Vec::new(), if use_dust { 50000 } else { 3000000 }, TEST_FINAL_CLTV).unwrap(); let (_, payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -5195,7 +5195,7 @@ fn do_htlc_claim_previous_remote_commitment_only(use_dust: bool, check_revoke_no let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); // Fail the payment, but don't deliver A's final RAA, resulting in the HTLC only being present // in B's previous (unrevoked) commitment transaction, but none of A's commitment transactions. @@ -5491,7 +5491,7 @@ fn test_onion_failure() { for node in nodes.iter() { *node.keys_manager.override_session_priv.lock().unwrap() = Some(SecretKey::from_slice(&[3; 32]).unwrap()); } - let channels = [create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()), create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported())]; + let channels = [create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()), create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known())]; let (_, payment_hash) = get_payment_preimage_hash!(nodes[0]); let route = nodes[0].router.get_route(&nodes[2].node.get_our_node_id(), None, &Vec::new(), 40000, TEST_FINAL_CLTV).unwrap(); // positve case @@ -5727,7 +5727,7 @@ fn bolt2_open_channel_sending_node_checks_part1() { //This test needs to be on i let push_msat=10001; nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42, None).unwrap(); let node0_to_1_send_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::supported(), &node0_to_1_send_open_channel); + nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &node0_to_1_send_open_channel); //Create a second channel with a channel_id collision assert!(nodes[0].node.create_channel(nodes[0].node.get_our_node_id(), channel_value_satoshis, push_msat, 42, None).is_err()); @@ -5789,7 +5789,7 @@ fn test_update_add_htlc_bolt2_sender_value_below_minimum_msat() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::supported(), InitFeatures::supported()); + let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known()); let mut route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 100000, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -5808,7 +5808,7 @@ fn test_update_add_htlc_bolt2_sender_zero_value_msat() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::supported(), InitFeatures::supported()); + let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known()); let mut route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 100000, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -5827,7 +5827,7 @@ fn test_update_add_htlc_bolt2_receiver_zero_value_msat() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::supported(), InitFeatures::supported()); + let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 100000, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -5850,7 +5850,7 @@ fn test_update_add_htlc_bolt2_sender_cltv_expiry_too_high() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 0, InitFeatures::supported(), InitFeatures::supported()); + let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 0, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 100000000, 500000001).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -5867,7 +5867,7 @@ fn test_update_add_htlc_bolt2_sender_exceed_max_htlc_num_and_htlc_id_increment() let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 0, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 0, InitFeatures::known(), InitFeatures::known()); let max_accepted_htlcs = nodes[1].node.channel_state.lock().unwrap().by_id.get(&chan.2).unwrap().their_max_accepted_htlcs as u64; for i in 0..max_accepted_htlcs { @@ -5910,7 +5910,7 @@ fn test_update_add_htlc_bolt2_sender_exceed_max_htlc_value_in_flight() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let channel_value = 100000; - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, channel_value, 0, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, channel_value, 0, InitFeatures::known(), InitFeatures::known()); let max_in_flight = get_channel_value_stat!(nodes[0], chan.2).their_max_htlc_value_in_flight_msat; send_payment(&nodes[0], &vec!(&nodes[1])[..], max_in_flight, max_in_flight); @@ -5934,7 +5934,7 @@ fn test_update_add_htlc_bolt2_receiver_check_amount_received_more_than_min() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known()); let htlc_minimum_msat: u64; { let chan_lock = nodes[0].node.channel_state.lock().unwrap(); @@ -5961,7 +5961,7 @@ fn test_update_add_htlc_bolt2_receiver_sender_can_afford_amount_sent() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known()); let their_channel_reserve = get_channel_value_stat!(nodes[0], chan.2).channel_reserve_msat; @@ -5988,7 +5988,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 3999999, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -6033,7 +6033,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_in_flight_msat() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 1000000, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); nodes[0].node.send_payment(&route, our_payment_hash, &None).unwrap(); @@ -6055,7 +6055,7 @@ fn test_update_add_htlc_bolt2_receiver_check_cltv_expiry() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 95000000, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 3999999, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); nodes[0].node.send_payment(&route, our_payment_hash, &None).unwrap(); @@ -6079,7 +6079,7 @@ fn test_update_add_htlc_bolt2_receiver_check_repeated_id_ignore() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 1000000, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); nodes[0].node.send_payment(&route, our_payment_hash, &None).unwrap(); @@ -6124,7 +6124,7 @@ fn test_update_fulfill_htlc_bolt2_update_fulfill_htlc_before_commitment() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 1000000, TEST_FINAL_CLTV).unwrap(); let (our_payment_preimage, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -6155,7 +6155,7 @@ fn test_update_fulfill_htlc_bolt2_update_fail_htlc_before_commitment() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 1000000, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -6186,7 +6186,7 @@ fn test_update_fulfill_htlc_bolt2_update_fail_malformed_htlc_before_commitment() let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 1000000, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -6218,7 +6218,7 @@ fn test_update_fulfill_htlc_bolt2_incorrect_htlc_id() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let our_payment_preimage = route_payment(&nodes[0], &[&nodes[1]], 100000).0; @@ -6259,7 +6259,7 @@ fn test_update_fulfill_htlc_bolt2_wrong_preimage() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let our_payment_preimage = route_payment(&nodes[0], &[&nodes[1]], 100000).0; @@ -6300,7 +6300,7 @@ fn test_update_fulfill_htlc_bolt2_missing_badonion_bit_for_malformed_htlc_messag let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[1].node.get_our_node_id(), None, &[], 1000000, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); nodes[0].node.send_payment(&route, our_payment_hash, &None).unwrap(); @@ -6346,8 +6346,8 @@ fn test_update_fulfill_htlc_bolt2_after_malformed_htlc_message_must_forward_upda let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1000000, 1000000, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1000000, 1000000, InitFeatures::known(), InitFeatures::known()); let route = nodes[0].router.get_route(&nodes[2].node.get_our_node_id(), None, &Vec::new(), 100000, TEST_FINAL_CLTV).unwrap(); let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); @@ -6424,7 +6424,7 @@ fn do_test_failure_delay_dust_htlc_local_commitment(announce_latest: bool) { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan =create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan =create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let bs_dust_limit = nodes[1].node.channel_state.lock().unwrap().by_id.get(&chan.2).unwrap().our_dust_limit_satoshis; @@ -6513,7 +6513,7 @@ fn test_no_failure_dust_htlc_local_commitment() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); // Rebalance a bit send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000, 8_000_000); @@ -6570,7 +6570,7 @@ fn do_test_sweep_outbound_htlc_failure_update(revoked: bool, local: bool) { let node_cfgs = create_node_cfgs(3, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let bs_dust_limit = nodes[1].node.channel_state.lock().unwrap().by_id.get(&chan.2).unwrap().our_dust_limit_satoshis; @@ -6670,7 +6670,7 @@ fn test_upfront_shutdown_script() { let nodes = create_network(3, &node_cfgs, &node_chanmgrs); // We test that in case of peer committing upfront to a script, if it changes at closing, we refuse to sign - let flags = InitFeatures::supported(); + let flags = InitFeatures::known(); let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 2, 1000000, 1000000, flags.clone(), flags.clone()); nodes[0].node.close_channel(&OutPoint::new(chan.3.txid(), 0).to_channel_id()).unwrap(); let mut node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[2].node.get_our_node_id()); @@ -6694,7 +6694,7 @@ fn test_upfront_shutdown_script() { } // We test that if case of peer non-signaling we don't enforce committed script at channel opening - let mut flags_no = InitFeatures::supported(); + let mut flags_no = InitFeatures::known(); flags_no.unset_upfront_shutdown_script(); let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, flags_no, flags.clone()); nodes[0].node.close_channel(&OutPoint::new(chan.3.txid(), 0).to_channel_id()).unwrap(); @@ -6768,7 +6768,7 @@ fn test_user_configurable_csv_delay() { nodes[1].node.create_channel(nodes[0].node.get_our_node_id(), 1000000, 1000000, 42, None).unwrap(); let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id()); open_channel.to_self_delay = 200; - if let Err(error) = Channel::new_from_req(&&test_utils::TestFeeEstimator { sat_per_kw: 253 }, &keys_manager, nodes[1].node.get_our_node_id(), InitFeatures::supported(), &open_channel, 0, Arc::new(test_utils::TestLogger::new()), &low_our_to_self_config) { + if let Err(error) = Channel::new_from_req(&&test_utils::TestFeeEstimator { sat_per_kw: 253 }, &keys_manager, nodes[1].node.get_our_node_id(), InitFeatures::known(), &open_channel, 0, Arc::new(test_utils::TestLogger::new()), &low_our_to_self_config) { match error { ChannelError::Close(err) => { assert_eq!(err, "Configured with an unreasonable our_to_self_delay putting user funds at risks"); }, _ => panic!("Unexpected event"), @@ -6777,10 +6777,10 @@ fn test_user_configurable_csv_delay() { // We test msg.to_self_delay <= config.their_to_self_delay is enforced in Chanel::accept_channel() nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 1000000, 1000000, 42, None).unwrap(); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::supported(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); accept_channel.to_self_delay = 200; - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::supported(), &accept_channel); + nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_channel); if let MessageSendEvent::HandleError { ref action, .. } = nodes[0].node.get_and_clear_pending_msg_events()[0] { match action { &ErrorAction::SendErrorMessage { ref msg } => { @@ -6794,7 +6794,7 @@ fn test_user_configurable_csv_delay() { nodes[1].node.create_channel(nodes[0].node.get_our_node_id(), 1000000, 1000000, 42, None).unwrap(); let mut open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id()); open_channel.to_self_delay = 200; - if let Err(error) = Channel::new_from_req(&&test_utils::TestFeeEstimator { sat_per_kw: 253 }, &keys_manager, nodes[1].node.get_our_node_id(), InitFeatures::supported(), &open_channel, 0, Arc::new(test_utils::TestLogger::new()), &high_their_to_self_config) { + if let Err(error) = Channel::new_from_req(&&test_utils::TestFeeEstimator { sat_per_kw: 253 }, &keys_manager, nodes[1].node.get_our_node_id(), InitFeatures::known(), &open_channel, 0, Arc::new(test_utils::TestLogger::new()), &high_their_to_self_config) { match error { ChannelError::Close(err) => { assert_eq!(err, "They wanted our payments to be delayed by a needlessly long period"); }, _ => panic!("Unexpected event"), @@ -6818,7 +6818,7 @@ fn test_data_loss_protect() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, InitFeatures::known(), InitFeatures::known()); // Cache node A state before any channel update let previous_node_state = nodes[0].node.encode(); @@ -6926,7 +6926,7 @@ fn test_check_htlc_underpaying() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Create some initial channels - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let (payment_preimage, payment_hash) = route_payment(&nodes[0], &[&nodes[1]], 10_000); @@ -6970,9 +6970,9 @@ fn test_announce_disable_channels() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let short_id_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).0.contents.short_channel_id; - let short_id_2 = create_announced_chan_between_nodes(&nodes, 1, 0, InitFeatures::supported(), InitFeatures::supported()).0.contents.short_channel_id; - let short_id_3 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).0.contents.short_channel_id; + let short_id_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id; + let short_id_2 = create_announced_chan_between_nodes(&nodes, 1, 0, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id; + let short_id_3 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id; // Disconnect peers nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false); @@ -7032,7 +7032,7 @@ fn test_bump_penalty_txn_on_revoked_commitment() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::known(), InitFeatures::known()); let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; let route = nodes[1].router.get_route(&nodes[0].node.get_our_node_id(), None, &Vec::new(), 3000000, 30).unwrap(); send_along_route(&nodes[1], route, &vec!(&nodes[0])[..], 3000000); @@ -7135,7 +7135,7 @@ fn test_bump_penalty_txn_on_revoked_htlcs() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::known(), InitFeatures::known()); // Lock HTLC in both directions let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3_000_000).0; route_payment(&nodes[1], &vec!(&nodes[0])[..], 3_000_000).0; @@ -7258,7 +7258,7 @@ fn test_bump_penalty_txn_on_remote_commitment() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::known(), InitFeatures::known()); let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0; route_payment(&nodes[1], &vec!(&nodes[0])[..], 3000000).0; @@ -7366,7 +7366,7 @@ fn test_set_outpoints_partial_claiming() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::known(), InitFeatures::known()); let payment_preimage_1 = route_payment(&nodes[1], &vec!(&nodes[0])[..], 3_000_000).0; let payment_preimage_2 = route_payment(&nodes[1], &vec!(&nodes[0])[..], 3_000_000).0; @@ -7467,7 +7467,7 @@ fn test_counterparty_raa_skip_no_crash() { let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).2; + let channel_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2; let commitment_seed = nodes[0].node.channel_state.lock().unwrap().by_id.get_mut(&channel_id).unwrap().local_keys.commitment_seed().clone(); const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1; @@ -7491,7 +7491,7 @@ fn test_bump_txn_sanitize_tracking_maps() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let nodes = create_network(2, &node_cfgs, &node_chanmgrs); - let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::supported(), InitFeatures::supported()); + let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::known(), InitFeatures::known()); // Lock HTLC in both directions let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 9_000_000).0; route_payment(&nodes[1], &vec!(&nodes[0])[..], 9_000_000).0; @@ -7565,7 +7565,7 @@ fn test_override_0msat_htlc_minimum() { let res = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); assert_eq!(res.htlc_minimum_msat, 1); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::supported(), &res); + nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &res); let res = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); assert_eq!(res.htlc_minimum_msat, 1); } @@ -7579,8 +7579,8 @@ fn test_simple_payment_secret() { let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let (payment_preimage, payment_hash) = get_payment_preimage_hash!(&nodes[0]); let payment_secret = PaymentSecret([0xdb; 32]); @@ -7601,10 +7601,10 @@ fn test_simple_mpp() { let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]); let nodes = create_network(4, &node_cfgs, &node_chanmgrs); - let chan_1_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()).0.contents.short_channel_id; - let chan_2_id = create_announced_chan_between_nodes(&nodes, 0, 2, InitFeatures::supported(), InitFeatures::supported()).0.contents.short_channel_id; - let chan_3_id = create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::supported(), InitFeatures::supported()).0.contents.short_channel_id; - let chan_4_id = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::supported(), InitFeatures::supported()).0.contents.short_channel_id; + let chan_1_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id; + let chan_2_id = create_announced_chan_between_nodes(&nodes, 0, 2, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id; + let chan_3_id = create_announced_chan_between_nodes(&nodes, 1, 3, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id; + let chan_4_id = create_announced_chan_between_nodes(&nodes, 2, 3, InitFeatures::known(), InitFeatures::known()).0.contents.short_channel_id; let (payment_preimage, payment_hash) = get_payment_preimage_hash!(&nodes[0]); let payment_secret = PaymentSecret([0xdb; 32]); @@ -7641,7 +7641,7 @@ fn test_update_err_monitor_lockdown() { let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); // Create some initial channel - let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); + let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); let outpoint = OutPoint { txid: chan_1.3.txid(), index: 0 }; // Rebalance the network to generate htlc in the two directions diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index b17b4aa083d..de8014a6ada 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1455,7 +1455,7 @@ mod tests { let sig_2 = get_sig_on!(privkey_2, secp_ctx, String::from("01010101010101010101010101010101")); let sig_3 = get_sig_on!(privkey_3, secp_ctx, String::from("01010101010101010101010101010101")); let sig_4 = get_sig_on!(privkey_4, secp_ctx, String::from("01010101010101010101010101010101")); - let mut features = ChannelFeatures::supported(); + let mut features = ChannelFeatures::known(); if unknown_features_bits { features = ChannelFeatures::from_le_bytes(vec![0xFF, 0xFF]); } diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 9399cfecf69..2dadf2ec614 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -548,7 +548,7 @@ impl PeerManager where peer.their_node_id = Some(their_node_id); insert_node_id!(); - let mut features = InitFeatures::supported(); + let mut features = InitFeatures::known(); if !self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) { features.clear_initial_routing_sync(); } @@ -642,7 +642,7 @@ impl PeerManager where } if !peer.outbound { - let mut features = InitFeatures::supported(); + let mut features = InitFeatures::known(); if !self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) { features.clear_initial_routing_sync(); } @@ -1358,7 +1358,7 @@ mod tests { let node_1_btckey = SecretKey::from_slice(&[40; 32]).unwrap(); let node_2_btckey = SecretKey::from_slice(&[39; 32]).unwrap(); let unsigned_ann = msgs::UnsignedChannelAnnouncement { - features: ChannelFeatures::supported(), + features: ChannelFeatures::known(), chain_hash: genesis_block(network).header.bitcoin_hash(), short_channel_id: short_chan_id, node_id_1: PublicKey::from_secret_key(&secp_ctx, &node_1_privkey), diff --git a/lightning/src/ln/reorg_tests.rs b/lightning/src/ln/reorg_tests.rs index 6b2c5d43234..49a55ade080 100644 --- a/lightning/src/ln/reorg_tests.rs +++ b/lightning/src/ln/reorg_tests.rs @@ -33,8 +33,8 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) { let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::supported(), InitFeatures::supported()); - let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::supported(), InitFeatures::supported()); + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()); + let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known()); let (our_payment_preimage, our_payment_hash) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1000000); diff --git a/lightning/src/ln/router.rs b/lightning/src/ln/router.rs index c7ebe86d7eb..9143d09bb95 100644 --- a/lightning/src/ln/router.rs +++ b/lightning/src/ln/router.rs @@ -1906,7 +1906,7 @@ mod tests { let first_announcement_time = 500; let mut unsigned_announcement = UnsignedNodeAnnouncement { - features: NodeFeatures::supported(), + features: NodeFeatures::known(), timestamp: first_announcement_time, node_id: node_id_1, rgb: [0; 3], @@ -1929,7 +1929,7 @@ mod tests { { // Announce a channel to add a corresponding node. let unsigned_announcement = UnsignedChannelAnnouncement { - features: ChannelFeatures::supported(), + features: ChannelFeatures::known(), chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(), short_channel_id: 0, node_id_1, @@ -2020,7 +2020,7 @@ mod tests { let mut unsigned_announcement = UnsignedChannelAnnouncement { - features: ChannelFeatures::supported(), + features: ChannelFeatures::known(), chain_hash: genesis_block(Network::Testnet).header.bitcoin_hash(), short_channel_id: 0, node_id_1, @@ -2591,7 +2591,7 @@ mod tests { { let mut unsigned_announcement = UnsignedNodeAnnouncement { - features: NodeFeatures::supported(), + features: NodeFeatures::known(), timestamp: 1000, node_id: node_id_1, rgb: [0; 3], @@ -2633,7 +2633,7 @@ mod tests { { // Later announcement which should not be relayed (excess data) prevent us from sharing a node let unsigned_announcement = UnsignedNodeAnnouncement { - features: NodeFeatures::supported(), + features: NodeFeatures::known(), timestamp: 1010, node_id: node_id_2, rgb: [0; 3], From 65ff1bf0beaeb33397c5024d278a65a780fc8ffd Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Wed, 15 Apr 2020 22:44:43 -0700 Subject: [PATCH 6/9] Generalize feature methods to work in any context Refactoring the features module allowed for making code specific to certain contexts generalizable. Specifically, KNOWN_FEATURE_MASK is defined on Context instead of hardcoded in each method specialization. Thus, such methods are no longer required. --- lightning/src/ln/features.rs | 59 +++++++++++++----------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index fc2526fe558..0dd5fa30493 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -284,33 +284,6 @@ impl InitFeatures { } } -impl ChannelFeatures { - /// Takes the flags that we know how to interpret in an init-context features that are also - /// relevant in a channel-context features and creates a channel-context features from them. - pub(crate) fn with_known_relevant_init_flags(_init_ctx: &InitFeatures) -> Self { - // There are currently no channel flags defined that we understand. - Self { flags: Vec::new(), mark: PhantomData, } - } -} - -impl NodeFeatures { - /// Takes the flags that we know how to interpret in an init-context features that are also - /// relevant in a node-context features and creates a node-context features from them. - /// Be sure to blank out features that are unknown to us. - pub(crate) fn with_known_relevant_init_flags(init_ctx: &InitFeatures) -> Self { - use ln::features::sealed::Context; - let byte_count = sealed::NodeContext::KNOWN_FEATURE_MASK.len(); - - let mut flags = Vec::new(); - for (i, feature_byte) in init_ctx.flags.iter().enumerate() { - if i < byte_count { - flags.push(feature_byte & sealed::NodeContext::KNOWN_FEATURE_MASK[i]); - } - } - Self { flags, mark: PhantomData, } - } -} - impl Features { /// Create a blank Features with no features set pub fn empty() -> Features { @@ -330,6 +303,20 @@ impl Features { } } + /// Takes the flags that we know how to interpret in an init-context features that are also + /// relevant in a node-context features and creates a node-context features from them. + /// Be sure to blank out features that are unknown to us. + pub(crate) fn with_known_relevant_init_flags(init_ctx: &InitFeatures) -> Self { + let byte_count = T::KNOWN_FEATURE_MASK.len(); + let mut flags = Vec::new(); + for (i, feature_byte) in init_ctx.flags.iter().enumerate() { + if i < byte_count { + flags.push(feature_byte & T::KNOWN_FEATURE_MASK[i]); + } + } + Self { flags, mark: PhantomData, } + } + #[cfg(test)] /// Create a Features given a set of flags, in LE. pub fn from_le_bytes(flags: Vec) -> Features { @@ -346,15 +333,13 @@ impl Features { } pub(crate) fn requires_unknown_bits(&self) -> bool { - use ln::features::sealed::Context; - let byte_count = sealed::InitContext::KNOWN_FEATURE_MASK.len(); - - // Bitwise AND-ing with all even bits set except for known features will select unknown - // required features. + // Bitwise AND-ing with all even bits set except for known features will select required + // unknown features. + let byte_count = T::KNOWN_FEATURE_MASK.len(); self.flags.iter().enumerate().any(|(i, &byte)| { let required_features = 0b01_01_01_01; let unknown_features = if i < byte_count { - !sealed::InitContext::KNOWN_FEATURE_MASK[i] + !T::KNOWN_FEATURE_MASK[i] } else { 0b11_11_11_11 }; @@ -363,14 +348,12 @@ impl Features { } pub(crate) fn supports_unknown_bits(&self) -> bool { - use ln::features::sealed::Context; - let byte_count = sealed::InitContext::KNOWN_FEATURE_MASK.len(); - // Bitwise AND-ing with all even and odd bits set except for known features will select - // unknown features. + // both required and optional unknown features. + let byte_count = T::KNOWN_FEATURE_MASK.len(); self.flags.iter().enumerate().any(|(i, &byte)| { let unknown_features = if i < byte_count { - !sealed::InitContext::KNOWN_FEATURE_MASK[i] + !T::KNOWN_FEATURE_MASK[i] } else { 0b11_11_11_11 }; From 4bd2c974a2c96a2ce98a4055a72b2b3c687e78bc Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Wed, 22 Apr 2020 16:52:11 -0700 Subject: [PATCH 7/9] Generalize with_known_relevant_init_flags Converting from InitFeatures to other Features is accomplished using Features::with_known_relevant_init_flags. Define a more general to_context method which converts from Features of one Context to another. Additionally, ensure the source context only has known flags before selecting flags for the target context. --- lightning/src/ln/features.rs | 64 ++++++++++++++++------------ lightning/src/ln/functional_tests.rs | 3 +- lightning/src/ln/router.rs | 10 ++--- 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 0dd5fa30493..381297703e8 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -282,6 +282,12 @@ impl InitFeatures { } self } + + /// Converts `InitFeatures` to `Features`. Only known `InitFeatures` relevant to context `C` + /// are included in the result. + pub(crate) fn to_context(&self) -> Features { + self.to_context_internal() + } } impl Features { @@ -303,18 +309,19 @@ impl Features { } } - /// Takes the flags that we know how to interpret in an init-context features that are also - /// relevant in a node-context features and creates a node-context features from them. - /// Be sure to blank out features that are unknown to us. - pub(crate) fn with_known_relevant_init_flags(init_ctx: &InitFeatures) -> Self { - let byte_count = T::KNOWN_FEATURE_MASK.len(); + /// Converts `Features` to `Features`. Only known `T` features relevant to context `C` are + /// included in the result. + fn to_context_internal(&self) -> Features { + let byte_count = C::KNOWN_FEATURE_MASK.len(); let mut flags = Vec::new(); - for (i, feature_byte) in init_ctx.flags.iter().enumerate() { + for (i, byte) in self.flags.iter().enumerate() { if i < byte_count { - flags.push(feature_byte & T::KNOWN_FEATURE_MASK[i]); + let known_source_features = T::KNOWN_FEATURE_MASK[i]; + let known_target_features = C::KNOWN_FEATURE_MASK[i]; + flags.push(byte & known_source_features & known_target_features); } } - Self { flags, mark: PhantomData, } + Features:: { flags, mark: PhantomData, } } #[cfg(test)] @@ -399,8 +406,9 @@ impl Features { ::supports_feature(&self.flags) } #[cfg(test)] - pub(crate) fn unset_upfront_shutdown_script(&mut self) { - ::clear_bits(&mut self.flags) + pub(crate) fn clear_upfront_shutdown_script(mut self) -> Self { + ::clear_bits(&mut self.flags); + self } } @@ -461,7 +469,7 @@ impl Readable for Features { #[cfg(test)] mod tests { - use super::{ChannelFeatures, InitFeatures, NodeFeatures, Features}; + use super::{ChannelFeatures, InitFeatures, NodeFeatures}; #[test] fn sanity_test_our_features() { @@ -503,26 +511,28 @@ mod tests { } #[test] - fn test_node_with_known_relevant_init_flags() { - // Create an InitFeatures with initial_routing_sync supported. - let init_features = InitFeatures::known(); + fn convert_to_context_with_relevant_flags() { + let init_features = InitFeatures::known().clear_upfront_shutdown_script(); assert!(init_features.initial_routing_sync()); + assert!(!init_features.supports_upfront_shutdown_script()); - // Attempt to pull out non-node-context feature flags from these InitFeatures. - let res = NodeFeatures::with_known_relevant_init_flags(&init_features); - + let node_features: NodeFeatures = init_features.to_context(); { - // Check that the flags are as expected: optional_data_loss_protect, - // option_upfront_shutdown_script, var_onion_optin, payment_secret, and - // basic_mpp. - assert_eq!(res.flags.len(), 3); - assert_eq!(res.flags[0], 0b00100010); - assert_eq!(res.flags[1], 0b10000010); - assert_eq!(res.flags[2], 0b00000010); + // Check that the flags are as expected: + // - option_data_loss_protect + // - var_onion_optin | payment_secret + // - basic_mpp + assert_eq!(node_features.flags.len(), 3); + assert_eq!(node_features.flags[0], 0b00000010); + assert_eq!(node_features.flags[1], 0b10000010); + assert_eq!(node_features.flags[2], 0b00000010); } - // Check that the initial_routing_sync feature was correctly blanked out. - let new_features: InitFeatures = Features::from_le_bytes(res.flags); - assert!(!new_features.initial_routing_sync()); + // Check that cleared flags are kept blank when converting back: + // - initial_routing_sync was not applicable to NodeContext + // - upfront_shutdown_script was cleared before converting + let features: InitFeatures = node_features.to_context_internal(); + assert!(!features.initial_routing_sync()); + assert!(!features.supports_upfront_shutdown_script()); } } diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 0a2d1b59002..d7bdcc2d2ac 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -6694,8 +6694,7 @@ fn test_upfront_shutdown_script() { } // We test that if case of peer non-signaling we don't enforce committed script at channel opening - let mut flags_no = InitFeatures::known(); - flags_no.unset_upfront_shutdown_script(); + let flags_no = InitFeatures::known().clear_upfront_shutdown_script(); let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000, flags_no, flags.clone()); nodes[0].node.close_channel(&OutPoint::new(chan.3.txid(), 0).to_channel_id()).unwrap(); let mut node_1_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); diff --git a/lightning/src/ln/router.rs b/lightning/src/ln/router.rs index 9143d09bb95..fb2364f7da3 100644 --- a/lightning/src/ln/router.rs +++ b/lightning/src/ln/router.rs @@ -893,9 +893,9 @@ impl Router { return Ok(Route { paths: vec![vec![RouteHop { pubkey: chan.remote_network_id, - node_features: NodeFeatures::with_known_relevant_init_flags(&chan.counterparty_features), + node_features: chan.counterparty_features.to_context(), short_channel_id, - channel_features: ChannelFeatures::with_known_relevant_init_flags(&chan.counterparty_features), + channel_features: chan.counterparty_features.to_context(), fee_msat: final_value_msat, cltv_expiry_delta: final_cltv, }]], @@ -972,7 +972,7 @@ impl Router { ( $node: expr, $node_id: expr, $fee_to_target_msat: expr ) => { if first_hops.is_some() { if let Some(&(ref first_hop, ref features)) = first_hop_targets.get(&$node_id) { - add_entry!(first_hop, $node_id, dummy_directional_info, ChannelFeatures::with_known_relevant_init_flags(&features), $fee_to_target_msat); + add_entry!(first_hop, $node_id, dummy_directional_info, features.to_context(), $fee_to_target_msat); } } @@ -1016,7 +1016,7 @@ impl Router { // bit lazy here. In the future, we should pull them out via our // ChannelManager, but there's no reason to waste the space until we // need them. - add_entry!(first_hop, hop.src_node_id, dummy_directional_info, ChannelFeatures::with_known_relevant_init_flags(&features), 0); + add_entry!(first_hop, hop.src_node_id, dummy_directional_info, features.to_context(), 0); } } // BOLT 11 doesn't allow inclusion of features for the last hop hints, which @@ -1031,7 +1031,7 @@ impl Router { let mut res = vec!(dist.remove(&network.our_node_id).unwrap().3); loop { if let Some(&(_, ref features)) = first_hop_targets.get(&res.last().unwrap().pubkey) { - res.last_mut().unwrap().node_features = NodeFeatures::with_known_relevant_init_flags(&features); + res.last_mut().unwrap().node_features = features.to_context(); } else if let Some(node) = network.nodes.get(&res.last().unwrap().pubkey) { res.last_mut().unwrap().node_features = node.features.clone(); } else { From b1c6499e1c50fc41c443883dde8e8248106089c3 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 27 Apr 2020 22:12:53 -0700 Subject: [PATCH 8/9] Expand testing of unknown feature bits Include tests for requires_unknown_bits and supports_unknown_bits when an unknown even bit, odd bit, or neither is set. Refactor bit clearing such that tests and production code share the same code path. Fix a potential spec incompatibility (currently only exposed in testing code) where trailing zero bytes are not removed after a bit is cleared. --- lightning/src/ln/features.rs | 79 ++++++++++++++++++++++++++++-------- lightning/src/ln/router.rs | 20 ++++----- 2 files changed, 71 insertions(+), 28 deletions(-) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 381297703e8..613d2db1459 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -173,6 +173,16 @@ mod sealed { (flags[Self::BYTE_OFFSET] & (Self::REQUIRED_MASK | Self::OPTIONAL_MASK)) != 0 } + /// Sets the feature's required (even) bit in the given flags. + #[inline] + fn set_required_bit(flags: &mut Vec) { + if flags.len() <= Self::BYTE_OFFSET { + flags.resize(Self::BYTE_OFFSET + 1, 0u8); + } + + flags[Self::BYTE_OFFSET] |= Self::REQUIRED_MASK; + } + /// Sets the feature's optional (odd) bit in the given flags. #[inline] fn set_optional_bit(flags: &mut Vec) { @@ -191,6 +201,10 @@ mod sealed { flags[Self::BYTE_OFFSET] &= !Self::REQUIRED_MASK; flags[Self::BYTE_OFFSET] &= !Self::OPTIONAL_MASK; } + + let last_non_zero_byte = flags.iter().rposition(|&byte| byte != 0); + let size = if let Some(offset) = last_non_zero_byte { offset + 1 } else { 0 }; + flags.resize(size, 0u8); } } @@ -219,6 +233,30 @@ mod sealed { "Feature flags for `payment_secret`."); define_feature!(17, BasicMPP, [InitContext, NodeContext], "Feature flags for `basic_mpp`."); + + #[cfg(test)] + define_context!(TestingContext { + required_features: [ + // Byte 0 + , + // Byte 1 + , + // Byte 2 + UnknownFeature, + ], + optional_features: [ + // Byte 0 + , + // Byte 1 + , + // Byte 2 + , + ], + }); + + #[cfg(test)] + define_feature!(23, UnknownFeature, [TestingContext], + "Feature flags for an unknown feature used in testing."); } /// Tracks the set of features which a node implements, templated by the context in which it @@ -375,23 +413,18 @@ impl Features { } #[cfg(test)] - pub(crate) fn set_require_unknown_bits(&mut self) { - let newlen = cmp::max(3, self.flags.len()); - self.flags.resize(newlen, 0u8); - self.flags[2] |= 0x40; + pub(crate) fn set_required_unknown_bits(&mut self) { + ::set_required_bit(&mut self.flags); } #[cfg(test)] - pub(crate) fn clear_require_unknown_bits(&mut self) { - let newlen = cmp::max(3, self.flags.len()); - self.flags.resize(newlen, 0u8); - self.flags[2] &= !0x40; - if self.flags.len() == 3 && self.flags[2] == 0 { - self.flags.resize(2, 0u8); - } - if self.flags.len() == 2 && self.flags[1] == 0 { - self.flags.resize(1, 0u8); - } + pub(crate) fn set_optional_unknown_bits(&mut self) { + ::set_optional_bit(&mut self.flags); + } + + #[cfg(test)] + pub(crate) fn clear_unknown_bits(&mut self) { + ::clear_bits(&mut self.flags); } } @@ -502,12 +535,22 @@ mod tests { } #[test] - fn sanity_test_unkown_bits_testing() { - let mut features = ChannelFeatures::known(); - features.set_require_unknown_bits(); + fn sanity_test_unknown_bits() { + let mut features = ChannelFeatures::empty(); + assert!(!features.requires_unknown_bits()); + assert!(!features.supports_unknown_bits()); + + features.set_required_unknown_bits(); assert!(features.requires_unknown_bits()); - features.clear_require_unknown_bits(); + assert!(features.supports_unknown_bits()); + + features.clear_unknown_bits(); + assert!(!features.requires_unknown_bits()); + assert!(!features.supports_unknown_bits()); + + features.set_optional_unknown_bits(); assert!(!features.requires_unknown_bits()); + assert!(features.supports_unknown_bits()); } #[test] diff --git a/lightning/src/ln/router.rs b/lightning/src/ln/router.rs index fb2364f7da3..1eec7533b65 100644 --- a/lightning/src/ln/router.rs +++ b/lightning/src/ln/router.rs @@ -1539,8 +1539,8 @@ mod tests { { // Disable channels 4 and 12 by requiring unknown feature bits let mut network = router.network_map.write().unwrap(); - network.channels.get_mut(&NetworkMap::get_key(4, zero_hash.clone())).unwrap().features.set_require_unknown_bits(); - network.channels.get_mut(&NetworkMap::get_key(12, zero_hash.clone())).unwrap().features.set_require_unknown_bits(); + network.channels.get_mut(&NetworkMap::get_key(4, zero_hash.clone())).unwrap().features.set_required_unknown_bits(); + network.channels.get_mut(&NetworkMap::get_key(12, zero_hash.clone())).unwrap().features.set_required_unknown_bits(); } { // If all the channels require some features we don't understand, route should fail @@ -1581,15 +1581,15 @@ mod tests { { // Re-enable channels 4 and 12 by wiping the unknown feature bits let mut network = router.network_map.write().unwrap(); - network.channels.get_mut(&NetworkMap::get_key(4, zero_hash.clone())).unwrap().features.clear_require_unknown_bits(); - network.channels.get_mut(&NetworkMap::get_key(12, zero_hash.clone())).unwrap().features.clear_require_unknown_bits(); + network.channels.get_mut(&NetworkMap::get_key(4, zero_hash.clone())).unwrap().features.clear_unknown_bits(); + network.channels.get_mut(&NetworkMap::get_key(12, zero_hash.clone())).unwrap().features.clear_unknown_bits(); } { // Disable nodes 1, 2, and 8 by requiring unknown feature bits let mut network = router.network_map.write().unwrap(); - network.nodes.get_mut(&node1).unwrap().features.set_require_unknown_bits(); - network.nodes.get_mut(&node2).unwrap().features.set_require_unknown_bits(); - network.nodes.get_mut(&node8).unwrap().features.set_require_unknown_bits(); + network.nodes.get_mut(&node1).unwrap().features.set_required_unknown_bits(); + network.nodes.get_mut(&node2).unwrap().features.set_required_unknown_bits(); + network.nodes.get_mut(&node8).unwrap().features.set_required_unknown_bits(); } { // If all nodes require some features we don't understand, route should fail @@ -1630,9 +1630,9 @@ mod tests { { // Re-enable nodes 1, 2, and 8 let mut network = router.network_map.write().unwrap(); - network.nodes.get_mut(&node1).unwrap().features.clear_require_unknown_bits(); - network.nodes.get_mut(&node2).unwrap().features.clear_require_unknown_bits(); - network.nodes.get_mut(&node8).unwrap().features.clear_require_unknown_bits(); + network.nodes.get_mut(&node1).unwrap().features.clear_unknown_bits(); + network.nodes.get_mut(&node2).unwrap().features.clear_unknown_bits(); + network.nodes.get_mut(&node8).unwrap().features.clear_unknown_bits(); } // Note that we don't test disabling node 3 and failing to route to it, as we (somewhat From ee27e8432ac13cdff5bc2d2db3245691facc2083 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 27 Apr 2020 23:24:46 -0700 Subject: [PATCH 9/9] Sanity check that known features are not required --- lightning/src/ln/features.rs | 41 ++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 613d2db1459..b65b9b1b245 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -166,6 +166,13 @@ mod sealed { /// [`BYTE_OFFSET`]: #associatedconstant.BYTE_OFFSET const OPTIONAL_MASK: u8 = 1 << (Self::ODD_BIT - 8 * Self::BYTE_OFFSET); + /// Returns whether the feature is required by the given flags. + #[inline] + fn requires_feature(flags: &Vec) -> bool { + flags.len() > Self::BYTE_OFFSET && + (flags[Self::BYTE_OFFSET] & Self::REQUIRED_MASK) != 0 + } + /// Returns whether the feature is supported by the given flags. #[inline] fn supports_feature(flags: &Vec) -> bool { @@ -429,12 +436,20 @@ impl Features { } impl Features { + #[cfg(test)] + pub(crate) fn requires_data_loss_protect(&self) -> bool { + ::requires_feature(&self.flags) + } pub(crate) fn supports_data_loss_protect(&self) -> bool { ::supports_feature(&self.flags) } } impl Features { + #[cfg(test)] + pub(crate) fn requires_upfront_shutdown_script(&self) -> bool { + ::requires_feature(&self.flags) + } pub(crate) fn supports_upfront_shutdown_script(&self) -> bool { ::supports_feature(&self.flags) } @@ -446,6 +461,10 @@ impl Features { } impl Features { + #[cfg(test)] + pub(crate) fn requires_variable_length_onion(&self) -> bool { + ::requires_feature(&self.flags) + } pub(crate) fn supports_variable_length_onion(&self) -> bool { ::supports_feature(&self.flags) } @@ -461,16 +480,24 @@ impl Features { } impl Features { - #[allow(dead_code)] + #[cfg(test)] + pub(crate) fn requires_payment_secret(&self) -> bool { + ::requires_feature(&self.flags) + } // Note that we never need to test this since what really matters is the invoice - iff the // invoice provides a payment_secret, we assume that we can use it (ie that the recipient // supports payment_secret). + #[allow(dead_code)] pub(crate) fn supports_payment_secret(&self) -> bool { ::supports_feature(&self.flags) } } impl Features { + #[cfg(test)] + pub(crate) fn requires_basic_mpp(&self) -> bool { + ::requires_feature(&self.flags) + } // We currently never test for this since we don't actually *generate* multipath routes. #[allow(dead_code)] pub(crate) fn supports_basic_mpp(&self) -> bool { @@ -505,7 +532,7 @@ mod tests { use super::{ChannelFeatures, InitFeatures, NodeFeatures}; #[test] - fn sanity_test_our_features() { + fn sanity_test_known_features() { assert!(!ChannelFeatures::known().requires_unknown_bits()); assert!(!ChannelFeatures::known().supports_unknown_bits()); assert!(!InitFeatures::known().requires_unknown_bits()); @@ -515,18 +542,28 @@ mod tests { assert!(InitFeatures::known().supports_upfront_shutdown_script()); assert!(NodeFeatures::known().supports_upfront_shutdown_script()); + assert!(!InitFeatures::known().requires_upfront_shutdown_script()); + assert!(!NodeFeatures::known().requires_upfront_shutdown_script()); assert!(InitFeatures::known().supports_data_loss_protect()); assert!(NodeFeatures::known().supports_data_loss_protect()); + assert!(!InitFeatures::known().requires_data_loss_protect()); + assert!(!NodeFeatures::known().requires_data_loss_protect()); assert!(InitFeatures::known().supports_variable_length_onion()); assert!(NodeFeatures::known().supports_variable_length_onion()); + assert!(!InitFeatures::known().requires_variable_length_onion()); + assert!(!NodeFeatures::known().requires_variable_length_onion()); assert!(InitFeatures::known().supports_payment_secret()); assert!(NodeFeatures::known().supports_payment_secret()); + assert!(!InitFeatures::known().requires_payment_secret()); + assert!(!NodeFeatures::known().requires_payment_secret()); assert!(InitFeatures::known().supports_basic_mpp()); assert!(NodeFeatures::known().supports_basic_mpp()); + assert!(!InitFeatures::known().requires_basic_mpp()); + assert!(!NodeFeatures::known().requires_basic_mpp()); let mut init_features = InitFeatures::known(); assert!(init_features.initial_routing_sync());