Skip to content

Commit d9b97e2

Browse files
committed
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.
1 parent dca5392 commit d9b97e2

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

bench/benches/bench.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ criterion_group!(benches,
2121
lightning_persister::fs_store::bench::bench_sends,
2222
lightning_rapid_gossip_sync::bench::bench_reading_full_graph_from_file,
2323
lightning::routing::gossip::benches::read_network_graph,
24-
lightning::routing::gossip::benches::write_network_graph);
24+
lightning::routing::gossip::benches::write_network_graph,
25+
lightning::routing::scoring::benches::decay_100k_channel_bounds);
2526
criterion_main!(benches);

lightning/src/routing/scoring.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,3 +3547,61 @@ mod tests {
35473547
Some(0.0));
35483548
}
35493549
}
3550+
3551+
#[cfg(ldk_bench)]
3552+
pub mod benches {
3553+
use super::*;
3554+
use criterion::Criterion;
3555+
use crate::routing::router::{bench_utils, RouteHop};
3556+
use crate::util::test_utils::TestLogger;
3557+
use crate::ln::features::{ChannelFeatures, NodeFeatures};
3558+
3559+
pub fn decay_100k_channel_bounds(bench: &mut Criterion) {
3560+
let logger = TestLogger::new();
3561+
let network_graph = bench_utils::read_network_graph(&logger).unwrap();
3562+
let mut scorer = ProbabilisticScorer::new(Default::default(), &network_graph, &logger);
3563+
// Score a number of random channels
3564+
let mut seed: u64 = 0xdeadbeef;
3565+
for _ in 0..100_000 {
3566+
seed = seed.overflowing_mul(6364136223846793005).0.overflowing_add(1).0;
3567+
let (victim, victim_dst, amt) = {
3568+
let rong = network_graph.read_only();
3569+
let channels = rong.channels();
3570+
let chan = channels.unordered_iter()
3571+
.skip((seed as usize) % channels.len())
3572+
.next().unwrap();
3573+
seed = seed.overflowing_mul(6364136223846793005).0.overflowing_add(1).0;
3574+
let amt = seed % chan.1.capacity_sats.map(|c| c * 1000)
3575+
.or(chan.1.one_to_two.as_ref().map(|info| info.htlc_maximum_msat))
3576+
.or(chan.1.two_to_one.as_ref().map(|info| info.htlc_maximum_msat))
3577+
.unwrap_or(1_000_000_000).saturating_add(1);
3578+
(*chan.0, chan.1.node_two, amt)
3579+
};
3580+
let path = Path {
3581+
hops: vec![RouteHop {
3582+
pubkey: victim_dst.as_pubkey().unwrap(),
3583+
node_features: NodeFeatures::empty(),
3584+
short_channel_id: victim,
3585+
channel_features: ChannelFeatures::empty(),
3586+
fee_msat: amt,
3587+
cltv_expiry_delta: 42,
3588+
maybe_announced_channel: true,
3589+
}],
3590+
blinded_tail: None
3591+
};
3592+
seed = seed.overflowing_mul(6364136223846793005).0.overflowing_add(1).0;
3593+
if seed % 1 == 0 {
3594+
scorer.probe_failed(&path, victim, Duration::ZERO);
3595+
} else {
3596+
scorer.probe_successful(&path, Duration::ZERO);
3597+
}
3598+
}
3599+
let mut cur_time = Duration::ZERO;
3600+
cur_time += Duration::from_millis(1);
3601+
scorer.decay_liquidity_certainty(cur_time);
3602+
bench.bench_function("decay_100k_channel_bounds", |b| b.iter(|| {
3603+
cur_time += Duration::from_millis(1);
3604+
scorer.decay_liquidity_certainty(cur_time);
3605+
}));
3606+
}
3607+
}

0 commit comments

Comments
 (0)