]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Make routing benchmark robust against path changes
authorMatt Corallo <git@bluematt.me>
Thu, 10 Mar 2022 21:07:37 +0000 (21:07 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 16 Mar 2022 22:10:46 +0000 (22:10 +0000)
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

index d6aef902f0c1f28bddd8ad23279324410cd988d6..582b6f24491069be1402513d2fa7343e2650c5a7 100644 (file)
@@ -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(|| {