From 30899e9e81489c385bac95bffd3e5175875e6073 Mon Sep 17 00:00:00 2001 From: Nadav Ivgi Date: Tue, 8 Aug 2023 20:38:46 +0300 Subject: [PATCH 1/8] Update rust-bitcoin to v0.30.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some API JSON data types were updated to match changes in the underlying rust-bitcoin data types: - vsize and weights were changed from u32 to u64 (in `GET /tx/:txid`, `GET /block/:hash`, `GET /mempool` and `GET /mempool/recent`) - The `fee_histogram` was changed from [(f32,u32)] to [(f64,u64)] (in `GET /mempool` and Electrum's `mempool.get_fee_histogram`) - Block mining difficulty was changed from u64 to u128 (in GET `/block/:hash`) The actual JSON string serialization should remain unchanged, as serde-json serializes u64/u128/f64 as standard JSON numbers. However, numbers over ECMAScript's MAX_SAFE_INTEGER (2⁵³-1) may now produce JSON that some clients may fail to read correctly, while previously they would overflow (or error) on the server side. This shouldn't matter in practice because there shouldn't be such large numbers for weights, vsizes or mining difficulty. And if there are, the new behaviour seems (arguably?) better. To retain DB compatibility, block weights are converted to a u32 for the BlockMeta storage. This is OK because u32::MAX is far above MAX_BLOCK_WEIGHT. --- Cargo.lock | 75 ++++++++++++++++++- Cargo.toml | 3 +- src/bin/tx-fingerprint-stats.rs | 4 +- src/chain.rs | 8 +- src/daemon.rs | 44 +++++------ src/electrum/client.rs | 12 ++- src/new_index/mempool.rs | 6 +- src/new_index/precache.rs | 4 +- src/new_index/schema.rs | 2 +- src/rest.rs | 129 ++++++++++++++------------------ src/util/block.rs | 27 +++++-- src/util/fees.rs | 15 ++-- src/util/mod.rs | 19 ++--- src/util/script.rs | 8 +- 14 files changed, 212 insertions(+), 144 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7fef399bf..d2a50dd3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,6 +106,12 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf9ff0bbfd639f15c74af777d81383cf53efb7c93613f6cab67c6c11e05bbf8b" +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + [[package]] name = "bincode" version = "1.3.3" @@ -140,7 +146,7 @@ version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a41df6ad9642c5c15ae312dd3d074de38fd3eb7cc87ad4ce10f90292a83fe4d" dependencies = [ - "bech32", + "bech32 0.8.1", "bitcoin_hashes 0.10.0", "secp256k1 0.20.3", "serde", @@ -152,12 +158,32 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42b2a9a8e3c7544f5ce2b475f2f56580a3102b37e0ee001558ad4faedcf56cf4" dependencies = [ - "bech32", + "bech32 0.8.1", "bitcoin_hashes 0.10.0", "secp256k1 0.22.1", "serde", ] +[[package]] +name = "bitcoin" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e99ff7289b20a7385f66a0feda78af2fc119d28fb56aea8886a9cd0a4abdd75" +dependencies = [ + "bech32 0.9.1", + "bitcoin-private", + "bitcoin_hashes 0.12.0", + "hex_lit", + "secp256k1 0.27.0", + "serde", +] + +[[package]] +name = "bitcoin-private" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" + [[package]] name = "bitcoin_hashes" version = "0.7.6" @@ -173,6 +199,16 @@ dependencies = [ "serde", ] +[[package]] +name = "bitcoin_hashes" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d7066118b13d4b20b23645932dfb3a81ce7e29f95726c2036fa33cd7b092501" +dependencies = [ + "bitcoin-private", + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -354,7 +390,7 @@ dependencies = [ "arrayref", "base64 0.13.0", "bincode", - "bitcoin 0.28.0", + "bitcoin 0.30.1", "clap", "crossbeam-channel", "dirs", @@ -363,6 +399,7 @@ dependencies = [ "error-chain", "glob", "hex", + "hex-conservative", "hyper", "hyperlocal", "itertools", @@ -571,6 +608,18 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hex-conservative" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" + +[[package]] +name = "hex_lit" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" + [[package]] name = "http" version = "0.2.6" @@ -1341,6 +1390,17 @@ dependencies = [ "serde", ] +[[package]] +name = "secp256k1" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" +dependencies = [ + "bitcoin_hashes 0.12.0", + "secp256k1-sys 0.8.1", + "serde", +] + [[package]] name = "secp256k1-sys" version = "0.4.2" @@ -1359,6 +1419,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" +dependencies = [ + "cc", +] + [[package]] name = "secp256k1-zkp" version = "0.6.0" diff --git a/Cargo.toml b/Cargo.toml index 7b8ec562c..f3b5ccc43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ arraydeque = "0.4" arrayref = "0.3.6" base64 = "0.13.0" bincode = "1.3.1" -bitcoin = { version = "0.28", features = [ "use-serde" ] } +bitcoin = { version = "0.30.1", features = [ "serde" ] } clap = "2.33.3" crossbeam-channel = "0.5.0" dirs = "4.0.0" @@ -55,6 +55,7 @@ hyper = "0.14" hyperlocal = "0.8" # close to same tokio version as dependent by hyper v0.14 and hyperlocal 0.8 -- things can go awry if they mismatch tokio = { version = "1", features = ["sync", "macros"] } +bhex = { package = "hex-conservative", version = "0.1.1" } # optional dependencies for electrum-discovery electrum-client = { version = "0.8", optional = true } diff --git a/src/bin/tx-fingerprint-stats.rs b/src/bin/tx-fingerprint-stats.rs index f3ccf45e0..da5318547 100644 --- a/src/bin/tx-fingerprint-stats.rs +++ b/src/bin/tx-fingerprint-stats.rs @@ -9,7 +9,7 @@ fn main() { use std::collections::HashSet; use std::sync::Arc; - use bitcoin::blockdata::script::Script; + use bitcoin::blockdata::script::ScriptBuf; use bitcoin::consensus::encode::deserialize; use electrs::{ chain::Transaction, @@ -118,7 +118,7 @@ fn main() { // test for sending back to one of the spent spks let has_reuse = { - let prev_spks: HashSet