From fef8acf70c3b27927e0c51b7a36e78be6d76bb11 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 10 Mar 2022 21:07:37 +0000 Subject: [PATCH] Make routing benchmark robust against path changes If the scoring in the routing benchmark causes us to take a different path from the original scan, we may end up deciding that the only path to a node has a too-high total CLTV delta, causing us to panic in the benchmarking phase. Here we simply check for that possibility and remove paths that fail post-scoring. --- lightning/src/routing/router.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index d6aef902..582b6f24 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -5433,7 +5433,7 @@ mod benches { let mut routes = Vec::new(); let mut route_endpoints = Vec::new(); let mut seed: usize = 0xdeadbeef; - 'load_endpoints: for _ in 0..100 { + 'load_endpoints: for _ in 0..150 { loop { seed *= 0xdeadbeef; let src = PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap(); @@ -5465,6 +5465,15 @@ mod benches { } } + // Because we've changed channel scores, its possible we'll take different routes to the + // selected destinations, possibly causing us to fail because, eg, the newly-selected path + // requires a too-high CLTV delta. + route_endpoints.retain(|(first_hop, params, amt)| { + get_route(&payer, params, &graph.read_only(), Some(&[first_hop]), *amt, 42, &DummyLogger{}, &scorer, &random_seed_bytes).is_ok() + }); + route_endpoints.truncate(100); + assert_eq!(route_endpoints.len(), 100); + // ...then benchmark finding paths between the nodes we learned. let mut idx = 0; bench.iter(|| { -- 2.30.2