Skip to content

Commit 1969bb7

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/main'
2 parents 9bc34a1 + c830123 commit 1969bb7

Some content is hidden

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

73 files changed

+3792
-1903
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ jobs:
1515
# 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, lightning-background-processor
1616
1.45.2,
1717
# 1.47.0 will be the MSRV for no-std builds using hashbrown once core2 is updated
18-
1.47.0,
19-
# 1.59.0 is the MSRV for lightning-transaction-sync
20-
1.59.0]
18+
1.47.0]
2119
include:
2220
- toolchain: stable
2321
build-net-tokio: true
@@ -73,11 +71,6 @@ jobs:
7371
build-futures: true
7472
build-no-std: true
7573
build-tx-sync: false
76-
- toolchain: 1.59.0
77-
build-net-tokio: false
78-
build-no-std: false
79-
build-futures: false
80-
build-tx-sync: true
8174
runs-on: ${{ matrix.platform }}
8275
steps:
8376
- name: Checkout source code
@@ -93,10 +86,10 @@ jobs:
9386
run: cargo update -p tokio --precise "1.14.0" --verbose
9487
env:
9588
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
96-
- name: Build on Rust ${{ matrix.toolchain }} with net-tokio and tx-sync
97-
if: "matrix.build-net-tokio && !matrix.coverage && matrix.build-tx-sync"
89+
- name: Build on Rust ${{ matrix.toolchain }} with net-tokio
90+
if: "matrix.build-net-tokio && !matrix.coverage"
9891
run: cargo build --verbose --color always
99-
- name: Build on Rust ${{ matrix.toolchain }} with net-tokio, tx-sync, and full code-linking for coverage generation
92+
- name: Build on Rust ${{ matrix.toolchain }} with net-tokio, and full code-linking for coverage generation
10093
if: matrix.coverage
10194
run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
10295
- name: Build on Rust ${{ matrix.toolchain }}
@@ -148,12 +141,13 @@ jobs:
148141
cargo test --verbose --color always --features esplora-async
149142
- name: Test backtrace-debug builds on Rust ${{ matrix.toolchain }}
150143
if: "matrix.toolchain == 'stable'"
144+
shell: bash # Default on Winblows is powershell
151145
run: |
152-
cd lightning && cargo test --verbose --color always --features backtrace
146+
cd lightning && RUST_BACKTRACE=1 cargo test --verbose --color always --features backtrace
153147
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio
154-
if: "matrix.build-net-tokio && !matrix.coverage && matrix.build-tx-sync"
148+
if: "matrix.build-net-tokio && !matrix.coverage"
155149
run: cargo test --verbose --color always
156-
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio, tx-sync, and full code-linking for coverage generation
150+
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio, and full code-linking for coverage generation
157151
if: matrix.coverage
158152
run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
159153
- name: Test no-std builds on Rust ${{ matrix.toolchain }}

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
members = [
44
"lightning",
55
"lightning-block-sync",
6-
"lightning-transaction-sync",
76
"lightning-invoice",
87
"lightning-net-tokio",
98
"lightning-persister",
@@ -13,6 +12,7 @@ members = [
1312

1413
exclude = [
1514
"lightning-custom-message",
15+
"lightning-transaction-sync",
1616
"no-std-check",
1717
]
1818

fuzz/src/bech32_parse.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
use crate::utils::test_logger;
11+
use core::convert::TryFrom;
12+
use lightning::offers::parse::{Bech32Encode, ParseError};
13+
14+
#[inline]
15+
pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
16+
if let Ok(bech32_encoded) = std::str::from_utf8(data) {
17+
if let Ok(bytes) = Bytes::from_bech32_str(bech32_encoded) {
18+
let bech32_encoded = bytes.to_string();
19+
assert_eq!(bytes, Bytes::from_bech32_str(&bech32_encoded).unwrap());
20+
}
21+
}
22+
}
23+
24+
#[derive(Debug, PartialEq)]
25+
struct Bytes(Vec<u8>);
26+
27+
impl Bech32Encode for Bytes {
28+
const BECH32_HRP: &'static str = "lno";
29+
}
30+
31+
impl AsRef<[u8]> for Bytes {
32+
fn as_ref(&self) -> &[u8] {
33+
&self.0
34+
}
35+
}
36+
37+
impl TryFrom<Vec<u8>> for Bytes {
38+
type Error = ParseError;
39+
fn try_from(data: Vec<u8>) -> Result<Self, ParseError> {
40+
Ok(Bytes(data))
41+
}
42+
}
43+
44+
impl core::fmt::Display for Bytes {
45+
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
46+
self.fmt_bech32_str(f)
47+
}
48+
}
49+
50+
pub fn bech32_parse_test<Out: test_logger::Output>(data: &[u8], out: Out) {
51+
do_test(data, out);
52+
}
53+
54+
#[no_mangle]
55+
pub extern "C" fn bech32_parse_run(data: *const u8, datalen: usize) {
56+
do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull {});
57+
}

fuzz/src/bin/bech32_parse_target.rs

Lines changed: 113 additions & 0 deletions
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::bech32_parse::*;
20+
21+
#[cfg(feature = "afl")]
22+
#[macro_use] extern crate afl;
23+
#[cfg(feature = "afl")]
24+
fn main() {
25+
fuzz!(|data| {
26+
bech32_parse_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+
bech32_parse_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+
bech32_parse_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+
bech32_parse_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+
bech32_parse_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/bech32_parse") {
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+
bech32_parse_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+
}

fuzz/src/bin/gen_target.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ GEN_TEST() {
66
echo "void $1_run(const unsigned char* data, size_t data_len);" >> ../../targets.h
77
}
88

9+
GEN_TEST bech32_parse
910
GEN_TEST chanmon_deser
1011
GEN_TEST chanmon_consistency
1112
GEN_TEST full_stack
13+
GEN_TEST invoice_deser
14+
GEN_TEST invoice_request_deser
15+
GEN_TEST offer_deser
1216
GEN_TEST onion_message
1317
GEN_TEST peer_crypt
1418
GEN_TEST process_network_graph
19+
GEN_TEST refund_deser
1520
GEN_TEST router
1621
GEN_TEST zbase32
1722
GEN_TEST indexedmap

fuzz/src/bin/invoice_deser_target.rs

Lines changed: 113 additions & 0 deletions
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::invoice_deser::*;
20+
21+
#[cfg(feature = "afl")]
22+
#[macro_use] extern crate afl;
23+
#[cfg(feature = "afl")]
24+
fn main() {
25+
fuzz!(|data| {
26+
invoice_deser_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+
invoice_deser_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+
invoice_deser_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+
invoice_deser_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+
invoice_deser_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/invoice_deser") {
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+
invoice_deser_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)