Skip to content

Commit bfc905c

Browse files
committed
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.
1 parent 2bba1d4 commit bfc905c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lightning/src/routing/router.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5433,7 +5433,7 @@ mod benches {
54335433
let mut routes = Vec::new();
54345434
let mut route_endpoints = Vec::new();
54355435
let mut seed: usize = 0xdeadbeef;
5436-
'load_endpoints: for _ in 0..100 {
5436+
'load_endpoints: for _ in 0..150 {
54375437
loop {
54385438
seed *= 0xdeadbeef;
54395439
let src = PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap();
@@ -5465,12 +5465,20 @@ mod benches {
54655465
}
54665466
}
54675467

5468+
// Because we've changed channel scores, its possible we'll take different routes to the
5469+
// selected destinations, possibly causing us to fail because, eg, the newly-selected path
5470+
// requires a too-high CLTV delta.
5471+
route_endpoints.retain(|(first_hop, params, amt)| {
5472+
get_route(&payer, params, &graph.read_only(), Some(&[first_hop]), *amt, 42, &DummyLogger{}, &scorer, &random_seed_bytes).is_ok()
5473+
});
5474+
route_endpoints.truncate(100);
5475+
assert_eq!(route_endpoints.len(), 100);
5476+
54685477
// ...then benchmark finding paths between the nodes we learned.
5469-
let mut idx = 0;
54705478
bench.iter(|| {
5471-
let (first_hop, params, amt) = &route_endpoints[idx % route_endpoints.len()];
5472-
assert!(get_route(&payer, params, &graph.read_only(), Some(&[first_hop]), *amt, 42, &DummyLogger{}, &scorer, &random_seed_bytes).is_ok());
5473-
idx += 1;
5479+
for (first_hop, params, amt) in route_endpoints.iter() {
5480+
assert!(get_route(&payer, params, &graph.read_only(), Some(&[first_hop]), *amt, 42, &DummyLogger{}, &scorer, &random_seed_bytes).is_ok());
5481+
}
54745482
});
54755483
}
54765484
}

0 commit comments

Comments
 (0)