Skip to content

Commit 4b3fac4

Browse files
author
Matt Corallo
committed
Merge PR '[0.3] Remaining Currently-Merged Backports' (#4801)
from 2026-07-0.3-beta-backports into 0.3 Reviewed-on: https://git.rust-bitcoin.org/lightningdevkit/rust-lightning/pulls/4801 Reviewed-by: wpaulino <wpaulino@noreply.gitea.bitcoin.ninja>
2 parents f680fd3 + 4f4e4df commit 4b3fac4

34 files changed

Lines changed: 6694 additions & 664 deletions

ci/ci-tests-common.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ PIN_RELEASE_DEPS # pin the release dependencies in our main workspace
1717
# The backtrace v0.3.75 crate relies on rustc 1.82
1818
[ "$RUSTC_MINOR_VERSION" -lt 82 ] && cargo update -p backtrace --precise "0.3.74" --quiet
1919

20-
# Starting with version 1.2.0, the `idna_adapter` crate has an MSRV of rustc 1.81.0.
21-
[ "$RUSTC_MINOR_VERSION" -lt 81 ] && cargo update -p idna_adapter --precise "1.1.0" --quiet
22-
23-
# Starting with version 0.27.8, the `hyper-rustls` crate has an MSRV of rustc 1.85.0.
24-
[ "$RUSTC_MINOR_VERSION" -lt 85 ] && cargo update -p hyper-rustls --precise "0.27.7" --quiet
25-
2620
# Starting with version 1.9.0, the `zeroize` crate uses Rust 2024.
2721
[ "$RUSTC_MINOR_VERSION" -lt 85 ] && cargo update -p zeroize --precise "1.8.2" --quiet
2822

23+
# Starting with version 0.1.35, the `jobserver` crate relies on rustc 1.85.
24+
[ "$RUSTC_MINOR_VERSION" -lt 85 ] && cargo update -p jobserver --precise "0.1.34" --quiet
25+
2926
export RUST_BACKTRACE=1
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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 target does not support cfg(not(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::payer_proof_deser::*;
27+
use lightning_fuzz::utils::test_logger;
28+
29+
#[cfg(feature = "afl")]
30+
#[macro_use] extern crate afl;
31+
#[cfg(feature = "afl")]
32+
fn main() {
33+
fuzz!(|data| {
34+
payer_proof_deser_test(&data, test_logger::DevNull {});
35+
});
36+
}
37+
38+
#[cfg(feature = "honggfuzz")]
39+
#[macro_use] extern crate honggfuzz;
40+
#[cfg(feature = "honggfuzz")]
41+
fn main() {
42+
loop {
43+
fuzz!(|data| {
44+
payer_proof_deser_test(&data, test_logger::DevNull {});
45+
});
46+
}
47+
}
48+
49+
#[cfg(feature = "libfuzzer_fuzz")]
50+
#[macro_use] extern crate libfuzzer_sys;
51+
#[cfg(feature = "libfuzzer_fuzz")]
52+
fuzz_target!(|data: &[u8]| {
53+
payer_proof_deser_test(data, test_logger::DevNull {});
54+
});
55+
56+
#[cfg(feature = "stdin_fuzz")]
57+
fn main() {
58+
use std::io::Read;
59+
60+
// On macOS, panic=abort causes the process to send SIGABRT which can leave it
61+
// stuck in an uninterruptible state due to the ReportCrash daemon. Using
62+
// process::exit in a panic hook avoids this by terminating cleanly.
63+
#[cfg(target_os = "macos")]
64+
std::panic::set_hook(Box::new(|panic_info| {
65+
use std::io::Write;
66+
let _ = std::io::stdout().flush();
67+
eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture());
68+
let _ = std::io::stderr().flush();
69+
std::process::exit(1);
70+
}));
71+
72+
let mut data = Vec::with_capacity(8192);
73+
std::io::stdin().read_to_end(&mut data).unwrap();
74+
payer_proof_deser_test(&data, test_logger::Stdout {});
75+
}
76+
77+
#[test]
78+
fn run_test_cases() {
79+
use std::fs;
80+
use std::io::Read;
81+
use lightning_fuzz::utils::test_logger::StringBuffer;
82+
83+
use std::sync::{atomic, Arc};
84+
{
85+
let data: Vec<u8> = vec![0];
86+
payer_proof_deser_test(&data, test_logger::DevNull {});
87+
}
88+
let mut threads = Vec::new();
89+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
90+
if let Ok(tests) = fs::read_dir("../test_cases/payer_proof_deser") {
91+
for test in tests {
92+
let mut data: Vec<u8> = Vec::new();
93+
let path = test.unwrap().path();
94+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
95+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
96+
97+
let thread_count_ref = Arc::clone(&threads_running);
98+
let main_thread_ref = std::thread::current();
99+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
100+
std::thread::spawn(move || {
101+
let string_logger = StringBuffer::new();
102+
103+
let panic_logger = string_logger.clone();
104+
let res = if ::std::panic::catch_unwind(move || {
105+
payer_proof_deser_test(&data, panic_logger);
106+
}).is_err() {
107+
Some(string_logger.into_string())
108+
} else { None };
109+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
110+
main_thread_ref.unpark();
111+
res
112+
})
113+
));
114+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
115+
std::thread::park();
116+
}
117+
}
118+
}
119+
let mut failed_outputs = Vec::new();
120+
for (test, thread) in threads.drain(..) {
121+
if let Some(output) = thread.join().unwrap() {
122+
println!("\nOutput of {}:\n{}\n", test, output);
123+
failed_outputs.push(test);
124+
}
125+
}
126+
if !failed_outputs.is_empty() {
127+
println!("Test cases which failed: ");
128+
for case in failed_outputs {
129+
println!("{}", case);
130+
}
131+
panic!();
132+
}
133+
}

