]> git.bitcoin.ninja Git - rust-lightning/commitdiff
f - Use FixedPenaltyScorer in tests
authorJeffrey Czyz <jkczyz@gmail.com>
Thu, 20 Jan 2022 06:41:04 +0000 (00:41 -0600)
committerJeffrey Czyz <jkczyz@gmail.com>
Thu, 20 Jan 2022 22:17:15 +0000 (16:17 -0600)
12 files changed:
fuzz/src/full_stack.rs
fuzz/src/router.rs
lightning-background-processor/src/lib.rs
lightning-invoice/src/utils.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/payment_tests.rs
lightning/src/ln/shutdown_tests.rs
lightning/src/routing/router.rs
lightning/src/routing/scoring.rs
lightning/src/util/test_utils.rs

index 34c6f554c18e3a550759415f649e872c002383b3..e8e40cd29b2bb64c11661806a5bd132ebb4dbdb1 100644 (file)
@@ -39,7 +39,7 @@ use lightning::ln::msgs::DecodeError;
 use lightning::ln::script::ShutdownScript;
 use lightning::routing::network_graph::{NetGraphMsgHandler, NetworkGraph};
 use lightning::routing::router::{find_route, Payee, RouteParameters};
-use lightning::routing::scoring::Scorer;
+use lightning::routing::scoring::FixedPenaltyScorer;
 use lightning::util::config::UserConfig;
 use lightning::util::errors::APIError;
 use lightning::util::events::Event;
@@ -390,7 +390,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
        let our_id = PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret());
        let network_graph = Arc::new(NetworkGraph::new(genesis_block(network).block_hash()));
        let net_graph_msg_handler = Arc::new(NetGraphMsgHandler::new(Arc::clone(&network_graph), None, Arc::clone(&logger)));
-       let scorer = Scorer::with_fixed_penalty(0);
+       let scorer = FixedPenaltyScorer::with_penalty(0);
 
        let peers = RefCell::new([false; 256]);
        let mut loss_detector = MoneyLossDetector::new(&peers, channelmanager.clone(), monitor.clone(), PeerManager::new(MessageHandler {
index d6aa97e42e7fc3939c327501017080b03e2552cb..45f562dab1bc48efbb5a4ab61d7e87ace4bdfca6 100644 (file)
@@ -17,7 +17,7 @@ use lightning::ln::channelmanager::{ChannelDetails, ChannelCounterparty};
 use lightning::ln::features::InitFeatures;
 use lightning::ln::msgs;
 use lightning::routing::router::{find_route, Payee, RouteHint, RouteHintHop, RouteParameters};
-use lightning::routing::scoring::Scorer;
+use lightning::routing::scoring::FixedPenaltyScorer;
 use lightning::util::logger::Logger;
 use lightning::util::ser::Readable;
 use lightning::routing::network_graph::{NetworkGraph, RoutingFees};
@@ -249,7 +249,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                                }]));
                                        }
                                }
