From: Matt Corallo Date: Mon, 9 Oct 2023 03:23:55 +0000 (+0000) Subject: Add a benchmark for decaying a 100k channel scorer's liquidity info X-Git-Tag: v0.0.119~4^2~4 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=40b4094e878413aa16e656462554c3ffc30918a2;p=rust-lightning Add a benchmark for decaying a 100k channel scorer's liquidity info This is a good gut-check to ensure we don't end up taking a ton of time decaying channel liquidity info. It currently clocks in around 1.25ms on an i7-1360P. --- diff --git a/bench/benches/bench.rs b/bench/benches/bench.rs index eaa3fcec5..b854ffb93 100644 --- a/bench/benches/bench.rs +++ b/bench/benches/bench.rs @@ -21,5 +21,6 @@ criterion_group!(benches, lightning_persister::fs_store::bench::bench_sends, lightning_rapid_gossip_sync::bench::bench_reading_full_graph_from_file, lightning::routing::gossip::benches::read_network_graph, - lightning::routing::gossip::benches::write_network_graph); + lightning::routing::gossip::benches::write_network_graph, + lightning::routing::scoring::benches::decay_100k_channel_bounds); criterion_main!(benches); diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index d6b1f4458..cf1393873 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -3748,3 +3748,61 @@ mod tests { Some(0.0)); } } + +#[cfg(ldk_bench)] +pub mod benches { + use super::*; + use criterion::Criterion; + use crate::routing::router::{bench_utils, RouteHop}; + use crate::util::test_utils::TestLogger; + use crate::ln::features::{ChannelFeatures, NodeFeatures}; + + pub fn decay_100k_channel_bounds(bench: &mut Criterion) { + let logger = TestLogger::new(); + let network_graph = bench_utils::read_network_graph(&logger).unwrap(); + let mut scorer = ProbabilisticScorer::new(Default::default(), &network_graph, &logger); + // Score a number of random channels + let mut seed: u64 = 0xdeadbeef; + for _ in 0..100_000 { + seed = seed.overflowing_mul(6364136223846793005).0.overflowing_add(1).0; + let (victim, victim_dst, amt) = { + let rong = network_graph.read_only(); + let channels = rong.channels(); + let chan = channels.unordered_iter() + .skip((seed as usize) % channels.len()) + .next().unwrap(); + seed = seed.overflowing_mul(6364136223846793005).0.overflowing_add(1).0; + let amt = seed % chan.1.capacity_sats.map(|c| c * 1000) + .or(chan.1.one_to_two.as_ref().map(|info| info.htlc_maximum_msat)) + .or(chan.1.two_to_one.as_ref().map(|info| info.htlc_maximum_msat)) + .unwrap_or(1_000_000_000).saturating_add(1); + (*chan.0, chan.1.node_two, amt) + }; + let path = Path { + hops: vec![RouteHop { + pubkey: victim_dst.as_pubkey().unwrap(), + node_features: NodeFeatures::empty(), + short_channel_id: victim, + channel_features: ChannelFeatures::empty(), + fee_msat: amt, + cltv_expiry_delta: 42, + maybe_announced_channel: true, + }], + blinded_tail: None + }; + seed = seed.overflowing_mul(6364136223846793005).0.overflowing_add(1).0; + if seed % 1 == 0 { + scorer.probe_failed(&path, victim, Duration::ZERO); + } else { + scorer.probe_successful(&path, Duration::ZERO); + } + } + let mut cur_time = Duration::ZERO; + cur_time += Duration::from_millis(1); + scorer.decay_liquidity_certainty(cur_time); + bench.bench_function("decay_100k_channel_bounds", |b| b.iter(|| { + cur_time += Duration::from_millis(1); + scorer.decay_liquidity_certainty(cur_time); + })); + } +}