Skip to content

Make generate_test_routes deterministic based on its seed #3754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lightning/src/routing/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8843,16 +8843,20 @@ pub(crate) mod bench_utils {
let payer = payer_pubkey();
let random_seed_bytes = [42; 32];

let nodes = graph.read_only().nodes().clone();
let mut nodes = graph.read_only().nodes().clone();
let mut route_endpoints = Vec::new();
for _ in 0..route_count {
loop {
seed = seed.overflowing_mul(6364136223846793005).0.overflowing_add(1).0;
let src = PublicKey::from_slice(nodes.unordered_keys()
.skip((seed as usize) % nodes.len()).next().unwrap().as_slice()).unwrap();
let src_idx = (seed as usize) % nodes.len();
let src_key = nodes.range(..).skip(src_idx).next().unwrap().0;
let src = PublicKey::from_slice(src_key.as_slice()).unwrap();

seed = seed.overflowing_mul(6364136223846793005).0.overflowing_add(1).0;
let dst = PublicKey::from_slice(nodes.unordered_keys()
.skip((seed as usize) % nodes.len()).next().unwrap().as_slice()).unwrap();
let dst_idx = (seed as usize) % nodes.len();
let dst_key = nodes.range(..).skip(dst_idx).next().unwrap().0;
let dst = PublicKey::from_slice(dst_key.as_slice()).unwrap();

let params = PaymentParameters::from_node_id(dst, 42)
.with_bolt11_features(features.clone()).unwrap();
let first_hop = first_hop(src);
Expand Down
Loading