-                               let scorer = Scorer::with_fixed_penalty(0);
+                               let scorer = FixedPenaltyScorer::with_penalty(0);
                                for target in node_pks.iter() {
                                        let params = RouteParameters {
                                                payee: Payee::from_node_id(*target).with_route_hints(last_hops.clone()),
index 2dbc8053b4eb1247e5d64dc482e1817ad5db08ec..0aaa43d7e9b673031dcb5030fff5194f46df16f8 100644 (file)
@@ -658,7 +658,7 @@ mod tests {
                let data_dir = nodes[0].persister.get_data_dir();
                let persister = move |node: &ChannelManager<InMemorySigner, Arc<ChainMonitor>, Arc<test_utils::TestBroadcaster>, Arc<KeysManager>, Arc<test_utils::TestFeeEstimator>, Arc<test_utils::TestLogger>>| FilesystemPersister::persist_manager(data_dir.clone(), node);
                let router = DefaultRouter::new(Arc::clone(&nodes[0].network_graph), Arc::clone(&nodes[0].logger));
-               let scorer = Arc::new(Mutex::new(test_utils::TestScorer::default()));
+               let scorer = Arc::new(Mutex::new(test_utils::TestScorer::with_penalty(0)));
                let invoice_payer = Arc::new(InvoicePayer::new(Arc::clone(&nodes[0].node), router, scorer, Arc::clone(&nodes[0].logger), |_: &_| {}, RetryAttempts(2)));
                let event_handler = Arc::clone(&invoice_payer);
                let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone());
index ffa84c98ef6191045a719a1d25aa7215ecabd186..e4267b44ccd9b31842f8d5cc829367b70b4702ed 100644 (file)
@@ -228,7 +228,7 @@ mod test {
                let first_hops = nodes[0].node.list_usable_channels();
                let network_graph = node_cfgs[0].network_graph;
                let logger = test_utils::TestLogger::new();
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let route = find_route(
                        &nodes[0].node.get_our_node_id(), &params, network_graph,
                        Some(&first_hops.iter().collect::<Vec<_>>()), &logger, &scorer,
index 77e9152d4c1d3ad5af0ff6283345301261d3dcbe..3e55fe913cf444e29ab25b7a4f90b70755b8912f 100644 (file)
@@ -6895,7 +6895,7 @@ mod tests {
                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::known(), InitFeatures::known());
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // To start (1), send a regular payment but don't claim it.
                let expected_route = [&nodes[1]];
@@ -7000,7 +7000,7 @@ mod tests {
                };
                let network_graph = nodes[0].network_graph;
                let first_hops = nodes[0].node.list_usable_channels();
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let route = find_route(
                        &payer_pubkey, &params, network_graph, Some(&first_hops.iter().collect::<Vec<_>>()),
                        nodes[0].logger, &scorer
@@ -7043,7 +7043,7 @@ mod tests {
                };
                let network_graph = nodes[0].network_graph;
                let first_hops = nodes[0].node.list_usable_channels();
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let route = find_route(
                        &payer_pubkey, &params, network_graph, Some(&first_hops.iter().collect::<Vec<_>>()),
                        nodes[0].logger, &scorer
@@ -7137,7 +7137,6 @@ pub mod bench {
        use ln::msgs::{ChannelMessageHandler, Init};
        use routing::network_graph::NetworkGraph;
        use routing::router::{Payee, get_route};
-       use routing::scoring::Scorer;
        use util::test_utils;
        use util::config::UserConfig;
        use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose};
@@ -7247,7 +7246,7 @@ pub mod bench {
                                let usable_channels = $node_a.list_usable_channels();
                                let payee = Payee::from_node_id($node_b.get_our_node_id())
                                        .with_features(InvoiceFeatures::known());
-                               let scorer = Scorer::with_fixed_penalty(0);
+                               let scorer = test_utils::TestScorer::with_penalty(0);
                                let route = get_route(&$node_a.get_our_node_id(), &payee, &dummy_graph,
                                        Some(&usable_channels.iter().map(|r| r).collect::<Vec<_>>()), 10_000, TEST_FINAL_CLTV, &logger_a, &scorer).unwrap();
 
index 2e8994b5880284337e19f62dcdc18cd0ab03c726..b544936cea510015e744b204dd447d81a5532d36 100644 (file)
@@ -1078,7 +1078,7 @@ macro_rules! get_route_and_payment_hash {
                let payee = $crate::routing::router::Payee::from_node_id($recv_node.node.get_our_node_id())
                        .with_features($crate::ln::features::InvoiceFeatures::known())
                        .with_route_hints($last_hops);
-               let scorer = $crate::util::test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = $crate::util::test_utils::TestScorer::with_penalty(0);
                let route = $crate::routing::router::get_route(
                        &$send_node.node.get_our_node_id(), &payee, $send_node.network_graph,
                        Some(&$send_node.node.list_usable_channels().iter().collect::<Vec<_>>()),
@@ -1533,7 +1533,7 @@ pub const TEST_FINAL_CLTV: u32 = 70;
 pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash, PaymentSecret) {
        let payee = Payee::from_node_id(expected_route.last().unwrap().node.get_our_node_id())
                .with_features(InvoiceFeatures::known());
-       let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+       let scorer = test_utils::TestScorer::with_penalty(0);
        let route = get_route(
                &origin_node.node.get_our_node_id(), &payee, &origin_node.network_graph,
                Some(&origin_node.node.list_usable_channels().iter().collect::<Vec<_>>()),
@@ -1551,7 +1551,7 @@ pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
 pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64)  {
        let payee = Payee::from_node_id(expected_route.last().unwrap().node.get_our_node_id())
                .with_features(InvoiceFeatures::known());
-       let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+       let scorer = test_utils::TestScorer::with_penalty(0);
        let route = get_route(&origin_node.node.get_our_node_id(), &payee, origin_node.network_graph, None, recv_value, TEST_FINAL_CLTV, origin_node.logger, &scorer).unwrap();
        assert_eq!(route.paths.len(), 1);
        assert_eq!(route.paths[0].len(), expected_route.len());
index 0993caf4c1d1bd74708ed35c66be20e107f6f78e..fc5260fe9cba565d483d26f469d4be4a478abafa 100644 (file)
@@ -7350,7 +7350,7 @@ fn test_check_htlc_underpaying() {
        // Create some initial channels
        create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
 
-       let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+       let scorer = test_utils::TestScorer::with_penalty(0);
        let payee = Payee::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
        let route = get_route(&nodes[0].node.get_our_node_id(), &payee, nodes[0].network_graph, None, 10_000, TEST_FINAL_CLTV, nodes[0].logger, &scorer).unwrap();
        let (_, our_payment_hash, _) = get_payment_preimage_hash!(nodes[0]);
@@ -7753,7 +7753,7 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
        let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::known(), InitFeatures::known());
        // Lock HTLC in both directions (using a slightly lower CLTV delay to provide timely RBF bumps)
        let payee = Payee::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
-       let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+       let scorer = test_utils::TestScorer::with_penalty(0);
        let route = get_route(&nodes[0].node.get_our_node_id(), &payee, &nodes[0].network_graph, None,
                3_000_000, 50, nodes[0].logger, &scorer).unwrap();
        let payment_preimage = send_along_route(&nodes[0], route, &[&nodes[1]], 3_000_000).0;
@@ -9290,7 +9290,7 @@ fn test_keysend_payments_to_public_node() {
                final_value_msat: 10000,
                final_cltv_expiry_delta: 40,
        };
-       let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+       let scorer = test_utils::TestScorer::with_penalty(0);
        let route = find_route(&payer_pubkey, &params, network_graph, None, nodes[0].logger, &scorer).unwrap();
 
        let test_preimage = PaymentPreimage([42; 32]);
@@ -9324,7 +9324,7 @@ fn test_keysend_payments_to_private_node() {
        };
        let network_graph = nodes[0].network_graph;
        let first_hops = nodes[0].node.list_usable_channels();
-       let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+       let scorer = test_utils::TestScorer::with_penalty(0);
        let route = find_route(
                &payer_pubkey, &params, network_graph, Some(&first_hops.iter().collect::<Vec<_>>()),
                nodes[0].logger, &scorer
index 960a255e998d939e474d652be8f14072d9da25db..a3130af40b5b42152bc22b52bf21c7e0fe15c1c0 100644 (file)
@@ -723,7 +723,7 @@ fn get_ldk_payment_preimage() {
 
        let payee = Payee::from_node_id(nodes[1].node.get_our_node_id())
                .with_features(InvoiceFeatures::known());
-       let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+       let scorer = test_utils::TestScorer::with_penalty(0);
        let route = get_route(
                &nodes[0].node.get_our_node_id(), &payee, &nodes[0].network_graph,
                Some(&nodes[0].node.list_usable_channels().iter().collect::<Vec<_>>()),
index 7afc982faabd3b8975646ea8f669172887974340..f3a07f99c5468f8c9fbdc2f627f397a777d8f1f7 100644 (file)
@@ -76,7 +76,7 @@ fn updates_shutdown_wait() {
        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 logger = test_utils::TestLogger::new();
-       let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+       let scorer = test_utils::TestScorer::with_penalty(0);
 
        let (payment_preimage, _, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 100000);
 
index 4955ecc303c2028a29b48273de0fcd0f39d10c74..9b308ee00e1bee13e054e06068902950115a26f0 100644 (file)
@@ -2003,7 +2003,7 @@ mod tests {
                let (secp_ctx, network_graph, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
                let payee = Payee::from_node_id(nodes[2]);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // Simple route to 2 via 1
 
@@ -2034,7 +2034,7 @@ mod tests {
                let (secp_ctx, network_graph, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
                let payee = Payee::from_node_id(nodes[2]);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // Simple route to 2 via 1
 
@@ -2053,7 +2053,7 @@ mod tests {
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
                let payee = Payee::from_node_id(nodes[2]);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // Simple route to 2 via 1
 
@@ -2178,7 +2178,7 @@ mod tests {
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
                let payee = Payee::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // A route to node#2 via two paths.
                // One path allows transferring 35-40 sats, another one also allows 35-40 sats.
@@ -2314,7 +2314,7 @@ mod tests {
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
                let payee = Payee::from_node_id(nodes[2]);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // // Disable channels 4 and 12 by flags=2
                update_channel(&net_graph_msg_handler, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
@@ -2372,7 +2372,7 @@ mod tests {
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
                let payee = Payee::from_node_id(nodes[2]);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // Disable nodes 1, 2, and 8 by requiring unknown feature bits
                let unknown_features = NodeFeatures::known().set_unknown_feature_required();
@@ -2413,7 +2413,7 @@ mod tests {
        fn our_chans_test() {
                let (secp_ctx, network_graph, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // Route to 1 via 2 and 3 because our channel to 1 is disabled
                let payee = Payee::from_node_id(nodes[0]);
@@ -2542,7 +2542,7 @@ mod tests {
        fn partial_route_hint_test() {
                let (secp_ctx, network_graph, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // Simple test across 2, 3, 5, and 4 via a last_hop channel
                // Tests the behaviour when the RouteHint contains a suboptimal hop.
@@ -2641,7 +2641,7 @@ mod tests {
                let (secp_ctx, network_graph, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
                let payee = Payee::from_node_id(nodes[6]).with_route_hints(empty_last_hop(&nodes));
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // Test handling of an empty RouteHint passed in Invoice.
 
@@ -2723,7 +2723,7 @@ mod tests {
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
                let payee = Payee::from_node_id(nodes[6]).with_route_hints(multi_hint_last_hops(&nodes));
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                // Test through channels 2, 3, 5, 8.
                // Test shows that multiple hop hints are considered.
 
@@ -2829,7 +2829,7 @@ mod tests {
                let (secp_ctx, network_graph, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
                let payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops_with_public_channel(&nodes));
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                // This test shows that public routes can be present in the invoice
                // which would be handled in the same manner.
 
@@ -2878,7 +2878,7 @@ mod tests {
        fn our_chans_last_hop_connect_test() {
                let (secp_ctx, network_graph, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // Simple test with outbound channel to 4 to test that last_hops and first_hops connect
                let our_chans = vec![get_channel_details(Some(42), nodes[3].clone(), InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)];
@@ -2999,7 +2999,7 @@ mod tests {
                }]);
                let payee = Payee::from_node_id(target_node_id).with_route_hints(vec![last_hops]);
                let our_chans = vec![get_channel_details(Some(42), middle_node_id, InitFeatures::from_le_bytes(vec![0b11]), outbound_capacity_msat)];
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                get_route(&source_node_id, &payee, &NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()), Some(&our_chans.iter().collect::<Vec<_>>()), route_val, 42, &test_utils::TestLogger::new(), &scorer)
        }
 
@@ -3053,7 +3053,7 @@ mod tests {
 
                let (secp_ctx, network_graph, mut net_graph_msg_handler, chain_monitor, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
 
                // We will use a simple single-path route from
@@ -3325,7 +3325,7 @@ mod tests {
                // one of the latter hops is limited.
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[3]).with_features(InvoiceFeatures::known());
 
                // Path via {node7, node2, node4} is channels {12, 13, 6, 11}.
@@ -3448,7 +3448,7 @@ mod tests {
        fn ignore_fee_first_hop_test() {
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[2]);
 
                // Path via node0 is channels {1, 3}. Limit them to 100 and 50 sats (total limit 50).
@@ -3494,7 +3494,7 @@ mod tests {
        fn simple_mpp_route_test() {
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
 
                // We need a route consisting of 3 paths:
@@ -3625,7 +3625,7 @@ mod tests {
        fn long_mpp_route_test() {
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[3]).with_features(InvoiceFeatures::known());
 
                // We need a route consisting of 3 paths:
@@ -3787,7 +3787,7 @@ mod tests {
        fn mpp_cheaper_route_test() {
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[3]).with_features(InvoiceFeatures::known());
 
                // This test checks that if we have two cheaper paths and one more expensive path,
@@ -3954,7 +3954,7 @@ mod tests {
                // if the fee is not properly accounted for, the behavior is different.
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[3]).with_features(InvoiceFeatures::known());
 
                // We need a route consisting of 2 paths:
@@ -4133,7 +4133,7 @@ mod tests {
                // This bug appeared in production in some specific channel configurations.
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(PublicKey::from_slice(&[02; 33]).unwrap()).with_features(InvoiceFeatures::known())
                        .with_route_hints(vec![RouteHint(vec![RouteHintHop {
                                src_node_id: nodes[2],
@@ -4221,7 +4221,7 @@ mod tests {
                // path finding we realize that we found more capacity than we need.
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
 
                // We need a route consisting of 3 paths:
@@ -4378,7 +4378,7 @@ mod tests {
                let network_graph = Arc::new(NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash()));
                let net_graph_msg_handler = NetGraphMsgHandler::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[6]);
 
                add_channel(&net_graph_msg_handler, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6);
@@ -4507,7 +4507,7 @@ mod tests {
                // we calculated fees on a higher value, resulting in us ignoring such paths.
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, _, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[2]);
 
                // We modify the graph to set the htlc_maximum of channel 2 to below the value we wish to
@@ -4569,7 +4569,7 @@ mod tests {
                // resulting in us thinking there is no possible path, even if other paths exist.
                let (secp_ctx, network_graph, net_graph_msg_handler, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
 
                // We modify the graph to set the htlc_minimum of channel 2 and 4 as needed - channel 2
@@ -4636,7 +4636,7 @@ mod tests {
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
                let logger = Arc::new(test_utils::TestLogger::new());
                let network_graph = NetworkGraph::new(genesis_block(Network::Testnet).header.block_hash());
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let payee = Payee::from_node_id(nodes[0]).with_features(InvoiceFeatures::known());
 
                {
@@ -4677,7 +4677,7 @@ mod tests {
                let payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes));
 
                // Without penalizing each hop 100 msats, a longer path with lower fees is chosen.
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let route = get_route(
                        &our_id, &payee, &network_graph, None, 100, 42,
                        Arc::clone(&logger), &scorer
@@ -4690,7 +4690,7 @@ mod tests {
 
                // Applying a 100 msat penalty to each hop results in taking channels 7 and 10 to nodes[6]
                // from nodes[2] rather than channel 6, 11, and 8, even though the longer path is cheaper.
-               let scorer = test_utils::TestScorer::with_fixed_penalty(100);
+               let scorer = test_utils::TestScorer::with_penalty(100);
                let route = get_route(
                        &our_id, &payee, &network_graph, None, 100, 42,
                        Arc::clone(&logger), &scorer
@@ -4744,7 +4744,7 @@ mod tests {
                let payee = Payee::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes));
 
                // A path to nodes[6] exists when no penalties are applied to any channel.
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
                let route = get_route(
                        &our_id, &payee, &network_graph, None, 100, 42,
                        Arc::clone(&logger), &scorer
@@ -4856,7 +4856,7 @@ mod tests {
                let (secp_ctx, network_graph, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
 
-               let scorer = test_utils::TestScorer::with_fixed_penalty(0);
+               let scorer = test_utils::TestScorer::with_penalty(0);
 
                // Make sure that generally there is at least one route available
                let feasible_max_total_cltv_delta = 1008;
@@ -4990,7 +4990,7 @@ mod benches {
        use chain::transaction::OutPoint;
        use ln::channelmanager::{ChannelCounterparty, ChannelDetails};
        use ln::features::{InitFeatures, InvoiceFeatures};
-       use routing::scoring::Scorer;
+       use routing::scoring::{FixedPenaltyScorer, Scorer};
        use util::logger::{Logger, Record};
 
        use test::Bencher;
@@ -5000,15 +5000,6 @@ mod benches {
                fn log(&self, _record: &Record) {}
        }
 
-       struct ZeroPenaltyScorer;
-       impl Score for ZeroPenaltyScorer {
-               fn channel_penalty_msat(
-                       &self, _short_channel_id: u64, _send_amt: u64, _capacity_msat: u64, _source: &NodeId, _target: &NodeId
-               ) -> u64 { 0 }
-               fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
-               fn payment_path_successful(&mut self, _path: &[&RouteHop]) {}
-       }
-
        fn read_network_graph() -> NetworkGraph {
                let mut d = test_utils::get_route_file().unwrap();
                NetworkGraph::read(&mut d).unwrap()
@@ -5051,14 +5042,14 @@ mod benches {
        #[bench]
        fn generate_routes_with_zero_penalty_scorer(bench: &mut Bencher) {
                let network_graph = read_network_graph();
-               let scorer = ZeroPenaltyScorer;
+               let scorer = FixedPenaltyScorer::with_penalty(0);
                generate_routes(bench, &network_graph, scorer, InvoiceFeatures::empty());
        }
 
        #[bench]
        fn generate_mpp_routes_with_zero_penalty_scorer(bench: &mut Bencher) {
                let network_graph = read_network_graph();
-               let scorer = ZeroPenaltyScorer;
+               let scorer = FixedPenaltyScorer::with_penalty(0);
                generate_routes(bench, &network_graph, scorer, InvoiceFeatures::known());
        }
 
index 311ddadac3d51b2c983745f9bb543ace72109265..acac35ab3359aa3f6e13f73a4a915ab695f0c5d3 100644 (file)
@@ -190,6 +190,28 @@ impl<'a, S: Writeable> Writeable for MutexGuard<'a, S> {
        }
 }
 
+/// [`Score`] implementation that uses a fixed penalty.
+pub struct FixedPenaltyScorer {
+       penalty_msat: u64,
+}
+
+impl FixedPenaltyScorer {
+       /// Creates a new scorer using `penalty_msat`.
+       pub fn with_penalty(penalty_msat: u64) -> Self {
+               Self { penalty_msat }
+       }
+}
+
+impl Score for FixedPenaltyScorer {
+       fn channel_penalty_msat( &self, _: u64, _: u64, _: u64, _: &NodeId, _: &NodeId) -> u64 {
+               self.penalty_msat
+       }
+
+       fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
+
+       fn payment_path_successful(&mut self, _path: &[&RouteHop]) {}
+}
+
 /// [`Score`] implementation that provides reasonable default behavior.
 ///
 /// Used to apply a fixed penalty to each channel, thus avoiding long paths when shorter paths with
@@ -306,18 +328,6 @@ impl<T: Time> ScorerUsingTime<T> {
                        channel_failures: HashMap::new(),
                }
        }
-
-       /// Creates a new scorer using `penalty_msat` as a fixed channel penalty.
-       #[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))]
-       pub fn with_fixed_penalty(penalty_msat: u64) -> Self {
-               Self::new(ScoringParameters {
-                       base_penalty_msat: penalty_msat,
-                       failure_penalty_msat: 0,
-                       failure_penalty_half_life: Duration::from_secs(0),
-                       overuse_penalty_start_1024th: 1024,
-                       overuse_penalty_msat_per_1024th: 0,
-               })
-       }
 }
 
 impl<T: Time> ChannelFailure<T> {
index 5b3865eda04fca2a864933b978485cab46d800d2..59e7c70c0e3148a6a5f4c655ee9c8aab45de3d64 100644 (file)
@@ -21,8 +21,7 @@ use ln::features::{ChannelFeatures, InitFeatures};
 use ln::msgs;
 use ln::msgs::OptionalField;
 use ln::script::ShutdownScript;
-use routing::scoring::ScorerUsingTime;
-use routing::scoring::time::Eternity;
+use routing::scoring::FixedPenaltyScorer;
 use util::enforcing_trait_impls::{EnforcingSigner, EnforcementState};
 use util::events;
 use util::logger::{Logger, Level, Record};
@@ -722,4 +721,4 @@ impl core::fmt::Debug for OnRegisterOutput {
 }
 
 /// A scorer useful in testing, when the passage of time isn't a concern.
-pub type TestScorer = ScorerUsingTime<Eternity>;
+pub type TestScorer = FixedPenaltyScorer;