Skip to content

Commit 3da69f7

Browse files
authored
Merge pull request #3861 from tnull/2025-06-simple-close-1
2 parents 9db0fb2 + 0293a3c commit 3da69f7

20 files changed

+1071
-202
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ check-cfg = [
6767
"cfg(require_route_graph_test)",
6868
"cfg(splicing)",
6969
"cfg(async_payments)",
70+
"cfg(simple_close)",
7071
]

ci/ci-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,6 @@ RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning
155155
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
156156
RUSTFLAGS="--cfg=async_payments" cargo test --verbose --color always -p lightning
157157
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
158+
RUSTFLAGS="--cfg=simple_close" cargo test --verbose --color always -p lightning
159+
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
158160
RUSTFLAGS="--cfg=lsps1_service" cargo test --verbose --color always -p lightning-liquidity

fuzz/src/bin/gen_target.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ GEN_TEST msg_accept_channel msg_targets::
3232
GEN_TEST msg_announcement_signatures msg_targets::
3333
GEN_TEST msg_channel_reestablish msg_targets::
3434
GEN_TEST msg_closing_signed msg_targets::
35+
GEN_TEST msg_closing_complete msg_targets::
36+
GEN_TEST msg_closing_sig msg_targets::
3537
GEN_TEST msg_commitment_signed msg_targets::
3638
GEN_TEST msg_decoded_onion_error_packet msg_targets::
3739
GEN_TEST msg_funding_created msg_targets::
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
#![cfg_attr(rustfmt, rustfmt_skip)]
15+
16+
#[cfg(not(fuzzing))]
17+
compile_error!("Fuzz targets need cfg=fuzzing");
18+
19+
#[cfg(not(hashes_fuzz))]
20+
compile_error!("Fuzz targets need cfg=hashes_fuzz");
21+
22+
#[cfg(not(secp256k1_fuzz))]
23+
compile_error!("Fuzz targets need cfg=secp256k1_fuzz");
24+
25+
extern crate lightning_fuzz;
26+
use lightning_fuzz::msg_targets::msg_closing_complete::*;
27+
28+
#[cfg(feature = "afl")]
29+
#[macro_use] extern crate afl;
30+
#[cfg(feature = "afl")]
31+
fn main() {
32+
fuzz!(|data| {
33+
msg_closing_complete_run(data.as_ptr(), data.len());
34+
});
35+
}
36+
37+
#[cfg(feature = "honggfuzz")]
38+
#[macro_use] extern crate honggfuzz;
39+
#[cfg(feature = "honggfuzz")]
40+
fn main() {
41+
loop {
42+
fuzz!(|data| {
43+
msg_closing_complete_run(data.as_ptr(), data.len());
44+
});
45+
}
46+
}
47+
48+
#[cfg(feature = "libfuzzer_fuzz")]
49+
#[macro_use] extern crate libfuzzer_sys;
50+
#[cfg(feature = "libfuzzer_fuzz")]
51+
fuzz_target!(|data: &[u8]| {
52+
msg_closing_complete_run(data.as_ptr(), data.len());
53+
});
54+
55+
#[cfg(feature = "stdin_fuzz")]
56+
fn main() {
57+
use std::io::Read;
58+
59+
let mut data = Vec::with_capacity(8192);
60+
std::io::stdin().read_to_end(&mut data).unwrap();
61+
msg_closing_complete_run(data.as_ptr(), data.len());
62+
}
63+
64+
#[test]
65+
fn run_test_cases() {
66+
use std::fs;
67+
use std::io::Read;
68+
use lightning_fuzz::utils::test_logger::StringBuffer;
69+
70+
use std::sync::{atomic, Arc};
71+
{
72+
let data: Vec<u8> = vec![0];
73+
msg_closing_complete_run(data.as_ptr(), data.len());
74+
}
75+
let mut threads = Vec::new();
76+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
77+
if let Ok(tests) = fs::read_dir("test_cases/msg_closing_complete") {
78+
for test in tests {
79+
let mut data: Vec<u8> = Vec::new();
80+
let path = test.unwrap().path();
81+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
82+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
83+
84+
let thread_count_ref = Arc::clone(&threads_running);
85+
let main_thread_ref = std::thread::current();
86+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
87+
std::thread::spawn(move || {
88+
let string_logger = StringBuffer::new();
89+
90+
let panic_logger = string_logger.clone();
91+
let res = if ::std::panic::catch_unwind(move || {
92+
msg_closing_complete_test(&data, panic_logger);
93+
}).is_err() {
94+
Some(string_logger.into_string())
95+
} else { None };
96+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
97+
main_thread_ref.unpark();
98+
res
99+
})
100+
));
101+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
102+
std::thread::park();
103+
}
104+
}
105+
}
106+
let mut failed_outputs = Vec::new();
107+
for (test, thread) in threads.drain(..) {
108+
if let Some(output) = thread.join().unwrap() {
109+
println!("\nOutput of {}:\n{}\n", test, output);
110+
failed_outputs.push(test);
111+
}
112+
}
113+
if !failed_outputs.is_empty() {
114+
println!("Test cases which failed: ");
115+
for case in failed_outputs {
116+
println!("{}", case);
117+
}
118+
panic!();
119+
}
120+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
#![cfg_attr(rustfmt, rustfmt_skip)]
15+
16+
#[cfg(not(fuzzing))]
17+
compile_error!("Fuzz targets need cfg=fuzzing");
18+
19+
#[cfg(not(hashes_fuzz))]
20+
compile_error!("Fuzz targets need cfg=hashes_fuzz");
21+
22+
#[cfg(not(secp256k1_fuzz))]
23+
compile_error!("Fuzz targets need cfg=secp256k1_fuzz");
24+
25+
extern crate lightning_fuzz;
26+
use lightning_fuzz::msg_targets::msg_closing_sig::*;
27+
28+
#[cfg(feature = "afl")]
29+
#[macro_use] extern crate afl;
30+
#[cfg(feature = "afl")]
31+
fn main() {
32+
fuzz!(|data| {
33+
msg_closing_sig_run(data.as_ptr(), data.len());
34+
});
35+
}
36+
37+
#[cfg(feature = "honggfuzz")]
38+
#[macro_use] extern crate honggfuzz;
39+
#[cfg(feature = "honggfuzz")]
40+
fn main() {
41+
loop {
42+
fuzz!(|data| {
43+
msg_closing_sig_run(data.as_ptr(), data.len());
44+
});
45+
}
46+
}
47+
48+
#[cfg(feature = "libfuzzer_fuzz")]
49+
#[macro_use] extern crate libfuzzer_sys;
50+
#[cfg(feature = "libfuzzer_fuzz")]
51+
fuzz_target!(|data: &[u8]| {
52+
msg_closing_sig_run(data.as_ptr(), data.len());
53+
});
54+
55+
#[cfg(feature = "stdin_fuzz")]
56+
fn main() {
57+
use std::io::Read;
58+
59+
let mut data = Vec::with_capacity(8192);
60+
std::io::stdin().read_to_end(&mut data).unwrap();
61+
msg_closing_sig_run(data.as_ptr(), data.len());
62+
}
63+
64+
#[test]
65+
fn run_test_cases() {
66+
use std::fs;
67+
use std::io::Read;
68+
use lightning_fuzz::utils::test_logger::StringBuffer;
69+
70+
use std::sync::{atomic, Arc};
71+
{
72+
let data: Vec<u8> = vec![0];
73+
msg_closing_sig_run(data.as_ptr(), data.len());
74+
}
75+
let mut threads = Vec::new();
76+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
77+
if let Ok(tests) = fs::read_dir("test_cases/msg_closing_sig") {
78+
for test in tests {
79+
let mut data: Vec<u8> = Vec::new();
80+
let path = test.unwrap().path();
81+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
82+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
83+
84+
let thread_count_ref = Arc::clone(&threads_running);
85+
let main_thread_ref = std::thread::current();
86+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
87+
std::thread::spawn(move || {
88+
let string_logger = StringBuffer::new();
89+
90+
let panic_logger = string_logger.clone();
91+
let res = if ::std::panic::catch_unwind(move || {
92+
msg_closing_sig_test(&data, panic_logger);
93+
}).is_err() {
94+
Some(string_logger.into_string())
95+
} else { None };
96+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
97+
main_thread_ref.unpark();
98+
res
99+
})
100+
));
101+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
102+
std::thread::park();
103+
}
104+
}
105+
}
106+
let mut failed_outputs = Vec::new();
107+
for (test, thread) in threads.drain(..) {
108+
if let Some(output) = thread.join().unwrap() {
109+
println!("\nOutput of {}:\n{}\n", test, output);
110+
failed_outputs.push(test);
111+
}
112+
}
113+
if !failed_outputs.is_empty() {
114+
println!("Test cases which failed: ");
115+
for case in failed_outputs {
116+
println!("{}", case);
117+
}
118+
panic!();
119+
}
120+
}

