Skip to content

Commit 4501dc7

Browse files
authored
Merge pull request #4523 from joostjager/fuzz-log-performance
fuzz: improve log performance
2 parents 044f3fa + d6ff54e commit 4501dc7

File tree

2 files changed

+9
-50
lines changed

2 files changed

+9
-50
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,7 @@ enum ChanType {
870870
}
871871

872872
#[inline]
873-
pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out: Out) {
874-
let out = SearchingOutput::new(underlying_out);
873+
pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], out: Out) {
875874
let broadcast_a = Arc::new(TestBroadcaster { txn_broadcasted: RefCell::new(Vec::new()) });
876875
let broadcast_b = Arc::new(TestBroadcaster { txn_broadcasted: RefCell::new(Vec::new()) });
877876
let broadcast_c = Arc::new(TestBroadcaster { txn_broadcasted: RefCell::new(Vec::new()) });
@@ -1859,11 +1858,7 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out:
18591858
// Can be generated as a result of calling `timer_tick_occurred` enough
18601859
// times while peers are disconnected
18611860
},
1862-
_ => if out.may_fail.load(atomic::Ordering::Acquire) {
1863-
return;
1864-
} else {
1865-
panic!("Unhandled message event {:?}", event)
1866-
},
1861+
_ => panic!("Unhandled message event {:?}", event),
18671862
}
18681863
if $limit_events != ProcessMessages::AllMessages {
18691864
break;
@@ -1903,13 +1898,7 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out:
19031898
MessageSendEvent::HandleError { ref action, .. } => {
19041899
assert_action_timeout_awaiting_response(action);
19051900
},
1906-
_ => {
1907-
if out.may_fail.load(atomic::Ordering::Acquire) {
1908-
return;
1909-
} else {
1910-
panic!("Unhandled message event")
1911-
}
1912-
},
1901+
_ => panic!("Unhandled message event"),
19131902
}
19141903
}
19151904
push_excess_b_events!(
@@ -1931,13 +1920,7 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out:
19311920
MessageSendEvent::HandleError { ref action, .. } => {
19321921
assert_action_timeout_awaiting_response(action);
19331922
},
1934-
_ => {
1935-
if out.may_fail.load(atomic::Ordering::Acquire) {
1936-
return;
1937-
} else {
1938-
panic!("Unhandled message event")
1939-
}
1940-
},
1923+
_ => panic!("Unhandled message event"),
19411924
}
19421925
}
19431926
push_excess_b_events!(
@@ -2050,13 +2033,7 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out:
20502033
..
20512034
} => {},
20522035

2053-
_ => {
2054-
if out.may_fail.load(atomic::Ordering::Acquire) {
2055-
return;
2056-
} else {
2057-
panic!("Unhandled event")
2058-
}
2059-
},
2036+
_ => panic!("Unhandled event"),
20602037
}
20612038
}
20622039
while nodes[$node].needs_pending_htlc_processing() {
@@ -2879,28 +2856,6 @@ pub fn do_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], underlying_out:
28792856
}
28802857
}
28812858

2882-
/// We actually have different behavior based on if a certain log string has been seen, so we have
2883-
/// to do a bit more tracking.
2884-
#[derive(Clone)]
2885-
struct SearchingOutput<O: Output> {
2886-
output: O,
2887-
may_fail: Arc<atomic::AtomicBool>,
2888-
}
2889-
impl<O: Output> Output for SearchingOutput<O> {
2890-
fn locked_write(&self, data: &[u8]) {
2891-
// We hit a design limitation of LN state machine (see CONCURRENT_INBOUND_HTLC_FEE_BUFFER)
2892-
if std::str::from_utf8(data).unwrap().contains("Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") {
2893-
self.may_fail.store(true, atomic::Ordering::Release);
2894-
}
2895-
self.output.locked_write(data)
2896-
}
2897-
}
2898-
impl<O: Output> SearchingOutput<O> {
2899-
pub fn new(output: O) -> Self {
2900-
Self { output, may_fail: Arc::new(atomic::AtomicBool::new(false)) }
2901-
}
2902-
}
2903-
29042859
pub fn chanmon_consistency_test<Out: Output + MaybeSend + MaybeSync>(data: &[u8], out: Out) {
29052860
do_test(data, out);
29062861
}

fuzz/src/utils/test_logger.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// licenses.
99

1010
use lightning::util::logger::{Logger, Record};
11+
use std::any::TypeId;
1112
use std::io::Write;
1213
use std::sync::{Arc, Mutex};
1314

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

6768
impl<Out: Output> Logger for TestLogger<Out> {
6869
fn log(&self, record: Record) {
70+
if TypeId::of::<Out>() == TypeId::of::<DevNull>() {
71+
return;
72+
}
6973
writeln!(LockedWriteAdapter(&self.out), "{:<6} {}", self.id, record).unwrap();
7074
}
7175
}

0 commit comments

Comments
 (0)