From: Matt Corallo Date: Tue, 9 Nov 2021 16:32:56 +0000 (+0000) Subject: fix fuzz stuff X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=8b7ff8b0328feeb788f37645982c249b59579930;p=rust-lightning fix fuzz stuff --- diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 4995faba6..e0f527dd2 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -50,8 +50,7 @@ use lightning::util::events::MessageSendEventsProvider; use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer}; use lightning::routing::router::{Route, RouteHop}; - -use utils::test_logger; +use utils::test_logger::{self, Output}; use utils::test_persister::TestPersister; use bitcoin::secp256k1::key::{PublicKey,SecretKey}; @@ -337,7 +336,8 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des } #[inline] -pub fn do_test(data: &[u8], out: Out) { +pub fn do_test(data: &[u8], underlying_out: Out) { + let out = SearchingOutput::new(underlying_out); let broadcast = Arc::new(TestBroadcaster{}); macro_rules! make_node { @@ -732,7 +732,8 @@ pub fn do_test(data: &[u8], out: Out) { // force-close which we should detect as an error). assert_eq!(msg.contents.flags & 2, 0); }, - _ => if out.locked_contains(&"Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") { + _ => if out.may_fail.load(atomic::Ordering::Acquire) { + return; } else { panic!("Unhandled message event {:?}", event) }, @@ -767,7 +768,8 @@ pub fn do_test(data: &[u8], out: Out) { events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => { assert_eq!(msg.contents.flags & 2, 0); // The disable bit must never be set! }, - _ => if out.locked_contains(&"Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") { + _ => if out.may_fail.load(atomic::Ordering::Acquire) { + return; } else { panic!("Unhandled message event") }, @@ -787,7 +789,8 @@ pub fn do_test(data: &[u8], out: Out) { events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => { assert_eq!(msg.contents.flags & 2, 0); // The disable bit must never be set! }, - _ => if out.locked_contains(&"Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") { + _ => if out.may_fail.load(atomic::Ordering::Acquire) { + return; } else { panic!("Unhandled message event") }, @@ -841,7 +844,8 @@ pub fn do_test(data: &[u8], out: Out) { events::Event::PendingHTLCsForwardable { .. } => { nodes[$node].process_pending_htlc_forwards(); }, - _ => if out.locked_contains(&"Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") { + _ => if out.may_fail.load(atomic::Ordering::Acquire) { + return; } else { panic!("Unhandled event") }, @@ -1129,7 +1133,8 @@ pub fn do_test(data: &[u8], out: Out) { // Finally, make sure that at least one end of each channel can make a substantial payment. // Unless we expected to hit a limitation of LN state machine (see comment in `send_update_fee_and_commit`) - if out.locked_contains(&"Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") { + if out.may_fail.load(atomic::Ordering::Acquire) { + return; } else { assert!( send_payment(&nodes[0], &nodes[1], chan_a, 10_000_000, &mut payment_id) || @@ -1158,7 +1163,28 @@ pub fn do_test(data: &[u8], out: Out) { } } -pub fn chanmon_consistency_test(data: &[u8], out: 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 { + output: O, + may_fail: Arc, +} +impl Output for SearchingOutput { + fn locked_write(&self, data: &[u8]) { + 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 SearchingOutput { + pub fn new(output: O) -> Self { + Self { output, may_fail: Arc::new(atomic::AtomicBool::new(false)) } + } +} + +pub fn chanmon_consistency_test(data: &[u8], out: Out) { do_test(data, out); } diff --git a/fuzz/src/utils/test_logger.rs b/fuzz/src/utils/test_logger.rs index ef6344ed4..f8c96f99b 100644 --- a/fuzz/src/utils/test_logger.rs +++ b/fuzz/src/utils/test_logger.rs @@ -13,16 +13,12 @@ use std::io::Write; pub trait Output : Clone + 'static { fn locked_write(&self, data: &[u8]); - fn locked_contains(&self, pattern: &str) -> bool; } #[derive(Clone)] pub struct DevNull {} impl Output for DevNull { fn locked_write(&self, _data: &[u8]) {} - fn locked_contains(&self, _pattern: &str) -> bool { - false - } } #[derive(Clone)] pub struct StringBuffer(Arc>); @@ -30,9 +26,6 @@ impl Output for StringBuffer { fn locked_write(&self, data: &[u8]) { self.0.lock().unwrap().push_str(&String::from_utf8(data.to_vec()).unwrap()); } - fn locked_contains(&self, pattern: &str) -> bool { - self.0.lock().unwrap().contains(pattern) - } } impl StringBuffer { pub fn new() -> Self {