fuzz/src/msg_targets/gen_target.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ GEN_TEST() {
1717
GEN_TEST lightning::ln::msgs::AcceptChannel test_msg_simple ""
1818
GEN_TEST lightning::ln::msgs::AnnouncementSignatures test_msg_simple ""
1919
GEN_TEST lightning::ln::msgs::ClosingSigned test_msg_simple ""
20+
GEN_TEST lightning::ln::msgs::ClosingComplete test_msg_simple ""
21+
GEN_TEST lightning::ln::msgs::ClosingSig test_msg_simple ""
2022
GEN_TEST lightning::ln::msgs::CommitmentSigned test_msg_simple ""
2123
GEN_TEST lightning::ln::msgs::FundingCreated test_msg_simple ""
2224
GEN_TEST lightning::ln::msgs::ChannelReady test_msg_simple ""

fuzz/src/msg_targets/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ mod utils;
33
pub mod msg_accept_channel;
44
pub mod msg_announcement_signatures;
55
pub mod msg_closing_signed;
6+
pub mod msg_closing_complete;
7+
pub mod msg_closing_sig;
68
pub mod msg_commitment_signed;
79
pub mod msg_funding_created;
810
pub mod msg_channel_ready;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 msg_target_template.txt
11+
// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
12+
13+
#![cfg_attr(rustfmt, rustfmt_skip)]
14+
15+
use crate::msg_targets::utils::VecWriter;
16+
use crate::utils::test_logger;
17+
18+
#[inline]
19+
pub fn msg_closing_complete_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
20+
test_msg_simple!(lightning::ln::msgs::ClosingComplete, data);
21+
}
22+
23+
#[no_mangle]
24+
pub extern "C" fn msg_closing_complete_run(data: *const u8, datalen: usize) {
25+
let data = unsafe { std::slice::from_raw_parts(data, datalen) };
26+
test_msg_simple!(lightning::ln::msgs::ClosingComplete, data);
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 msg_target_template.txt
11+
// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
12+
13+
#![cfg_attr(rustfmt, rustfmt_skip)]
14+
15+
use crate::msg_targets::utils::VecWriter;
16+
use crate::utils::test_logger;
17+
18+
#[inline]
19+
pub fn msg_closing_sig_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
20+
test_msg_simple!(lightning::ln::msgs::ClosingSig, data);
21+
}
22+
23+
#[no_mangle]
24+
pub extern "C" fn msg_closing_sig_run(data: *const u8, datalen: usize) {
25+
let data = unsafe { std::slice::from_raw_parts(data, datalen) };
26+
test_msg_simple!(lightning::ln::msgs::ClosingSig, data);
27+
}

