From d48ac225d3be20ba980391920eb17441a8d91697 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 23 Jun 2023 12:33:39 +1000 Subject: [PATCH 1/5] Pin dependencies in CI for MSRV build Recently the MSRV build broke. We can pin the dependencies in the MSRV CI job. Pin `log` and `rustls` when running the MSRV CI job. --- .github/workflows/cont_integration.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 6cad605c..74f9839e 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -48,6 +48,9 @@ jobs: run: rustup component add clippy - name: Update toolchain run: rustup update + - name: pin dependencies + if: ${{ matrix.rust.version }} == 1.57.0 + run: cargo update -p log --precise 0.4.18 && cargo update -p rustls@0.21.2 --precise 0.21.1 - name: Build run: cargo build --features ${{ matrix.features }} --no-default-features - name: Clippy From ea1b6d1b447cdcf36240080dafea2004d0ce419b Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 23 Jun 2023 12:35:16 +1000 Subject: [PATCH 2/5] Upgrade bitcoin to v0.30.0 Upgrade `rust-bitcoin` to v0.30.3, including: - bitcoin - electrsd - electrum-client Also includes addition of a dependency on `bitcoin-internals` for the `DisplayHex` trait. This is a temporary fix while we wait for release of the new `github.com/rust-bitcoin/hex-conservative` crate. --- Cargo.toml | 8 +++++--- src/api.rs | 14 +++++++------- src/async.rs | 13 +++++++------ src/blocking.rs | 14 ++++++++------ src/lib.rs | 28 ++++++++++++++++++---------- 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c19b1069..beca42f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,9 @@ path = "src/lib.rs" [dependencies] serde = { version = "1.0", features = ["derive"] } -bitcoin = { version = "0.29.1", features = ["serde"], default-features = false } +bitcoin = { version = "0.30.0", features = ["serde", "std"], default-features = false } +# Temporary dependency on internals until the rust-bitcoin devs release the hex-conservative crate. +bitcoin-internals = { version = "0.1.0", features = ["alloc"] } log = "^0.4" ureq = { version = "2.5.0", features = ["json"], optional = true } reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] } @@ -25,8 +27,8 @@ reqwest = { version = "0.11", optional = true, default-features = false, feature [dev-dependencies] serde_json = "1.0" tokio = { version = "1.20.1", features = ["full"] } -electrsd = { version = "0.22.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_22_0"] } -electrum-client = "0.12.0" +electrsd = { version = "0.24.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_22_0"] } +electrum-client = "0.15.1" lazy_static = "1.4.0" # zip versions after 0.6.3 don't work with our MSRV 1.57.0 zip = "=0.6.3" diff --git a/src/api.rs b/src/api.rs index 5c2fce86..1a3d2395 100644 --- a/src/api.rs +++ b/src/api.rs @@ -4,14 +4,14 @@ pub use bitcoin::consensus::{deserialize, serialize}; pub use bitcoin::hashes::hex::FromHex; -pub use bitcoin::{BlockHash, OutPoint, Script, Transaction, TxIn, TxOut, Txid, Witness}; +pub use bitcoin::{BlockHash, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Txid, Witness}; use serde::Deserialize; #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] pub struct PrevOut { pub value: u64, - pub scriptpubkey: Script, + pub scriptpubkey: ScriptBuf, } #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] @@ -20,7 +20,7 @@ pub struct Vin { pub vout: u32, // None if coinbase pub prevout: Option, - pub scriptsig: Script, + pub scriptsig: ScriptBuf, #[serde(deserialize_with = "deserialize_witness", default)] pub witness: Vec>, pub sequence: u32, @@ -30,7 +30,7 @@ pub struct Vin { #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] pub struct Vout { pub value: u64, - pub scriptpubkey: Script, + pub scriptpubkey: ScriptBuf, } #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] @@ -87,14 +87,14 @@ pub struct BlockSummary { pub time: BlockTime, /// Hash of the previous block, will be `None` for the genesis block. pub previousblockhash: Option, - pub merkle_root: bitcoin::TxMerkleNode, + pub merkle_root: bitcoin::hash_types::TxMerkleNode, } impl Tx { pub fn to_tx(&self) -> Transaction { Transaction { version: self.version, - lock_time: bitcoin::PackedLockTime(self.locktime), + lock_time: bitcoin::absolute::LockTime::from_consensus(self.locktime), input: self .vin .iter() @@ -106,7 +106,7 @@ impl Tx { }, script_sig: vin.scriptsig, sequence: bitcoin::Sequence(vin.sequence), - witness: Witness::from_vec(vin.witness), + witness: Witness::from_slice(&vin.witness), }) .collect(), output: self diff --git a/src/async.rs b/src/async.rs index bc1012fc..5778e823 100644 --- a/src/async.rs +++ b/src/async.rs @@ -15,9 +15,10 @@ use std::collections::HashMap; use std::str::FromStr; use bitcoin::consensus::{deserialize, serialize}; -use bitcoin::hashes::hex::{FromHex, ToHex}; +use bitcoin::hashes::hex::FromHex; use bitcoin::hashes::{sha256, Hash}; -use bitcoin::{Block, BlockHash, BlockHeader, MerkleBlock, Script, Transaction, Txid}; +use bitcoin::{Block, BlockHash, block::Header as BlockHeader, MerkleBlock, Script, Transaction, Txid}; +use bitcoin_internals::hex::display::DisplayHex; #[allow(unused_imports)] use log::{debug, error, info, trace}; @@ -212,7 +213,7 @@ impl AsyncClient { pub async fn broadcast(&self, transaction: &Transaction) -> Result<(), Error> { self.client .post(&format!("{}/tx", self.url)) - .body(serialize(transaction).to_hex()) + .body(serialize(transaction).to_lower_hex_string()) .send() .await? .error_for_status()?; @@ -269,13 +270,13 @@ impl AsyncClient { script: &Script, last_seen: Option, ) -> Result, Error> { - let script_hash = sha256::Hash::hash(script.as_bytes()).into_inner().to_hex(); + let script_hash = sha256::Hash::hash(script.as_bytes()); let url = match last_seen { Some(last_seen) => format!( - "{}/scripthash/{}/txs/chain/{}", + "{}/scripthash/{:x}/txs/chain/{}", self.url, script_hash, last_seen ), - None => format!("{}/scripthash/{}/txs", self.url, script_hash), + None => format!("{}/scripthash/{:x}/txs", self.url, script_hash), }; Ok(self .client diff --git a/src/blocking.rs b/src/blocking.rs index 8c56c4b4..51f5be5d 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -23,9 +23,11 @@ use log::{debug, error, info, trace}; use ureq::{Agent, Proxy, Response}; use bitcoin::consensus::{deserialize, serialize}; -use bitcoin::hashes::hex::{FromHex, ToHex}; +use bitcoin::hashes::hex::FromHex; use bitcoin::hashes::{sha256, Hash}; -use bitcoin::{Block, BlockHash, BlockHeader, MerkleBlock, Script, Transaction, Txid}; +use bitcoin::{Block, BlockHash, block::Header as BlockHeader, MerkleBlock, Script, Transaction, Txid}; + +use bitcoin_internals::hex::display::DisplayHex; use crate::{BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus}; @@ -244,7 +246,7 @@ impl BlockingClient { let resp = self .agent .post(&format!("{}/tx", self.url)) - .send_string(&serialize(transaction).to_hex()); + .send_string(&serialize(transaction).to_lower_hex_string()); match resp { Ok(_) => Ok(()), // We do not return the txid? @@ -329,13 +331,13 @@ impl BlockingClient { script: &Script, last_seen: Option, ) -> Result, Error> { - let script_hash = sha256::Hash::hash(script.as_bytes()).into_inner().to_hex(); + let script_hash = sha256::Hash::hash(script.as_bytes()); let url = match last_seen { Some(last_seen) => format!( - "{}/scripthash/{}/txs/chain/{}", + "{}/scripthash/{:x}/txs/chain/{}", self.url, script_hash, last_seen ), - None => format!("{}/scripthash/{}/txs", self.url, script_hash), + None => format!("{}/scripthash/{:x}/txs", self.url, script_hash), }; Ok(self.agent.get(&url).call()?.into_json()?) } diff --git a/src/lib.rs b/src/lib.rs index 574618ad..cacb1155 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -224,10 +224,10 @@ mod test { bitcoin::hashes::Hash, bitcoin::Amount, electrsd::{ - bitcoind::bitcoincore_rpc::bitcoincore_rpc_json::AddressType, + bitcoind::bitcoincore_rpc::json::AddressType, bitcoind::bitcoincore_rpc::RpcApi, + electrum_client::ElectrumApi, }, - electrum_client::ElectrumApi, std::time::Duration, tokio::sync::OnceCell, }; @@ -292,7 +292,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let _block_hashes = BITCOIND .client .generate_to_address(num as u64, &address) @@ -383,7 +384,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -413,7 +415,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -443,7 +446,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -572,7 +576,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -603,7 +608,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -643,7 +649,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( @@ -741,7 +748,8 @@ mod test { let address = BITCOIND .client .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap(); + .unwrap() + .assume_checked(); let txid = BITCOIND .client .send_to_address( From 73768c5e2c6a37c4bebc50068774b5f6be013279 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 28 Jun 2023 08:03:54 +1000 Subject: [PATCH 3/5] Add pinning note to electrum-client dependency A pending to `rust-electrum-client` [0] fixes the pinning here in our CI, add a comment to remind us to fix the pinning when the PR is merged and released. [0] https://github.com/bitcoindevkit/rust-electrum-client/pull/110 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index beca42f2..bc3990ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ reqwest = { version = "0.11", optional = true, default-features = false, feature serde_json = "1.0" tokio = { version = "1.20.1", features = ["full"] } electrsd = { version = "0.24.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_22_0"] } -electrum-client = "0.15.1" +electrum-client = "0.15.1" # When updating to 0.16 remove version number from rustls pin in CI. lazy_static = "1.4.0" # zip versions after 0.6.3 don't work with our MSRV 1.57.0 zip = "=0.6.3" From 8d1f90745103aaf5e90a6502c770f9572de5311d Mon Sep 17 00:00:00 2001 From: Vladimir Fomene Date: Wed, 28 Jun 2023 20:14:04 +0300 Subject: [PATCH 4/5] Upgrade electrum-client to 0.16.0 --- .github/workflows/cont_integration.yml | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 74f9839e..c549e548 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -49,8 +49,8 @@ jobs: - name: Update toolchain run: rustup update - name: pin dependencies - if: ${{ matrix.rust.version }} == 1.57.0 - run: cargo update -p log --precise 0.4.18 && cargo update -p rustls@0.21.2 --precise 0.21.1 + if: matrix.rust.version == '1.57.0' + run: cargo update -p log --precise 0.4.18 && cargo update -p rustls:0.21.2 --precise 0.21.1 && cargo update -p time:0.3.15 --precise 0.3.13 - name: Build run: cargo build --features ${{ matrix.features }} --no-default-features - name: Clippy diff --git a/Cargo.toml b/Cargo.toml index bc3990ab..3ff00a87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ reqwest = { version = "0.11", optional = true, default-features = false, feature serde_json = "1.0" tokio = { version = "1.20.1", features = ["full"] } electrsd = { version = "0.24.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_22_0"] } -electrum-client = "0.15.1" # When updating to 0.16 remove version number from rustls pin in CI. +electrum-client = "0.16.0" lazy_static = "1.4.0" # zip versions after 0.6.3 don't work with our MSRV 1.57.0 zip = "=0.6.3" From cd497a75a21bad18b514f4ff3da050c223295aaa Mon Sep 17 00:00:00 2001 From: Vladimir Fomene Date: Thu, 29 Jun 2023 09:41:52 +0300 Subject: [PATCH 5/5] Redundant import --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index cacb1155..f4fe6444 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,7 +64,6 @@ use std::fmt; use std::io; use bitcoin::consensus; -use bitcoin::{BlockHash, Txid}; pub mod api;