From: Matt Corallo Date: Thu, 8 Sep 2022 21:04:11 +0000 (+0000) Subject: Stop relying on the `*Features::known` method in `routing` tests X-Git-Tag: v0.0.112~37^2~11 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=1a3273792b0b97fbdf0f5339f3d6fdbfb04e5e7d;p=rust-lightning Stop relying on the `*Features::known` method in `routing` tests 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. --- diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 6504b590e..f5c56ce4b 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -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: F, node_key: &SecretKey, secp_ctx: &Secp256k1) -> 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]), diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 4c00dc5fc..8fdc92ba8 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -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( diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index a3d970715..4f980825d 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -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, },