]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Stop relying on the `*Features::known` method in `routing` tests
authorMatt Corallo <git@bluematt.me>
Thu, 8 Sep 2022 21:04:11 +0000 (21:04 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 14 Sep 2022 20:09:35 +0000 (20:09 +0000)
As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in the `routing` module,
which was only used in tests.

lightning/src/routing/gossip.rs
lightning/src/routing/router.rs
lightning/src/routing/scoring.rs

index 6504b590e1095a83f314ed2ce30f8ecde0fbe669..f5c56ce4bcb99272bddd92fa4ec0e5d471c8413e 100644 (file)
@@ -1869,9 +1869,10 @@ impl ReadOnlyNetworkGraph<'_> {
 #[cfg(test)]
 mod tests {
        use chain;
+       use ln::channelmanager;
        use ln::chan_utils::make_funding_redeemscript;
        use ln::PaymentHash;
-       use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
+       use ln::features::InitFeatures;
        use routing::gossip::{P2PGossipSync, NetworkGraph, NetworkUpdate, NodeAlias, MAX_EXCESS_BYTES_FOR_RELAY, NodeId, RoutingFees, ChannelUpdateInfo, ChannelInfo, NodeAnnouncementInfo, NodeInfo};
        use ln::msgs::{RoutingMessageHandler, UnsignedNodeAnnouncement, NodeAnnouncement,
                UnsignedChannelAnnouncement, ChannelAnnouncement, UnsignedChannelUpdate, ChannelUpdate,
@@ -1934,7 +1935,7 @@ mod tests {
        fn get_signed_node_announcement<F: Fn(&mut UnsignedNodeAnnouncement)>(f: F, node_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> NodeAnnouncement {
                let node_id = PublicKey::from_secret_key(&secp_ctx, node_key);
                let mut unsigned_announcement = UnsignedNodeAnnouncement {
-                       features: NodeFeatures::known(),
+                       features: channelmanager::provided_node_features(),
                        timestamp: 100,
                        node_id: node_id,
                        rgb: [0; 3],
@@ -1958,7 +1959,7 @@ mod tests {
                let node_2_btckey = &SecretKey::from_slice(&[39; 32]).unwrap();
 
                let mut unsigned_announcement = UnsignedChannelAnnouncement {
-                       features: ChannelFeatures::known(),
+                       features: channelmanager::provided_channel_features(),
                        chain_hash: genesis_block(Network::Testnet).header.block_hash(),
                        short_channel_id: 0,
                        node_id_1,
@@ -2616,7 +2617,7 @@ mod tests {
 
                // It should ignore if gossip_queries feature is not enabled
                {
-                       let init_msg = Init { features: InitFeatures::known().clear_gossip_queries(), remote_network_address: None };
+                       let init_msg = Init { features: InitFeatures::empty(), remote_network_address: None };
                        gossip_sync.peer_connected(&node_id_1, &init_msg).unwrap();
                        let events = gossip_sync.get_and_clear_pending_msg_events();
                        assert_eq!(events.len(), 0);
@@ -2624,7 +2625,9 @@ mod tests {
 
                // It should send a gossip_timestamp_filter with the correct information
                {
-                       let init_msg = Init { features: InitFeatures::known(), remote_network_address: None };
+                       let mut features = InitFeatures::empty();
+                       features.set_gossip_queries_optional();
+                       let init_msg = Init { features, remote_network_address: None };
                        gossip_sync.peer_connected(&node_id_1, &init_msg).unwrap();
                        let events = gossip_sync.get_and_clear_pending_msg_events();
                        assert_eq!(events.len(), 1);
@@ -3014,7 +3017,7 @@ mod tests {
                // 2. Test encoding/decoding of ChannelInfo
                // Check we can encode/decode ChannelInfo without ChannelUpdateInfo fields present.
                let chan_info_none_updates = ChannelInfo {
-                       features: ChannelFeatures::known(),
+                       features: channelmanager::provided_channel_features(),
                        node_one: NodeId::from_pubkey(&nodes[0].node.get_our_node_id()),
                        one_to_two: None,
                        node_two: NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
@@ -3032,7 +3035,7 @@ mod tests {
 
                // Check we can encode/decode ChannelInfo with ChannelUpdateInfo fields present.
                let chan_info_some_updates = ChannelInfo {
-                       features: ChannelFeatures::known(),
+                       features: channelmanager::provided_channel_features(),
                        node_one: NodeId::from_pubkey(&nodes[0].node.get_our_node_id()),
                        one_to_two: Some(chan_update_info.clone()),
                        node_two: NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
@@ -3074,7 +3077,7 @@ mod tests {
                // 1. Check we can read a valid NodeAnnouncementInfo and fail on an invalid one
                let valid_netaddr = ::ln::msgs::NetAddress::Hostname { hostname: ::util::ser::Hostname::try_from("A".to_string()).unwrap(), port: 1234 };
                let valid_node_ann_info = NodeAnnouncementInfo {
-                       features: NodeFeatures::known(),
+                       features: channelmanager::provided_node_features(),
                        last_update: 0,
                        rgb: [0u8; 3],
                        alias: NodeAlias([0u8; 32]),
index 4c00dc5fcf9327126d0f9bd580823fd1447ea4f7..8fdc92ba8a3b3320c9fb66c7fc09e6aa90e25c34 100644 (file)
@@ -1939,7 +1939,7 @@ mod tests {
        use routing::scoring::{ChannelUsage, Score, ProbabilisticScorer, ProbabilisticScoringParameters};
        use chain::transaction::OutPoint;
        use chain::keysinterface::KeysInterface;
-       use ln::features::{ChannelFeatures, InitFeatures, InvoiceFeatures, NodeFeatures};
+       use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
        use ln::msgs::{ErrorAction, LightningError, UnsignedChannelAnnouncement, ChannelAnnouncement, RoutingMessageHandler,
                NodeAnnouncement, UnsignedNodeAnnouncement, ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
        use ln::channelmanager;
@@ -2656,7 +2656,7 @@ mod tests {
        fn htlc_minimum_overpay_test() {
                let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
+               let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features());
                let scorer = test_utils::TestScorer::with_penalty(0);
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -3629,7 +3629,7 @@ mod tests {
                let scorer = test_utils::TestScorer::with_penalty(0);
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
-               let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
+               let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features());
 
                // We will use a simple single-path route from
                // our node to node2 via node0: channels {1, 3}.
@@ -3903,7 +3903,7 @@ mod tests {
                let scorer = test_utils::TestScorer::with_penalty(0);
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
-               let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(InvoiceFeatures::known());
+               let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
 
                // Path via {node7, node2, node4} is channels {12, 13, 6, 11}.
                // {12, 13, 11} have the capacities of 100, {6} has a capacity of 50.
@@ -4077,7 +4077,7 @@ mod tests {
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                let payment_params = PaymentParameters::from_node_id(nodes[2])
-                       .with_features(InvoiceFeatures::known());
+                       .with_features(channelmanager::provided_invoice_features());
 
                // We need a route consisting of 3 paths:
                // From our node to node2 via node0, node7, node1 (three paths one hop each).
@@ -4235,7 +4235,7 @@ mod tests {
                let scorer = test_utils::TestScorer::with_penalty(0);
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
-               let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(InvoiceFeatures::known());
+               let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
 
                // We need a route consisting of 3 paths:
                // From our node to node3 via {node0, node2}, {node7, node2, node4} and {node7, node2}.
@@ -4399,7 +4399,7 @@ mod tests {
                let scorer = test_utils::TestScorer::with_penalty(0);
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
-               let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(InvoiceFeatures::known());
+               let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
 
                // This test checks that if we have two cheaper paths and one more expensive path,
                // so that liquidity-wise any 2 of 3 combination is sufficient,
@@ -4568,7 +4568,7 @@ mod tests {
                let scorer = test_utils::TestScorer::with_penalty(0);
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
-               let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(InvoiceFeatures::known());
+               let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
 
                // We need a route consisting of 2 paths:
                // From our node to node3 via {node0, node2} and {node7, node2, node4}.
@@ -4749,7 +4749,7 @@ mod tests {
                let scorer = test_utils::TestScorer::with_penalty(0);
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
-               let payment_params = PaymentParameters::from_node_id(PublicKey::from_slice(&[02; 33]).unwrap()).with_features(InvoiceFeatures::known())
+               let payment_params = PaymentParameters::from_node_id(PublicKey::from_slice(&[02; 33]).unwrap()).with_features(channelmanager::provided_invoice_features())
                        .with_route_hints(vec![RouteHint(vec![RouteHintHop {
                                src_node_id: nodes[2],
                                short_channel_id: 42,
@@ -4840,7 +4840,7 @@ mod tests {
                let scorer = test_utils::TestScorer::with_penalty(0);
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
-               let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known())
+               let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features())
                        .with_max_channel_saturation_power_of_half(0);
 
                // We need a route consisting of 3 paths:
@@ -5196,7 +5196,7 @@ mod tests {
                let scorer = test_utils::TestScorer::with_penalty(0);
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
-               let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
+               let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features());
 
                // We modify the graph to set the htlc_minimum of channel 2 and 4 as needed - channel 2
                // gets an htlc_maximum_msat of 80_000 and channel 4 an htlc_minimum_msat of 90_000. We
@@ -5245,7 +5245,7 @@ mod tests {
                        assert_eq!(route.paths[0][1].short_channel_id, 13);
                        assert_eq!(route.paths[0][1].fee_msat, 90_000);
                        assert_eq!(route.paths[0][1].cltv_expiry_delta, 42);
-                       assert_eq!(route.paths[0][1].node_features.le_flags(), InvoiceFeatures::known().le_flags());
+                       assert_eq!(route.paths[0][1].node_features.le_flags(), channelmanager::provided_invoice_features().le_flags());
                        assert_eq!(route.paths[0][1].channel_features.le_flags(), &id_to_feature_flags(13));
                }
        }
@@ -5264,14 +5264,14 @@ mod tests {
                let logger = Arc::new(test_utils::TestLogger::new());
                let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger));
                let scorer = test_utils::TestScorer::with_penalty(0);
-               let payment_params = PaymentParameters::from_node_id(nodes[0]).with_features(InvoiceFeatures::known());
+               let payment_params = PaymentParameters::from_node_id(nodes[0]).with_features(channelmanager::provided_invoice_features());
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
 
                {
                        let route = get_route(&our_id, &payment_params, &network_graph.read_only(), Some(&[
-                               &get_channel_details(Some(3), nodes[0], InitFeatures::known(), 200_000),
-                               &get_channel_details(Some(2), nodes[0], InitFeatures::known(), 10_000),
+                               &get_channel_details(Some(3), nodes[0], channelmanager::provided_init_features(), 200_000),
+                               &get_channel_details(Some(2), nodes[0], channelmanager::provided_init_features(), 10_000),
                        ]), 100_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
                        assert_eq!(route.paths.len(), 1);
                        assert_eq!(route.paths[0].len(), 1);
@@ -5282,8 +5282,8 @@ mod tests {
                }
                {
                        let route = get_route(&our_id, &payment_params, &network_graph.read_only(), Some(&[
-                               &get_channel_details(Some(3), nodes[0], InitFeatures::known(), 50_000),
-                               &get_channel_details(Some(2), nodes[0], InitFeatures::known(), 50_000),
+                               &get_channel_details(Some(3), nodes[0], channelmanager::provided_init_features(), 50_000),
+                               &get_channel_details(Some(2), nodes[0], channelmanager::provided_init_features(), 50_000),
                        ]), 100_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
                        assert_eq!(route.paths.len(), 2);
                        assert_eq!(route.paths[0].len(), 1);
@@ -5308,14 +5308,14 @@ mod tests {
                        // smallest of them, avoiding further fragmenting our available outbound balance to
                        // this node.
                        let route = get_route(&our_id, &payment_params, &network_graph.read_only(), Some(&[
-                               &get_channel_details(Some(2), nodes[0], InitFeatures::known(), 50_000),
-                               &get_channel_details(Some(3), nodes[0], InitFeatures::known(), 50_000),
-                               &get_channel_details(Some(5), nodes[0], InitFeatures::known(), 50_000),
-                               &get_channel_details(Some(6), nodes[0], InitFeatures::known(), 300_000),
-                               &get_channel_details(Some(7), nodes[0], InitFeatures::known(), 50_000),
-                               &get_channel_details(Some(8), nodes[0], InitFeatures::known(), 50_000),
-                               &get_channel_details(Some(9), nodes[0], InitFeatures::known(), 50_000),
-                               &get_channel_details(Some(4), nodes[0], InitFeatures::known(), 1_000_000),
+                               &get_channel_details(Some(2), nodes[0], channelmanager::provided_init_features(), 50_000),
+                               &get_channel_details(Some(3), nodes[0], channelmanager::provided_init_features(), 50_000),
+                               &get_channel_details(Some(5), nodes[0], channelmanager::provided_init_features(), 50_000),
+                               &get_channel_details(Some(6), nodes[0], channelmanager::provided_init_features(), 300_000),
+                               &get_channel_details(Some(7), nodes[0], channelmanager::provided_init_features(), 50_000),
+                               &get_channel_details(Some(8), nodes[0], channelmanager::provided_init_features(), 50_000),
+                               &get_channel_details(Some(9), nodes[0], channelmanager::provided_init_features(), 50_000),
+                               &get_channel_details(Some(4), nodes[0], channelmanager::provided_init_features(), 1_000_000),
                        ]), 100_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
                        assert_eq!(route.paths.len(), 1);
                        assert_eq!(route.paths[0].len(), 1);
@@ -5759,7 +5759,7 @@ mod tests {
                        excess_data: Vec::new()
                });
 
-               let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
+               let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features());
                let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                // 100,000 sats is less than the available liquidity on each channel, set above.
@@ -5843,7 +5843,7 @@ mod tests {
                                let src = &PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap();
                                seed = seed.overflowing_mul(0xdeadbeef).0;
                                let dst = PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap();
-                               let payment_params = PaymentParameters::from_node_id(dst).with_features(InvoiceFeatures::known());
+                               let payment_params = PaymentParameters::from_node_id(dst).with_features(channelmanager::provided_invoice_features());
                                let amt = seed as u64 % 200_000_000;
                                let params = ProbabilisticScoringParameters::default();
                                let scorer = ProbabilisticScorer::new(params, &graph, &logger);
@@ -5926,7 +5926,7 @@ mod benches {
        use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
        use chain::transaction::OutPoint;
        use chain::keysinterface::{KeysManager,KeysInterface};
-       use ln::channelmanager::{ChannelCounterparty, ChannelDetails};
+       use ln::channelmanager::{self, ChannelCounterparty, ChannelDetails};
        use ln::features::{InitFeatures, InvoiceFeatures};
        use routing::gossip::NetworkGraph;
        use routing::scoring::{FixedPenaltyScorer, ProbabilisticScorer, ProbabilisticScoringParameters};
@@ -5955,7 +5955,7 @@ mod benches {
                ChannelDetails {
                        channel_id: [0; 32],
                        counterparty: ChannelCounterparty {
-                               features: InitFeatures::known(),
+                               features: channelmanager::provided_init_features(),
                                node_id,
                                unspendable_punishment_reserve: 0,
                                forwarding_info: None,
@@ -6001,7 +6001,7 @@ mod benches {
                let logger = DummyLogger {};
                let network_graph = read_network_graph(&logger);
                let scorer = FixedPenaltyScorer::with_penalty(0);
-               generate_routes(bench, &network_graph, scorer, InvoiceFeatures::known());
+               generate_routes(bench, &network_graph, scorer, channelmanager::provided_invoice_features());
        }
 
        #[bench]
@@ -6019,7 +6019,7 @@ mod benches {
                let network_graph = read_network_graph(&logger);
                let params = ProbabilisticScoringParameters::default();
                let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
-               generate_routes(bench, &network_graph, scorer, InvoiceFeatures::known());
+               generate_routes(bench, &network_graph, scorer, channelmanager::provided_invoice_features());
        }
 
        fn generate_routes<S: Score>(
index a3d970715872433d40572d98301b0309419876ab..4f980825d1aef1fe6151a5895d6051ae8a2c8563 100644 (file)
@@ -1281,7 +1281,7 @@ mod tests {
        use util::time::Time;
        use util::time::tests::SinceEpoch;
 
-       use ln::features::{ChannelFeatures, NodeFeatures};
+       use ln::channelmanager;
        use ln::msgs::{ChannelAnnouncement, ChannelUpdate, UnsignedChannelAnnouncement, UnsignedChannelUpdate};
        use routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId};
        use routing::router::RouteHop;
@@ -1372,7 +1372,7 @@ mod tests {
                let node_2_secret = &SecretKey::from_slice(&[40; 32]).unwrap();
                let secp_ctx = Secp256k1::new();
                let unsigned_announcement = UnsignedChannelAnnouncement {
-                       features: ChannelFeatures::known(),
+                       features: channelmanager::provided_channel_features(),
                        chain_hash: genesis_hash,
                        short_channel_id,
                        node_id_1: PublicKey::from_secret_key(&secp_ctx, &node_1_key),
@@ -1426,25 +1426,25 @@ mod tests {
                vec![
                        RouteHop {
                                pubkey: source_pubkey(),
-                               node_features: NodeFeatures::known(),
+                               node_features: channelmanager::provided_node_features(),
                                short_channel_id: 41,
-                               channel_features: ChannelFeatures::known(),
+                               channel_features: channelmanager::provided_channel_features(),
                                fee_msat: 1,
                                cltv_expiry_delta: 18,
                        },
                        RouteHop {
                                pubkey: target_pubkey(),
-                               node_features: NodeFeatures::known(),
+                               node_features: channelmanager::provided_node_features(),
                                short_channel_id: 42,
-                               channel_features: ChannelFeatures::known(),
+                               channel_features: channelmanager::provided_channel_features(),
                                fee_msat: 2,
                                cltv_expiry_delta: 18,
                        },
                        RouteHop {
                                pubkey: recipient_pubkey(),
-                               node_features: NodeFeatures::known(),
+                               node_features: channelmanager::provided_node_features(),
                                short_channel_id: 43,
-                               channel_features: ChannelFeatures::known(),
+                               channel_features: channelmanager::provided_channel_features(),
                                fee_msat: amount_msat,
                                cltv_expiry_delta: 18,
                        },