fuzz/src/bin/gen_target.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ GEN_FAKE_HASHES_TEST onion_message
3434
GEN_FAKE_HASHES_TEST peer_crypt
3535
GEN_FAKE_HASHES_TEST process_network_graph
3636
GEN_FAKE_HASHES_TEST process_onion_failure
37+
GEN_FAKE_HASHES_TEST payer_proof_deser
3738
GEN_FAKE_HASHES_TEST refund_deser
3839
GEN_FAKE_HASHES_TEST router
3940
GEN_FAKE_HASHES_TEST zbase32

fuzz/src/chanmon_consistency.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,8 @@ fn assert_disconnect_action(action: &msgs::ErrorAction) -> (&msgs::WarningMessag
775775
// Since sending/receiving messages may be delayed, `timer_tick_occurred` may cause a node to
776776
// disconnect their counterparty if they're expecting a timely response.
777777
if let msgs::ErrorAction::DisconnectPeerWithWarning { ref msg } = action {
778-
let is_quiescent_msg = msg.data.contains("already sent splice_locked, cannot RBF");
778+
let is_quiescent_msg = msg.data.contains("already sent splice_locked, cannot RBF")
779+
|| msg.data.contains("contribution no longer valid at quiescence");
779780
if !msg.data.contains("Disconnecting due to timeout awaiting response") && !is_quiescent_msg
780781
{
781782
panic!("Unexpected disconnect case: {}", msg.data);
@@ -3395,6 +3396,13 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], out: Out) {
33953396
}
33963397

33973398
harness.checkpoint_manager_persistences();
3399+
3400+
// Compute `ChannelDetails` for every channel after each step (ignoring the result) so the
3401+
// fuzzer exercises the splice-details derivation in `to_details` across as many states as
3402+
// possible.
3403+
for node in harness.nodes.iter() {
3404+
let _ = node.list_channels();
3405+
}
33983406
}
33993407
harness.finish();
34003408
}

