Skip to content

Commit 22a271f

Browse files
committed
Merging main
2 parents 883d255 + 4dce209 commit 22a271f

File tree

85 files changed

+5464
-1805
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+5464
-1805
lines changed

.github/workflows/build.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ jobs:
141141
cd ..
142142
- name: Run benchmarks on Rust ${{ matrix.toolchain }}
143143
run: |
144-
RUSTC_BOOTSTRAP=1 cargo bench --features _bench_unstable
144+
cd bench
145+
RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench
146+
- name: Run benchmarks with hashbrown on Rust ${{ matrix.toolchain }}
147+
run: |
148+
cd bench
149+
RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench --features hashbrown
145150
146151
check_commits:
147152
runs-on: ubuntu-latest

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ lightning-c-bindings/a.out
88
Cargo.lock
99
.idea
1010
lightning/target
11-
lightning/ldk-net_graph-*.bin
11+
lightning/net_graph-*.bin
12+
lightning-rapid-gossip-sync/res/full_graph.lngossip
1213
lightning-custom-message/target
14+
lightning-transaction-sync/target
1315
no-std-check/target

Cargo.toml

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exclude = [
1414
"lightning-custom-message",
1515
"lightning-transaction-sync",
1616
"no-std-check",
17+
"bench",
1718
]
1819

1920
# Our tests do actual crypto and lots of work, the tradeoff for -O2 is well
@@ -35,8 +36,3 @@ lto = "off"
3536
opt-level = 3
3637
lto = true
3738
panic = "abort"
38-
39-
[profile.bench]
40-
opt-level = 3
41-
codegen-units = 1
42-
lto = true

bench/Cargo.toml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "lightning-bench"
3+
version = "0.0.1"
4+
authors = ["Matt Corallo"]
5+
edition = "2018"
6+
7+
[[bench]]
8+
name = "bench"
9+
harness = false
10+
11+
[features]
12+
hashbrown = ["lightning/hashbrown"]
13+
14+
[dependencies]
15+
lightning = { path = "../lightning", features = ["_test_utils", "criterion"] }
16+
lightning-persister = { path = "../lightning-persister", features = ["criterion"] }
17+
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync", features = ["criterion"] }
18+
criterion = { version = "0.4", default-features = false }
19+
20+
[profile.release]
21+
opt-level = 3
22+
codegen-units = 1
23+
lto = true
24+
panic = "abort"
25+
debug = true

bench/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This crate uses criterion to benchmark various LDK functions.
2+
3+
It can be run as `RUSTFLAGS=--cfg=ldk_bench cargo bench`.
4+
5+
For routing or other HashMap-bottlenecked functions, the `hashbrown` feature
6+
should also be benchmarked.

bench/benches/bench.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
extern crate lightning;
2+
extern crate lightning_persister;
3+
4+
extern crate criterion;
5+
6+
use criterion::{criterion_group, criterion_main};
7+
8+
criterion_group!(benches,
9+
// Note that benches run in the order given here. Thus, they're sorted according to how likely
10+
// developers are to be working on the specific code listed, then by runtime.
11+
lightning::routing::router::benches::generate_routes_with_zero_penalty_scorer,
12+
lightning::routing::router::benches::generate_mpp_routes_with_zero_penalty_scorer,
13+
lightning::routing::router::benches::generate_routes_with_probabilistic_scorer,
14+
lightning::routing::router::benches::generate_mpp_routes_with_probabilistic_scorer,
15+
lightning::routing::router::benches::generate_large_mpp_routes_with_probabilistic_scorer,
16+
lightning::sign::benches::bench_get_secure_random_bytes,
17+
lightning::ln::channelmanager::bench::bench_sends,
18+
lightning_persister::bench::bench_sends,
19+
lightning_rapid_gossip_sync::bench::bench_reading_full_graph_from_file,
20+
lightning::routing::gossip::benches::read_network_graph,
21+
lightning::routing::gossip::benches::write_network_graph);
22+
criterion_main!(benches);

fuzz/src/bin/gen_target.sh

+12
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,15 @@ GEN_TEST msg_ping msg_targets::
5656
GEN_TEST msg_pong msg_targets::
5757

