From 7ff7561f2d5b70bd58e441161b863c03d08542b2 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Sun, 11 Nov 2018 22:40:01 +0000 Subject: [PATCH] Update to rust-bitcoin v0.15 --- Cargo.toml | 4 ++-- fuzz/Cargo.toml | 2 +- fuzz/fuzz_targets/full_stack_target.rs | 8 ++++---- src/chain/chaininterface.rs | 3 +-- src/chain/transaction.rs | 4 ++-- src/ln/channel.rs | 18 ++++++++---------- src/ln/channelmanager.rs | 9 +++------ src/ln/channelmonitor.rs | 14 ++++++-------- 8 files changed, 27 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 052f2fc03..9ecd10fb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ max_level_info = [] max_level_debug = [] [dependencies] -bitcoin = "0.14" +bitcoin = "0.15" rust-crypto = "0.2" rand = "0.4" secp256k1 = "0.11" @@ -32,7 +32,7 @@ secp256k1 = "0.11" cc = "1.0" [dev-dependencies.bitcoin] -version = "0.14" +version = "0.15" features = ["bitcoinconsensus"] [dev-dependencies] diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index a457df1a7..ecf3809c5 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -18,7 +18,7 @@ honggfuzz_fuzz = ["honggfuzz"] [dependencies] afl = { version = "0.4", optional = true } lightning = { path = "..", features = ["fuzztarget"] } -bitcoin = { version = "0.14", features = ["fuzztarget"] } +bitcoin = { version = "0.15", features = ["fuzztarget"] } hex = "0.3" honggfuzz = { version = "0.5", optional = true } rust-crypto = "0.2" diff --git a/fuzz/fuzz_targets/full_stack_target.rs b/fuzz/fuzz_targets/full_stack_target.rs index f94394553..3b277906b 100644 --- a/fuzz/fuzz_targets/full_stack_target.rs +++ b/fuzz/fuzz_targets/full_stack_target.rs @@ -7,9 +7,9 @@ use bitcoin::blockdata::block::BlockHeader; use bitcoin::blockdata::transaction::{Transaction, TxOut}; use bitcoin::blockdata::script::{Builder, Script}; use bitcoin::blockdata::opcodes; +use bitcoin::consensus::encode::{deserialize, serialize}; use bitcoin::network::constants::Network; -use bitcoin::network::serialize::{deserialize, serialize, BitcoinHash}; -use bitcoin::util::hash::{Sha256dHash, Hash160}; +use bitcoin::util::hash::{BitcoinHash, Sha256dHash, Hash160}; use crypto::digest::Digest; @@ -168,7 +168,7 @@ impl<'a> MoneyLossDetector<'a> { let mut txn = Vec::with_capacity(all_txn.len()); let mut txn_idxs = Vec::with_capacity(all_txn.len()); for (idx, tx) in all_txn.iter().enumerate() { - let txid = Sha256dHash::from_data(&serialize(tx).unwrap()[..]); + let txid = tx.txid(); match self.txids_confirmed.entry(txid) { hash_map::Entry::Vacant(e) => { e.insert(self.height); @@ -432,7 +432,7 @@ pub fn do_test(data: &[u8], logger: &Arc) { value: funding_generation.1, script_pubkey: funding_generation.2, }] }; let funding_output = 'search_loop: loop { - let funding_txid = Sha256dHash::from_data(&serialize(&tx).unwrap()[..]); + let funding_txid = tx.txid(); if let None = loss_detector.txids_confirmed.get(&funding_txid) { let outpoint = OutPoint::new(funding_txid, 0); for chan in channelmanager.list_channels() { diff --git a/src/chain/chaininterface.rs b/src/chain/chaininterface.rs index 9999177de..7b5e0d074 100644 --- a/src/chain/chaininterface.rs +++ b/src/chain/chaininterface.rs @@ -8,9 +8,8 @@ use bitcoin::blockdata::block::{Block, BlockHeader}; use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::script::Script; use bitcoin::blockdata::constants::genesis_block; -use bitcoin::util::hash::Sha256dHash; +use bitcoin::util::hash::{BitcoinHash, Sha256dHash}; use bitcoin::network::constants::Network; -use bitcoin::network::serialize::BitcoinHash; use util::logger::Logger; diff --git a/src/chain/transaction.rs b/src/chain/transaction.rs index e8ebae709..a9b314dd0 100644 --- a/src/chain/transaction.rs +++ b/src/chain/transaction.rs @@ -44,13 +44,13 @@ mod tests { use chain::transaction::OutPoint; use bitcoin::blockdata::transaction::Transaction; - use bitcoin::network::serialize; + use bitcoin::consensus::encode; use hex; #[test] fn test_channel_id_calculation() { - let tx: Transaction = serialize::deserialize(&hex::decode("020000000001010e0adef48412e4361325ac1c6e36411299ab09d4f083b9d8ddb55fbc06e1b0c00000000000feffffff0220a1070000000000220020f81d95e040bd0a493e38bae27bff52fe2bb58b93b293eb579c01c31b05c5af1dc072cfee54a3000016001434b1d6211af5551905dc2642d05f5b04d25a8fe80247304402207f570e3f0de50546aad25a872e3df059d277e776dda4269fa0d2cc8c2ee6ec9a022054e7fae5ca94d47534c86705857c24ceea3ad51c69dd6051c5850304880fc43a012103cb11a1bacc223d98d91f1946c6752e358a5eb1a1c983b3e6fb15378f453b76bd00000000").unwrap()[..]).unwrap(); + let tx: Transaction = encode::deserialize(&hex::decode("020000000001010e0adef48412e4361325ac1c6e36411299ab09d4f083b9d8ddb55fbc06e1b0c00000000000feffffff0220a1070000000000220020f81d95e040bd0a493e38bae27bff52fe2bb58b93b293eb579c01c31b05c5af1dc072cfee54a3000016001434b1d6211af5551905dc2642d05f5b04d25a8fe80247304402207f570e3f0de50546aad25a872e3df059d277e776dda4269fa0d2cc8c2ee6ec9a022054e7fae5ca94d47534c86705857c24ceea3ad51c69dd6051c5850304880fc43a012103cb11a1bacc223d98d91f1946c6752e358a5eb1a1c983b3e6fb15378f453b76bd00000000").unwrap()[..]).unwrap(); assert_eq!(&OutPoint { txid: tx.txid(), index: 0 diff --git a/src/ln/channel.rs b/src/ln/channel.rs index b9a81f6eb..207eda418 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -2,11 +2,9 @@ use bitcoin::blockdata::block::BlockHeader; use bitcoin::blockdata::script::{Script,Builder}; use bitcoin::blockdata::transaction::{TxIn, TxOut, Transaction, SigHashType}; use bitcoin::blockdata::opcodes; -use bitcoin::util::hash::{Sha256dHash, Hash160}; +use bitcoin::util::hash::{BitcoinHash, Sha256dHash, Hash160}; use bitcoin::util::bip143; -use bitcoin::network; -use bitcoin::network::serialize::{BitcoinHash, RawDecoder, RawEncoder}; -use bitcoin::network::encodable::{ConsensusEncodable, ConsensusDecodable}; +use bitcoin::consensus::encode::{self, Encodable, Decodable}; use secp256k1::key::{PublicKey,SecretKey}; use secp256k1::{Secp256k1,Message,Signature}; @@ -3511,9 +3509,9 @@ impl Writeable for Channel { (self.last_local_commitment_txn.len() as u64).write(writer)?; for tx in self.last_local_commitment_txn.iter() { - if let Err(e) = tx.consensus_encode(&mut RawEncoder::new(WriterWriteAdaptor(writer))) { + if let Err(e) = tx.consensus_encode(&mut WriterWriteAdaptor(writer)) { match e { - network::serialize::Error::Io(e) => return Err(e), + encode::Error::Io(e) => return Err(e), _ => panic!("last_local_commitment_txn must have been well-formed!"), } } @@ -3690,7 +3688,7 @@ impl ReadableArgs> for Channel { let last_local_commitment_txn_count: u64 = Readable::read(reader)?; let mut last_local_commitment_txn = Vec::with_capacity(cmp::min(last_local_commitment_txn_count as usize, OUR_MAX_HTLCS as usize*2 + 1)); for _ in 0..last_local_commitment_txn_count { - last_local_commitment_txn.push(match Transaction::consensus_decode(&mut RawDecoder::new(reader.by_ref())) { + last_local_commitment_txn.push(match Transaction::consensus_decode(reader.by_ref()) { Ok(tx) => tx, Err(_) => return Err(DecodeError::InvalidValue), }); @@ -3818,7 +3816,7 @@ impl ReadableArgs> for Channel { mod tests { use bitcoin::util::hash::{Sha256dHash, Hash160}; use bitcoin::util::bip143; - use bitcoin::network::serialize::serialize; + use bitcoin::consensus::encode::serialize; use bitcoin::blockdata::script::{Script, Builder}; use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::opcodes; @@ -3940,7 +3938,7 @@ mod tests { chan.sign_commitment_transaction(&mut unsigned_tx.0, &their_signature); - assert_eq!(serialize(&unsigned_tx.0).unwrap()[..], + assert_eq!(serialize(&unsigned_tx.0)[..], hex::decode($tx_hex).unwrap()[..]); }; } @@ -3973,7 +3971,7 @@ mod tests { } chan.sign_htlc_transaction(&mut htlc_tx, &remote_signature, &preimage, &htlc, &keys).unwrap(); - assert_eq!(serialize(&htlc_tx).unwrap()[..], + assert_eq!(serialize(&htlc_tx)[..], hex::decode($tx_hex).unwrap()[..]); }; } diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index a650c89bb..1f765eb19 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -12,8 +12,7 @@ use bitcoin::blockdata::block::BlockHeader; use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::constants::genesis_block; use bitcoin::network::constants::Network; -use bitcoin::network::serialize::BitcoinHash; -use bitcoin::util::hash::Sha256dHash; +use bitcoin::util::hash::{BitcoinHash, Sha256dHash}; use secp256k1::key::{SecretKey,PublicKey}; use secp256k1::{Secp256k1,Message}; @@ -3224,13 +3223,11 @@ mod tests { use util::ser::{Writeable, Writer, ReadableArgs}; use util::config::UserConfig; - use bitcoin::util::hash::Sha256dHash; + use bitcoin::util::hash::{BitcoinHash, Sha256dHash}; use bitcoin::blockdata::block::{Block, BlockHeader}; use bitcoin::blockdata::transaction::{Transaction, TxOut}; use bitcoin::blockdata::constants::genesis_block; use bitcoin::network::constants::Network; - use bitcoin::network::serialize::serialize; - use bitcoin::network::serialize::BitcoinHash; use hex; @@ -3520,7 +3517,7 @@ mod tests { tx = Transaction { version: chan_id as u32, lock_time: 0, input: Vec::new(), output: vec![TxOut { value: *channel_value_satoshis, script_pubkey: output_script.clone(), }]}; - funding_output = OutPoint::new(Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), 0); + funding_output = OutPoint::new(tx.txid(), 0); node_a.node.funding_transaction_generated(&temporary_channel_id, funding_output); let mut added_monitors = node_a.chan_monitor.added_monitors.lock().unwrap(); diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index 5d1e4e095..458c0dec7 100644 --- a/src/ln/channelmonitor.rs +++ b/src/ln/channelmonitor.rs @@ -15,10 +15,8 @@ use bitcoin::blockdata::block::BlockHeader; use bitcoin::blockdata::transaction::{TxIn,TxOut,SigHashType,Transaction}; use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint; use bitcoin::blockdata::script::Script; -use bitcoin::network::serialize; -use bitcoin::network::serialize::BitcoinHash; -use bitcoin::network::encodable::{ConsensusDecodable, ConsensusEncodable}; -use bitcoin::util::hash::Sha256dHash; +use bitcoin::consensus::encode::{self, Decodable, Encodable}; +use bitcoin::util::hash::{BitcoinHash,Sha256dHash}; use bitcoin::util::bip143; use crypto::digest::Digest; @@ -731,9 +729,9 @@ impl ChannelMonitor { macro_rules! serialize_local_tx { ($local_tx: expr) => { - if let Err(e) = $local_tx.tx.consensus_encode(&mut serialize::RawEncoder::new(WriterWriteAdaptor(writer))) { + if let Err(e) = $local_tx.tx.consensus_encode(&mut WriterWriteAdaptor(writer)) { match e { - serialize::Error::Io(e) => return Err(e), + encode::Error::Io(e) => return Err(e), _ => panic!("local tx must have been well-formed!"), } } @@ -1579,10 +1577,10 @@ impl ReadableArgs> for (Sha256dHash, ChannelM macro_rules! read_local_tx { () => { { - let tx = match Transaction::consensus_decode(&mut serialize::RawDecoder::new(reader.by_ref())) { + let tx = match Transaction::consensus_decode(reader.by_ref()) { Ok(tx) => tx, Err(e) => match e { - serialize::Error::Io(ioe) => return Err(DecodeError::Io(ioe)), + encode::Error::Io(ioe) => return Err(DecodeError::Io(ioe)), _ => return Err(DecodeError::InvalidValue), }, }; -- 2.39.5