From: Dr. Maxim Orlovsky Date: Mon, 27 Apr 2020 15:53:13 +0000 (+0200) Subject: Adopting new bitcoin hash types and crate version X-Git-Tag: v0.0.12~70^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=27079e04d7b542058e48cafaf5c2e7114b3b8e15;p=rust-lightning Adopting new bitcoin hash types and crate version --- diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 5e3197f8f..115f3e8a4 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -19,11 +19,9 @@ stdin_fuzz = [] [dependencies] afl = { version = "0.4", optional = true } lightning = { path = "../lightning", features = ["fuzztarget"] } -bitcoin = { version = "0.21", features = ["fuzztarget"] } -bitcoin_hashes = { version = "0.7", features = ["fuzztarget"] } +bitcoin = { version = "0.23", features = ["fuzztarget"] } hex = "0.3" honggfuzz = { version = "0.5", optional = true } -secp256k1 = { version = "0.15", features=["fuzztarget"] } libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git", optional = true } [build-dependencies] diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index d458c6b96..8a57c4fc2 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -19,7 +19,7 @@ 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::hash_types::BlockHash; use lightning::chain::chaininterface; use lightning::chain::transaction::OutPoint; @@ -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()); @@ -215,7 +215,7 @@ pub fn do_test(data: &[u8], out: Out) { 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], out: Out) { 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) } } } diff --git a/fuzz/src/chanmon_deser.rs b/fuzz/src/chanmon_deser.rs index 45da43c0b..52caf36e1 100644 --- a/fuzz/src/chanmon_deser.rs +++ b/fuzz/src/chanmon_deser.rs @@ -1,7 +1,7 @@ // This file is auto-generated by gen_target.sh based on msg_target_template.txt // To modify it, modify msg_target_template.txt and run gen_target.sh instead. -use bitcoin::hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hash_types::BlockHash; use lightning::util::enforcing_trait_impls::EnforcingChannelKeys; use lightning::ln::channelmonitor; @@ -26,10 +26,10 @@ impl Writer for VecWriter { #[inline] pub fn do_test(data: &[u8], out: Out) { let logger = Arc::new(test_logger::TestLogger::new("".to_owned(), out)); - if let Ok((latest_block_hash, monitor)) = <(Sha256dHash, channelmonitor::ChannelMonitor)>::read(&mut Cursor::new(data), logger.clone()) { + if let Ok((latest_block_hash, monitor)) = <(BlockHash, channelmonitor::ChannelMonitor)>::read(&mut Cursor::new(data), logger.clone()) { let mut w = VecWriter(Vec::new()); monitor.write_for_disk(&mut w).unwrap(); - let deserialized_copy = <(Sha256dHash, channelmonitor::ChannelMonitor)>::read(&mut Cursor::new(&w.0), logger.clone()).unwrap(); + let deserialized_copy = <(BlockHash, channelmonitor::ChannelMonitor)>::read(&mut Cursor::new(&w.0), logger.clone()).unwrap(); assert!(latest_block_hash == deserialized_copy.0); assert!(monitor == deserialized_copy.1); } diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 83318abe8..377c9b0d7 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -14,9 +14,9 @@ use bitcoin::util::hash::BitcoinHash; use bitcoin::hashes::Hash as TraitImport; use bitcoin::hashes::HashEngine as TraitImportEngine; -use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::hashes::hash160::Hash as Hash160; -use bitcoin::hashes::sha256d::Hash as Sha256dHash; +use bitcoin::hashes::sha256::Hash as Sha256; +use bitcoin::hash_types::{Txid, BlockHash}; use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil}; use lightning::chain::transaction::OutPoint; @@ -38,7 +38,6 @@ use bitcoin::secp256k1::Secp256k1; use std::cell::RefCell; use std::collections::{HashMap, hash_map}; use std::cmp; -use std::hash::Hash; use std::sync::Arc; use std::sync::atomic::{AtomicU64,AtomicUsize,Ordering}; @@ -129,7 +128,7 @@ impl<'a> PartialEq for Peer<'a> { } } impl<'a> Eq for Peer<'a> {} -impl<'a> Hash for Peer<'a> { +impl<'a> std::hash::Hash for Peer<'a> { fn hash(&self, h: &mut H) { self.id.hash(h) } @@ -142,8 +141,8 @@ struct MoneyLossDetector<'a> { peers: &'a RefCell<[bool; 256]>, funding_txn: Vec, - txids_confirmed: HashMap, - header_hashes: Vec, + txids_confirmed: HashMap, + header_hashes: Vec, height: usize, max_height: usize, blocks_connected: u32, diff --git a/fuzz/src/lib.rs b/fuzz/src/lib.rs index f87c7511c..dbda28acf 100644 --- a/fuzz/src/lib.rs +++ b/fuzz/src/lib.rs @@ -1,7 +1,5 @@ extern crate bitcoin; -extern crate bitcoin_hashes; extern crate lightning; -extern crate secp256k1; extern crate hex; pub mod utils; diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index ae164ae2f..2ff160e4e 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -1,7 +1,7 @@ -use bitcoin::hashes::sha256d::Hash as Sha256dHash; use bitcoin::blockdata::script::{Script, Builder}; use bitcoin::blockdata::block::Block; use bitcoin::blockdata::transaction::Transaction; +use bitcoin::hash_types::{Txid, BlockHash}; use lightning::chain::chaininterface::{ChainError,ChainWatchInterface}; use lightning::ln::channelmanager::ChannelDetails; @@ -72,15 +72,15 @@ struct DummyChainWatcher { } impl ChainWatchInterface for DummyChainWatcher { - fn install_watch_tx(&self, _txid: &Sha256dHash, _script_pub_key: &Script) { } - fn install_watch_outpoint(&self, _outpoint: (Sha256dHash, u32), _out_script: &Script) { } + fn install_watch_tx(&self, _txid: &Txid, _script_pub_key: &Script) { } + fn install_watch_outpoint(&self, _outpoint: (Txid, u32), _out_script: &Script) { } fn watch_all_txn(&self) { } fn filter_block<'a>(&self, _block: &'a Block) -> (Vec<&'a Transaction>, Vec) { (Vec::new(), Vec::new()) } fn reentered(&self) -> usize { 0 } - fn get_chain_utxo(&self, _genesis_hash: Sha256dHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> { + fn get_chain_utxo(&self, _genesis_hash: BlockHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> { match self.input.get_slice(2) { Some(&[0, _]) => Err(ChainError::NotSupported), Some(&[1, _]) => Err(ChainError::NotWatched), diff --git a/lightning-net-tokio/Cargo.toml b/lightning-net-tokio/Cargo.toml index 70bc36a18..bdcb91139 100644 --- a/lightning-net-tokio/Cargo.toml +++ b/lightning-net-tokio/Cargo.toml @@ -10,7 +10,7 @@ For Rust-Lightning clients which wish to make direct connections to Lightning P2 """ [dependencies] -bitcoin = "0.21" +bitcoin = "0.23" lightning = { version = "0.0.11", path = "../lightning" } tokio = { version = ">=0.2.12", features = [ "io-util", "macros", "rt-core", "sync", "tcp", "time" ] } diff --git a/lightning/Cargo.toml b/lightning/Cargo.toml index 3b78a905b..50859aab2 100644 --- a/lightning/Cargo.toml +++ b/lightning/Cargo.toml @@ -22,10 +22,10 @@ max_level_info = [] max_level_debug = [] [dependencies] -bitcoin = "0.21" +bitcoin = "0.23" [dev-dependencies.bitcoin] -version = "0.21" +version = "0.23" features = ["bitcoinconsensus"] [dev-dependencies] diff --git a/lightning/src/chain/chaininterface.rs b/lightning/src/chain/chaininterface.rs index f49723655..814193af0 100644 --- a/lightning/src/chain/chaininterface.rs +++ b/lightning/src/chain/chaininterface.rs @@ -9,8 +9,8 @@ use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::script::Script; use bitcoin::blockdata::constants::genesis_block; use bitcoin::util::hash::BitcoinHash; -use bitcoin::hashes::sha256d::Hash as Sha256dHash; use bitcoin::network::constants::Network; +use bitcoin::hash_types::{Txid, BlockHash}; use util::logger::Logger; @@ -40,11 +40,11 @@ pub enum ChainError { /// events). pub trait ChainWatchInterface: Sync + Send { /// Provides a txid/random-scriptPubKey-in-the-tx which much be watched for. - fn install_watch_tx(&self, txid: &Sha256dHash, script_pub_key: &Script); + fn install_watch_tx(&self, txid: &Txid, script_pub_key: &Script); /// Provides an outpoint which must be watched for, providing any transactions which spend the /// given outpoint. - fn install_watch_outpoint(&self, outpoint: (Sha256dHash, u32), out_script: &Script); + fn install_watch_outpoint(&self, outpoint: (Txid, u32), out_script: &Script); /// Indicates that a listener needs to see all transactions. fn watch_all_txn(&self); @@ -53,7 +53,7 @@ pub trait ChainWatchInterface: Sync + Send { /// short_channel_id (aka unspent_tx_output_identier). For BTC/tBTC channels the top three /// bytes are the block height, the next 3 the transaction index within the block, and the /// final two the output within the transaction. - fn get_chain_utxo(&self, genesis_hash: Sha256dHash, unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError>; + fn get_chain_utxo(&self, genesis_hash: BlockHash, unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError>; /// Gets the list of transactions and transaction indices that the ChainWatchInterface is /// watching for. @@ -135,11 +135,11 @@ pub struct ChainWatchedUtil { // We are more conservative in matching during testing to ensure everything matches *exactly*, // even though during normal runtime we take more optimized match approaches... #[cfg(test)] - watched_txn: HashSet<(Sha256dHash, Script)>, + watched_txn: HashSet<(Txid, Script)>, #[cfg(not(test))] watched_txn: HashSet