fuzz/targets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ void msg_accept_channel_run(const unsigned char* data, size_t data_len);
2424
void msg_announcement_signatures_run(const unsigned char* data, size_t data_len);
2525
void msg_channel_reestablish_run(const unsigned char* data, size_t data_len);
2626
void msg_closing_signed_run(const unsigned char* data, size_t data_len);
27+
void msg_closing_complete_run(const unsigned char* data, size_t data_len);
28+
void msg_closing_sig_run(const unsigned char* data, size_t data_len);
2729
void msg_commitment_signed_run(const unsigned char* data, size_t data_len);
2830
void msg_decoded_onion_error_packet_run(const unsigned char* data, size_t data_len);
2931
void msg_funding_created_run(const unsigned char* data, size_t data_len);

lightning-net-tokio/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,10 @@ mod tests {
716716
fn handle_channel_ready(&self, _their_node_id: PublicKey, _msg: &ChannelReady) {}
717717
fn handle_shutdown(&self, _their_node_id: PublicKey, _msg: &Shutdown) {}
718718
fn handle_closing_signed(&self, _their_node_id: PublicKey, _msg: &ClosingSigned) {}
719+
#[cfg(simple_close)]
720+
fn handle_closing_complete(&self, _their_node_id: PublicKey, _msg: ClosingComplete) {}
721+
#[cfg(simple_close)]
722+
fn handle_closing_sig(&self, _their_node_id: PublicKey, _msg: ClosingSig) {}
719723
fn handle_update_add_htlc(&self, _their_node_id: PublicKey, _msg: &UpdateAddHTLC) {}
720724
fn handle_update_fulfill_htlc(&self, _their_node_id: PublicKey, _msg: &UpdateFulfillHTLC) {}
721725
fn handle_update_fail_htlc(&self, _their_node_id: PublicKey, _msg: &UpdateFailHTLC) {}

0 commit comments

Comments
 (0)