Skip to content

Update to rust-bitcoin v0.15 #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,7 +32,7 @@ secp256k1 = "0.11"
cc = "1.0"

[dev-dependencies.bitcoin]
version = "0.14"
version = "0.15"
features = ["bitcoinconsensus"]

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions fuzz/fuzz_targets/full_stack_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -432,7 +432,7 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
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() {
Expand Down
3 changes: 1 addition & 2 deletions src/chain/chaininterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/chain/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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!"),
}
}
Expand Down Expand Up @@ -3690,7 +3688,7 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> 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),
});
Expand Down Expand Up @@ -3818,7 +3816,7 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> 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;
Expand Down Expand Up @@ -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()[..]);
};
}
Expand Down Expand Up @@ -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()[..]);
};
}
Expand Down
9 changes: 3 additions & 6 deletions src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
14 changes: 6 additions & 8 deletions src/ln/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!"),
}
}
Expand Down Expand Up @@ -1579,10 +1577,10 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> 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),
},
};
Expand Down