Skip to content

Commit 4b4cb98

Browse files
committed
Merge remote-tracking branch 'upstream/master' into modular_handshake
# Conflicts: # fuzz/src/full_stack.rs # lightning/src/ln/peers/handler.rs
2 parents 5e9c350 + 9098240 commit 4b4cb98

File tree

104 files changed

+5793
-3081
lines changed

Some content is hidden

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

104 files changed

+5793
-3081
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
[*]
44
indent_style = tab
5+
insert_final_newline = true

.github/workflows/build.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Continuous Integration Checks
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
strategy:
8+
matrix:
9+
toolchain: [ stable,
10+
beta,
11+
# 1.22.0 is MSRV for rust-lightning in general:
12+
1.22.0,
13+
# 1.34.2 is Debian stable
14+
1.34.2,
15+
# 1.39.0 is MSRV for lightning-net-tokio and generates coverage
16+
1.39.0]
17+
include:
18+
- toolchain: stable
19+
build-net-tokio: true
20+
- toolchain: beta
21+
build-net-tokio: true
22+
- toolchain: 1.39.0
23+
build-net-tokio: true
24+
coverage: true
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout source code
28+
uses: actions/checkout@v2
29+
- name: Install Rust ${{ matrix.toolchain }} toolchain
30+
uses: actions-rs/toolchain@v1
31+
with:
32+
toolchain: ${{ matrix.toolchain }}
33+
override: true
34+
profile: minimal
35+
- name: Build on Rust ${{ matrix.toolchain }} with net-tokio
36+
if: matrix.build-net-tokio
37+
run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
38+
- name: Build on Rust ${{ matrix.toolchain }}
39+
if: "! matrix.build-net-tokio"
40+
run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always -p lightning
41+
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio
42+
if: matrix.build-net-tokio
43+
run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
44+
- name: Test on Rust ${{ matrix.toolchain }}
45+
if: "! matrix.build-net-tokio"
46+
run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always -p lightning
47+
- name: Install deps for kcov
48+
if: matrix.coverage
49+
run: |
50+
sudo apt-get update
51+
sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
52+
- name: Install kcov
53+
if: matrix.coverage
54+
run: |
55+
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
56+
tar xzf master.tar.gz
57+
cd kcov-master && mkdir build && cd build
58+
cmake ..
59+
make
60+
make install DESTDIR=../../kcov-build
61+
cd ../.. && rm -rf kcov-master master.tar.gz
62+
- name: Generate coverage report
63+
if: matrix.coverage
64+
run: |
65+
for file in target/debug/lightning-*; do
66+
[ -x "${file}" ] || continue;
67+
mkdir -p "target/cov/$(basename $file)";
68+
./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
69+
done
70+
- name: Upload coverage
71+
if: matrix.coverage
72+
uses: codecov/codecov-action@v1
73+
with:
74+
fail_ci_if_error: true
75+
76+
fuzz:
77+
runs-on: ubuntu-latest
78+
env:
79+
TOOLCHAIN: stable
80+
steps:
81+
- name: Checkout source code
82+
uses: actions/checkout@v2
83+
- name: Install Rust ${{ env.TOOLCHAIN }} toolchain
84+
uses: actions-rs/toolchain@v1
85+
with:
86+
toolchain: ${{ env.TOOLCHAIN }}
87+
override: true
88+
profile: minimal
89+
- name: Install dependencies for honggfuzz
90+
run: |
91+
sudo apt-get update
92+
sudo apt-get -y install build-essential binutils-dev libunwind-dev
93+
- name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
94+
run: cd fuzz && cargo test --verbose --color always
95+
- name: Run fuzzers
96+
run: cd fuzz && ./ci-fuzz.sh

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ script:
2626
- if [ "$BUILD_NET_TOKIO" == "1" ]; then RUSTFLAGS="-C link-dead-code" cargo test --verbose; fi
2727
- if [ "$BUILD_NET_TOKIO" != "1" ]; then RUSTFLAGS="-C link-dead-code" cargo test --verbose -p lightning; fi
2828
# Run lightning workspace fuzz tests on Rust stable
29-
- if [ "$(rustup show | grep default | grep stable)" != "" ]; then cd fuzz && cargo test --verbose && ./travis-fuzz.sh; fi
29+
- if [ "$(rustup show | grep default | grep stable)" != "" ]; then cd fuzz && cargo test --verbose && ./ci-fuzz.sh; fi
3030
# Generate code cov information on Rust 1.39.0
3131
- if [ "$(rustup show | grep default | grep 1.39.0)" != "" ]; then
3232
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&

ARCH.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ receive `ChannelMonitorUpdate`s from `ChannelManager` and persist them to disk b
1111
channel steps forward.
1212

