X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=fuzz%2Fsrc%2Fchanmon_consistency.rs;h=8a57c4fc2693d75c88278e0d39369f44fad80ffd;hb=27079e04d7b542058e48cafaf5c2e7114b3b8e15;hp=3d14808b0160471ae04f6eb11ef677ada8a96393;hpb=59b1bf6d0f718b2bef7ff44b5d2fc5bddce27b3b;p=rust-lightning diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 3d14808b..8a57c4fc 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -16,10 +16,10 @@ use bitcoin::blockdata::script::{Builder, Script}; use bitcoin::blockdata::opcodes; use bitcoin::network::constants::Network; -use bitcoin_hashes::Hash as TraitImport; -use bitcoin_hashes::hash160::Hash as Hash160; -use bitcoin_hashes::sha256::Hash as Sha256; -use bitcoin_hashes::sha256d::Hash as Sha256d; +use bitcoin::hashes::Hash as TraitImport; +use bitcoin::hashes::hash160::Hash as Hash160; +use bitcoin::hashes::sha256::Hash as Sha256; +use bitcoin::hash_types::BlockHash; use lightning::chain::chaininterface; use lightning::chain::transaction::OutPoint; @@ -40,8 +40,8 @@ use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer}; use utils::test_logger; -use secp256k1::key::{PublicKey,SecretKey}; -use secp256k1::Secp256k1; +use bitcoin::secp256k1::key::{PublicKey,SecretKey}; +use bitcoin::secp256k1::Secp256k1; use std::mem; use std::cmp::Ordering; @@ -73,9 +73,9 @@ impl Writer for VecWriter { } } -pub struct TestChannelMonitor { +struct TestChannelMonitor { pub logger: Arc, - pub simple_monitor: Arc, Arc>>, + pub simple_monitor: Arc, Arc>>, pub update_ret: Mutex>, // If we reload a node with an old copy of ChannelMonitors, the ChannelManager deserialization // logic will automatically force-close our channels for us (as we don't have an up-to-date @@ -86,7 +86,7 @@ pub struct TestChannelMonitor { pub should_update_manager: atomic::AtomicBool, } impl TestChannelMonitor { - pub fn new(chain_monitor: Arc, broadcaster: Arc, logger: Arc, feeest: Arc) -> Self { + pub fn new(chain_monitor: Arc, broadcaster: Arc, logger: Arc, feeest: Arc) -> Self { Self { simple_monitor: Arc::new(channelmonitor::SimpleManyChannelMonitor::new(chain_monitor, broadcaster, logger.clone(), feeest)), logger, @@ -114,7 +114,7 @@ impl channelmonitor::ManyChannelMonitor for TestChannelMon hash_map::Entry::Occupied(entry) => entry, hash_map::Entry::Vacant(_) => panic!("Didn't have monitor on update call"), }; - let mut deserialized_monitor = <(Sha256d, channelmonitor::ChannelMonitor)>:: + let mut deserialized_monitor = <(BlockHash, channelmonitor::ChannelMonitor)>:: read(&mut Cursor::new(&map_entry.get().1), Arc::clone(&self.logger)).unwrap().1; deserialized_monitor.update_monitor(update.clone(), &&TestBroadcaster {}).unwrap(); let mut ser = VecWriter(Vec::new()); @@ -180,13 +180,13 @@ impl KeysInterface for KeyProvider { } #[inline] -pub fn do_test(data: &[u8]) { +pub fn do_test(data: &[u8], out: Out) { let fee_est = Arc::new(FuzzEstimator{}); let broadcast = Arc::new(TestBroadcaster{}); macro_rules! make_node { ($node_id: expr) => { { - let logger: Arc = Arc::new(test_logger::TestLogger::new($node_id.to_string())); + let logger: Arc = Arc::new(test_logger::TestLogger::new($node_id.to_string(), out.clone())); let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin, Arc::clone(&logger))); let monitor = Arc::new(TestChannelMonitor::new(watch.clone(), broadcast.clone(), logger.clone(), fee_est.clone())); @@ -202,7 +202,7 @@ pub fn do_test(data: &[u8]) { macro_rules! reload_node { ($ser: expr, $node_id: expr, $old_monitors: expr) => { { - let logger: Arc = Arc::new(test_logger::TestLogger::new($node_id.to_string())); + let logger: Arc = Arc::new(test_logger::TestLogger::new($node_id.to_string(), out.clone())); let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin, Arc::clone(&logger))); let monitor = Arc::new(TestChannelMonitor::new(watch.clone(), broadcast.clone(), logger.clone(), fee_est.clone())); @@ -215,7 +215,7 @@ pub fn do_test(data: &[u8]) { let mut monitors = HashMap::new(); let mut old_monitors = $old_monitors.latest_monitors.lock().unwrap(); for (outpoint, (update_id, monitor_ser)) in old_monitors.drain() { - monitors.insert(outpoint, <(Sha256d, ChannelMonitor)>::read(&mut Cursor::new(&monitor_ser), Arc::clone(&logger)).expect("Failed to read monitor").1); + monitors.insert(outpoint, <(BlockHash, ChannelMonitor)>::read(&mut Cursor::new(&monitor_ser), Arc::clone(&logger)).expect("Failed to read monitor").1); monitor.latest_monitors.lock().unwrap().insert(outpoint, (update_id, monitor_ser)); } let mut monitor_refs = HashMap::new(); @@ -233,7 +233,7 @@ pub fn do_test(data: &[u8]) { channel_monitors: &mut monitor_refs, }; - (<(Sha256d, ChannelManager, Arc, Arc, Arc>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, monitor) + (<(BlockHash, ChannelManager, Arc, Arc, Arc>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, monitor) } } } @@ -794,7 +794,11 @@ pub fn do_test(data: &[u8]) { } } +pub fn chanmon_consistency_test(data: &[u8], out: Out) { + do_test(data, out); +} + #[no_mangle] pub extern "C" fn chanmon_consistency_run(data: *const u8, datalen: usize) { - do_test(unsafe { std::slice::from_raw_parts(data, datalen) }); + do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull{}); }