From 4512fd36850c6499e00d0a01f8b53635e5b7dcfe Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Sun, 16 Jan 2022 21:07:57 -0600 Subject: [PATCH] Benchmark router using a scorer seeded with data Scorers may have different performance characteristics after seeing failed and successful paths. Seed the scorer with some random data before executing the benchmark in order to exercise such behavior. --- lightning/src/routing/router.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 49d82f344..8e3b5ae8f 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -5032,13 +5032,14 @@ mod benches { } fn generate_routes( - bench: &mut Bencher, graph: &NetworkGraph, scorer: S, features: InvoiceFeatures + bench: &mut Bencher, graph: &NetworkGraph, mut scorer: S, features: InvoiceFeatures ) { let nodes = graph.read_only().nodes().clone(); let payer = payer_pubkey(); // First, get 100 (source, destination) pairs for which route-getting actually succeeds... - let mut path_endpoints = Vec::new(); + let mut routes = Vec::new(); + let mut route_endpoints = Vec::new(); let mut seed: usize = 0xdeadbeef; 'load_endpoints: for _ in 0..100 { loop { @@ -5049,17 +5050,33 @@ mod benches { let params = PaymentParameters::from_node_id(dst).with_features(features.clone()); let first_hop = first_hop(src); let amt = seed as u64 % 1_000_000; - if get_route(&payer, ¶ms, &graph, Some(&[&first_hop]), amt, 42, &DummyLogger{}, &scorer).is_ok() { - path_endpoints.push((first_hop, params, amt)); + if let Ok(route) = get_route(&payer, ¶ms, &graph, Some(&[&first_hop]), amt, 42, &DummyLogger{}, &scorer) { + routes.push(route); + route_endpoints.push((first_hop, params, amt)); continue 'load_endpoints; } } } + // ...and seed the scorer with success and failure data... + for route in routes { + let amount = route.get_total_amount(); + if amount < 250_000 { + for path in route.paths { + scorer.payment_path_successful(&path.iter().collect::>()); + } + } else if amount > 750_000 { + for path in route.paths { + let short_channel_id = path[path.len() / 2].short_channel_id; + scorer.payment_path_failed(&path.iter().collect::>(), short_channel_id); + } + } + } + // ...then benchmark finding paths between the nodes we learned. let mut idx = 0; bench.iter(|| { - let (first_hop, params, amt) = &path_endpoints[idx % path_endpoints.len()]; + let (first_hop, params, amt) = &route_endpoints[idx % route_endpoints.len()]; assert!(get_route(&payer, params, &graph, Some(&[first_hop]), *amt, 42, &DummyLogger{}, &scorer).is_ok()); idx += 1; }); -- 2.39.5