From 79daadb5897d164204e03fcdb8363acd3923d516 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 23 Jan 2025 10:11:51 +0530 Subject: [PATCH 1/2] replace bitcoind with corpc-node crate --- roles/Cargo.lock | 269 +++++++++++++++--- roles/tests-integration/Cargo.toml | 2 +- .../lib/template_provider.rs | 18 +- 3 files changed, 237 insertions(+), 52 deletions(-) diff --git a/roles/Cargo.lock b/roles/Cargo.lock index c676e28f1..21a79749e 100644 --- a/roles/Cargo.lock +++ b/roles/Cargo.lock @@ -367,6 +367,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bech32" version = "0.9.1" @@ -415,6 +421,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce6bc65742dea50536e35ad42492b234c27904a27f0abdcbce605015cb4ea026" dependencies = [ "base58ck", + "base64 0.21.7", "bech32 0.11.0", "bitcoin-internals 0.3.0", "bitcoin-io", @@ -493,43 +500,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitcoincore-rpc" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aedd23ae0fd321affb4bbbc36126c6f49a32818dc6b979395d24da8c9d4e80ee" -dependencies = [ - "bitcoincore-rpc-json", - "jsonrpc", - "log", - "serde", - "serde_json", -] - -[[package]] -name = "bitcoincore-rpc-json" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8909583c5fab98508e80ef73e5592a651c954993dc6b7739963257d19f0e71a" -dependencies = [ - "bitcoin 0.32.5", - "serde", - "serde_json", -] - -[[package]] -name = "bitcoind" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ce6620b7c942dbe28cc49c21d95e792feb9ffd95a093205e7875ccfa69c2925" -dependencies = [ - "anyhow", - "bitcoincore-rpc", - "log", - "tempfile", - "which", -] - [[package]] name = "bitflags" version = "2.6.0" @@ -605,12 +575,35 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" +[[package]] +name = "bzip2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "cc" version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf" dependencies = [ + "jobserver", + "libc", "shlex", ] @@ -775,6 +768,12 @@ dependencies = [ name = "const_sv2" version = "3.0.0" +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + [[package]] name = "convert_case" version = "0.6.0" @@ -784,6 +783,51 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "corepc-client" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb85495f0577f4765ea2ece0a69003d38acdddba2ac06bdde180ac2b969a9a63" +dependencies = [ + "bitcoin 0.32.5", + "corepc-types", + "jsonrpc", + "log", + "serde", + "serde_json", +] + +[[package]] +name = "corepc-node" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "887faf7fdf38a5b99b3efb69e18e27fb9de77c812c5c48956a8076c7f9076b99" +dependencies = [ + "anyhow", + "bitcoin_hashes 0.14.0", + "corepc-client", + "flate2", + "log", + "minreq", + "serde_json", + "tar", + "tempfile", + "which", + "zip", +] + +[[package]] +name = "corepc-types" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282d9bd7fd9d944471a0c0ad44fd1581acd87a79739652c5455ffdae25177db6" +dependencies = [ + "bitcoin 0.32.5", + "bitcoin-internals 0.3.0", + "serde", + "serde_json", +] + [[package]] name = "cpufeatures" version = "0.2.16" @@ -834,6 +878,15 @@ dependencies = [ "cipher", ] +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "derive_codec_sv2" version = "1.1.1" @@ -858,6 +911,7 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", "crypto-common", + "subtle", ] [[package]] @@ -1219,6 +1273,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "home" version = "0.5.9" @@ -1339,9 +1402,9 @@ version = "0.1.0" dependencies = [ "async-channel 1.9.0", "binary_sv2", - "bitcoind", "codec_sv2", "const_sv2", + "corepc-node", "flate2", "jd_client", "jd_server", @@ -1433,6 +1496,15 @@ dependencies = [ "const_sv2", ] +[[package]] +name = "jobserver" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +dependencies = [ + "libc", +] + [[package]] name = "js-sys" version = "0.3.76" @@ -1714,6 +1786,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.46" @@ -1798,12 +1876,35 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + [[package]] name = "pathdiff" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3" +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest 0.10.7", + "hmac", + "password-hash", + "sha2 0.10.8", +] + [[package]] name = "pest" version = "2.7.15" @@ -1872,6 +1973,12 @@ dependencies = [ "futures-io", ] +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + [[package]] name = "polling" version = "3.7.4" @@ -1936,6 +2043,12 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -2162,7 +2275,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" dependencies = [ "bitcoin_hashes 0.14.0", - "rand", "secp256k1-sys 0.10.1", "serde", ] @@ -2243,6 +2355,17 @@ dependencies = [ "serde", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + [[package]] name = "sha2" version = "0.9.9" @@ -2445,6 +2568,25 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -2966,3 +3108,52 @@ name = "zeroize" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zip" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +dependencies = [ + "aes", + "byteorder", + "bzip2", + "constant_time_eq", + "crc32fast", + "crossbeam-utils", + "flate2", + "hmac", + "pbkdf2", + "sha1", + "time", + "zstd", +] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.13+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/roles/tests-integration/Cargo.toml b/roles/tests-integration/Cargo.toml index 81d468596..262907dd6 100644 --- a/roles/tests-integration/Cargo.toml +++ b/roles/tests-integration/Cargo.toml @@ -12,8 +12,8 @@ keywords = ["stratum", "mining", "bitcoin", "protocol"] [dependencies] async-channel = "1.5.1" +corepc-node = "0.5.0" binary_sv2 = { path = "../../protocols/v2/binary-sv2/binary-sv2" } -bitcoind = "0.36.0" codec_sv2 = { path = "../../protocols/v2/codec-sv2", features = ["noise_sv2"] } const_sv2 = { path = "../../protocols/v2/const-sv2" } flate2 = "1.0.32" diff --git a/roles/tests-integration/lib/template_provider.rs b/roles/tests-integration/lib/template_provider.rs index 17ce20c18..6670e625b 100644 --- a/roles/tests-integration/lib/template_provider.rs +++ b/roles/tests-integration/lib/template_provider.rs @@ -1,4 +1,4 @@ -use bitcoind::{bitcoincore_rpc::RpcApi, BitcoinD, Conf}; +use corepc_node::{Conf, Node}; use flate2::read::GzDecoder; use std::{ env, @@ -62,7 +62,7 @@ fn get_bitcoind_filename(os: &str, arch: &str) -> String { #[derive(Debug)] pub struct TemplateProvider { - bitcoind: BitcoinD, + bitcoind: Node, } impl TemplateProvider { @@ -127,24 +127,18 @@ impl TemplateProvider { } env::set_var("BITCOIND_EXE", bitcoin_exe_home.join("bitcoind")); - let exe_path = bitcoind::exe_path().unwrap(); + let exe_path = corepc_node::exe_path().unwrap(); - let bitcoind = BitcoinD::with_conf(exe_path, &conf).unwrap(); + let bitcoind = Node::with_conf(exe_path, &conf).unwrap(); TemplateProvider { bitcoind } } pub fn generate_blocks(&self, n: u64) { - let mining_address = self - .bitcoind - .client - .get_new_address(None, None) - .unwrap() - .require_network(bitcoind::bitcoincore_rpc::bitcoin::Network::Regtest) - .unwrap(); + let mining_address = self.bitcoind.client.new_address().unwrap(); self.bitcoind .client - .generate_to_address(n, &mining_address) + .generate_to_address(n as usize, &mining_address) .unwrap(); } } From 1db0b6954f1f9b012ca387cb5ecf621689e1143d Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Thu, 23 Jan 2025 20:38:06 +0530 Subject: [PATCH 2/2] replace unwraps with expects block for error verbosity --- roles/tests-integration/lib/template_provider.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/roles/tests-integration/lib/template_provider.rs b/roles/tests-integration/lib/template_provider.rs index 6670e625b..28031626a 100644 --- a/roles/tests-integration/lib/template_provider.rs +++ b/roles/tests-integration/lib/template_provider.rs @@ -127,18 +127,22 @@ impl TemplateProvider { } env::set_var("BITCOIND_EXE", bitcoin_exe_home.join("bitcoind")); - let exe_path = corepc_node::exe_path().unwrap(); + let exe_path = corepc_node::exe_path().expect("Failed to get bitcoind path"); - let bitcoind = Node::with_conf(exe_path, &conf).unwrap(); + let bitcoind = Node::with_conf(exe_path, &conf).expect("Failed to create Node"); TemplateProvider { bitcoind } } pub fn generate_blocks(&self, n: u64) { - let mining_address = self.bitcoind.client.new_address().unwrap(); + let mining_address = self + .bitcoind + .client + .new_address() + .expect("Failed to get mining address"); self.bitcoind .client .generate_to_address(n as usize, &mining_address) - .unwrap(); + .expect("Failed to generate blocks"); } }