Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 5 additions & 50 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,7 @@ enum ChanType {
}

#[inline]
pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out: Out) {
let out = SearchingOutput::new(underlying_out);
pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], out: Out) {
let broadcast_a = Arc::new(TestBroadcaster { txn_broadcasted: RefCell::new(Vec::new()) });
let broadcast_b = Arc::new(TestBroadcaster { txn_broadcasted: RefCell::new(Vec::new()) });
let broadcast_c = Arc::new(TestBroadcaster { txn_broadcasted: RefCell::new(Vec::new()) });
Expand Down Expand Up @@ -1859,11 +1858,7 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out:
// Can be generated as a result of calling `timer_tick_occurred` enough
// times while peers are disconnected
},
_ => if out.may_fail.load(atomic::Ordering::Acquire) {
return;
} else {
panic!("Unhandled message event {:?}", event)
},
_ => panic!("Unhandled message event {:?}", event),
}
if $limit_events != ProcessMessages::AllMessages {
break;
Expand Down Expand Up @@ -1903,13 +1898,7 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out:
MessageSendEvent::HandleError { ref action, .. } => {
assert_action_timeout_awaiting_response(action);
},
_ => {
if out.may_fail.load(atomic::Ordering::Acquire) {
return;
} else {
panic!("Unhandled message event")
}
},
_ => panic!("Unhandled message event"),
}
}
push_excess_b_events!(
Expand All @@ -1931,13 +1920,7 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out:
MessageSendEvent::HandleError { ref action, .. } => {
assert_action_timeout_awaiting_response(action);
},
_ => {
if out.may_fail.load(atomic::Ordering::Acquire) {
return;
} else {
panic!("Unhandled message event")
}
},
_ => panic!("Unhandled message event"),
}
}
push_excess_b_events!(
Expand Down Expand Up @@ -2050,13 +2033,7 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out:
..
} => {},

_ => {
if out.may_fail.load(atomic::Ordering::Acquire) {
return;
} else {
panic!("Unhandled event")
}
},
_ => panic!("Unhandled event"),
}
}
while nodes[$node].needs_pending_htlc_processing() {
Expand Down Expand Up @@ -2879,28 +2856,6 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out:
}
}

/// We actually have different behavior based on if a certain log string has been seen, so we have
/// to do a bit more tracking.
#[derive(Clone)]
struct SearchingOutput<O: Output> {
output: O,
may_fail: Arc<atomic::AtomicBool>,
}
impl<O: Output> Output for SearchingOutput<O> {
fn locked_write(&self, data: &[u8]) {
// We hit a design limitation of LN state machine (see CONCURRENT_INBOUND_HTLC_FEE_BUFFER)
if std::str::from_utf8(data).unwrap().contains("Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") {
self.may_fail.store(true, atomic::Ordering::Release);
}
self.output.locked_write(data)
}
}
impl<O: Output> SearchingOutput<O> {
pub fn new(output: O) -> Self {
Self { output, may_fail: Arc::new(atomic::AtomicBool::new(false)) }
}
}

pub fn chanmon_consistency_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], out: Out) {
do_test(data, out);
}
Expand Down
4 changes: 4 additions & 0 deletions fuzz/src/utils/test_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// licenses.

use lightning::util::logger::{Logger, Record};
use std::any::TypeId;
use std::io::Write;
use std::sync::{Arc, Mutex};

Expand Down Expand Up @@ -66,6 +67,9 @@ impl<'a, Out: Output> Write for LockedWriteAdapter<'a, Out> {

impl<Out: Output> Logger for TestLogger<Out> {
fn log(&self, record: Record) {
if TypeId::of::<Out>() == TypeId::of::<DevNull>() {
return;
}
writeln!(LockedWriteAdapter(&self.out), "{:<6} {}", self.id, record).unwrap();
}
}
Loading