From 8b744219b0d298ec448703bc215527bc715450f9 Mon Sep 17 00:00:00 2001 From: driftluo Date: Thu, 13 Jun 2024 15:21:58 +0800 Subject: [PATCH 1/6] chore: upgrade deps --- Cargo.lock | 155 ++++++++++-------- Cargo.toml | 146 +++++++++-------- benches/Cargo.toml | 4 +- miner/Cargo.toml | 8 +- miner/src/worker/mod.rs | 2 +- network/Cargo.toml | 32 ++-- network/src/network.rs | 6 +- network/src/peer_store/addr_manager.rs | 2 +- network/src/protocols/tests/mod.rs | 2 +- .../src/services/dns_seeding/seed_record.rs | 2 +- network/src/services/dns_seeding/tests.rs | 2 +- sync/Cargo.toml | 10 +- sync/src/tests/net_time_checker.rs | 2 +- sync/src/tests/types.rs | 4 +- test/Cargo.toml | 9 +- test/src/specs/mining/fee.rs | 4 +- test/src/txo.rs | 2 +- util/app-config/Cargo.toml | 16 +- util/crypto/Cargo.toml | 6 +- util/crypto/src/secp/privkey.rs | 2 +- util/crypto/src/secp/pubkey.rs | 2 +- util/crypto/src/secp/signature.rs | 2 +- util/gen-types/Cargo.toml | 17 +- util/multisig/Cargo.toml | 2 +- util/types/Cargo.toml | 16 +- verification/contextual/Cargo.toml | 10 +- 26 files changed, 263 insertions(+), 202 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 96aa488a20..58b578e4a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -383,6 +383,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "tinyvec", +] + [[package]] name = "bstr" version = "1.9.1" @@ -420,7 +429,7 @@ version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "142316461ed3a3dfcba10417317472da5bfd0461e4d276bf7c07b330766d9490" dependencies = [ - "digest 0.10.7", + "digest", "either", "futures", "hex", @@ -601,7 +610,7 @@ dependencies = [ "ckb-types", "clap", "path-clean", - "rand 0.7.3", + "rand 0.8.5", "sentry", "serde", "serde_json", @@ -646,7 +655,7 @@ dependencies = [ "ckb-verification-traits", "criterion", "lazy_static", - "rand 0.7.3", + "rand 0.8.5", "tempfile", ] @@ -791,7 +800,7 @@ dependencies = [ "ckb-fixed-hash", "faster-hex", "lazy_static", - "rand 0.7.3", + "rand 0.8.5", "secp256k1", "thiserror", ] @@ -1192,7 +1201,7 @@ dependencies = [ "indicatif", "jsonrpc-core", "lru", - "rand 0.7.3", + "rand 0.8.5", "rand_distr", "serde", "serde_json", @@ -1206,7 +1215,7 @@ dependencies = [ "ckb-crypto", "ckb-error", "ckb-logger", - "rand 0.7.3", + "rand 0.8.5", ] [[package]] @@ -1215,7 +1224,7 @@ version = "0.117.0-pre" dependencies = [ "bitflags 1.3.2", "bloom-filters", - "bs58", + "bs58 0.4.0", "ckb-app-config", "ckb-hash", "ckb-logger", @@ -1233,13 +1242,13 @@ dependencies = [ "num_cpus", "once_cell", "proptest", - "rand 0.7.3", + "rand 0.8.5", "secp256k1", "sentry", "serde", "serde_json", "snap", - "socket2 0.4.10", + "socket2 0.5.6", "tempfile", "tentacle", "tokio", @@ -1612,7 +1621,7 @@ dependencies = [ "keyed_priority_queue", "lru", "once_cell", - "rand 0.7.3", + "rand 0.8.5", "sentry", "sled", "tempfile", @@ -1777,7 +1786,7 @@ dependencies = [ "ckb-types", "ckb-verification", "ckb-verification-traits", - "rand 0.7.3", + "rand 0.8.5", "rayon", "tokio", ] @@ -2144,17 +2153,31 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" [[package]] name = "curve25519-dalek" -version = "3.2.0" +version = "4.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.5.1", + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "fiat-crypto", + "platforms", + "rustc_version", "subtle", "zeroize", ] +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "daemonize" version = "0.5.0" @@ -2259,15 +2282,6 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - [[package]] name = "digest" version = "0.10.7" @@ -2449,6 +2463,12 @@ dependencies = [ "libc", ] +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + [[package]] name = "finl_unicode" version = "1.2.0" @@ -2655,10 +2675,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if", - "js-sys", "libc", "wasi 0.9.0+wasi-snapshot-preview1", - "wasm-bindgen", ] [[package]] @@ -2668,8 +2686,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -2887,7 +2907,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.7", + "digest", ] [[package]] @@ -3452,7 +3472,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" dependencies = [ "cfg-if", - "digest 0.10.7", + "digest", ] [[package]] @@ -3536,9 +3556,9 @@ dependencies = [ [[package]] name = "molecule" -version = "0.7.5" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd9767ab5e5f2ea40f71ff4c8bdb633c50509052e093c2fdd0e390a749dfa3" +checksum = "6efe1c7efcd0bdf4ca590e104bcb13087d9968956ae4ae98e92fb8c1da0f3730" dependencies = [ "bytes", "cfg-if", @@ -4090,6 +4110,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" +[[package]] +name = "platforms" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" + [[package]] name = "plotters" version = "0.3.5" @@ -4369,12 +4395,12 @@ dependencies = [ [[package]] name = "rand_distr" -version = "0.3.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e9532ada3929fb8b2e9dbe28d1e06c9b2cc65813f074fcb6bd5fbefeff9d56" +checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" dependencies = [ "num-traits", - "rand 0.7.3", + "rand 0.8.5", ] [[package]] @@ -4757,18 +4783,18 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.24.3" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b1629c9c557ef9b293568b338dddfc8208c98a18c59d722a9d53f859d9c9b62" +checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" dependencies = [ "secp256k1-sys", ] [[package]] name = "secp256k1-sys" -version = "0.6.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83080e2c2fc1006e625be82e5d1eb6a43b7fd9578b617fcc55814daf286bba4b" +checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" dependencies = [ "cc", ] @@ -4974,7 +5000,7 @@ checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.7", + "digest", ] [[package]] @@ -4985,7 +5011,7 @@ checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.7", + "digest", ] [[package]] @@ -4996,7 +5022,7 @@ checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.7", + "digest", ] [[package]] @@ -5098,16 +5124,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.6" @@ -5257,7 +5273,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da7a2b3c2bc9693bcb40870c4e9b5bf0d79f9cb46273321bf855ec513e919082" dependencies = [ "base64 0.21.7", - "digest 0.10.7", + "digest", "hex", "miette", "serde", @@ -5338,9 +5354,9 @@ dependencies = [ [[package]] name = "tentacle" -version = "0.4.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ffbbdb4f54a9605ceda168884efcf5fb24ef655103362af211e6cfe61eff832" +checksum = "d335523ec132a2bbefbaf403b52eba047fb50bc83bed2d0b1d22c119bae2fec1" dependencies = [ "async-trait", "bytes", @@ -5354,7 +5370,7 @@ dependencies = [ "once_cell", "parking_lot 0.12.1", "rand 0.8.5", - "socket2 0.4.10", + "socket2 0.5.6", "tentacle-multiaddr", "tentacle-secio", "thiserror", @@ -5368,11 +5384,11 @@ dependencies = [ [[package]] name = "tentacle-multiaddr" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "895b25a7de42f7bba27b011495a4a48ea7f0591c079f59c8fdb07936ca8aa3d1" +checksum = "8a9e71b28bf0bbf274b92f47cb2c5b42755d84a11e2246cf7bcb7b65c89483b9" dependencies = [ - "bs58", + "bs58 0.5.1", "bytes", "serde", "sha2", @@ -5381,23 +5397,23 @@ dependencies = [ [[package]] name = "tentacle-secio" -version = "0.5.7" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78a41abd9ae459d1f744f59670d8f4e9a25c4597b12b9060740fbd17bf9687fc" +checksum = "cac8b23a7879426a4961acea6ae66287f7fe9a934d131a722cbb88f145e97fea" dependencies = [ - "bs58", + "bs58 0.5.1", "bytes", "chacha20poly1305", "futures", + "getrandom 0.2.12", "hmac", "log", "molecule", "openssl", "openssl-sys", - "rand 0.7.3", "rand 0.8.5", - "rand_core 0.5.1", - "ring 0.16.20", + "rand_core 0.6.4", + "ring 0.17.7", "secp256k1", "sha2", "tokio", @@ -6044,9 +6060,9 @@ dependencies = [ [[package]] name = "unsigned-varint" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6889a77d49f1f013504cec6bf97a2c730394adedaeb1deb5ea08949a50541105" +checksum = "eb066959b24b5196ae73cb057f45598450d2c5f71460e98c49b738086eff9c06" [[package]] name = "untrusted" @@ -6510,12 +6526,13 @@ dependencies = [ [[package]] name = "x25519-dalek" -version = "1.1.1" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a0c105152107e3b96f6a00a65e86ce82d9b125230e1c4302940eca58ff71f4f" +checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277" dependencies = [ "curve25519-dalek", - "rand_core 0.5.1", + "rand_core 0.6.4", + "serde", "zeroize", ] diff --git a/Cargo.toml b/Cargo.toml index 3361e53e1d..4f04646ca8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,77 +23,77 @@ console-subscriber = { version = "0.2.0", optional = true } [workspace] # To get a list sorted by dependencies, run devtools/ci/check-cyclic-dependencies.py members = [ - "util", - "util/occupied-capacity/core", - "util/channel", - "util/systemtime", - "util/fixed-hash/core", - "util/build-info", - "util/logger", - "util/logger-config", - "util/metrics-config", - "util/hash", - "util/rational", - "benches", - "db-schema", - "util/spawn", - "util/occupied-capacity/macros", - "util/fixed-hash/macros", - "util/logger-service", - "util/runtime", - "util/stop-handler", - "util/metrics", - "util/metrics-service", - "util/fixed-hash", - "util/occupied-capacity", - "util/crypto", - "util/constant", - "error", - "util/multisig", - "util/gen-types", - "util/migrate/migration-template", - "util/types", - "util/jsonrpc-types", - "freezer", - "resource", - "pow", - "util/dao/utils", - "traits", - "spec", - "util/proposal-table", - "script", - "util/app-config", - "db", - "network", - "miner", - "notify", - "util/memory-tracker", - "db-migration", - "util/network-alert", - "store", - "util/indexer-sync", - "util/indexer", - "util/rich-indexer", - "util/chain-iter", - "util/dao", - "util/test-chain-utils", - "util/reward-calculator", - "util/snapshot", - "util/migrate", - "verification/traits", - "verification", - "verification/contextual", - "tx-pool", - "shared", - "block-filter", - "chain", - "sync", - "util/instrument", - "rpc", - "util/light-client-protocol-server", - "util/launcher", - "devtools/doc/rpc-gen", - "ckb-bin" + "util", + "util/occupied-capacity/core", + "util/channel", + "util/systemtime", + "util/fixed-hash/core", + "util/build-info", + "util/logger", + "util/logger-config", + "util/metrics-config", + "util/hash", + "util/rational", + "benches", + "db-schema", + "util/spawn", + "util/occupied-capacity/macros", + "util/fixed-hash/macros", + "util/logger-service", + "util/runtime", + "util/stop-handler", + "util/metrics", + "util/metrics-service", + "util/fixed-hash", + "util/occupied-capacity", + "util/crypto", + "util/constant", + "error", + "util/multisig", + "util/gen-types", + "util/migrate/migration-template", + "util/types", + "util/jsonrpc-types", + "freezer", + "resource", + "pow", + "util/dao/utils", + "traits", + "spec", + "util/proposal-table", + "script", + "util/app-config", + "db", + "network", + "miner", + "notify", + "util/memory-tracker", + "db-migration", + "util/network-alert", + "store", + "util/indexer-sync", + "util/indexer", + "util/rich-indexer", + "util/chain-iter", + "util/dao", + "util/test-chain-utils", + "util/reward-calculator", + "util/snapshot", + "util/migrate", + "verification/traits", + "verification", + "verification/contextual", + "tx-pool", + "shared", + "block-filter", + "chain", + "sync", + "util/instrument", + "rpc", + "util/light-client-protocol-server", + "util/launcher", + "devtools/doc/rpc-gen", + "ckb-bin", ] [workspace.dependencies] @@ -115,7 +115,9 @@ lto = true codegen-units = 1 [target.'cfg(all(not(target_env = "msvc"), not(target_os="macos")))'.dependencies] -tikv-jemallocator = { version = "0.5.0", features = ["unprefixed_malloc_on_supported_platforms"] } +tikv-jemallocator = { version = "0.5.0", features = [ + "unprefixed_malloc_on_supported_platforms", +] } [features] default = [] diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 6962393d9b..8d8fa37d6a 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -18,8 +18,8 @@ ckb-types = { path = "../util/types", version = "= 0.117.0-pre" } ckb-shared = { path = "../shared", version = "= 0.117.0-pre" } ckb-store = { path = "../store", version = "= 0.117.0-pre" } ckb-chain-spec = { path = "../spec", version = "= 0.117.0-pre" } -rand = "0.7" -ckb-hash = {path = "../util/hash", version = "= 0.117.0-pre"} +rand = "0.8" +ckb-hash = { path = "../util/hash", version = "= 0.117.0-pre" } ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.117.0-pre" } ckb-dao-utils = { path = "../util/dao/utils", version = "= 0.117.0-pre" } ckb-dao = { path = "../util/dao", version = "= 0.117.0-pre" } diff --git a/miner/Cargo.toml b/miner/Cargo.toml index da3134b29e..97f613ba23 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -15,12 +15,12 @@ ckb-types = { path = "../util/types", version = "= 0.117.0-pre" } ckb-channel = { path = "../util/channel", version = "= 0.117.0-pre" } ckb-hash = { path = "../util/hash", version = "= 0.117.0-pre" } ckb-pow = { path = "../pow", version = "= 0.117.0-pre" } -rand = "0.7" -rand_distr = "0.3" +rand = "0.8" +rand_distr = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" ckb-jsonrpc-types = { path = "../util/jsonrpc-types", version = "= 0.117.0-pre" } -hyper = { version = "0.14", features = ["client", "http2", "http1", "server"] } +hyper = { version = "0.14", features = ["client", "http2", "http1", "server"] } hyper-tls = "0.5" futures = "0.3" lru = "0.7.1" @@ -31,4 +31,4 @@ console = ">=0.9.1, <1.0.0" eaglesong = "0.1" base64 = "0.21.0" jsonrpc-core = "18.0" -tokio = { version = "1", features = ["sync"] } +tokio = { version = "1", features = ["sync"] } diff --git a/miner/src/worker/mod.rs b/miner/src/worker/mod.rs index 14a4ad4e25..86d5e028d6 100644 --- a/miner/src/worker/mod.rs +++ b/miner/src/worker/mod.rs @@ -58,7 +58,7 @@ fn partition_nonce(id: u128, total: u128) -> Range { fn nonce_generator(range: Range) -> impl FnMut() -> u128 { let mut rng = rand::thread_rng(); let Range { start, end } = range; - move || rng.gen_range(start, end) + move || rng.gen_range(start..end) } const PROGRESS_BAR_TEMPLATE: &str = "{prefix:.bold.dim} {spinner:.green} [{elapsed_precise}] {msg}"; diff --git a/network/Cargo.toml b/network/Cargo.toml index a0fa919f96..e840fe4170 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -7,26 +7,26 @@ edition = "2021" description = "ckb network implementation" homepage = "https://github.com/nervosnetwork/ckb" repository = "https://github.com/nervosnetwork/ckb" -exclude = [ "fuzz" ] +exclude = ["fuzz"] [dependencies] -rand = "0.7" +rand = "0.8" serde = { version = "1.0", features = ["derive"] } ckb-util = { path = "../util", version = "= 0.117.0-pre" } ckb-stop-handler = { path = "../util/stop-handler", version = "= 0.117.0-pre" } ckb-logger = { path = "../util/logger", version = "= 0.117.0-pre" } ckb-app-config = { path = "../util/app-config", version = "= 0.117.0-pre" } -ckb-metrics = {path = "../util/metrics", version = "= 0.117.0-pre"} +ckb-metrics = { path = "../util/metrics", version = "= 0.117.0-pre" } tokio = { version = "1", features = ["sync", "macros"] } tokio-util = { version = "0.7", features = ["codec"] } futures = "0.3" -ckb-systemtime = {path = "../util/systemtime", version = "= 0.117.0-pre"} +ckb-systemtime = { path = "../util/systemtime", version = "= 0.117.0-pre" } lazy_static = { version = "1.3.0", optional = true } bs58 = { version = "0.4.0", optional = true } sentry = { version = "0.26.0", optional = true } faster-hex = { version = "0.6", optional = true } -ckb-hash = {path = "../util/hash", version = "= 0.117.0-pre"} -secp256k1 = {version = "0.24", features = ["recovery"], optional = true } +ckb-hash = { path = "../util/hash", version = "= 0.117.0-pre" } +secp256k1 = { version = "0.29", features = ["recovery"], optional = true } trust-dns-resolver = { version = "0.20", optional = true } snap = "1" ckb-types = { path = "../util/types", version = "= 0.117.0-pre" } @@ -34,14 +34,24 @@ ipnetwork = "0.18" serde_json = "1.0" bloom-filters = "0.1" ckb-spawn = { path = "../util/spawn", version = "= 0.117.0-pre" } -socket2 = "0.4" +socket2 = "0.5" bitflags = "1.0" -p2p = { version="0.4.0", package="tentacle", features = ["upnp", "parking_lot", "openssl-vendored"] } +p2p = { version = "0.6.1", package = "tentacle", features = [ + "upnp", + "parking_lot", + "openssl-vendored", +] } [features] with_sentry = ["sentry"] -with_dns_seeding = ["lazy_static", "bs58", "faster-hex", "trust-dns-resolver", "secp256k1"] +with_dns_seeding = [ + "lazy_static", + "bs58", + "faster-hex", + "trust-dns-resolver", + "secp256k1", +] fuzz = [] [dev-dependencies] @@ -50,7 +60,9 @@ criterion = "0.5" proptest = "1.0" num_cpus = "1.10" once_cell = "1.8.0" -ckb-systemtime = {path = "../util/systemtime", version = "= 0.117.0-pre", features = ["enable_faketime"]} +ckb-systemtime = { path = "../util/systemtime", version = "= 0.117.0-pre", features = [ + "enable_faketime", +] } [[bench]] name = "peer_store" diff --git a/network/src/network.rs b/network/src/network.rs index 2a768936ac..ea7a135eee 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -32,7 +32,7 @@ use p2p::{ context::{ServiceContext, SessionContext}, error::{DialerErrorKind, HandshakeErrorKind, ProtocolHandleErrorKind, SendErrorKind}, multiaddr::{Multiaddr, Protocol}, - secio::{self, error::SecioError, PeerId}, + secio::{self, error::SecioError, PeerId, SecioKeyPair}, service::{ ProtocolHandle, Service, ServiceAsyncControl, ServiceError, ServiceEvent, TargetProtocol, TargetSession, @@ -762,7 +762,7 @@ impl ServiceHandle for EventHandler { /// Ckb network service, use to start p2p network pub struct NetworkService { - p2p_service: Service, + p2p_service: Service, network_state: Arc, ping_controller: Option>, // Background services @@ -890,7 +890,7 @@ impl NetworkService { network_state: Arc::clone(&network_state), }; service_builder = service_builder - .key_pair(network_state.local_private_key.clone()) + .handshake_type(network_state.local_private_key.clone().into()) .upnp(config.upnp) .yamux_config(yamux_config) .forever(true) diff --git a/network/src/peer_store/addr_manager.rs b/network/src/peer_store/addr_manager.rs index cadac4b0e9..b4b5179ba3 100644 --- a/network/src/peer_store/addr_manager.rs +++ b/network/src/peer_store/addr_manager.rs @@ -52,7 +52,7 @@ impl AddrManager { for i in 0..self.random_ids.len() { // reuse the for loop to shuffle random ids // https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle - let j = rng.gen_range(i, self.random_ids.len()); + let j = rng.gen_range(i..self.random_ids.len()); self.swap_random_id(j, i); let addr_info: AddrInfo = self.id_to_info[&self.random_ids[i]].to_owned(); if let Some(socket_addr) = multiaddr_to_socketaddr(&addr_info.addr) { diff --git a/network/src/protocols/tests/mod.rs b/network/src/protocols/tests/mod.rs index a2df501448..985e5d98d6 100644 --- a/network/src/protocols/tests/mod.rs +++ b/network/src/protocols/tests/mod.rs @@ -218,7 +218,7 @@ fn net_service_start( .insert_protocol(feeler_meta); let mut p2p_service = service_builder - .key_pair(network_state.local_private_key().clone()) + .handshake_type(network_state.local_private_key().clone().into()) .upnp(config.upnp) .forever(true) .build(EventHandler { diff --git a/network/src/services/dns_seeding/seed_record.rs b/network/src/services/dns_seeding/seed_record.rs index ed6c96f08d..80abd6e271 100644 --- a/network/src/services/dns_seeding/seed_record.rs +++ b/network/src/services/dns_seeding/seed_record.rs @@ -108,7 +108,7 @@ impl SeedRecord { let data = Self::data_to_sign(ip, port, peer_id.as_ref(), valid_until); let hash = blake2b_256(data); - let message = Message::from_slice(&hash).expect("create message error"); + let message = Message::from_digest_slice(&hash).expect("create message error"); if let Ok(pubkey) = SECP256K1.recover_ecdsa(&message, &signature) { Ok(SeedRecord { diff --git a/network/src/services/dns_seeding/tests.rs b/network/src/services/dns_seeding/tests.rs index 611fa960da..81ddea0521 100644 --- a/network/src/services/dns_seeding/tests.rs +++ b/network/src/services/dns_seeding/tests.rs @@ -57,7 +57,7 @@ impl SeedRecord { let data = Self::data_to_sign(self.ip, self.port, self.peer_id.as_ref(), self.valid_until); let hash = blake2b_256(&data); - let message = Message::from_slice(&hash).expect("create message error"); + let message = Message::from_digest_slice(&hash).expect("create message error"); let signature = SECP256K1.sign_ecdsa_recoverable(&message, privkey); let (recid, signed_data) = signature.serialize_compact(); diff --git a/sync/Cargo.toml b/sync/Cargo.toml index 1bf285f6c7..ae99571dc0 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -43,14 +43,18 @@ itertools.workspace = true [dev-dependencies] ckb-test-chain-utils = { path = "../util/test-chain-utils", version = "= 0.117.0-pre" } -rand = "0.7" +rand = "0.8" ckb-dao = { path = "../util/dao", version = "= 0.117.0-pre" } ckb-dao-utils = { path = "../util/dao/utils", version = "= 0.117.0-pre" } ckb-reward-calculator = { path = "../util/reward-calculator", version = "= 0.117.0-pre" } -ckb-chain = { path = "../chain", version = "= 0.117.0-pre", features = ["mock"] } +ckb-chain = { path = "../chain", version = "= 0.117.0-pre", features = [ + "mock", +] } faux = "^0.1" once_cell = "1.8.0" -ckb-systemtime = { path = "../util/systemtime", version = "= 0.117.0-pre", features = ["enable_faketime"] } +ckb-systemtime = { path = "../util/systemtime", version = "= 0.117.0-pre", features = [ + "enable_faketime", +] } ckb-proposal-table = { path = "../util/proposal-table", version = "= 0.117.0-pre" } [features] diff --git a/sync/src/tests/net_time_checker.rs b/sync/src/tests/net_time_checker.rs index d849458754..846e07d796 100644 --- a/sync/src/tests/net_time_checker.rs +++ b/sync/src/tests/net_time_checker.rs @@ -99,7 +99,7 @@ fn net_service_start() -> Node { ); let mut p2p_service = service_builder - .key_pair(network_state.local_private_key().clone()) + .handshake_type(network_state.local_private_key().clone().into()) .upnp(config.upnp) .forever(true) .build(EventHandler::new(Arc::clone(&network_state))); diff --git a/sync/src/tests/types.rs b/sync/src/tests/types.rs index 081c95a012..148e6b2308 100644 --- a/sync/src/tests/types.rs +++ b/sync/src/tests/types.rs @@ -76,8 +76,8 @@ fn test_get_ancestor_use_skip_list() { header }; for _ in 0..100 { - let from: u64 = rng.gen_range(0, SKIPLIST_LENGTH); - let to: u64 = rng.gen_range(0, from + 1); + let from: u64 = rng.gen_range(0..SKIPLIST_LENGTH); + let to: u64 = rng.gen_range(0..=from); let view_from = &header_map[&hashes[&from]]; let view_to = &header_map[&hashes[&to]]; let view_0 = &header_map[&hashes[&0]]; diff --git a/test/Cargo.toml b/test/Cargo.toml index a33d367381..b829a8c5e3 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -31,7 +31,7 @@ ckb-error = { path = "../error", version = "= 0.117.0-pre" } ckb-constant = { path = "../util/constant", version = "= 0.117.0-pre" } tempfile = "3" reqwest = { version = "=0.11.20", features = ["blocking", "json"] } -rand = "0.7" +rand = "0.8" ckb-systemtime = { path = "../util/systemtime", version = "= 0.117.0-pre" } serde_json = "1.0" lazy_static = "1.4.0" @@ -44,7 +44,12 @@ log = "0.4" nix = { version = "0.24.0", default-features = false, features = ["signal"] } [target.'cfg(target_os="windows")'.dependencies] -windows-sys = { version = "0.52", features = ["Win32_Foundation", "Win32_System_Threading", "Win32_Security", "Win32_System_Console"] } +windows-sys = { version = "0.52", features = [ + "Win32_Foundation", + "Win32_System_Threading", + "Win32_Security", + "Win32_System_Console", +] } # Prevent this from interfering with workspaces [workspace] diff --git a/test/src/specs/mining/fee.rs b/test/src/specs/mining/fee.rs index 9d10a4b833..abadc4daf8 100644 --- a/test/src/specs/mining/fee.rs +++ b/test/src/specs/mining/fee.rs @@ -77,7 +77,7 @@ impl Spec for FeeOfMaxBlockProposalsLimit { .map(|cell| { let minimal_capacity = cell.occupied_capacity().unwrap().as_u64(); let maximal_capacity = cell.capacity().as_u64(); - let random_capacity = rng.gen_range(minimal_capacity, maximal_capacity + 1); + let random_capacity = rng.gen_range(minimal_capacity..=maximal_capacity); let output = CellOutput::new_builder() .capacity(random_capacity.pack()) .lock(cell.cell_output.lock()) @@ -133,7 +133,7 @@ impl Spec for FeeOfMultipleMaxBlockProposalsLimit { .map(|cell| { let minimal_capacity = cell.occupied_capacity().unwrap().as_u64(); let maximal_capacity = cell.capacity().as_u64(); - let random_capacity = rng.gen_range(minimal_capacity, maximal_capacity + 1); + let random_capacity = rng.gen_range(minimal_capacity..=maximal_capacity); let output = CellOutput::new_builder() .capacity(random_capacity.pack()) .lock(cell.cell_output.lock()) diff --git a/test/src/txo.rs b/test/src/txo.rs index 86f0fc359b..7d9868b6f4 100644 --- a/test/src/txo.rs +++ b/test/src/txo.rs @@ -162,7 +162,7 @@ impl TXOSet { .map(|txo| { let maximal_capacity = txo.capacity(); let minimal_capacity: u64 = txo.to_minimal_output().capacity().unpack(); - let actual_capacity = rng.gen_range(minimal_capacity, maximal_capacity + 1); + let actual_capacity = rng.gen_range(minimal_capacity..=maximal_capacity); let output = txo .to_equivalent_output() .as_builder() diff --git a/util/app-config/Cargo.toml b/util/app-config/Cargo.toml index daf5d2968b..600f8eebd7 100644 --- a/util/app-config/Cargo.toml +++ b/util/app-config/Cargo.toml @@ -18,16 +18,16 @@ path-clean = "0.1.0" ckb-logger = { path = "../../util/logger", version = "= 0.117.0-pre" } ckb-logger-config = { path = "../../util/logger-config", version = "= 0.117.0-pre" } ckb-metrics-config = { path = "../../util/metrics-config", version = "= 0.117.0-pre" } -ckb-chain-spec = {path = "../../spec", version = "= 0.117.0-pre"} -ckb-jsonrpc-types = {path = "../jsonrpc-types", version = "= 0.117.0-pre"} +ckb-chain-spec = { path = "../../spec", version = "= 0.117.0-pre" } +ckb-jsonrpc-types = { path = "../jsonrpc-types", version = "= 0.117.0-pre" } ckb-pow = { path = "../../pow", version = "= 0.117.0-pre" } -ckb-resource = { path = "../../resource", version = "= 0.117.0-pre"} +ckb-resource = { path = "../../resource", version = "= 0.117.0-pre" } ckb-build-info = { path = "../build-info", version = "= 0.117.0-pre" } ckb-types = { path = "../types", version = "= 0.117.0-pre" } ckb-constant = { path = "../constant", version = "= 0.117.0-pre" } -secio = { version="0.5.7", package="tentacle-secio" } -multiaddr = { version="0.3.0", package="tentacle-multiaddr" } -rand = "0.7" +secio = { version = "0.6", package = "tentacle-secio" } +multiaddr = { version = "0.3.0", package = "tentacle-multiaddr" } +rand = "0.8" sentry = { version = "0.26.0", optional = true } ckb-systemtime = { path = "../systemtime", version = "= 0.117.0-pre" } url = { version = "2.2.2", features = ["serde"] } @@ -38,4 +38,6 @@ with_sentry = ["sentry"] [dev-dependencies] tempfile.workspace = true -ckb-systemtime = { path = "../systemtime", version = "= 0.117.0-pre" ,features = ["enable_faketime"]} +ckb-systemtime = { path = "../systemtime", version = "= 0.117.0-pre", features = [ + "enable_faketime", +] } diff --git a/util/crypto/Cargo.toml b/util/crypto/Cargo.toml index bd6455aca0..5a86cab3b4 100644 --- a/util/crypto/Cargo.toml +++ b/util/crypto/Cargo.toml @@ -11,11 +11,11 @@ repository = "https://github.com/nervosnetwork/ckb" [dependencies] ckb-fixed-hash = { path = "../fixed-hash", version = "= 0.117.0-pre" } lazy_static = "1.3" -secp256k1 = { version = "0.24", features = ["recovery"], optional = true } +secp256k1 = { version = "0.29", features = ["recovery"], optional = true } thiserror = "1.0.22" -rand = { version = "0.7", features = ["small_rng"] } +rand = { version = "0.8", features = ["small_rng"] } faster-hex = "0.6" [features] -default = [ "secp" ] +default = ["secp"] secp = ["secp256k1"] diff --git a/util/crypto/src/secp/privkey.rs b/util/crypto/src/secp/privkey.rs index 1cad3c0ced..3eb8431d61 100644 --- a/util/crypto/src/secp/privkey.rs +++ b/util/crypto/src/secp/privkey.rs @@ -20,7 +20,7 @@ impl Privkey { let context = &SECP256K1; let message = message.as_ref(); let privkey = SecretKey::from_slice(self.inner.as_bytes())?; - let message = SecpMessage::from_slice(message)?; + let message = SecpMessage::from_digest_slice(message)?; let data = context.sign_ecdsa_recoverable(&message, &privkey); let (rec_id, data) = data.serialize_compact(); Ok(Signature::from_compact(rec_id, data)) diff --git a/util/crypto/src/secp/pubkey.rs b/util/crypto/src/secp/pubkey.rs index c7dbfef72b..279901adaf 100644 --- a/util/crypto/src/secp/pubkey.rs +++ b/util/crypto/src/secp/pubkey.rs @@ -30,7 +30,7 @@ impl Pubkey { let recoverable_signature = signature.to_recoverable()?; let signature = recoverable_signature.to_standard(); - let message = SecpMessage::from_slice(message.as_bytes())?; + let message = SecpMessage::from_digest_slice(message.as_bytes())?; context.verify_ecdsa(&message, &signature, &pubkey)?; Ok(()) } diff --git a/util/crypto/src/secp/signature.rs b/util/crypto/src/secp/signature.rs index 4928f39f4e..a5a0e45dd9 100644 --- a/util/crypto/src/secp/signature.rs +++ b/util/crypto/src/secp/signature.rs @@ -90,7 +90,7 @@ impl Signature { pub fn recover(&self, message: &Message) -> Result { let context = &SECP256K1; let recoverable_signature = self.to_recoverable()?; - let message = SecpMessage::from_slice(message.as_bytes())?; + let message = SecpMessage::from_digest_slice(message.as_bytes())?; let pubkey = context.recover_ecdsa(&message, &recoverable_signature)?; let serialized = pubkey.serialize_uncompressed(); diff --git a/util/gen-types/Cargo.toml b/util/gen-types/Cargo.toml index 0e411083ff..5f4d7e2f1b 100644 --- a/util/gen-types/Cargo.toml +++ b/util/gen-types/Cargo.toml @@ -20,13 +20,24 @@ check-data = [] # Enable the `serialized-size` extension for CKB contract development in `no-std` env serialized-size = ["calc-hash"] # Enable all in `std` env -std = ["molecule/std", "ckb-hash/default", "ckb-fixed-hash", "ckb-error", "ckb-occupied-capacity", "numext-fixed-uint"] +std = [ + "molecule/std", + "ckb-hash/default", + "ckb-fixed-hash", + "ckb-error", + "ckb-occupied-capacity", + "numext-fixed-uint", +] [dependencies] cfg-if = "1.0" -molecule = { version = "0.7.5", default-features = false } +molecule = { version = "0.8", default-features = false } ckb-hash = { path = "../hash", version = "= 0.117.0-pre", default-features = false, optional = true } ckb-fixed-hash = { path = "../fixed-hash", version = "= 0.117.0-pre", optional = true } ckb-error = { path = "../../error", version = "= 0.117.0-pre", optional = true } ckb-occupied-capacity = { path = "../occupied-capacity", version = "= 0.117.0-pre", optional = true } -numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"], optional = true } +numext-fixed-uint = { version = "0.1", features = [ + "support_rand", + "support_heapsize", + "support_serde", +], optional = true } diff --git a/util/multisig/Cargo.toml b/util/multisig/Cargo.toml index 451fecdf7e..a0cc3d55f5 100644 --- a/util/multisig/Cargo.toml +++ b/util/multisig/Cargo.toml @@ -14,4 +14,4 @@ ckb-logger = { path = "../logger", version = "= 0.117.0-pre" } ckb-crypto = { path = "../crypto", version = "= 0.117.0-pre" } [dev-dependencies] -rand = "0.7" +rand = "0.8" diff --git a/util/types/Cargo.toml b/util/types/Cargo.toml index 94ed038a1a..eda3465de5 100644 --- a/util/types/Cargo.toml +++ b/util/types/Cargo.toml @@ -9,10 +9,14 @@ homepage = "https://github.com/nervosnetwork/ckb" repository = "https://github.com/nervosnetwork/ckb" [dependencies] -molecule = "=0.7.5" +molecule = "0.8" ckb-fixed-hash = { path = "../fixed-hash", version = "= 0.117.0-pre" } -numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } -bytes = { version="1", features = ["serde"] } +numext-fixed-uint = { version = "0.1", features = [ + "support_rand", + "support_heapsize", + "support_serde", +] } +bytes = { version = "1", features = ["serde"] } merkle-cbt = "0.3" ckb-occupied-capacity = { path = "../occupied-capacity", version = "= 0.117.0-pre" } ckb-hash = { path = "../hash", version = "= 0.117.0-pre" } @@ -23,7 +27,9 @@ bit-vec = "0.6.3" ckb-error = { path = "../../error", version = "= 0.117.0-pre" } ckb-rational = { path = "../rational", version = "= 0.117.0-pre" } once_cell = "1.8.0" -derive_more = { version = "0.99.0", default-features=false, features = ["display"] } +derive_more = { version = "0.99.0", default-features = false, features = [ + "display", +] } ckb-merkle-mountain-range = "0.5.2" golomb-coded-set = "0.2.0" paste = "1.0" @@ -32,4 +38,4 @@ paste = "1.0" proptest = "1.0" [package.metadata.cargo-shear] -ignored = ["bytes"] \ No newline at end of file +ignored = ["bytes"] diff --git a/verification/contextual/Cargo.toml b/verification/contextual/Cargo.toml index b01517384b..163fe0e86f 100644 --- a/verification/contextual/Cargo.toml +++ b/verification/contextual/Cargo.toml @@ -17,8 +17,8 @@ ckb-traits = { path = "../../traits", version = "= 0.117.0-pre" } ckb-chain-spec = { path = "../../spec", version = "= 0.117.0-pre" } ckb-dao = { path = "../../util/dao", version = "= 0.117.0-pre" } ckb-dao-utils = { path = "../../util/dao/utils", version = "= 0.117.0-pre" } -ckb-logger = {path = "../../util/logger", version = "= 0.117.0-pre"} -ckb-reward-calculator= { path = "../../util/reward-calculator", version = "= 0.117.0-pre" } +ckb-logger = { path = "../../util/logger", version = "= 0.117.0-pre" } +ckb-reward-calculator = { path = "../../util/reward-calculator", version = "= 0.117.0-pre" } ckb-error = { path = "../../error", version = "= 0.117.0-pre" } tokio = { version = "1", features = ["sync", "rt-multi-thread"] } ckb-async-runtime = { path = "../../util/runtime", version = "= 0.117.0-pre" } @@ -30,5 +30,7 @@ ckb-merkle-mountain-range = "0.5.2" ckb-chain = { path = "../../chain", version = "= 0.117.0-pre" } ckb-shared = { path = "../../shared", version = "= 0.117.0-pre" } ckb-test-chain-utils = { path = "../../util/test-chain-utils", version = "= 0.117.0-pre" } -ckb-systemtime = { path = "../../util/systemtime", version = "= 0.117.0-pre", features = ["enable_faketime"]} -rand = "0.7" +ckb-systemtime = { path = "../../util/systemtime", version = "= 0.117.0-pre", features = [ + "enable_faketime", +] } +rand = "0.8" From 4964299def29e5837896b38a440e48b420dbd111 Mon Sep 17 00:00:00 2001 From: EthanYuan Date: Mon, 17 Jun 2024 10:12:04 +0800 Subject: [PATCH 2/6] fix postgres: use instead of to avoid performance issues. --- .../async_indexer_handle/get_cells.rs | 22 ++++++++- .../get_cells_capacity.rs | 22 ++++++++- .../async_indexer_handle/get_transactions.rs | 49 ++++++++++++++++--- .../async_indexer_handle/mod.rs | 40 ++++++++++++--- util/rich-indexer/src/tests/query.rs | 2 +- 5 files changed, 115 insertions(+), 20 deletions(-) diff --git a/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_cells.rs b/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_cells.rs index f66eaa28b6..63a89d4800 100644 --- a/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_cells.rs +++ b/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_cells.rs @@ -169,9 +169,18 @@ impl AsyncRichIndexerHandle { .bind(search_key.script.args.as_bytes()) .bind(get_binary_upper_boundary(search_key.script.args.as_bytes())); } - Some(IndexerSearchMode::Exact) | Some(IndexerSearchMode::Partial) => { + Some(IndexerSearchMode::Exact) => { query = query.bind(search_key.script.args.as_bytes()); } + Some(IndexerSearchMode::Partial) => match self.store.db_driver { + DBDriver::Postgres => { + let new_args = escape_and_wrap_for_postgres_like(&search_key.script.args); + query = query.bind(new_args); + } + DBDriver::Sqlite => { + query = query.bind(search_key.script.args.as_bytes()); + } + }, } if let Some(filter) = search_key.filter.as_ref() { if let Some(script) = filter.script.as_ref() { @@ -190,9 +199,18 @@ impl AsyncRichIndexerHandle { .bind(data.as_bytes()) .bind(get_binary_upper_boundary(data.as_bytes())); } - Some(IndexerSearchMode::Exact) | Some(IndexerSearchMode::Partial) => { + Some(IndexerSearchMode::Exact) => { query = query.bind(data.as_bytes()); } + Some(IndexerSearchMode::Partial) => match self.store.db_driver { + DBDriver::Postgres => { + let new_data = escape_and_wrap_for_postgres_like(data); + query = query.bind(new_data); + } + DBDriver::Sqlite => { + query = query.bind(data.as_bytes()); + } + }, } } } diff --git a/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_cells_capacity.rs b/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_cells_capacity.rs index dca41b72df..5a14d90592 100644 --- a/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_cells_capacity.rs +++ b/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_cells_capacity.rs @@ -129,9 +129,18 @@ impl AsyncRichIndexerHandle { .bind(search_key.script.args.as_bytes()) .bind(get_binary_upper_boundary(search_key.script.args.as_bytes())); } - Some(IndexerSearchMode::Exact) | Some(IndexerSearchMode::Partial) => { + Some(IndexerSearchMode::Exact) => { query = query.bind(search_key.script.args.as_bytes()); } + Some(IndexerSearchMode::Partial) => match self.store.db_driver { + DBDriver::Postgres => { + let new_args = escape_and_wrap_for_postgres_like(&search_key.script.args); + query = query.bind(new_args); + } + DBDriver::Sqlite => { + query = query.bind(search_key.script.args.as_bytes()); + } + }, } if let Some(filter) = search_key.filter.as_ref() { if let Some(script) = filter.script.as_ref() { @@ -150,9 +159,18 @@ impl AsyncRichIndexerHandle { .bind(data.as_bytes()) .bind(get_binary_upper_boundary(data.as_bytes())); } - Some(IndexerSearchMode::Exact) | Some(IndexerSearchMode::Partial) => { + Some(IndexerSearchMode::Exact) => { query = query.bind(data.as_bytes()); } + Some(IndexerSearchMode::Partial) => match self.store.db_driver { + DBDriver::Postgres => { + let new_data = escape_and_wrap_for_postgres_like(data); + query = query.bind(new_data); + } + DBDriver::Sqlite => { + query = query.bind(data.as_bytes()); + } + }, } } } diff --git a/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_transactions.rs b/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_transactions.rs index e4de2a9c80..d8d58e0d68 100644 --- a/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_transactions.rs +++ b/util/rich-indexer/src/indexer_handle/async_indexer_handle/get_transactions.rs @@ -194,9 +194,18 @@ pub async fn get_tx_with_cell( .bind(search_key.script.args.as_bytes()) .bind(get_binary_upper_boundary(search_key.script.args.as_bytes())); } - Some(IndexerSearchMode::Exact) | Some(IndexerSearchMode::Partial) => { + Some(IndexerSearchMode::Exact) => { query = query.bind(search_key.script.args.as_bytes()); } + Some(IndexerSearchMode::Partial) => match db_driver { + DBDriver::Postgres => { + let new_args = escape_and_wrap_for_postgres_like(&search_key.script.args); + query = query.bind(new_args); + } + DBDriver::Sqlite => { + query = query.bind(search_key.script.args.as_bytes()); + } + }, } if let Some(filter) = search_key.filter.as_ref() { if let Some(script) = filter.script.as_ref() { @@ -215,9 +224,18 @@ pub async fn get_tx_with_cell( .bind(data.as_bytes()) .bind(get_binary_upper_boundary(data.as_bytes())); } - Some(IndexerSearchMode::Exact) | Some(IndexerSearchMode::Partial) => { + Some(IndexerSearchMode::Exact) => { query = query.bind(data.as_bytes()); } + Some(IndexerSearchMode::Partial) => match db_driver { + DBDriver::Postgres => { + let new_data = escape_and_wrap_for_postgres_like(data); + query = query.bind(new_data); + } + DBDriver::Sqlite => { + query = query.bind(data.as_bytes()); + } + }, } } } @@ -326,9 +344,18 @@ pub async fn get_tx_with_cells( .bind(search_key.script.args.as_bytes()) .bind(get_binary_upper_boundary(search_key.script.args.as_bytes())); } - Some(IndexerSearchMode::Exact) | Some(IndexerSearchMode::Partial) => { + Some(IndexerSearchMode::Exact) => { query = query.bind(search_key.script.args.as_bytes()); } + Some(IndexerSearchMode::Partial) => match db_driver { + DBDriver::Postgres => { + let new_args = escape_and_wrap_for_postgres_like(&search_key.script.args); + query = query.bind(new_args); + } + DBDriver::Sqlite => { + query = query.bind(search_key.script.args.as_bytes()); + } + }, } if let Some(filter) = search_key.filter.as_ref() { if let Some(script) = filter.script.as_ref() { @@ -347,9 +374,18 @@ pub async fn get_tx_with_cells( .bind(data.as_bytes()) .bind(get_binary_upper_boundary(data.as_bytes())); } - Some(IndexerSearchMode::Exact) | Some(IndexerSearchMode::Partial) => { + Some(IndexerSearchMode::Exact) => { query = query.bind(data.as_bytes()); } + Some(IndexerSearchMode::Partial) => match db_driver { + DBDriver::Postgres => { + let new_data = escape_and_wrap_for_postgres_like(data); + query = query.bind(new_data); + } + DBDriver::Sqlite => { + query = query.bind(data.as_bytes()); + } + }, } } } @@ -566,10 +602,7 @@ fn build_filter( Some(IndexerSearchMode::Partial) => { match db_driver { DBDriver::Postgres => { - query_builder.and_where(format!( - "position(${} in output.data) > 0", - param_index - )); + query_builder.and_where(format!("output.data LIKE ${}", param_index)); } DBDriver::Sqlite => { query_builder diff --git a/util/rich-indexer/src/indexer_handle/async_indexer_handle/mod.rs b/util/rich-indexer/src/indexer_handle/async_indexer_handle/mod.rs index c0fb7c50a6..7f6032ef25 100644 --- a/util/rich-indexer/src/indexer_handle/async_indexer_handle/mod.rs +++ b/util/rich-indexer/src/indexer_handle/async_indexer_handle/mod.rs @@ -9,7 +9,7 @@ use ckb_app_config::DBDriver; use ckb_indexer_sync::{Error, Pool}; use ckb_jsonrpc_types::{ IndexerRange, IndexerScriptType, IndexerSearchKey, IndexerSearchKeyFilter, IndexerSearchMode, - IndexerTip, + IndexerTip, JsonBytes, }; use ckb_types::H256; use num_bigint::BigUint; @@ -99,7 +99,7 @@ fn build_query_script_sql( Some(IndexerSearchMode::Partial) => { match db_driver { DBDriver::Postgres => { - query_builder.and_where(format!("position(${} in args) > 0", param_index)); + query_builder.and_where(format!("args LIKE ${}", param_index)); } DBDriver::Sqlite => { query_builder.and_where(format!("instr(args, ${}) > 0", param_index)); @@ -140,7 +140,7 @@ fn build_query_script_id_sql( Some(IndexerSearchMode::Partial) => { match db_driver { DBDriver::Postgres => { - query_builder.and_where(format!("position(${} in args) > 0", param_index)); + query_builder.and_where(format!("args LIKE ${}", param_index)); } DBDriver::Sqlite => { query_builder.and_where(format!("instr(args, ${}) > 0", param_index)); @@ -229,10 +229,7 @@ fn build_cell_filter( Some(IndexerSearchMode::Partial) => { match db_driver { DBDriver::Postgres => { - query_builder.and_where(format!( - "position(${} in output.data) > 0", - param_index - )); + query_builder.and_where(format!("output.data LIKE ${}", param_index)); } DBDriver::Sqlite => { query_builder @@ -316,6 +313,35 @@ pub(crate) fn convert_max_values_in_search_filter( }) } +/// Escapes special characters and wraps data with '%' for PostgreSQL LIKE queries. +/// +/// This function escapes the characters '%', '\' and '_' in the input `JsonBytes` by prefixing them with '\'. +/// It then wraps the processed data with '%' at both the start and end for use in PostgreSQL LIKE queries. +/// Note: This function is not suitable for SQLite queries if the data contains NUL characters (0x00), +/// as SQLite treats NUL as the end of the string. +fn escape_and_wrap_for_postgres_like(data: &JsonBytes) -> Vec { + // 0x5c is the default escape character '\' + // 0x25 is the '%' wildcard + // 0x5f is the '_' wildcard + + let mut new_data: Vec = data + .as_bytes() + .iter() + .flat_map(|&b| { + if b == 0x25 || b == 0x5c || b == 0x5f { + vec![0x5c, b] + } else { + vec![b] + } + }) + .collect(); + + new_data.insert(0, 0x25); // Start with % + new_data.push(0x25); // End with % + + new_data +} + #[cfg(test)] mod tests { use super::*; diff --git a/util/rich-indexer/src/tests/query.rs b/util/rich-indexer/src/tests/query.rs index d9e0c52a26..80731de569 100644 --- a/util/rich-indexer/src/tests/query.rs +++ b/util/rich-indexer/src/tests/query.rs @@ -1566,7 +1566,7 @@ async fn output_data_filter_mode_rpc() { .unwrap(); assert_eq!(1, cells.objects.len(),); - // test get_cells_capacity rpc with output_data Partial search mode + // test get_cells_capacity rpc with output_data Prefix search mode let cells = rpc .get_cells_capacity(IndexerSearchKey { script: lock_script11.clone().into(), From 9502271a45799f37b43b26a4573181b3c864c51f Mon Sep 17 00:00:00 2001 From: EthanYuan Date: Mon, 17 Jun 2024 10:51:19 +0800 Subject: [PATCH 3/6] Appending a block might fail, particularly in scenarios where the hardware capabilities are significantly limited. Under such conditions, executing complex queries concurrently can lead to prolonged table locking, which in turn increases the likelihood of insertion failures. --- util/indexer-sync/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/util/indexer-sync/src/lib.rs b/util/indexer-sync/src/lib.rs index b4558b71d5..135d516e17 100644 --- a/util/indexer-sync/src/lib.rs +++ b/util/indexer-sync/src/lib.rs @@ -161,7 +161,9 @@ impl IndexerSyncService { block.number(), block.hash() ); - indexer.append(&block).expect("append block should be OK"); + if let Err(e) = indexer.append(&block) { + error!("Failed to append block: {}. Will attempt to retry.", e); + } } else { info!( "{} rollback {}, {}", @@ -178,7 +180,11 @@ impl IndexerSyncService { } } Ok(None) => match self.get_block_by_number(0) { - Some(block) => indexer.append(&block).expect("append block should be OK"), + Some(block) => { + if let Err(e) = indexer.append(&block) { + error!("Failed to append block: {}. Will attempt to retry.", e); + } + } None => { error!("CKB node returns an empty genesis block"); break; From 52269fcd08ceb241b727be7312e264a0f5210fb0 Mon Sep 17 00:00:00 2001 From: EthanYuan Date: Mon, 17 Jun 2024 11:28:09 +0800 Subject: [PATCH 4/6] PostgreSQL 16 supports hexadecimal, octal, and binary integer literals as 0x, 0o, and 0b prefixes. --- util/rich-indexer/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/rich-indexer/README.md b/util/rich-indexer/README.md index da67f9e0bb..9579fed5f8 100644 --- a/util/rich-indexer/README.md +++ b/util/rich-indexer/README.md @@ -13,6 +13,7 @@ In order to run a CKB node with the Rich-Indexer enabled, it is recommended to a - Processor: 4 core - RAM: 8 GB +- Disk: Solid State Drive (SSD) to ensure performance ## Quick Start @@ -57,7 +58,7 @@ Note that CKB starting options `--indexer` and `--rich-indexer` can only be used ## Enabling Rich Indexer with PostgreSQL -To enable PostgreSQL, you must first set up a functional PostgreSQL service on your own. Please refer to [Server Administration](https://www.postgresql.org/docs/16/admin.html) for guidance. It is recommended to install version 12 or above. +To enable PostgreSQL, you must first set up a functional PostgreSQL service on your own. Please refer to [Server Administration](https://www.postgresql.org/docs/16/admin.html) for guidance. It is recommended to install version 16 or above. For hardware with 4 cores and 8 GB of RAM, it is recommended to make the following two configuration parameter adjustments in PostgreSQL to achieve optimal query performance. From 481500d0245fbbc58ec579e4e5df144e4bb8e23f Mon Sep 17 00:00:00 2001 From: driftluo Date: Wed, 19 Jun 2024 11:57:41 +0800 Subject: [PATCH 5/6] upgrade curve25519-dalek --- Cargo.lock | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58b578e4a6..128d1ef557 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2153,15 +2153,14 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" [[package]] name = "curve25519-dalek" -version = "4.1.2" +version = "4.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ "cfg-if", "cpufeatures", "curve25519-dalek-derive", "fiat-crypto", - "platforms", "rustc_version", "subtle", "zeroize", @@ -4110,12 +4109,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" -[[package]] -name = "platforms" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" - [[package]] name = "plotters" version = "0.3.5" From 60b16544ae9ab82d62a8ec4f2929afcad8dff074 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Sat, 11 May 2024 09:16:26 +0800 Subject: [PATCH 6/6] Re-execute `make gen-rpc-doc` --- tx-pool/src/chunk_process.rs | 2 +- tx-pool/src/process.rs | 31 ++++++++-------- .../src/contextual_block_verifier.rs | 37 ++++++++++--------- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/tx-pool/src/chunk_process.rs b/tx-pool/src/chunk_process.rs index 0d9b03f2f3..d5837cf1cc 100644 --- a/tx-pool/src/chunk_process.rs +++ b/tx-pool/src/chunk_process.rs @@ -220,7 +220,7 @@ impl ChunkProcess { let (ret, snapshot) = self.service.pre_check(&tx).await; let (tip_hash, rtx, status, fee, tx_size) = try_or_return_with_snapshot!(ret, snapshot); - let cached = self.service.fetch_tx_verify_cache(&tx_hash).await; + let cached = self.service.fetch_tx_verify_cache(&tx).await; let tip_header = snapshot.tip_header(); let consensus = snapshot.cloned_consensus(); diff --git a/tx-pool/src/process.rs b/tx-pool/src/process.rs index 39627ccf9a..4738f5132e 100644 --- a/tx-pool/src/process.rs +++ b/tx-pool/src/process.rs @@ -80,9 +80,9 @@ impl TxPoolService { } } - pub(crate) async fn fetch_tx_verify_cache(&self, hash: &Byte32) -> Option { + pub(crate) async fn fetch_tx_verify_cache(&self, tx: &TransactionView) -> Option { let guard = self.txs_verify_cache.read().await; - guard.peek(hash).cloned() + guard.peek(&tx.witness_hash()).cloned() } async fn fetch_txs_verify_cache( @@ -91,8 +91,11 @@ impl TxPoolService { ) -> HashMap { let guard = self.txs_verify_cache.read().await; txs.filter_map(|tx| { - let hash = tx.hash(); - guard.peek(&hash).cloned().map(|value| (hash, value)) + let wtx_hash = tx.witness_hash(); + guard + .peek(&wtx_hash) + .cloned() + .map(|value| (wtx_hash, value)) }) .collect() } @@ -678,7 +681,7 @@ impl TxPoolService { remote: Option<(Cycle, PeerIndex)>, ) -> Option<(Result, Arc)> { let limit_cycles = self.tx_pool_config.max_tx_verify_cycles; - let tx_hash = tx.hash(); + let wtx_hash = tx.witness_hash(); let (ret, snapshot) = self.pre_check(&tx).await; let (tip_hash, rtx, status, fee, tx_size) = try_or_return_with_snapshot!(ret, snapshot); @@ -691,7 +694,7 @@ impl TxPoolService { return None; } - let cached = self.fetch_tx_verify_cache(&tx_hash).await; + let cached = self.fetch_tx_verify_cache(&tx).await; let tip_header = snapshot.tip_header(); let tx_env = Arc::new(status.with_env(tip_header)); @@ -783,7 +786,7 @@ impl TxPoolService { let txs_verify_cache = Arc::clone(&self.txs_verify_cache); tokio::spawn(async move { let mut guard = txs_verify_cache.write().await; - guard.put(tx_hash, CacheEntry::Completed(completed)); + guard.put(wtx_hash, CacheEntry::Completed(completed)); }); } @@ -800,11 +803,11 @@ impl TxPoolService { cached: CacheEntry, remote: Option<(Cycle, PeerIndex)>, ) -> Result<(), Reject> { - let tx_hash = tx.hash(); + let wtx_hash = tx.witness_hash(); let mut chunk = self.chunk.write().await; if chunk.add_tx(tx, remote) { let mut guard = self.txs_verify_cache.write().await; - guard.put(tx_hash, cached); + guard.put(wtx_hash, cached); } Ok(()) @@ -815,7 +818,7 @@ impl TxPoolService { tx: TransactionView, declared_cycles: Option, ) -> Option<(Result, Arc)> { - let tx_hash = tx.hash(); + let wtx_hash = tx.witness_hash(); let (ret, snapshot) = self.pre_check(&tx).await; @@ -829,7 +832,7 @@ impl TxPoolService { return None; } - let verify_cache = self.fetch_tx_verify_cache(&tx_hash).await; + let verify_cache = self.fetch_tx_verify_cache(&tx).await; let max_cycles = declared_cycles.unwrap_or_else(|| self.consensus.max_block_cycles()); let tip_header = snapshot.tip_header(); let tx_env = Arc::new(status.with_env(tip_header)); @@ -865,7 +868,7 @@ impl TxPoolService { let txs_verify_cache = Arc::clone(&self.txs_verify_cache); tokio::spawn(async move { let mut guard = txs_verify_cache.write().await; - guard.put(tx_hash, CacheEntry::Completed(verified)); + guard.put(wtx_hash, CacheEntry::Completed(verified)); }); } @@ -873,15 +876,13 @@ impl TxPoolService { } pub(crate) async fn _test_accept_tx(&self, tx: TransactionView) -> Result { - let tx_hash = tx.hash(); - let (pre_check_ret, snapshot) = self.pre_check(&tx).await; let (_tip_hash, rtx, status, _fee, _tx_size) = pre_check_ret?; // skip check the delay window - let verify_cache = self.fetch_tx_verify_cache(&tx_hash).await; + let verify_cache = self.fetch_tx_verify_cache(&tx).await; let max_cycles = self.consensus.max_block_cycles(); let tip_header = snapshot.tip_header(); let tx_env = Arc::new(status.with_env(tip_header)); diff --git a/verification/contextual/src/contextual_block_verifier.rs b/verification/contextual/src/contextual_block_verifier.rs index 28fec9b09e..af0c32a873 100644 --- a/verification/contextual/src/contextual_block_verifier.rs +++ b/verification/contextual/src/contextual_block_verifier.rs @@ -345,17 +345,24 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, } } - fn fetched_cache + Send + 'static>( - &self, - keys: K, - ) -> HashMap { + fn fetched_cache(&self, rtxs: &'a [Arc]) -> HashMap { let (sender, receiver) = oneshot::channel(); let txs_verify_cache = Arc::clone(self.txs_verify_cache); + let wtx_hashes: Vec = rtxs + .iter() + .skip(1) + .map(|rtx| rtx.transaction.witness_hash()) + .collect(); self.handle.spawn(async move { let guard = txs_verify_cache.read().await; - let ret = keys + let ret = wtx_hashes .into_iter() - .filter_map(|hash| guard.peek(&hash).cloned().map(|value| (hash, value))) + .filter_map(|wtx_hash| { + guard + .peek(&wtx_hash) + .cloned() + .map(|value| (wtx_hash, value)) + }) .collect(); if let Err(e) = sender.send(ret) { @@ -385,13 +392,7 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, // We should skip updating tx_verify_cache about the cellbase tx, // putting it in cache that will never be used until lru cache expires. let fetched_cache = if resolved.len() > 1 { - let keys: Vec = resolved - .iter() - .skip(1) - .map(|rtx| rtx.transaction.hash()) - .collect(); - - self.fetched_cache(keys) + self.fetched_cache(resolved) } else { HashMap::new() }; @@ -403,9 +404,9 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, .par_iter() .enumerate() .map(|(index, tx)| { - let tx_hash = tx.transaction.hash(); + let wtx_hash = tx.transaction.witness_hash(); - if let Some(cache_entry) = fetched_cache.get(&tx_hash) { + if let Some(cache_entry) = fetched_cache.get(&wtx_hash) { match cache_entry { CacheEntry::Completed(completed) => TimeRelativeTransactionVerifier::new( Arc::clone(tx), @@ -421,7 +422,7 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, } .into() }) - .map(|_| (tx_hash, *completed)), + .map(|_| (wtx_hash, *completed)), CacheEntry::Suspended(suspended) => ContextualTransactionVerifier::new( Arc::clone(tx), Arc::clone(&self.context.consensus), @@ -440,7 +441,7 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, } .into() }) - .map(|completed| (tx_hash, completed)), + .map(|completed| (wtx_hash, completed)), } } else { ContextualTransactionVerifier::new( @@ -460,7 +461,7 @@ impl<'a, 'b, CS: ChainStore + VersionbitsIndexer + 'static> BlockTxsVerifier<'a, } .into() }) - .map(|completed| (tx_hash, completed)) + .map(|completed| (wtx_hash, completed)) }.and_then(|result| { if self.context.consensus.rfc0044_active(self.parent.epoch().number()) { DaoScriptSizeVerifier::new(