5858
GEN_TEST msg_channel_details msg_targets::
59+
60+
GEN_TEST msg_open_channel_v2 msg_targets::
61+
GEN_TEST msg_accept_channel_v2 msg_targets::
62+
GEN_TEST msg_tx_add_input msg_targets::
63+
GEN_TEST msg_tx_add_output msg_targets::
64+
GEN_TEST msg_tx_remove_input msg_targets::
65+
GEN_TEST msg_tx_remove_output msg_targets::
66+
GEN_TEST msg_tx_complete msg_targets::
67+
GEN_TEST msg_tx_signatures msg_targets::
68+
GEN_TEST msg_tx_init_rbf msg_targets::
69+
GEN_TEST msg_tx_ack_rbf msg_targets::
70+
GEN_TEST msg_tx_abort msg_targets::
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
// This file is auto-generated by gen_target.sh based on target_template.txt
11+
// To modify it, modify target_template.txt and run gen_target.sh instead.
12+
13+
#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
14+
15+
#[cfg(not(fuzzing))]
16+
compile_error!("Fuzz targets need cfg=fuzzing");
17+
18+
extern crate lightning_fuzz;
19+
use lightning_fuzz::msg_targets::msg_accept_channel_v2::*;
20+
21+
#[cfg(feature = "afl")]
22+
#[macro_use] extern crate afl;
23+
#[cfg(feature = "afl")]
24+
fn main() {
25+
fuzz!(|data| {
26+
msg_accept_channel_v2_run(data.as_ptr(), data.len());
27+
});
28+
}
29+
30+
#[cfg(feature = "honggfuzz")]
31+
#[macro_use] extern crate honggfuzz;
32+
#[cfg(feature = "honggfuzz")]
33+
fn main() {
34+
loop {
35+
fuzz!(|data| {
36+
msg_accept_channel_v2_run(data.as_ptr(), data.len());
37+
});
38+
}
39+
}
40+
41+
#[cfg(feature = "libfuzzer_fuzz")]
42+
#[macro_use] extern crate libfuzzer_sys;
43+
#[cfg(feature = "libfuzzer_fuzz")]
44+
fuzz_target!(|data: &[u8]| {
45+
msg_accept_channel_v2_run(data.as_ptr(), data.len());
46+
});
47+
48+
#[cfg(feature = "stdin_fuzz")]
49+
fn main() {
50+
use std::io::Read;
51+
52+
let mut data = Vec::with_capacity(8192);
53+
std::io::stdin().read_to_end(&mut data).unwrap();
54+
msg_accept_channel_v2_run(data.as_ptr(), data.len());
55+
}
56+
57+
#[test]
58+
fn run_test_cases() {
59+
use std::fs;
60+
use std::io::Read;
61+
use lightning_fuzz::utils::test_logger::StringBuffer;
62+
63+
use std::sync::{atomic, Arc};
64+
{
65+
let data: Vec<u8> = vec![0];
66+
msg_accept_channel_v2_run(data.as_ptr(), data.len());
67+
}
68+
let mut threads = Vec::new();
69+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
70+
if let Ok(tests) = fs::read_dir("test_cases/msg_accept_channel_v2") {
71+
for test in tests {
72+
let mut data: Vec<u8> = Vec::new();
73+
let path = test.unwrap().path();
74+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
75+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
76+
77+
let thread_count_ref = Arc::clone(&threads_running);
78+
let main_thread_ref = std::thread::current();
79+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
80+
std::thread::spawn(move || {
81+
let string_logger = StringBuffer::new();
82+
83+
let panic_logger = string_logger.clone();
84+
let res = if ::std::panic::catch_unwind(move || {
85+
msg_accept_channel_v2_test(&data, panic_logger);
86+
}).is_err() {
87+
Some(string_logger.into_string())
88+
} else { None };
89+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
90+
main_thread_ref.unpark();
91+
res
92+
})
93+
));
94+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
95+
std::thread::park();
96+
}
97+
}
98+
}
99+
let mut failed_outputs = Vec::new();
100+
for (test, thread) in threads.drain(..) {
101+
if let Some(output) = thread.join().unwrap() {
102+
println!("\nOutput of {}:\n{}\n", test, output);
103+
failed_outputs.push(test);
104+
}
105+
}
106+
if !failed_outputs.is_empty() {
107+
println!("Test cases which failed: ");
108+
for case in failed_outputs {
109+
println!("{}", case);
110+
}
111+
panic!();
112+
}
113+
}
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
// This file is auto-generated by gen_target.sh based on target_template.txt
11+
// To modify it, modify target_template.txt and run gen_target.sh instead.
12+
13+
#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
14+
15+
#[cfg(not(fuzzing))]
16+
compile_error!("Fuzz targets need cfg=fuzzing");
17+
18+
extern crate lightning_fuzz;
19+
use lightning_fuzz::msg_targets::msg_open_channel_v2::*;
20+
21+
#[cfg(feature = "afl")]
22+
#[macro_use] extern crate afl;
23+
#[cfg(feature = "afl")]
24+
fn main() {
25+
fuzz!(|data| {
26+
msg_open_channel_v2_run(data.as_ptr(), data.len());
27+
});
28+
}
29+
30+
#[cfg(feature = "honggfuzz")]
31+
#[macro_use] extern crate honggfuzz;
32+
#[cfg(feature = "honggfuzz")]
33+
fn main() {
34+
loop {
35+
fuzz!(|data| {
36+
msg_open_channel_v2_run(data.as_ptr(), data.len());
37+
});
38+
}
39+
}
40+
41+
#[cfg(feature = "libfuzzer_fuzz")]
42+
#[macro_use] extern crate libfuzzer_sys;
43+
#[cfg(feature = "libfuzzer_fuzz")]
44+
fuzz_target!(|data: &[u8]| {
45+
msg_open_channel_v2_run(data.as_ptr(), data.len());
46+
});
47+
48+
#[cfg(feature = "stdin_fuzz")]
49+
fn main() {
50+
use std::io::Read;
51+
52+
let mut data = Vec::with_capacity(8192);
53+
std::io::stdin().read_to_end(&mut data).unwrap();
54+
msg_open_channel_v2_run(data.as_ptr(), data.len());
55+
}
56+
57+
#[test]
58+
fn run_test_cases() {
59+
use std::fs;
60+
use std::io::Read;
61+
use lightning_fuzz::utils::test_logger::StringBuffer;
62+
63+
use std::sync::{atomic, Arc};
64+
{
65+
let data: Vec<u8> = vec![0];
66+
msg_open_channel_v2_run(data.as_ptr(), data.len());
67+
}
68+
let mut threads = Vec::new();
69+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
70+
if let Ok(tests) = fs::read_dir("test_cases/msg_open_channel_v2") {
71+
for test in tests {
72+
let mut data: Vec<u8> = Vec::new();
73+
let path = test.unwrap().path();
74+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
75+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
76+
77+
let thread_count_ref = Arc::clone(&threads_running);
78+
let main_thread_ref = std::thread::current();
79+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
80+
std::thread::spawn(move || {
81+
let string_logger = StringBuffer::new();
82+
83+
let panic_logger = string_logger.clone();
84+
let res = if ::std::panic::catch_unwind(move || {
85+
msg_open_channel_v2_test(&data, panic_logger);
86+
}).is_err() {
87+
Some(string_logger.into_string())
88+
} else { None };
89+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
90+
main_thread_ref.unpark();
91+
res
92+
})
93+
));
94+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
95+
std::thread::park();
96+
}
97+
}
98+
}
99+
let mut failed_outputs = Vec::new();
100+
for (test, thread) in threads.drain(..) {
101+
if let Some(output) = thread.join().unwrap() {
102+
println!("\nOutput of {}:\n{}\n", test, output);
103+
failed_outputs.push(test);
104+
}
105+
}
106+
if !failed_outputs.is_empty() {
107+
println!("Test cases which failed: ");
108+
for case in failed_outputs {
109+
println!("{}", case);
110+
}
111+
panic!();
112+
}
113+
}

0 commit comments

Comments
 (0)