1313
There are two additional important structures that you may use either on the same device
14-
as the `ChannelManager` or on a separate one. `Router` handles receiving channel and node
15-
node announcements and calculates routes for sending payments. `PeerManager` handles the
14+
as the `ChannelManager` or on a separate one. `Router` handles receiving channel and node
15+
announcements and calculates routes for sending payments. `PeerManager` handles the
1616
authenticated and encrypted communication protocol, monitoring for liveness of peers,
1717
routing messages to `ChannelManager` and `Router` instances directly, and receiving
1818
messages from them via the `EventsProvider` interface.

fuzz/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ stdin_fuzz = []
1919
[dependencies]
2020
afl = { version = "0.4", optional = true }
2121
lightning = { path = "../lightning", features = ["fuzztarget"] }
22-
bitcoin = { version = "0.21", features = ["fuzztarget"] }
23-
bitcoin_hashes = { version = "0.7", features = ["fuzztarget"] }
22+
bitcoin = { version = "0.23", features = ["fuzztarget"] }
2423
hex = "0.3"
2524
honggfuzz = { version = "0.5", optional = true }
26-
secp256k1 = { version = "0.15", features=["fuzztarget"] }
2725
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git", optional = true }
2826

2927
[build-dependencies]
@@ -37,6 +35,10 @@ members = ["."]
3735
lto = true
3836
codegen-units = 1
3937

38+
# When testing a large fuzz corpus, -O1 offers a nice speedup
39+
[profile.dev]
40+
opt-level = 1
41+
4042
[lib]
4143
name = "lightning_fuzz"
4244
path = "src/lib.rs"

