Skip to content

Commit 29d0644

Browse files
committed
Fetch network graph cache and run benchmarks on CI
1 parent ff5b400 commit 29d0644

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

.github/workflows/build.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,39 @@ jobs:
126126
token: f421b687-4dc2-4387-ac3d-dc3b2528af57
127127
fail_ci_if_error: true
128128

129+
benchmark:
130+
runs-on: ubuntu-latest
131+
env:
132+
TOOLCHAIN: nightly
133+
steps:
134+
- name: Checkout source code
135+
uses: actions/checkout@v2
136+
- name: Install Rust ${{ env.TOOLCHAIN }} toolchain
137+
uses: actions-rs/toolchain@v1
138+
with:
139+
toolchain: ${{ env.TOOLCHAIN }}
140+
override: true
141+
profile: minimal
142+
- name: Cache routing graph snapshot
143+
id: cache-graph
144+
uses: actions/cache@v2
145+
with:
146+
path: lightning/net_graph-2021-02-12.bin
147+
key: net_graph-2021-02-12
148+
- name: Fetch routing graph snapshot
149+
if: steps.cache-graph.outputs.cache-hit != 'true'
150+
run: |
151+
wget -O lightning/net_graph-2021-02-12.bin https://bitcoin.ninja/ldk-net_graph-879e309c128-2020-02-12.bin
152+
if [ "$(sha256sum lightning/net_graph-2021-02-12.bin | awk '{ print $1 }')" != "890a1f80dfb6ef674a1e4ff0f23cd73d740731c395f99d85abbede0cfbb701ab" ]; then
153+
echo "Bad hash"
154+
exit 1
155+
fi
156+
- name: Run benchmarks on Rust ${{ matrix.toolchain }}
157+
run: |
158+
cd lightning
159+
cargo bench --features unstable
160+
cd ..
161+
129162
check_commits:
130163
runs-on: ubuntu-latest
131164
env:

lightning/src/routing/router.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,16 +1295,31 @@ mod benches {
12951295

12961296
#[bench]
12971297
fn generate_routes(bench: &mut Bencher) {
1298-
let mut seed: usize = 0xdeadbeef;
12991298
let mut d = File::open("net_graph-2021-02-12.bin").expect("Please fetch https://bitcoin.ninja/ldk-net_graph-879e309c128-2020-02-12.bin and place it at lightning/net_graph-2021-02-12.bin");
13001299
let graph = NetworkGraph::read(&mut d).unwrap();
1301-
let node_count = graph.get_nodes().len();
1300+
1301+
// First, get 100 (source, destination) pairs for which route-getting actually succeeds...
1302+
let mut path_endpoints = Vec::new();
1303+
let mut seed: usize = 0xdeadbeef;
1304+
'load_endpoints: for _ in 0..100 {
1305+
loop {
1306+
seed *= 0xdeadbeef;
1307+
let src = graph.get_nodes().keys().skip(seed % graph.get_nodes().len()).next().unwrap();
1308+
seed *= 0xdeadbeef;
1309+
let dst = graph.get_nodes().keys().skip(seed % graph.get_nodes().len()).next().unwrap();
1310+
if get_route(src, &graph, dst, None, &[], seed as u64 % 1_000_000, 42, &DummyLogger{}).is_ok() {
1311+
path_endpoints.push((src, dst));
1312+
continue 'load_endpoints;
1313+
}
1314+
}
1315+
}
1316+
1317+
// ...then benchmark finding paths between the nodes we learned.
1318+
let mut idx = 0;
13021319
bench.iter(|| {
1303-
seed *= 0xdeadbeef;
1304-
let src = graph.get_nodes().keys().skip(seed % node_count).next().unwrap();
1305-
seed *= 0xdeadbeef;
1306-
let dst = graph.get_nodes().keys().skip(seed % node_count).next().unwrap();
1307-
let _ = get_route(src, &graph, dst, None, &[], seed as u64 % 1_000_000, 42, &DummyLogger{});
1320+
let (src, dst) = path_endpoints[idx % path_endpoints.len()];
1321+
assert!(get_route(src, &graph, dst, None, &[], seed as u64 % 1_000_000, 42, &DummyLogger{}).is_ok());
1322+
idx += 1;
13081323
});
13091324
}
13101325
}

0 commit comments

Comments
 (0)