fuzz/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub mod lsps_message;
3636
pub mod offer_deser;
3737
pub mod onion_hop_data;
3838
pub mod onion_message;
39+
pub mod payer_proof_deser;
3940
pub mod peer_crypt;
4041
pub mod process_network_graph;
4142
pub mod process_onion_failure;

fuzz/src/payer_proof_deser.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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::payer_proof::PayerProof;
13+
use lightning::util::ser::Writeable;
14+
15+
#[inline]
16+
pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
17+
if let Ok(payer_proof) = PayerProof::try_from(data.to_vec()) {
18+
let mut bytes = Vec::with_capacity(data.len());
19+
payer_proof.write(&mut bytes).unwrap();
20+
assert_eq!(data, bytes);
21+
}
22+
}
23+
24+
pub fn payer_proof_deser_test<Out: test_logger::Output>(data: &[u8], out: Out) {
25+
do_test(data, out);
26+
}
27+
28+
#[no_mangle]
29+
pub extern "C" fn payer_proof_deser_run(data: *const u8, datalen: usize) {
30+
do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull {});
31+
}

fuzz/src/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
257257
pending_inbound_htlcs: Vec::new(),
258258
pending_outbound_htlcs: Vec::new(),
259259
current_dust_exposure_msat: None,
260+
splice_details: None,
260261
});
261262
}
262263
Some(&$first_hops_vec[..])

fuzz/targets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ void onion_message_run(const unsigned char* data, size_t data_len);
1212
void peer_crypt_run(const unsigned char* data, size_t data_len);
1313
void process_network_graph_run(const unsigned char* data, size_t data_len);
1414
void process_onion_failure_run(const unsigned char* data, size_t data_len);
15+
void payer_proof_deser_run(const unsigned char* data, size_t data_len);
1516
void refund_deser_run(const unsigned char* data, size_t data_len);
1617
void router_run(const unsigned char* data, size_t data_len);
1718
void zbase32_run(const unsigned char* data, size_t data_len);

lightning-liquidity/src/lsps0/ser.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,9 @@ impl LSPSDateTime {
256256
now_seconds_since_epoch > datetime_seconds_since_epoch
257257
}
258258

259-
/// Returns the absolute difference between two datetimes as a `Duration`.
259+
/// Returns the elapsed duration from `other` to `self`, or zero if `other` is later.
260260
pub fn duration_since(&self, other: &Self) -> Duration {
261-
let diff_secs = self.0.timestamp().abs_diff(other.0.timestamp());
262-
Duration::from_secs(diff_secs)
261+
self.0.signed_duration_since(other.0).to_std().unwrap_or(Duration::ZERO)
263262
}
264263

265264
/// Returns the time in seconds since the unix epoch.
@@ -986,6 +985,8 @@ pub(crate) mod u32_fee_rate {
986985
mod tests {
987986
use super::*;
988987

988+
use core::time::Duration;
989+
989990
use lightning::io::Cursor;
990991

991992
#[test]
@@ -997,6 +998,18 @@ mod tests {
997998
assert_eq!(expected_datetime, decoded_datetime);
998999
}
9991000

1001+
#[test]
1002+
fn datetime_duration_since_is_directional() {
1003+
let earlier = LSPSDateTime::new_from_duration_since_epoch(Duration::from_secs(30));
1004+
let later = LSPSDateTime::new_from_duration_since_epoch(Duration::from_secs(90));
1005+
let later_with_millis =
1006+
LSPSDateTime::new_from_duration_since_epoch(Duration::from_millis(90_100));
1007+
1008+
assert_eq!(later.duration_since(&earlier), Duration::from_secs(60));
1009+
assert_eq!(later_with_millis.duration_since(&later), Duration::from_millis(100));
1010+
assert_eq!(earlier.duration_since(&later), Duration::ZERO);
1011+
}
1012+
10001013
#[test]
10011014
fn is_past_handles_pre_epoch_datetime() {
10021015
// A peer-controlled RFC3339 datetime before 1970 must be rejected at parse

0 commit comments

Comments
 (0)