fuzz/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ export RUST_BACKTRACE=1
8383
cargo test
8484
```
8585

86-
This will reproduce the failing fuzz input and yield a usable stack trace.
86+
This will reproduce the failing fuzz input and yield a usable stack trace.

fuzz/travis-fuzz.sh renamed to fuzz/ci-fuzz.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ rm *_target.rs
1212
[ "$(git diff)" != "" ] && exit 1
1313
popd
1414

15-
cargo install --force honggfuzz
15+
cargo install --color always --force honggfuzz
1616
sed -i 's/lto = true//' Cargo.toml
17-
HFUZZ_BUILD_ARGS="--features honggfuzz_fuzz" cargo hfuzz build
17+
HFUZZ_BUILD_ARGS="--features honggfuzz_fuzz" cargo --color always hfuzz build
1818
for TARGET in src/bin/*.rs; do
1919
FILENAME=$(basename $TARGET)
2020
FILE="${FILENAME%.*}"
2121
HFUZZ_RUN_ARGS="--exit_upon_crash -v -n2"
2222
if [ "$FILE" = "chanmon_consistency_target" ]; then
2323
HFUZZ_RUN_ARGS="$HFUZZ_RUN_ARGS -F 64 -N100000"
24+
elif [ "$FILE" = "full_stack_target" ]; then
25+
HFUZZ_RUN_ARGS="$HFUZZ_RUN_ARGS -t0 -N1000000"
2426
else
2527
HFUZZ_RUN_ARGS="$HFUZZ_RUN_ARGS -N1000000"
2628
fi
2729
export HFUZZ_RUN_ARGS
28-
HFUZZ_BUILD_ARGS="--features honggfuzz_fuzz" cargo hfuzz run $FILE
30+
HFUZZ_BUILD_ARGS="--features honggfuzz_fuzz" cargo --color always hfuzz run $FILE
2931
if [ -f hfuzz_workspace/$FILE/HONGGFUZZ.REPORT.TXT ]; then
3032
cat hfuzz_workspace/$FILE/HONGGFUZZ.REPORT.TXT
3133
for CASE in hfuzz_workspace/$FILE/SIG*; do

fuzz/src/bin/chanmon_consistency_target.rs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
extern crate lightning_fuzz;
77
use lightning_fuzz::chanmon_consistency::*;
88

9-
use std::fs;
10-
use std::io::Read;
11-
129
#[cfg(feature = "afl")]
1310
#[macro_use] extern crate afl;
1411
#[cfg(feature = "afl")]
@@ -38,22 +35,59 @@ fuzz_target!(|data: &[u8]| {
3835

3936
#[cfg(feature = "stdin_fuzz")]
4037
fn main() {
38+
use std::io::Read;
39+
4140
let mut data = Vec::with_capacity(8192);
4241
std::io::stdin().read_to_end(&mut data).unwrap();
4342
chanmon_consistency_run(data.as_ptr(), data.len());
4443
}
4544

4645
#[test]
4746
fn run_test_cases() {
48-
let mut data: Vec<u8> = vec![0];
49-
chanmon_consistency_run(data.as_ptr(), data.len());
47+
use std::fs;
48+
use std::io::Read;
49+
use lightning_fuzz::utils::test_logger::StringBuffer;
50+
51+
use std::sync::{atomic, Arc};
52+
{
53+
let data: Vec<u8> = vec![0];
54+
chanmon_consistency_run(data.as_ptr(), data.len());
55+
}
56+
let mut threads = Vec::new();
57+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
5058
if let Ok(tests) = fs::read_dir("test_cases/chanmon_consistency") {
5159
for test in tests {
52-
data.clear();
60+
let mut data: Vec<u8> = Vec::new();
5361
let path = test.unwrap().path();
54-
println!("Running test {}...", path.file_name().unwrap().to_str().unwrap());
55-
fs::File::open(path).unwrap().read_to_end(&mut data).unwrap();
56-
chanmon_consistency_run(data.as_ptr(), data.len());
62+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
63+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
64+
65+
let thread_count_ref = Arc::clone(&threads_running);
66+
let main_thread_ref = std::thread::current();
67+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
68+
std::thread::spawn(move || {
69+
let string_logger = StringBuffer::new();
70+
71+
let panic_logger = string_logger.clone();
72+
let res = if ::std::panic::catch_unwind(move || {
73+
chanmon_consistency_test(&data, panic_logger);
74+
}).is_err() {
75+
Some(string_logger.into_string())
76+
} else { None };
77+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
78+
main_thread_ref.unpark();
79+
res
80+
})
81+
));
82+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
83+
std::thread::park();
84+
}
85+
}
86+
}
87+
for (test, thread) in threads.drain(..) {
88+
if let Some(output) = thread.join().unwrap() {
89+
println!("Output of {}:\n{}", test, output);
90+
panic!();
5791
}
5892
}
5993
}

fuzz/src/bin/chanmon_deser_target.rs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
extern crate lightning_fuzz;
77
use lightning_fuzz::chanmon_deser::*;
88

9-
use std::fs;
10-
use std::io::Read;
11-
129
#[cfg(feature = "afl")]
1310
#[macro_use] extern crate afl;
1411
#[cfg(feature = "afl")]
@@ -38,22 +35,59 @@ fuzz_target!(|data: &[u8]| {
3835

3936
#[cfg(feature = "stdin_fuzz")]
4037
fn main() {
38+
use std::io::Read;
39+
4140
let mut data = Vec::with_capacity(8192);
4241
std::io::stdin().read_to_end(&mut data).unwrap();
4342
chanmon_deser_run(data.as_ptr(), data.len());
4443
}
4544

4645
#[test]
4746
fn run_test_cases() {
48-
let mut data: Vec<u8> = vec![0];
49-
chanmon_deser_run(data.as_ptr(), data.len());
47+
use std::fs;
48+
use std::io::Read;
49+
use lightning_fuzz::utils::test_logger::StringBuffer;
50+
51+
use std::sync::{atomic, Arc};
52+
{
53+
let data: Vec<u8> = vec![0];
54+
chanmon_deser_run(data.as_ptr(), data.len());
55+
}
56+
let mut threads = Vec::new();
57+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
5058
if let Ok(tests) = fs::read_dir("test_cases/chanmon_deser") {
5159
for test in tests {
52-
data.clear();
60+
let mut data: Vec<u8> = Vec::new();
5361
let path = test.unwrap().path();
54-
println!("Running test {}...", path.file_name().unwrap().to_str().unwrap());
55-
fs::File::open(path).unwrap().read_to_end(&mut data).unwrap();
56-
chanmon_deser_run(data.as_ptr(), data.len());
62+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
63+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
64+
65+
let thread_count_ref = Arc::clone(&threads_running);
66+
let main_thread_ref = std::thread::current();
67+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
68+
std::thread::spawn(move || {
69+
let string_logger = StringBuffer::new();
70+
71+
let panic_logger = string_logger.clone();
72+
let res = if ::std::panic::catch_unwind(move || {
73+
chanmon_deser_test(&data, panic_logger);
74+
}).is_err() {
75+
Some(string_logger.into_string())
76+
} else { None };
77+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
78+
main_thread_ref.unpark();
79+
res
80+
})
81+
));
82+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
83+
std::thread::park();
84+
}
85+
}
86+
}
87+
for (test, thread) in threads.drain(..) {
88+
if let Some(output) = thread.join().unwrap() {
89+
println!("Output of {}:\n{}", test, output);
90+
panic!();
5791
}
5892
}
5993
}

0 commit comments

Comments
 (0)