X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=fuzz%2Fsrc%2Fchanmon_consistency.rs;h=ca05e5db942ae4a10fcf7257a3e69f5bc939f374;hb=c7ef6df672b6eb7a8bec9230195fb7cee6d7393e;hp=eba0cb9e4f91adcb17699623ca991aa3a6c13b7c;hpb=0133739e9e585ebe966ba4a1d41b003f4f4769bf;p=rust-lightning diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index eba0cb9e4..ca05e5db9 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -1,3 +1,12 @@ +// This file is Copyright its original authors, visible in version control +// history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in accordance with one or both of these +// licenses. + //! Test that monitor update failures don't get our channel state out of sync. //! One of the biggest concern with the monitor update failure handling code is that messages //! resent after monitor updating is restored are delivered out-of-order, resulting in @@ -9,7 +18,6 @@ //! send-side handling is correct, other peers. We consider it a failure if any action results in a //! channel being force-closed. -use bitcoin::BitcoinHash; use bitcoin::blockdata::block::BlockHeader; use bitcoin::blockdata::transaction::{Transaction, TxOut}; use bitcoin::blockdata::script::{Builder, Script}; @@ -25,7 +33,7 @@ use lightning::chain::transaction::OutPoint; use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil,ChainWatchInterface}; use lightning::chain::keysinterface::{KeysInterface, InMemoryChannelKeys}; use lightning::ln::channelmonitor; -use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, HTLCUpdate}; +use lightning::ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, MonitorEvent}; use lightning::ln::channelmanager::{ChannelManager, PaymentHash, PaymentPreimage, PaymentSecret, ChannelManagerReadArgs}; use lightning::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, ErrorAction, UpdateAddHTLC, Init}; @@ -126,15 +134,14 @@ impl channelmonitor::ManyChannelMonitor for TestChannelMonitor { self.update_ret.lock().unwrap().clone() } - fn get_and_clear_pending_htlcs_updated(&self) -> Vec { - return self.simple_monitor.get_and_clear_pending_htlcs_updated(); + fn get_and_clear_pending_monitor_events(&self) -> Vec { + return self.simple_monitor.get_and_clear_pending_monitor_events(); } } struct KeyProvider { node_id: u8, - session_id: atomic::AtomicU8, - channel_id: atomic::AtomicU8, + rand_bytes_id: atomic::AtomicU8, } impl KeysInterface for KeyProvider { type ChanKeySigner = EnforcingChannelKeys; @@ -170,14 +177,8 @@ impl KeysInterface for KeyProvider { )) } - fn get_onion_rand(&self) -> (SecretKey, [u8; 32]) { - let id = self.session_id.fetch_add(1, atomic::Ordering::Relaxed); - (SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, id, 10, self.node_id]).unwrap(), - [0; 32]) - } - - fn get_channel_id(&self) -> [u8; 32] { - let id = self.channel_id.fetch_add(1, atomic::Ordering::Relaxed); + fn get_secure_random_bytes(&self) -> [u8; 32] { + let id = self.rand_bytes_id.fetch_add(1, atomic::Ordering::Relaxed); [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, id, 11, self.node_id] } } @@ -193,7 +194,7 @@ pub fn do_test(data: &[u8], out: Out) { let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin)); let monitor = Arc::new(TestChannelMonitor::new(watch.clone(), broadcast.clone(), logger.clone(), fee_est.clone())); - let keys_manager = Arc::new(KeyProvider { node_id: $node_id, session_id: atomic::AtomicU8::new(0), channel_id: atomic::AtomicU8::new(0) }); + let keys_manager = Arc::new(KeyProvider { node_id: $node_id, rand_bytes_id: atomic::AtomicU8::new(0) }); let mut config = UserConfig::default(); config.channel_options.fee_proportional_millionths = 0; config.channel_options.announced_channel = true; @@ -209,7 +210,7 @@ pub fn do_test(data: &[u8], out: Out) { let watch = Arc::new(ChainWatchInterfaceUtil::new(Network::Bitcoin)); let monitor = Arc::new(TestChannelMonitor::new(watch.clone(), broadcast.clone(), logger.clone(), fee_est.clone())); - let keys_manager = Arc::new(KeyProvider { node_id: $node_id, session_id: atomic::AtomicU8::new(0), channel_id: atomic::AtomicU8::new(0) }); + let keys_manager = Arc::new(KeyProvider { node_id: $node_id, rand_bytes_id: atomic::AtomicU8::new(0) }); let mut config = UserConfig::default(); config.channel_options.fee_proportional_millionths = 0; config.channel_options.announced_channel = true; @@ -233,7 +234,7 @@ pub fn do_test(data: &[u8], out: Out) { tx_broadcaster: broadcast.clone(), logger, default_config: config, - channel_monitors: &mut monitor_refs, + channel_monitors: monitor_refs, }; (<(BlockHash, ChannelManager, Arc, Arc, Arc, Arc>)>::read(&mut Cursor::new(&$ser.0), read_args).expect("Failed to read manager").1, monitor) @@ -315,7 +316,7 @@ pub fn do_test(data: &[u8], out: Out) { } $node.block_connected(&header, 1, &txn, &posn); for i in 2..100 { - header = BlockHeader { version: 0x20000000, prev_blockhash: header.bitcoin_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 }; + header = BlockHeader { version: 0x20000000, prev_blockhash: header.block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 }; $node.block_connected(&header, i, &Vec::new(), &[0; 0]); } } }