From: Jeffrey Czyz Date: Mon, 17 Jan 2022 03:07:57 +0000 (-0600) Subject: Benchmark router using a scorer seeded with data X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=20f41dfe060d24f330565e69e8302c309b5920d4;p=rust-lightning 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. --- diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 0e4e96a82..65a9e143e 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 payee = Payee::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, &payee, &graph, Some(&[&first_hop]), amt, 42, &DummyLogger{}, &scorer).is_ok() { - path_endpoints.push((first_hop, payee, amt)); + if let Ok(route) = get_route(&payer, &payee, &graph, Some(&[&first_hop]), amt, 42, &DummyLogger{}, &scorer) { + routes.push(route); + route_endpoints.push((first_hop, payee, 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, payee, amt) = &path_endpoints[idx % path_endpoints.len()]; + let (first_hop, payee, amt) = &route_endpoints[idx % route_endpoints.len()]; assert!(get_route(&payer, payee, &graph, Some(&[first_hop]), *amt, 42, &DummyLogger{}, &scorer).is_ok()); idx += 1; });