From f29838bb1316140d2d9f0ed48d94af19a9f17cfd Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Thu, 6 Mar 2025 16:33:24 +0800 Subject: [PATCH 1/2] feat: enable rpc http compression --- Cargo.lock | 233 +++++++++++++++++++++++++++++++++++++--------- rpc/Cargo.toml | 6 +- rpc/src/server.rs | 10 +- 3 files changed, 201 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a8884d328..6d0c5d9abf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,6 +67,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "allocator-api2" version = "0.2.21" @@ -168,6 +183,22 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +[[package]] +name = "async-compression" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "310c9bcae737a48ef5cdee3174184e6d548b292739ede61a1f955ef76a738861" +dependencies = [ + "brotli", + "flate2", + "futures-core", + "memchr", + "pin-project-lite", + "tokio", + "zstd", + "zstd-safe", +] + [[package]] name = "async-stream" version = "0.3.6" @@ -240,9 +271,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.4.5", + "bytes", + "futures-util", + "http 1.2.0", + "http-body", + "http-body-util", + "itoa", + "matchit 0.7.3", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper", + "tower 0.5.2", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d6fd624c75e18b3b4c6b9caf42b1afe24437daaee904069137d8bab077be8b8" +dependencies = [ + "axum-core 0.5.0", "base64 0.22.1", "bytes", + "form_urlencoded", "futures-util", "http 1.2.0", "http-body", @@ -250,7 +308,7 @@ dependencies = [ "hyper", "hyper-util", "itoa", - "matchit", + "matchit 0.8.4", "memchr", "mime", "percent-encoding", @@ -263,7 +321,7 @@ dependencies = [ "sha1", "sync_wrapper", "tokio", - "tokio-tungstenite 0.24.0", + "tokio-tungstenite", "tower 0.5.2", "tower-layer", "tower-service", @@ -288,6 +346,25 @@ dependencies = [ "sync_wrapper", "tower-layer", "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df1362f362fd16024ae199c1970ce98f9661bf5ef94b9808fee734bc3698b733" +dependencies = [ + "bytes", + "futures-util", + "http 1.2.0", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", "tracing", ] @@ -433,6 +510,27 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "brotli" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc97b8f16f944bba54f0433f07e30be199b6dc2bd25937444bbad560bcea29bd" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74fa05ad7d803d413eb8380983b092cbbaf9a85f151b871360e7b00cd7060b37" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + [[package]] name = "bs58" version = "0.5.1" @@ -1481,7 +1579,7 @@ version = "0.201.0-pre" dependencies = [ "async-stream", "async-trait", - "axum", + "axum 0.8.1", "ckb-app-config", "ckb-async-runtime", "ckb-chain", @@ -3256,6 +3354,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9171a2ea8a68358193d15dd5d70c1c10a2afc3e7e4c5bc92bc9f025cebd7359c" + [[package]] name = "httparse" version = "1.10.1" @@ -3697,6 +3801,16 @@ dependencies = [ "serde", ] +[[package]] +name = "iri-string" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc0f0a572e8ffe56e2ff4f769f32ffe919282c3916799f8b68688b6030063bea" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "is-terminal" version = "0.4.15" @@ -3789,12 +3903,12 @@ dependencies = [ [[package]] name = "jsonrpc-utils" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b70b75b921afd705aef070f0eab39e566031b929433cffa9fc01ea44ce1339d0" +checksum = "bfc593717463fbe2b1587dfd661e25a663d1cf31d4e1adbfc4c884179d53f992" dependencies = [ "anyhow", - "axum", + "axum 0.8.1", "futures-core", "futures-util", "hex", @@ -3808,9 +3922,9 @@ dependencies = [ [[package]] name = "jsonrpc-utils-macros" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34fe3ce66f7e4909575f6be478862325559bf5b5d0a681d106aae2c9849e1857" +checksum = "9e0e4f62c1f2205484a4738e8127fa84f7e498cf2b7fddc1cd7776fafdd0dac1" dependencies = [ "proc-macro2", "quote", @@ -3950,6 +4064,12 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + [[package]] name = "md-5" version = "0.10.6" @@ -4013,6 +4133,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -6190,7 +6320,7 @@ dependencies = [ "tentacle-secio", "thiserror 1.0.69", "tokio", - "tokio-tungstenite 0.26.2", + "tokio-tungstenite", "tokio-util", "tokio-yamux", "wasm-bindgen", @@ -6514,18 +6644,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-tungstenite" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edc5f74e248dc973e0dbb7b74c7e0d6fcc301c694ff50049504004ef4d0cdcd9" -dependencies = [ - "futures-util", - "log", - "tokio", - "tungstenite 0.24.0", -] - [[package]] name = "tokio-tungstenite" version = "0.26.2" @@ -6535,7 +6653,7 @@ dependencies = [ "futures-util", "log", "tokio", - "tungstenite 0.26.2", + "tungstenite", ] [[package]] @@ -6584,7 +6702,7 @@ checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" dependencies = [ "async-stream", "async-trait", - "axum", + "axum 0.7.9", "base64 0.22.1", "bytes", "h2", @@ -6648,14 +6766,29 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "403fa3b783d4b626a8ad51d766ab03cb6d2dbfc46b1c5d4448395e6628dc9697" dependencies = [ + "async-compression", + "base64 0.22.1", "bitflags 2.9.0", "bytes", + "futures-core", + "futures-util", "http 1.2.0", "http-body", + "http-body-util", + "http-range-header", + "httpdate", + "iri-string", + "mime", + "mime_guess", + "percent-encoding", "pin-project-lite", "tokio", + "tokio-util", + "tower 0.5.2", "tower-layer", "tower-service", + "tracing", + "uuid", ] [[package]] @@ -6724,24 +6857,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "tungstenite" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e5b8366ee7a95b16d32197d0b2604b43a0be89dc5fac9f8e96ccafbaedda8a" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http 1.2.0", - "httparse", - "log", - "rand 0.8.5", - "sha1", - "thiserror 1.0.69", - "utf-8", -] - [[package]] name = "tungstenite" version = "0.26.2" @@ -6845,6 +6960,12 @@ dependencies = [ "unic-common", ] +[[package]] +name = "unicase" +version = "2.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" + [[package]] name = "unicode-bidi" version = "0.3.18" @@ -7710,3 +7831,31 @@ dependencies = [ "quote", "syn 2.0.99", ] + +[[package]] +name = "zstd" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3051792fbdc2e1e143244dc28c60f73d8470e93f3f9cbd0ead44da5ed802722" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.14+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fb060d4926e4ac3a3ad15d864e99ceb5f343c6b34f5bd6d81ae6ed417311be5" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 8a58ecde55..9725eae062 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -24,7 +24,7 @@ ckb-app-config = { path = "../util/app-config", version = "= 0.201.0-pre" } ckb-constant = { path = "../util/constant", version = "= 0.201.0-pre" } jsonrpc-core = "18.0" serde_json = "1.0" -jsonrpc-utils = { version = "0.3", features = ["server", "macros", "axum"] } +jsonrpc-utils = { version = "0.4", features = ["server", "macros", "axum"] } ckb-jsonrpc-types = { path = "../util/jsonrpc-types", version = "= 0.201.0-pre" } ckb-verification = { path = "../verification", version = "= 0.201.0-pre" } ckb-verification-traits = { path = "../verification/traits", version = "= 0.201.0-pre" } @@ -44,10 +44,10 @@ ckb-stop-handler = { path = "../util/stop-handler", version = "= 0.201.0-pre" } itertools.workspace = true tokio = "1" async-trait = "0.1" -axum = "0.7" +axum = "0.8" tokio-util = { version = "0.7.3", features = ["codec"] } futures-util = { version = "0.3.21" } -tower-http = { version = "0.6", features = ["timeout", "cors"] } +tower-http = { version = "0.6", features = ["full"] } async-stream = "0.3.3" ckb-async-runtime = { path = "../util/runtime", version = "= 0.201.0-pre" } schemars.workspace = true diff --git a/rpc/src/server.rs b/rpc/src/server.rs index 2eb055433a..e2b74189f6 100644 --- a/rpc/src/server.rs +++ b/rpc/src/server.rs @@ -28,8 +28,10 @@ use std::sync::OnceLock; use std::time::Duration; use tokio::net::TcpListener; use tokio_util::codec::{FramedRead, FramedWrite, LinesCodec, LinesCodecError}; -use tower_http::cors::CorsLayer; -use tower_http::timeout::TimeoutLayer; +use tower_http::{ + compression::CompressionLayer, cors::CorsLayer, decompression::RequestDecompressionLayer, + timeout::TimeoutLayer, +}; static JSONRPC_BATCH_LIMIT: OnceLock = OnceLock::new(); @@ -118,10 +120,12 @@ impl RpcServer { let app = Router::new() .route("/", method_router.clone()) - .route("/*path", method_router) + .route("/{*path}", method_router) .route("/ping", get(ping_handler)) .layer(Extension(Arc::clone(rpc))) .layer(CorsLayer::permissive()) + .layer(CompressionLayer::new()) + .layer(RequestDecompressionLayer::new()) .layer(TimeoutLayer::new(Duration::from_secs(30))) .layer(Extension(stream_config)); From a6e8246b95618a63be302c872e9162b4974840f8 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Thu, 6 Mar 2025 16:50:45 +0800 Subject: [PATCH 2/2] chore: Allow Zlib license --- deny.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deny.toml b/deny.toml index 61f781ab1e..d34572b812 100644 --- a/deny.toml +++ b/deny.toml @@ -102,9 +102,8 @@ allow = [ "BSD-2-Clause", "ISC", "CC0-1.0", - "Unicode-DFS-2016", - "OpenSSL", "Unicode-3.0", + "Zlib" #"Apache-2.0 WITH LLVM-exception", ] # The confidence threshold for detecting a license from license text.