From 92b557d84e6b39a695ca7e205e51dfa61ffd429d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 12 May 2023 00:54:21 +0200 Subject: [PATCH] chore(deps): bump jsonrpsee 0.18 (#2640) --- Cargo.lock | 139 +++++++++++++++--------- crates/rpc/ipc/Cargo.toml | 2 +- crates/rpc/ipc/src/server/ipc.rs | 84 +++----------- crates/rpc/ipc/src/server/mod.rs | 39 +------ crates/rpc/rpc-api/Cargo.toml | 2 +- crates/rpc/rpc-api/src/admin.rs | 2 +- crates/rpc/rpc-api/src/debug.rs | 24 ++-- crates/rpc/rpc-api/src/engine.rs | 40 +++---- crates/rpc/rpc-api/src/eth.rs | 83 +++++++------- crates/rpc/rpc-api/src/eth_filter.rs | 16 +-- crates/rpc/rpc-api/src/eth_pubsub.rs | 6 +- crates/rpc/rpc-api/src/net.rs | 8 +- crates/rpc/rpc-api/src/trace.rs | 24 ++-- crates/rpc/rpc-api/src/txpool.rs | 10 +- crates/rpc/rpc-api/src/web3.rs | 6 +- crates/rpc/rpc-builder/Cargo.toml | 4 +- crates/rpc/rpc-builder/src/error.rs | 2 +- crates/rpc/rpc-builder/src/lib.rs | 3 +- crates/rpc/rpc-builder/tests/it/http.rs | 4 +- crates/rpc/rpc-engine-api/Cargo.toml | 4 +- crates/rpc/rpc-engine-api/src/error.rs | 8 +- crates/rpc/rpc-types/Cargo.toml | 2 +- crates/rpc/rpc-types/src/eth/syncing.rs | 4 +- crates/rpc/rpc/Cargo.toml | 4 +- crates/rpc/rpc/src/admin.rs | 11 +- crates/rpc/rpc/src/debug.rs | 4 +- crates/rpc/rpc/src/eth/api/server.rs | 13 +-- crates/rpc/rpc/src/eth/error.rs | 12 +- crates/rpc/rpc/src/eth/filter.rs | 2 +- crates/rpc/rpc/src/eth/pubsub.rs | 71 +++++++++--- crates/rpc/rpc/src/layers/auth_layer.rs | 2 +- crates/rpc/rpc/src/result.rs | 41 ++++--- deny.toml | 7 ++ 33 files changed, 352 insertions(+), 331 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 523755108..85032889b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -188,6 +188,8 @@ dependencies = [ "memchr", "pin-project-lite", "tokio", + "zstd", + "zstd-safe", ] [[package]] @@ -316,6 +318,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" + [[package]] name = "base64" version = "0.21.0" @@ -2670,9 +2678,9 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.23.2" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" +checksum = "0646026eb1b3eea4cd9ba47912ea5ce9cc07713d105b1a14698f4e6433d348b7" dependencies = [ "http", "hyper", @@ -2681,7 +2689,6 @@ dependencies = [ "rustls-native-certs", "tokio", "tokio-rustls", - "webpki-roots", ] [[package]] @@ -2901,11 +2908,12 @@ checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" [[package]] name = "iri-string" -version = "0.4.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f0f7638c1e223529f1bfdc48c8b133b9e0b434094d1d28473161ee48b235f78" +checksum = "21859b667d66a4c1dacd9df0863b3efb65785474255face87f5bca39dd8407c0" dependencies = [ - "nom", + "memchr", + "serde", ] [[package]] @@ -2975,9 +2983,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.16.2" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d291e3a5818a2384645fd9756362e6d89cf0541b0b916fa7702ea4a9833608e" +checksum = "1822d18e4384a5e79d94dc9e4d1239cfa9fad24e55b44d2efeff5b394c9fece4" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -2992,18 +3000,15 @@ dependencies = [ [[package]] name = "jsonrpsee-client-transport" -version = "0.16.2" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "965de52763f2004bc91ac5bcec504192440f0b568a5d621c59d9dbd6f886c3fb" +checksum = "11aa5766d5c430b89cb26a99b88f3245eb91534be8126102cea9e45ee3891b22" dependencies = [ - "anyhow", "futures-channel", - "futures-timer", "futures-util", "gloo-net", "http", "jsonrpsee-core", - "jsonrpsee-types", "pin-project", "rustls-native-certs", "soketto", @@ -3017,16 +3022,14 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.16.2" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4e70b4439a751a5de7dd5ed55eacff78ebf4ffe0fc009cb1ebb11417f5b536b" +checksum = "64c6832a55f662b5a6ecc844db24b8b9c387453f923de863062c60ce33d62b81" dependencies = [ "anyhow", - "arrayvec", "async-lock", "async-trait", "beef", - "futures-channel", "futures-timer", "futures-util", "globset", @@ -3040,34 +3043,35 @@ dependencies = [ "soketto", "thiserror", "tokio", + "tokio-stream", "tracing", "wasm-bindgen-futures", ] [[package]] name = "jsonrpsee-http-client" -version = "0.16.2" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc345b0a43c6bc49b947ebeb936e886a419ee3d894421790c969cc56040542ad" +checksum = "1705c65069729e3dccff6fd91ee431d5d31cabcf00ce68a62a2c6435ac713af9" dependencies = [ "async-trait", "hyper", "hyper-rustls", "jsonrpsee-core", "jsonrpsee-types", - "rustc-hash", "serde", "serde_json", "thiserror", "tokio", + "tower", "tracing", ] [[package]] name = "jsonrpsee-proc-macros" -version = "0.16.2" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baa6da1e4199c10d7b1d0a6e5e8bd8e55f351163b6f4b3cbb044672a69bd4c1c" +checksum = "c6027ac0b197ce9543097d02a290f550ce1d9432bf301524b013053c0b75cc94" dependencies = [ "heck", "proc-macro-crate", @@ -3078,13 +3082,11 @@ dependencies = [ [[package]] name = "jsonrpsee-server" -version = "0.16.2" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb69dad85df79527c019659a992498d03f8495390496da2f07e6c24c2b356fc" +checksum = "4f06661d1a6b6e5b85469dc9c29acfbb9b3bb613797a6fd10a3ebb8a70754057" dependencies = [ - "futures-channel", "futures-util", - "http", "hyper", "jsonrpsee-core", "jsonrpsee-types", @@ -3100,9 +3102,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.16.2" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bd522fe1ce3702fd94812965d7bb7a3364b1c9aba743944c5a00529aae80f8c" +checksum = "6e5bf6c75ce2a4217421154adfc65a24d2b46e77286e59bba5d9fa6544ccc8f4" dependencies = [ "anyhow", "beef", @@ -3114,9 +3116,9 @@ dependencies = [ [[package]] name = "jsonrpsee-wasm-client" -version = "0.16.2" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a77310456f43c6c89bcba1f6b2fc2a28300da7c341f320f5128f8c83cc63232d" +checksum = "34e6ea7c6d862e60f8baebd946c037b70c6808a4e4e31e792a4029184e3ce13a" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", @@ -3125,9 +3127,9 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-client" -version = "0.16.2" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b83daeecfc6517cfe210df24e570fb06213533dfb990318fae781f4c7119dd9" +checksum = "a64b2589680ba1ad7863f279cd2d5083c1dc0a7c0ea959d22924553050f8ab9f" dependencies = [ "http", "jsonrpsee-client-transport", @@ -5738,14 +5740,14 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.8" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "c911ba11bc8433e811ce56fde130ccf32f5127cab0e0194e9c68c5a5b671791e" dependencies = [ "log", "ring", + "rustls-webpki", "sct", - "webpki", ] [[package]] @@ -5769,6 +5771,16 @@ dependencies = [ "base64 0.21.0", ] +[[package]] +name = "rustls-webpki" +version = "0.100.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.11" @@ -6722,13 +6734,12 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.23.4" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +checksum = "e0d409377ff5b1e3ca6437aa86c1eb7d40c134bfec254e44c830defa92669db5" dependencies = [ "rustls", "tokio", - "webpki", ] [[package]] @@ -6865,12 +6876,12 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858" +checksum = "5d1d42a9b3f3ec46ba828e8d376aec14592ea199f70a06a548587ecd1c4ab658" dependencies = [ "async-compression", - "base64 0.13.1", + "base64 0.20.0", "bitflags", "bytes", "futures-core", @@ -7467,23 +7478,13 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "webpki-roots" -version = "0.22.6" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +checksum = "aa54963694b65584e170cf5dc46aeb4dcaa5584e652ff5f3952e56d66aff0125" dependencies = [ - "webpki", + "rustls-webpki", ] [[package]] @@ -7762,3 +7763,33 @@ dependencies = [ "quote 1.0.26", "syn 2.0.15", ] + +[[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.8+zstd.1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" +dependencies = [ + "cc", + "libc", + "pkg-config", +] diff --git a/crates/rpc/ipc/Cargo.toml b/crates/rpc/ipc/Cargo.toml index e42aed3ae..b1d6ee985 100644 --- a/crates/rpc/ipc/Cargo.toml +++ b/crates/rpc/ipc/Cargo.toml @@ -21,7 +21,7 @@ pin-project = "1.0" tower = "0.4" # misc -jsonrpsee = { version = "0.16", features = ["server", "client"] } +jsonrpsee = { version = "0.18", features = ["server", "client"] } serde_json = "1.0" tracing = "0.1.37" bytes = "1.4" diff --git a/crates/rpc/ipc/src/server/ipc.rs b/crates/rpc/ipc/src/server/ipc.rs index 1e48e4359..81d5c3226 100644 --- a/crates/rpc/ipc/src/server/ipc.rs +++ b/crates/rpc/ipc/src/server/ipc.rs @@ -2,19 +2,17 @@ use futures::{stream::FuturesOrdered, StreamExt}; use jsonrpsee::{ core::{ - server::{ - helpers::{prepare_error, BatchResponse, BatchResponseBuilder, MethodResponse}, - resource_limiting::Resources, - rpc_module::{MethodKind, Methods}, - }, + server::helpers::{prepare_error, BatchResponseBuilder, MethodResponse}, tracing::{rx_log_from_json, tx_log_from_str}, JsonRawValue, }, + helpers::batch_response_error, server::{ logger, logger::{Logger, TransportProtocol}, }, types::{error::ErrorCode, ErrorObject, Id, InvalidRequest, Notification, Params, Request}, + MethodCallback, Methods, }; use std::sync::Arc; use tokio::sync::OwnedSemaphorePermit; @@ -36,7 +34,6 @@ pub(crate) struct CallData<'a, L: Logger> { methods: &'a Methods, max_response_body_size: u32, max_log_length: u32, - resources: &'a Resources, request_start: L::Instant, } @@ -44,7 +41,7 @@ pub(crate) struct CallData<'a, L: Logger> { // request in the batch and read the results off of a new channel, `rx_batch`, and then send the // complete batch response back to the client over `tx`. #[instrument(name = "batch", skip(b), level = "TRACE")] -pub(crate) async fn process_batch_request(b: Batch<'_, L>) -> BatchResponse +pub(crate) async fn process_batch_request(b: Batch<'_, L>) -> String where L: Logger, { @@ -60,9 +57,7 @@ where .filter_map(|v| { if let Ok(req) = serde_json::from_str::>(v.get()) { Some(Either::Right(execute_call(req, call.clone()))) - } else if let Ok(_notif) = - serde_json::from_str::>(v.get()) - { + } else if let Ok(_notif) = serde_json::from_str::>(v.get()) { // notifications should not be answered. got_notif = true; None @@ -87,12 +82,12 @@ where } if got_notif && batch_response.is_empty() { - BatchResponse { result: String::new(), success: true } + String::new() } else { batch_response.finish() } } else { - BatchResponse::error(Id::Null, ErrorObject::from(ErrorCode::ParseError)) + batch_response_error(Id::Null, ErrorObject::from(ErrorCode::ParseError)) } } @@ -123,7 +118,6 @@ pub(crate) async fn execute_call( call: CallData<'_, L>, ) -> MethodResponse { let CallData { - resources, methods, logger, max_response_body_size, @@ -148,61 +142,28 @@ pub(crate) async fn execute_call( ); MethodResponse::error(id, ErrorObject::from(ErrorCode::MethodNotFound)) } - Some((name, method)) => match &method.inner() { - MethodKind::Sync(callback) => { + Some((name, method)) => match method { + MethodCallback::Sync(callback) => { logger.on_call( name, params.clone(), logger::MethodKind::MethodCall, TransportProtocol::Http, ); - - match method.claim(name, resources) { - Ok(guard) => { - let r = (callback)(id, params, max_response_body_size as usize); - drop(guard); - r - } - Err(err) => { - tracing::error!( - "[Methods::execute_with_resources] failed to lock resources: {}", - err - ); - MethodResponse::error(id, ErrorObject::from(ErrorCode::ServerIsBusy)) - } - } + (callback)(id, params, max_response_body_size as usize) } - MethodKind::Async(callback) => { + MethodCallback::Async(callback) => { logger.on_call( name, params.clone(), logger::MethodKind::MethodCall, TransportProtocol::Http, ); - match method.claim(name, resources) { - Ok(guard) => { - let id = id.into_owned(); - let params = params.into_owned(); - - (callback)( - id, - params, - conn_id, - max_response_body_size as usize, - Some(guard), - ) - .await - } - Err(err) => { - tracing::error!( - "[Methods::execute_with_resources] failed to lock resources: {}", - err - ); - MethodResponse::error(id, ErrorObject::from(ErrorCode::ServerIsBusy)) - } - } + let id = id.into_owned(); + let params = params.into_owned(); + (callback)(id, params, conn_id, max_response_body_size as usize).await } - MethodKind::Subscription(_) | MethodKind::Unsubscription(_) => { + MethodCallback::Subscription(_) | MethodCallback::Unsubscription(_) => { logger.on_call( name, params.clone(), @@ -231,7 +192,6 @@ fn execute_notification(notif: Notif<'_>, max_log_length: u32) -> MethodResponse #[allow(unused)] pub(crate) struct HandleRequest { pub(crate) methods: Methods, - pub(crate) resources: Resources, pub(crate) max_request_body_size: u32, pub(crate) max_response_body_size: u32, pub(crate) max_log_length: u32, @@ -241,15 +201,7 @@ pub(crate) struct HandleRequest { } pub(crate) async fn handle_request(request: String, input: HandleRequest) -> String { - let HandleRequest { - methods, - resources, - max_response_body_size, - max_log_length, - logger, - conn, - .. - } = input; + let HandleRequest { methods, max_response_body_size, max_log_length, logger, conn, .. } = input; enum Kind { Single, @@ -273,7 +225,6 @@ pub(crate) async fn handle_request(request: String, input: HandleRequ methods: &methods, max_response_body_size, max_log_length, - resources: &resources, request_start, }; // Single request or notification @@ -281,8 +232,7 @@ pub(crate) async fn handle_request(request: String, input: HandleRequ let response = process_single_request(request.into_bytes(), call).await; response.result } else { - let response = process_batch_request(Batch { data: request.into_bytes(), call }).await; - response.result + process_batch_request(Batch { data: request.into_bytes(), call }).await }; drop(conn); diff --git a/crates/rpc/ipc/src/server/mod.rs b/crates/rpc/ipc/src/server/mod.rs index 35cfdd582..b7b0ccf4b 100644 --- a/crates/rpc/ipc/src/server/mod.rs +++ b/crates/rpc/ipc/src/server/mod.rs @@ -6,11 +6,9 @@ use crate::server::{ }; use futures::{FutureExt, SinkExt, Stream, StreamExt}; use jsonrpsee::{ - core::{ - server::{resource_limiting::Resources, rpc_module::Methods}, - Error, TEN_MB_SIZE_BYTES, - }, + core::{Error, TEN_MB_SIZE_BYTES}, server::{logger::Logger, IdProvider, RandomIntegerIdProvider, ServerHandle}, + Methods, }; use std::{ future::Future, @@ -39,7 +37,6 @@ mod ipc; pub struct IpcServer { /// The endpoint we listen for incoming transactions endpoint: Endpoint, - resources: Resources, logger: L, id_provider: Arc, cfg: Settings, @@ -63,7 +60,7 @@ impl IpcServer { /// async fn run_server() -> Result<(), Box> { /// let server = Builder::default().build("/tmp/my-uds")?; /// let mut module = RpcModule::new(()); - /// module.register_method("say_hello", |_, _| Ok("lo"))?; + /// module.register_method("say_hello", |_, _| "lo")?; /// let handle = server.start(module).await?; /// /// // In this example we don't care about doing shutdown so let's it run forever. @@ -74,7 +71,7 @@ impl IpcServer { /// } /// ``` pub async fn start(mut self, methods: impl Into) -> Result { - let methods = methods.into().initialize_resources(&self.resources)?; + let methods = methods.into(); let (stop_tx, stop_rx) = watch::channel(()); let stop_handle = StopHandle::new(stop_rx); @@ -110,7 +107,6 @@ impl IpcServer { let max_request_body_size = self.cfg.max_request_body_size; let max_response_body_size = self.cfg.max_response_body_size; let max_log_length = self.cfg.max_log_length; - let resources = self.resources; let id_provider = self.id_provider; let max_subscriptions_per_connection = self.cfg.max_subscriptions_per_connection; let logger = self.logger; @@ -148,7 +144,6 @@ impl IpcServer { let tower_service = TowerService { inner: ServiceData { methods: methods.clone(), - resources: resources.clone(), max_request_body_size, max_response_body_size, max_log_length, @@ -184,7 +179,6 @@ impl std::fmt::Debug for IpcServer { .field("endpoint", &self.endpoint.path()) .field("cfg", &self.cfg) .field("id_provider", &self.id_provider) - .field("resources", &self.resources) .finish() } } @@ -195,8 +189,6 @@ impl std::fmt::Debug for IpcServer { pub(crate) struct ServiceData { /// Registered server methods. pub(crate) methods: Methods, - /// Tracker for currently used resources on the server. - pub(crate) resources: Resources, /// Max request body size. pub(crate) max_request_body_size: u32, /// Max request body size. @@ -246,7 +238,6 @@ impl Service for TowerService { // handle the request let data = ipc::HandleRequest { methods: self.inner.methods.clone(), - resources: self.inner.resources.clone(), max_request_body_size: self.inner.max_request_body_size, max_response_body_size: self.inner.max_response_body_size, max_log_length: self.inner.max_log_length, @@ -382,7 +373,6 @@ impl Default for Settings { #[derive(Debug)] pub struct Builder { settings: Settings, - resources: Resources, logger: L, /// Subscription ID provider. id_provider: Arc, @@ -393,7 +383,6 @@ impl Default for Builder { fn default() -> Self { Builder { settings: Settings::default(), - resources: Resources::default(), logger: (), id_provider: Arc::new(RandomIntegerIdProvider), service_builder: tower::ServiceBuilder::new(), @@ -432,26 +421,10 @@ impl Builder { self } - /// Register a new resource kind. Errors if `label` is already registered, or if the number of - /// registered resources on this server instance would exceed 8. - /// - /// See the module documentation for - /// [`resource_limiting`][jsonrpsee::core::server::resource_limiting] for details. - pub fn register_resource( - mut self, - label: &'static str, - capacity: u16, - default: u16, - ) -> Result { - self.resources.register(label, capacity, default)?; - Ok(self) - } - /// Add a logger to the builder [`Logger`]. pub fn set_logger(self, logger: T) -> Builder { Builder { settings: self.settings, - resources: self.resources, logger, id_provider: self.id_provider, service_builder: self.service_builder, @@ -513,7 +486,6 @@ impl Builder { pub fn set_middleware(self, service_builder: tower::ServiceBuilder) -> Builder { Builder { settings: self.settings, - resources: self.resources, logger: self.logger, id_provider: self.id_provider, service_builder, @@ -531,7 +503,6 @@ impl Builder { Ok(IpcServer { endpoint, cfg: self.settings, - resources: self.resources, logger: self.logger, id_provider: self.id_provider, service_builder: self.service_builder, @@ -554,7 +525,7 @@ mod tests { let server = Builder::default().build(&endpoint).unwrap(); let mut module = RpcModule::new(()); let msg = r#"{"jsonrpc":"2.0","id":83,"result":"0x7a69"}"#; - module.register_method("eth_chainId", move |_, _| Ok(msg)).unwrap(); + module.register_method("eth_chainId", move |_, _| msg).unwrap(); let handle = server.start(module).await.unwrap(); tokio::spawn(handle.stopped()); diff --git a/crates/rpc/rpc-api/Cargo.toml b/crates/rpc/rpc-api/Cargo.toml index 9fe4cd97b..fb7c0f984 100644 --- a/crates/rpc/rpc-api/Cargo.toml +++ b/crates/rpc/rpc-api/Cargo.toml @@ -15,7 +15,7 @@ reth-primitives = { path = "../../primitives" } reth-rpc-types = { path = "../rpc-types" } # misc -jsonrpsee = { version = "0.16", features = ["server", "macros"] } +jsonrpsee = { version = "0.18", features = ["server", "macros"] } serde_json = "1.0" [features] diff --git a/crates/rpc/rpc-api/src/admin.rs b/crates/rpc/rpc-api/src/admin.rs index 61a435931..a2cc24d67 100644 --- a/crates/rpc/rpc-api/src/admin.rs +++ b/crates/rpc/rpc-api/src/admin.rs @@ -34,7 +34,7 @@ pub trait AdminApi { unsubscribe = "admin_peerEvents_unsubscribe", item = String )] - fn subscribe_peer_events(&self); + async fn subscribe_peer_events(&self) -> jsonrpsee::core::SubscriptionResult; /// Returns the ENR of the node. #[method(name = "admin_nodeInfo")] diff --git a/crates/rpc/rpc-api/src/debug.rs b/crates/rpc/rpc-api/src/debug.rs index ab9b80f42..281b46057 100644 --- a/crates/rpc/rpc-api/src/debug.rs +++ b/crates/rpc/rpc-api/src/debug.rs @@ -1,4 +1,4 @@ -use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc}; +use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::{BlockId, BlockNumberOrTag, Bytes, H256}; use reth_rpc_types::{ trace::geth::{ @@ -14,23 +14,23 @@ use reth_rpc_types::{ pub trait DebugApi { /// Returns an RLP-encoded header. #[method(name = "debug_getRawHeader")] - async fn raw_header(&self, block_id: BlockId) -> Result; + async fn raw_header(&self, block_id: BlockId) -> RpcResult; /// Returns an RLP-encoded block. #[method(name = "debug_getRawBlock")] - async fn raw_block(&self, block_id: BlockId) -> Result; + async fn raw_block(&self, block_id: BlockId) -> RpcResult; /// Returns a EIP-2718 binary-encoded transaction. #[method(name = "debug_getRawTransaction")] - async fn raw_transaction(&self, hash: H256) -> Result; + async fn raw_transaction(&self, hash: H256) -> RpcResult; /// Returns an array of EIP-2718 binary-encoded receipts. #[method(name = "debug_getRawReceipts")] - async fn raw_receipts(&self, block_id: BlockId) -> Result>; + async fn raw_receipts(&self, block_id: BlockId) -> RpcResult>; /// Returns an array of recent bad blocks that the client has seen on the network. #[method(name = "debug_getBadBlocks")] - async fn bad_blocks(&self) -> Result>; + async fn bad_blocks(&self) -> RpcResult>; /// Returns the structured logs created during the execution of EVM between two blocks /// (excluding start) as a JSON object. @@ -39,7 +39,7 @@ pub trait DebugApi { &self, start_exclusive: BlockNumberOrTag, end_inclusive: BlockNumberOrTag, - ) -> Result>; + ) -> RpcResult>; /// The `debug_traceBlock` method will return a full stack trace of all invoked opcodes of all /// transaction that were included in this block. @@ -53,7 +53,7 @@ pub trait DebugApi { &self, rlp_block: Bytes, opts: GethDebugTracingOptions, - ) -> Result>; + ) -> RpcResult>; /// Similar to `debug_traceBlock`, `debug_traceBlockByHash` accepts a block hash and will replay /// the block that is already present in the database. For the second parameter see @@ -63,7 +63,7 @@ pub trait DebugApi { &self, block: H256, opts: GethDebugTracingOptions, - ) -> Result>; + ) -> RpcResult>; /// Similar to `debug_traceBlockByNumber`, `debug_traceBlockByHash` accepts a block number /// [BlockNumberOrTag] and will replay the block that is already present in the database. @@ -73,7 +73,7 @@ pub trait DebugApi { &self, block: BlockNumberOrTag, opts: GethDebugTracingOptions, - ) -> Result>; + ) -> RpcResult>; /// The `debug_traceTransaction` debugging method will attempt to run the transaction in the /// exact same manner as it was executed on the network. It will replay any transaction that @@ -84,7 +84,7 @@ pub trait DebugApi { &self, tx_hash: H256, opts: GethDebugTracingOptions, - ) -> Result; + ) -> RpcResult; /// The debug_traceCall method lets you run an `eth_call` within the context of the given block /// execution using the final state of parent block as the base. @@ -101,5 +101,5 @@ pub trait DebugApi { request: CallRequest, block_number: Option, opts: GethDebugTracingCallOptions, - ) -> Result; + ) -> RpcResult; } diff --git a/crates/rpc/rpc-api/src/engine.rs b/crates/rpc/rpc-api/src/engine.rs index b2e2be162..bc84a2586 100644 --- a/crates/rpc/rpc-api/src/engine.rs +++ b/crates/rpc/rpc-api/src/engine.rs @@ -1,4 +1,4 @@ -use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc}; +use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::{ filter::Filter, Address, BlockHash, BlockId, BlockNumberOrTag, Bytes, H256, U256, U64, }; @@ -17,11 +17,11 @@ pub trait EngineApi { /// See also /// Caution: This should not accept the `withdrawals` field #[method(name = "engine_newPayloadV1")] - async fn new_payload_v1(&self, payload: ExecutionPayload) -> Result; + async fn new_payload_v1(&self, payload: ExecutionPayload) -> RpcResult; /// See also #[method(name = "engine_newPayloadV2")] - async fn new_payload_v2(&self, payload: ExecutionPayload) -> Result; + async fn new_payload_v2(&self, payload: ExecutionPayload) -> RpcResult; /// See also /// @@ -31,7 +31,7 @@ pub trait EngineApi { &self, fork_choice_state: ForkchoiceState, payload_attributes: Option, - ) -> Result; + ) -> RpcResult; /// See also #[method(name = "engine_forkchoiceUpdatedV2")] @@ -39,7 +39,7 @@ pub trait EngineApi { &self, fork_choice_state: ForkchoiceState, payload_attributes: Option, - ) -> Result; + ) -> RpcResult; /// See also /// @@ -51,7 +51,7 @@ pub trait EngineApi { /// Note: /// > Client software MAY stop the corresponding build process after serving this call. #[method(name = "engine_getPayloadV1")] - async fn get_payload_v1(&self, payload_id: PayloadId) -> Result; + async fn get_payload_v1(&self, payload_id: PayloadId) -> RpcResult; /// See also /// @@ -59,14 +59,14 @@ pub trait EngineApi { /// payload build process at the time of receiving this call. Note: /// > Client software MAY stop the corresponding build process after serving this call. #[method(name = "engine_getPayloadV2")] - async fn get_payload_v2(&self, payload_id: PayloadId) -> Result; + async fn get_payload_v2(&self, payload_id: PayloadId) -> RpcResult; /// See also #[method(name = "engine_getPayloadBodiesByHashV1")] async fn get_payload_bodies_by_hash_v1( &self, block_hashes: Vec, - ) -> Result; + ) -> RpcResult; /// See also #[method(name = "engine_getPayloadBodiesByRangeV1")] @@ -74,18 +74,18 @@ pub trait EngineApi { &self, start: U64, count: U64, - ) -> Result; + ) -> RpcResult; /// See also #[method(name = "engine_exchangeTransitionConfigurationV1")] async fn exchange_transition_configuration( &self, transition_configuration: TransitionConfiguration, - ) -> Result; + ) -> RpcResult; /// See also #[method(name = "engine_exchangeCapabilities")] - async fn exchange_capabilities(&self, capabilities: Vec) -> Result>; + async fn exchange_capabilities(&self, capabilities: Vec) -> RpcResult>; } /// A subset of the ETH rpc interface: @@ -97,15 +97,15 @@ pub trait EngineApi { pub trait EngineEthApi { /// Returns an object with data about the sync status or false. #[method(name = "eth_syncing")] - fn syncing(&self) -> Result; + fn syncing(&self) -> RpcResult; /// Returns the chain ID of the current network. #[method(name = "eth_chainId")] - async fn chain_id(&self) -> Result>; + async fn chain_id(&self) -> RpcResult>; /// Returns the number of most recent block. #[method(name = "eth_blockNumber")] - fn block_number(&self) -> Result; + fn block_number(&self) -> RpcResult; /// Executes a new message call immediately without creating a transaction on the block chain. #[method(name = "eth_call")] @@ -114,15 +114,15 @@ pub trait EngineEthApi { request: CallRequest, block_number: Option, state_overrides: Option, - ) -> Result; + ) -> RpcResult; /// Returns code at a given address at given block number. #[method(name = "eth_getCode")] - async fn get_code(&self, address: Address, block_number: Option) -> Result; + async fn get_code(&self, address: Address, block_number: Option) -> RpcResult; /// Returns information about a block by hash. #[method(name = "eth_getBlockByHash")] - async fn block_by_hash(&self, hash: H256, full: bool) -> Result>; + async fn block_by_hash(&self, hash: H256, full: bool) -> RpcResult>; /// Returns information about a block by number. #[method(name = "eth_getBlockByNumber")] @@ -130,13 +130,13 @@ pub trait EngineEthApi { &self, number: BlockNumberOrTag, full: bool, - ) -> Result>; + ) -> RpcResult>; /// Sends signed transaction, returning its hash. #[method(name = "eth_sendRawTransaction")] - async fn send_raw_transaction(&self, bytes: Bytes) -> Result; + async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult; /// Returns logs matching given filter object. #[method(name = "eth_getLogs")] - async fn logs(&self, filter: Filter) -> Result>; + async fn logs(&self, filter: Filter) -> RpcResult>; } diff --git a/crates/rpc/rpc-api/src/eth.rs b/crates/rpc/rpc-api/src/eth.rs index 0b9921f11..f4e9792f9 100644 --- a/crates/rpc/rpc-api/src/eth.rs +++ b/crates/rpc/rpc-api/src/eth.rs @@ -1,4 +1,4 @@ -use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc}; +use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::{ serde_helper::JsonStorageKey, AccessListWithGasUsed, Address, BlockId, BlockNumberOrTag, Bytes, H256, H64, U256, U64, @@ -15,31 +15,31 @@ use reth_rpc_types::{ pub trait EthApi { /// Returns the protocol version encoded as a string. #[method(name = "eth_protocolVersion")] - async fn protocol_version(&self) -> Result; + async fn protocol_version(&self) -> RpcResult; /// Returns an object with data about the sync status or false. #[method(name = "eth_syncing")] - fn syncing(&self) -> Result; + fn syncing(&self) -> RpcResult; /// Returns the client coinbase address. #[method(name = "eth_coinbase")] - async fn author(&self) -> Result
; + async fn author(&self) -> RpcResult
; /// Returns a list of addresses owned by client. #[method(name = "eth_accounts")] - async fn accounts(&self) -> Result>; + async fn accounts(&self) -> RpcResult>; /// Returns the number of most recent block. #[method(name = "eth_blockNumber")] - fn block_number(&self) -> Result; + fn block_number(&self) -> RpcResult; /// Returns the chain ID of the current network. #[method(name = "eth_chainId")] - async fn chain_id(&self) -> Result>; + async fn chain_id(&self) -> RpcResult>; /// Returns information about a block by hash. #[method(name = "eth_getBlockByHash")] - async fn block_by_hash(&self, hash: H256, full: bool) -> Result>; + async fn block_by_hash(&self, hash: H256, full: bool) -> RpcResult>; /// Returns information about a block by number. #[method(name = "eth_getBlockByNumber")] @@ -47,26 +47,29 @@ pub trait EthApi { &self, number: BlockNumberOrTag, full: bool, - ) -> Result>; + ) -> RpcResult>; /// Returns the number of transactions in a block from a block matching the given block hash. #[method(name = "eth_getBlockTransactionCountByHash")] - async fn block_transaction_count_by_hash(&self, hash: H256) -> Result>; + async fn block_transaction_count_by_hash(&self, hash: H256) -> RpcResult>; /// Returns the number of transactions in a block matching the given block number. #[method(name = "eth_getBlockTransactionCountByNumber")] async fn block_transaction_count_by_number( &self, number: BlockNumberOrTag, - ) -> Result>; + ) -> RpcResult>; /// Returns the number of uncles in a block from a block matching the given block hash. #[method(name = "eth_getUncleCountByBlockHash")] - async fn block_uncles_count_by_hash(&self, hash: H256) -> Result>; + async fn block_uncles_count_by_hash(&self, hash: H256) -> RpcResult>; /// Returns the number of uncles in a block with given block number. #[method(name = "eth_getUncleCountByBlockNumber")] - async fn block_uncles_count_by_number(&self, number: BlockNumberOrTag) -> Result>; + async fn block_uncles_count_by_number( + &self, + number: BlockNumberOrTag, + ) -> RpcResult>; /// Returns an uncle block of the given block and index. #[method(name = "eth_getUncleByBlockHashAndIndex")] @@ -74,7 +77,7 @@ pub trait EthApi { &self, hash: H256, index: Index, - ) -> Result>; + ) -> RpcResult>; /// Returns an uncle block of the given block and index. #[method(name = "eth_getUncleByBlockNumberAndIndex")] @@ -82,11 +85,11 @@ pub trait EthApi { &self, number: BlockNumberOrTag, index: Index, - ) -> Result>; + ) -> RpcResult>; /// Returns the information about a transaction requested by transaction hash. #[method(name = "eth_getTransactionByHash")] - async fn transaction_by_hash(&self, hash: H256) -> Result>; + async fn transaction_by_hash(&self, hash: H256) -> RpcResult>; /// Returns information about a transaction by block hash and transaction index position. #[method(name = "eth_getTransactionByBlockHashAndIndex")] @@ -94,7 +97,7 @@ pub trait EthApi { &self, hash: H256, index: Index, - ) -> Result>; + ) -> RpcResult>; /// Returns information about a transaction by block number and transaction index position. #[method(name = "eth_getTransactionByBlockNumberAndIndex")] @@ -102,15 +105,15 @@ pub trait EthApi { &self, number: BlockNumberOrTag, index: Index, - ) -> Result>; + ) -> RpcResult>; /// Returns the receipt of a transaction by transaction hash. #[method(name = "eth_getTransactionReceipt")] - async fn transaction_receipt(&self, hash: H256) -> Result>; + async fn transaction_receipt(&self, hash: H256) -> RpcResult>; /// Returns the balance of the account of given address. #[method(name = "eth_getBalance")] - async fn balance(&self, address: Address, block_number: Option) -> Result; + async fn balance(&self, address: Address, block_number: Option) -> RpcResult; /// Returns the value from a storage position at a given address #[method(name = "eth_getStorageAt")] @@ -119,7 +122,7 @@ pub trait EthApi { address: Address, index: JsonStorageKey, block_number: Option, - ) -> Result; + ) -> RpcResult; /// Returns the number of transactions sent from an address at given block number. #[method(name = "eth_getTransactionCount")] @@ -127,11 +130,11 @@ pub trait EthApi { &self, address: Address, block_number: Option, - ) -> Result; + ) -> RpcResult; /// Returns code at a given address at given block number. #[method(name = "eth_getCode")] - async fn get_code(&self, address: Address, block_number: Option) -> Result; + async fn get_code(&self, address: Address, block_number: Option) -> RpcResult; /// Executes a new message call immediately without creating a transaction on the block chain. #[method(name = "eth_call")] @@ -140,7 +143,7 @@ pub trait EthApi { request: CallRequest, block_number: Option, state_overrides: Option, - ) -> Result; + ) -> RpcResult; /// Generates an access list for a transaction. /// @@ -161,7 +164,7 @@ pub trait EthApi { &self, request: CallRequest, block_number: Option, - ) -> Result; + ) -> RpcResult; /// Generates and returns an estimate of how much gas is necessary to allow the transaction to /// complete. @@ -170,15 +173,15 @@ pub trait EthApi { &self, request: CallRequest, block_number: Option, - ) -> Result; + ) -> RpcResult; /// Returns the current price per gas in wei. #[method(name = "eth_gasPrice")] - async fn gas_price(&self) -> Result; + async fn gas_price(&self) -> RpcResult; /// Introduced in EIP-1159, returns suggestion for the priority for dynamic fee transactions. #[method(name = "eth_maxPriorityFeePerGas")] - async fn max_priority_fee_per_gas(&self) -> Result; + async fn max_priority_fee_per_gas(&self) -> RpcResult; /// Returns the Transaction fee history /// @@ -193,20 +196,20 @@ pub trait EthApi { block_count: U64, newest_block: BlockId, reward_percentiles: Option>, - ) -> Result; + ) -> RpcResult; /// Returns whether the client is actively mining new blocks. #[method(name = "eth_mining")] - async fn is_mining(&self) -> Result; + async fn is_mining(&self) -> RpcResult; /// Returns the number of hashes per second that the node is mining with. #[method(name = "eth_hashrate")] - async fn hashrate(&self) -> Result; + async fn hashrate(&self) -> RpcResult; /// Returns the hash of the current block, the seedHash, and the boundary condition to be met /// (“target”) #[method(name = "eth_getWork")] - async fn get_work(&self) -> Result; + async fn get_work(&self) -> RpcResult; /// Used for submitting mining hashrate. /// @@ -214,34 +217,34 @@ pub trait EthApi { /// It accepts the miner hash rate and an identifier which must be unique between nodes. /// Returns `true` if the block was successfully submitted, `false` otherwise. #[method(name = "eth_submitHashrate")] - async fn submit_hashrate(&self, hashrate: U256, id: H256) -> Result; + async fn submit_hashrate(&self, hashrate: U256, id: H256) -> RpcResult; /// Used for submitting a proof-of-work solution. #[method(name = "eth_submitWork")] - async fn submit_work(&self, nonce: H64, pow_hash: H256, mix_digest: H256) -> Result; + async fn submit_work(&self, nonce: H64, pow_hash: H256, mix_digest: H256) -> RpcResult; /// Sends transaction; will block waiting for signer to return the /// transaction hash. #[method(name = "eth_sendTransaction")] - async fn send_transaction(&self, request: TransactionRequest) -> Result; + async fn send_transaction(&self, request: TransactionRequest) -> RpcResult; /// Sends signed transaction, returning its hash. #[method(name = "eth_sendRawTransaction")] - async fn send_raw_transaction(&self, bytes: Bytes) -> Result; + async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult; /// Returns an Ethereum specific signature with: sign(keccak256("\x19Ethereum Signed Message:\n" /// + len(message) + message))). #[method(name = "eth_sign")] - async fn sign(&self, address: Address, message: Bytes) -> Result; + async fn sign(&self, address: Address, message: Bytes) -> RpcResult; /// Signs a transaction that can be submitted to the network at a later time using with /// `eth_sendRawTransaction.` #[method(name = "eth_signTransaction")] - async fn sign_transaction(&self, transaction: CallRequest) -> Result; + async fn sign_transaction(&self, transaction: CallRequest) -> RpcResult; /// Signs data via [EIP-712](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md). #[method(name = "eth_signTypedData")] - async fn sign_typed_data(&self, address: Address, data: serde_json::Value) -> Result; + async fn sign_typed_data(&self, address: Address, data: serde_json::Value) -> RpcResult; /// Returns the account and storage values of the specified account including the Merkle-proof. /// This call can be used to verify that the data you are pulling from is not tampered with. @@ -251,5 +254,5 @@ pub trait EthApi { address: Address, keys: Vec, block_number: Option, - ) -> Result; + ) -> RpcResult; } diff --git a/crates/rpc/rpc-api/src/eth_filter.rs b/crates/rpc/rpc-api/src/eth_filter.rs index e7bdbe200..7663cf0e9 100644 --- a/crates/rpc/rpc-api/src/eth_filter.rs +++ b/crates/rpc/rpc-api/src/eth_filter.rs @@ -1,4 +1,4 @@ -use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc}; +use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::filter::Filter; use reth_rpc_types::{FilterChanges, FilterId, Log}; @@ -8,29 +8,29 @@ use reth_rpc_types::{FilterChanges, FilterId, Log}; pub trait EthFilterApi { /// Creates anew filter and returns its id. #[method(name = "eth_newFilter")] - async fn new_filter(&self, filter: Filter) -> Result; + async fn new_filter(&self, filter: Filter) -> RpcResult; /// Creates a new block filter and returns its id. #[method(name = "eth_newBlockFilter")] - async fn new_block_filter(&self) -> Result; + async fn new_block_filter(&self) -> RpcResult; /// Creates a pending transaction filter and returns its id. #[method(name = "eth_newPendingTransactionFilter")] - async fn new_pending_transaction_filter(&self) -> Result; + async fn new_pending_transaction_filter(&self) -> RpcResult; /// Returns all filter changes since last poll. #[method(name = "eth_getFilterChanges")] - async fn filter_changes(&self, id: FilterId) -> Result; + async fn filter_changes(&self, id: FilterId) -> RpcResult; /// Returns all logs matching given filter (in a range 'from' - 'to'). #[method(name = "eth_getFilterLogs")] - async fn filter_logs(&self, id: FilterId) -> Result>; + async fn filter_logs(&self, id: FilterId) -> RpcResult>; /// Uninstalls filter. #[method(name = "eth_uninstallFilter")] - async fn uninstall_filter(&self, id: FilterId) -> Result; + async fn uninstall_filter(&self, id: FilterId) -> RpcResult; /// Returns logs matching given filter object. #[method(name = "eth_getLogs")] - async fn logs(&self, filter: Filter) -> Result>; + async fn logs(&self, filter: Filter) -> RpcResult>; } diff --git a/crates/rpc/rpc-api/src/eth_pubsub.rs b/crates/rpc/rpc-api/src/eth_pubsub.rs index 790c4251a..342b09165 100644 --- a/crates/rpc/rpc-api/src/eth_pubsub.rs +++ b/crates/rpc/rpc-api/src/eth_pubsub.rs @@ -10,5 +10,9 @@ pub trait EthPubSubApi { unsubscribe = "eth_unsubscribe", item = reth_rpc_types::pubsub::SubscriptionResult )] - fn subscribe(&self, kind: SubscriptionKind, params: Option); + async fn subscribe( + &self, + kind: SubscriptionKind, + params: Option, + ) -> jsonrpsee::core::SubscriptionResult; } diff --git a/crates/rpc/rpc-api/src/net.rs b/crates/rpc/rpc-api/src/net.rs index 6e75683e0..153d92150 100644 --- a/crates/rpc/rpc-api/src/net.rs +++ b/crates/rpc/rpc-api/src/net.rs @@ -1,4 +1,4 @@ -use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc}; +use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_rpc_types::PeerCount; /// Net rpc interface. @@ -7,14 +7,14 @@ use reth_rpc_types::PeerCount; pub trait NetApi { /// Returns protocol version. #[method(name = "net_version")] - fn version(&self) -> Result; + fn version(&self) -> RpcResult; /// Returns number of peers connected to node. #[method(name = "net_peerCount")] - fn peer_count(&self) -> Result; + fn peer_count(&self) -> RpcResult; /// Returns true if client is actively listening for network connections. /// Otherwise false. #[method(name = "net_listening")] - fn is_listening(&self) -> Result; + fn is_listening(&self) -> RpcResult; } diff --git a/crates/rpc/rpc-api/src/trace.rs b/crates/rpc/rpc-api/src/trace.rs index f5670283f..b969315bd 100644 --- a/crates/rpc/rpc-api/src/trace.rs +++ b/crates/rpc/rpc-api/src/trace.rs @@ -1,4 +1,4 @@ -use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc}; +use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::{BlockId, Bytes, H256}; use reth_rpc_types::{ trace::{filter::TraceFilter, parity::*}, @@ -17,7 +17,7 @@ pub trait TraceApi { call: CallRequest, trace_types: HashSet, block_id: Option, - ) -> Result; + ) -> RpcResult; /// Performs multiple call traces on top of the same block. i.e. transaction n will be executed /// on top of a pending block with all n-1 transactions applied (traced) first. Allows to trace @@ -27,7 +27,7 @@ pub trait TraceApi { &self, calls: Vec<(CallRequest, HashSet)>, block_id: Option, - ) -> Result>; + ) -> RpcResult>; /// Traces a call to `eth_sendRawTransaction` without making the call, returning the traces. /// @@ -38,7 +38,7 @@ pub trait TraceApi { data: Bytes, trace_types: HashSet, block_id: Option, - ) -> Result; + ) -> RpcResult; /// Replays all transactions in a block returning the requested traces for each transaction. #[method(name = "trace_replayBlockTransactions")] @@ -46,7 +46,7 @@ pub trait TraceApi { &self, block_id: BlockId, trace_types: HashSet, - ) -> Result>>; + ) -> RpcResult>>; /// Replays a transaction, returning the traces. #[method(name = "trace_replayTransaction")] @@ -54,18 +54,18 @@ pub trait TraceApi { &self, transaction: H256, trace_types: HashSet, - ) -> Result; + ) -> RpcResult; /// Returns traces created at given block. #[method(name = "trace_block")] async fn trace_block( &self, block_id: BlockId, - ) -> Result>>; + ) -> RpcResult>>; /// Returns traces matching given filter #[method(name = "trace_filter")] - async fn trace_filter(&self, filter: TraceFilter) -> Result>; + async fn trace_filter(&self, filter: TraceFilter) -> RpcResult>; /// Returns transaction trace at given index. #[method(name = "trace_get")] @@ -73,10 +73,12 @@ pub trait TraceApi { &self, hash: H256, indices: Vec, - ) -> Result>; + ) -> RpcResult>; /// Returns all traces of given transaction. #[method(name = "trace_transaction")] - async fn trace_transaction(&self, hash: H256) - -> Result>>; + async fn trace_transaction( + &self, + hash: H256, + ) -> RpcResult>>; } diff --git a/crates/rpc/rpc-api/src/txpool.rs b/crates/rpc/rpc-api/src/txpool.rs index 941d50a2b..30d8ac4a0 100644 --- a/crates/rpc/rpc-api/src/txpool.rs +++ b/crates/rpc/rpc-api/src/txpool.rs @@ -1,4 +1,4 @@ -use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc}; +use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::Address; use reth_rpc_types::txpool::{TxpoolContent, TxpoolContentFrom, TxpoolInspect, TxpoolStatus}; @@ -11,26 +11,26 @@ pub trait TxPoolApi { /// well as the ones that are being scheduled for future execution only. /// Ref: [Here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_status) #[method(name = "txpool_status")] - async fn txpool_status(&self) -> Result; + async fn txpool_status(&self) -> RpcResult; /// Returns a summary of all the transactions currently pending for inclusion in the next /// block(s), as well as the ones that are being scheduled for future execution only. /// /// See [here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_inspect) for more details #[method(name = "txpool_inspect")] - async fn txpool_inspect(&self) -> Result; + async fn txpool_inspect(&self) -> RpcResult; /// Retrieves the transactions contained within the txpool, returning pending as well as queued /// transactions of this address, grouped by nonce. /// /// See [here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_contentFrom) for more details #[method(name = "txpool_contentFrom")] - async fn txpool_content_from(&self, from: Address) -> Result; + async fn txpool_content_from(&self, from: Address) -> RpcResult; /// Returns the details of all transactions currently pending for inclusion in the next /// block(s), as well as the ones that are being scheduled for future execution only. /// /// See [here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_content) for more details #[method(name = "txpool_content")] - async fn txpool_content(&self) -> Result; + async fn txpool_content(&self) -> RpcResult; } diff --git a/crates/rpc/rpc-api/src/web3.rs b/crates/rpc/rpc-api/src/web3.rs index fec593cbf..9116ee0e0 100644 --- a/crates/rpc/rpc-api/src/web3.rs +++ b/crates/rpc/rpc-api/src/web3.rs @@ -1,4 +1,4 @@ -use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc}; +use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::{Bytes, H256}; /// Web3 rpc interface. @@ -8,9 +8,9 @@ use reth_primitives::{Bytes, H256}; pub trait Web3Api { /// Returns current client version. #[method(name = "web3_clientVersion")] - async fn client_version(&self) -> Result; + async fn client_version(&self) -> RpcResult; /// Returns sha3 of the given data. #[method(name = "web3_sha3")] - fn sha3(&self, input: Bytes) -> Result; + fn sha3(&self, input: Bytes) -> RpcResult; } diff --git a/crates/rpc/rpc-builder/Cargo.toml b/crates/rpc/rpc-builder/Cargo.toml index dfce673ca..d8760fb72 100644 --- a/crates/rpc/rpc-builder/Cargo.toml +++ b/crates/rpc/rpc-builder/Cargo.toml @@ -21,8 +21,8 @@ reth-tasks = { path = "../../tasks" } reth-transaction-pool = { path = "../../transaction-pool" } # rpc/net -jsonrpsee = { version = "0.16", features = ["server"] } -tower-http = { version = "0.3", features = ["full"] } +jsonrpsee = { version = "0.18", features = ["server"] } +tower-http = { version = "0.4", features = ["full"] } tower = { version = "0.4", features = ["full"] } hyper = "0.14" diff --git a/crates/rpc/rpc-builder/src/error.rs b/crates/rpc/rpc-builder/src/error.rs index 325811f02..d1689c089 100644 --- a/crates/rpc/rpc-builder/src/error.rs +++ b/crates/rpc/rpc-builder/src/error.rs @@ -63,7 +63,7 @@ impl RpcError { } } } - RpcError::RpcError(err.into()) + RpcError::RpcError(JsonRpseeError::Transport(err)) } _ => err.into(), } diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index d95d9fb09..1b45e3049 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -100,9 +100,8 @@ use constants::*; use error::{RpcError, ServerKind}; use jsonrpsee::{ - core::server::rpc_module::Methods, server::{IdProvider, Server, ServerHandle}, - RpcModule, + Methods, RpcModule, }; use reth_ipc::server::IpcServer; use reth_network_api::{NetworkInfo, Peers}; diff --git a/crates/rpc/rpc-builder/tests/it/http.rs b/crates/rpc/rpc-builder/tests/it/http.rs index cb86772dd..71ed65353 100644 --- a/crates/rpc/rpc-builder/tests/it/http.rs +++ b/crates/rpc/rpc-builder/tests/it/http.rs @@ -6,7 +6,7 @@ use jsonrpsee::{ client::{ClientT, SubscriptionClientT}, error::Error, }, - types::error::{CallError, ErrorCode}, + types::error::ErrorCode, }; use reth_primitives::{ hex_literal::hex, Address, BlockId, BlockNumberOrTag, Bytes, NodeRecord, TxHash, H256, H64, @@ -22,7 +22,7 @@ use std::collections::HashSet; fn is_unimplemented(err: Error) -> bool { match err { - Error::Call(CallError::Custom(error_obj)) => { + Error::Call(error_obj) => { error_obj.code() == ErrorCode::InternalError.code() && error_obj.message() == "unimplemented" } diff --git a/crates/rpc/rpc-engine-api/Cargo.toml b/crates/rpc/rpc-engine-api/Cargo.toml index 4b916c636..9a4c467ff 100644 --- a/crates/rpc/rpc-engine-api/Cargo.toml +++ b/crates/rpc/rpc-engine-api/Cargo.toml @@ -22,8 +22,8 @@ tokio = { version = "1", features = ["sync"] } # misc async-trait = "0.1" thiserror = "1.0.37" -jsonrpsee-types = "0.16" -jsonrpsee-core = "0.16" +jsonrpsee-types = "0.18" +jsonrpsee-core = "0.18" tracing = "0.1" [dev-dependencies] diff --git a/crates/rpc/rpc-engine-api/src/error.rs b/crates/rpc/rpc-engine-api/src/error.rs index 1f4fa4b3c..9be67f0f4 100644 --- a/crates/rpc/rpc-engine-api/src/error.rs +++ b/crates/rpc/rpc-engine-api/src/error.rs @@ -93,7 +93,7 @@ impl From for EngineApiError { } } -impl From for jsonrpsee_types::error::CallError { +impl From for jsonrpsee_types::error::ErrorObject<'static> { fn from(error: EngineApiError) -> Self { let code = match error { EngineApiError::InvalidBodiesRange { .. } | @@ -105,17 +105,17 @@ impl From for jsonrpsee_types::error::CallError { // Any other server error _ => INTERNAL_ERROR_CODE, }; - jsonrpsee_types::error::CallError::Custom(jsonrpsee_types::error::ErrorObject::owned( + jsonrpsee_types::error::ErrorObject::owned( code, // TODO properly convert to rpc error error.to_string(), None::<()>, - )) + ) } } impl From for jsonrpsee_core::error::Error { fn from(error: EngineApiError) -> Self { - jsonrpsee_types::error::CallError::from(error).into() + jsonrpsee_core::error::Error::Call(error.into()) } } diff --git a/crates/rpc/rpc-types/Cargo.toml b/crates/rpc/rpc-types/Cargo.toml index 3c6404f45..66dcb70a0 100644 --- a/crates/rpc/rpc-types/Cargo.toml +++ b/crates/rpc/rpc-types/Cargo.toml @@ -23,7 +23,7 @@ tokio = { version = "1", features = ["sync"] } # misc serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -jsonrpsee-types = { version = "0.16" } +jsonrpsee-types = { version = "0.18" } lru = "0.9" [dev-dependencies] diff --git a/crates/rpc/rpc-types/src/eth/syncing.rs b/crates/rpc/rpc-types/src/eth/syncing.rs index e9ff68e09..e2eddaa74 100644 --- a/crates/rpc/rpc-types/src/eth/syncing.rs +++ b/crates/rpc/rpc-types/src/eth/syncing.rs @@ -32,7 +32,7 @@ pub struct Peers { } /// Number of peers connected to. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] #[serde(untagged)] pub enum PeerCount { /// Peer count as integer @@ -98,7 +98,7 @@ pub struct PipProtocolInfo { } /// Sync status -#[derive(Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq)] pub enum SyncStatus { /// Info when syncing Info(SyncInfo), diff --git a/crates/rpc/rpc/Cargo.toml b/crates/rpc/rpc/Cargo.toml index eafff6dbc..b39ecd680 100644 --- a/crates/rpc/rpc/Cargo.toml +++ b/crates/rpc/rpc/Cargo.toml @@ -31,7 +31,7 @@ revm-primitives = { version = "1.1", features = ["serde"] } # rpc -jsonrpsee = { version = "0.16" } +jsonrpsee = { version = "0.18" } http = "0.2.8" http-body = "0.4.5" hyper = "0.14.24" @@ -62,4 +62,4 @@ schnellru = "0.2" futures = "0.3.26" [dev-dependencies] -jsonrpsee = { version = "0.16", features = ["client"] } +jsonrpsee = { version = "0.18", features = ["client"] } diff --git a/crates/rpc/rpc/src/admin.rs b/crates/rpc/rpc/src/admin.rs index dca1be1e9..596fd6030 100644 --- a/crates/rpc/rpc/src/admin.rs +++ b/crates/rpc/rpc/src/admin.rs @@ -1,4 +1,4 @@ -use crate::result::{internal_rpc_err, ToRpcResult}; +use crate::result::ToRpcResult; use async_trait::async_trait; use jsonrpsee::core::RpcResult; use reth_network_api::{NetworkInfo, PeerKind, Peers}; @@ -51,12 +51,11 @@ where } /// Handler for `admin_peerEvents` - fn subscribe_peer_events( + async fn subscribe_peer_events( &self, - sink: jsonrpsee::SubscriptionSink, - ) -> jsonrpsee::types::SubscriptionResult { - sink.close(internal_rpc_err("admin_peerEvents is not implemented yet")); - Ok(()) + _pending: jsonrpsee::PendingSubscriptionSink, + ) -> jsonrpsee::core::SubscriptionResult { + Err("admin_peerEvents is not implemented yet".into()) } /// Handler for `admin_nodeInfo` diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index d45bf16d0..7fdc58236 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -261,8 +261,8 @@ where BlockId::Hash(hash) => self.client.header(&hash.into()).to_rpc_result()?, BlockId::Number(number_or_tag) => { let number = - self.client.convert_block_number(number_or_tag).to_rpc_result()?.ok_or( - jsonrpsee::core::Error::Custom("Pending block not supported".to_string()), + self.client.convert_block_number(number_or_tag).to_rpc_result()?.ok_or_else( + || internal_rpc_err("Pending block not supported".to_string()), )?; self.client.header_by_number(number).to_rpc_result()? } diff --git a/crates/rpc/rpc/src/eth/api/server.rs b/crates/rpc/rpc/src/eth/api/server.rs index b3397849e..9296e0129 100644 --- a/crates/rpc/rpc/src/eth/api/server.rs +++ b/crates/rpc/rpc/src/eth/api/server.rs @@ -365,10 +365,7 @@ where #[cfg(test)] mod tests { use crate::{eth::cache::EthStateCache, EthApi}; - use jsonrpsee::{ - core::{error::Error as RpcError, RpcResult}, - types::error::{CallError, INVALID_PARAMS_CODE}, - }; + use jsonrpsee::types::error::INVALID_PARAMS_CODE; use rand::random; use reth_network_api::test_utils::NoopNetwork; use reth_primitives::{Block, BlockNumberOrTag, Header, TransactionSigned, H256, U256}; @@ -393,8 +390,8 @@ mod tests { None, ) .await; - assert!(matches!(response, RpcResult::Err(RpcError::Call(CallError::Custom(_))))); - let Err(RpcError::Call(CallError::Custom(error_object))) = response else { unreachable!() }; + assert!(response.is_err()); + let error_object = response.unwrap_err(); assert_eq!(error_object.code(), INVALID_PARAMS_CODE); let block_count = 10; @@ -477,8 +474,8 @@ mod tests { Some(vec![10.0]), ) .await; - assert!(matches!(response, RpcResult::Err(RpcError::Call(CallError::Custom(_))))); - let Err(RpcError::Call(CallError::Custom(error_object))) = response else { unreachable!() }; + assert!(response.is_err()); + let error_object = response.unwrap_err(); assert_eq!(error_object.code(), INVALID_PARAMS_CODE); // newest_block is finalized diff --git a/crates/rpc/rpc/src/eth/error.rs b/crates/rpc/rpc/src/eth/error.rs index 2547e02a2..23b6b773c 100644 --- a/crates/rpc/rpc/src/eth/error.rs +++ b/crates/rpc/rpc/src/eth/error.rs @@ -1,7 +1,7 @@ //! Implementation specific Errors for the `eth_` namespace. use crate::result::{internal_rpc_err, invalid_params_rpc_err, rpc_err, rpc_error_with_code}; -use jsonrpsee::core::Error as RpcError; +use jsonrpsee::{core::Error as RpcError, types::ErrorObject}; use reth_primitives::{abi::decode_revert_reason, Address, Bytes, U256}; use reth_rpc_types::{error::EthRpcErrorCode, BlockError}; use reth_transaction_pool::error::{InvalidPoolTransactionError, PoolError}; @@ -65,7 +65,7 @@ pub enum EthApiError { InvalidRewardPercentile(f64), } -impl From for RpcError { +impl From for ErrorObject<'static> { fn from(error: EthApiError) -> Self { match error { EthApiError::FailedToDecodeSignedTransaction | @@ -91,6 +91,12 @@ impl From for RpcError { } } +impl From for RpcError { + fn from(error: EthApiError) -> Self { + RpcError::Call(error.into()) + } +} + impl From> for EthApiError where T: Into, @@ -227,7 +233,7 @@ impl InvalidTransactionError { } } -impl From for RpcError { +impl From for ErrorObject<'static> { fn from(err: InvalidTransactionError) -> Self { match err { InvalidTransactionError::Revert(revert) => { diff --git a/crates/rpc/rpc/src/eth/filter.rs b/crates/rpc/rpc/src/eth/filter.rs index c9c1cc3a4..5d2e45bb6 100644 --- a/crates/rpc/rpc/src/eth/filter.rs +++ b/crates/rpc/rpc/src/eth/filter.rs @@ -399,7 +399,7 @@ pub enum FilterError { } // convert the error -impl From for jsonrpsee::core::Error { +impl From for jsonrpsee::types::error::ErrorObject<'static> { fn from(err: FilterError) -> Self { match err { FilterError::FilterNotFound(_) => rpc_error_with_code( diff --git a/crates/rpc/rpc/src/eth/pubsub.rs b/crates/rpc/rpc/src/eth/pubsub.rs index 984cfa4ea..6485b8f66 100644 --- a/crates/rpc/rpc/src/eth/pubsub.rs +++ b/crates/rpc/rpc/src/eth/pubsub.rs @@ -1,11 +1,12 @@ //! `eth_` PubSub RPC handler implementation use crate::eth::logs_utils; use futures::StreamExt; -use jsonrpsee::{types::SubscriptionResult, SubscriptionSink}; +use jsonrpsee::{server::SubscriptionMessage, PendingSubscriptionSink, SubscriptionSink}; use reth_network_api::NetworkInfo; use reth_primitives::{filter::FilteredParams, TxHash}; use reth_provider::{BlockProvider, CanonStateSubscriptions, EvmEnvProvider}; use reth_rpc_api::EthPubSubApiServer; + use reth_rpc_types::{ pubsub::{ Params, PubSubSyncStatus, SubscriptionKind, SubscriptionResult as EthSubscriptionResult, @@ -15,6 +16,7 @@ use reth_rpc_types::{ }; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use reth_transaction_pool::TransactionPool; +use serde::Serialize; use tokio_stream::{ wrappers::{BroadcastStream, ReceiverStream}, Stream, @@ -54,6 +56,7 @@ impl EthPubSub { } } +#[async_trait::async_trait] impl EthPubSubApiServer for EthPubSub where Client: BlockProvider + EvmEnvProvider + Clone + 'static, @@ -62,17 +65,16 @@ where Network: NetworkInfo + Clone + 'static, { /// Handler for `eth_subscribe` - fn subscribe( + async fn subscribe( &self, - mut sink: SubscriptionSink, + pending: PendingSubscriptionSink, kind: SubscriptionKind, params: Option, - ) -> SubscriptionResult { - sink.accept()?; - + ) -> jsonrpsee::core::SubscriptionResult { + let sink = pending.accept().await?; let pubsub = self.inner.clone(); self.subscription_task_spawner.spawn(Box::pin(async move { - handle_accepted(pubsub, sink, kind, params).await; + let _ = handle_accepted(pubsub, sink, kind, params).await; })); Ok(()) @@ -82,10 +84,11 @@ where /// The actual handler for and accepted [`EthPubSub::subscribe`] call. async fn handle_accepted( pubsub: EthPubSubInner, - mut accepted_sink: SubscriptionSink, + accepted_sink: SubscriptionSink, kind: SubscriptionKind, params: Option, -) where +) -> Result<(), jsonrpsee::core::Error> +where Client: BlockProvider + EvmEnvProvider + Clone + 'static, Pool: TransactionPool + 'static, Events: CanonStateSubscriptions + Clone + 'static, @@ -96,7 +99,7 @@ async fn handle_accepted( let stream = pubsub .into_new_headers_stream() .map(|block| EthSubscriptionResult::Header(Box::new(block.into()))); - accepted_sink.pipe_from_stream(stream).await; + pipe_from_stream(accepted_sink, stream).await } SubscriptionKind::Logs => { // if no params are provided, used default filter params @@ -106,13 +109,13 @@ async fn handle_accepted( }; let stream = pubsub.into_log_stream(filter).map(|log| EthSubscriptionResult::Log(Box::new(log))); - accepted_sink.pipe_from_stream(stream).await; + pipe_from_stream(accepted_sink, stream).await } SubscriptionKind::NewPendingTransactions => { let stream = pubsub .into_pending_transaction_stream() .map(EthSubscriptionResult::TransactionHash); - accepted_sink.pipe_from_stream(stream).await; + pipe_from_stream(accepted_sink, stream).await } SubscriptionKind::Syncing => { // get new block subscription @@ -123,7 +126,10 @@ async fn handle_accepted( let current_sub_res = pubsub.sync_status(initial_sync_status).await; // send the current status immediately - let _ = accepted_sink.send(¤t_sub_res); + let msg = SubscriptionMessage::from_json(¤t_sub_res)?; + if accepted_sink.send(msg).await.is_err() { + return Ok(()) + } while (canon_state.next().await).is_some() { let current_syncing = pubsub.network.is_syncing(); @@ -134,7 +140,44 @@ async fn handle_accepted( // send a new message now that the status changed let sync_status = pubsub.sync_status(current_syncing).await; - let _ = accepted_sink.send(&sync_status); + let msg = SubscriptionMessage::from_json(&sync_status)?; + if accepted_sink.send(msg).await.is_err() { + break + } + } + } + + Ok(()) + } + } +} + +/// Pipes all stream items to the subscription sink. +async fn pipe_from_stream( + sink: SubscriptionSink, + mut stream: St, +) -> Result<(), jsonrpsee::core::Error> +where + St: Stream + Unpin, + T: Serialize, +{ + loop { + tokio::select! { + _ = sink.closed() => { + // connection dropped + break Ok(()) + }, + maybe_item = stream.next() => { + let item = match maybe_item { + Some(item) => item, + None => { + // stream ended + break Ok(()) + }, + }; + let msg = SubscriptionMessage::from_json(&item)?; + if sink.send(msg).await.is_err() { + break Ok(()); } } } diff --git a/crates/rpc/rpc/src/layers/auth_layer.rs b/crates/rpc/rpc/src/layers/auth_layer.rs index 537bdd33f..b3a92de80 100644 --- a/crates/rpc/rpc/src/layers/auth_layer.rs +++ b/crates/rpc/rpc/src/layers/auth_layer.rs @@ -284,7 +284,7 @@ mod tests { // Create a mock rpc module let mut module = RpcModule::new(()); - module.register_method("greet_melkor", |_, _| Ok("You are the dark lord")).unwrap(); + module.register_method("greet_melkor", |_, _| "You are the dark lord").unwrap(); server.start(module).unwrap() } diff --git a/crates/rpc/rpc/src/result.rs b/crates/rpc/rpc/src/result.rs index a3e1d458d..3902d4630 100644 --- a/crates/rpc/rpc/src/result.rs +++ b/crates/rpc/rpc/src/result.rs @@ -1,7 +1,7 @@ //! Additional helpers for converting errors. use crate::eth::error::EthApiError; -use jsonrpsee::core::{Error as RpcError, RpcResult}; +use jsonrpsee::core::RpcResult; use reth_interfaces::Result as RethResult; use reth_primitives::Block; use std::fmt::Display; @@ -126,12 +126,16 @@ impl ToRpcResultExt for RethResult> { } /// Constructs an invalid params JSON-RPC error. -pub(crate) fn invalid_params_rpc_err(msg: impl Into) -> jsonrpsee::core::Error { +pub(crate) fn invalid_params_rpc_err( + msg: impl Into, +) -> jsonrpsee::types::error::ErrorObject<'static> { rpc_err(jsonrpsee::types::error::INVALID_PARAMS_CODE, msg, None) } /// Constructs an internal JSON-RPC error. -pub(crate) fn internal_rpc_err(msg: impl Into) -> jsonrpsee::core::Error { +pub(crate) fn internal_rpc_err( + msg: impl Into, +) -> jsonrpsee::types::error::ErrorObject<'static> { rpc_err(jsonrpsee::types::error::INTERNAL_ERROR_CODE, msg, None) } @@ -139,27 +143,32 @@ pub(crate) fn internal_rpc_err(msg: impl Into) -> jsonrpsee::core::Error pub(crate) fn internal_rpc_err_with_data( msg: impl Into, data: &[u8], -) -> jsonrpsee::core::Error { +) -> jsonrpsee::types::error::ErrorObject<'static> { rpc_err(jsonrpsee::types::error::INTERNAL_ERROR_CODE, msg, Some(data)) } /// Constructs an internal JSON-RPC error with code and message -pub(crate) fn rpc_error_with_code(code: i32, msg: impl Into) -> jsonrpsee::core::Error { +pub(crate) fn rpc_error_with_code( + code: i32, + msg: impl Into, +) -> jsonrpsee::types::error::ErrorObject<'static> { rpc_err(code, msg, None) } /// Constructs a JSON-RPC error, consisting of `code`, `message` and optional `data`. -pub(crate) fn rpc_err(code: i32, msg: impl Into, data: Option<&[u8]>) -> RpcError { - RpcError::Call(jsonrpsee::types::error::CallError::Custom( - jsonrpsee::types::error::ErrorObject::owned( - code, - msg.into(), - data.map(|data| { - jsonrpsee::core::to_json_raw_value(&format!("0x{}", hex::encode(data))) - .expect("serializing String does fail") - }), - ), - )) +pub(crate) fn rpc_err( + code: i32, + msg: impl Into, + data: Option<&[u8]>, +) -> jsonrpsee::types::error::ErrorObject<'static> { + jsonrpsee::types::error::ErrorObject::owned( + code, + msg.into(), + data.map(|data| { + jsonrpsee::core::to_json_raw_value(&format!("0x{}", hex::encode(data))) + .expect("serializing String does fail") + }), + ) } #[cfg(test)] diff --git a/deny.toml b/deny.toml index de8eaac88..c76bbe889 100644 --- a/deny.toml +++ b/deny.toml @@ -53,6 +53,8 @@ allow = [ "LicenseRef-ring", # https://github.com/briansmith/webpki/issues/148 "LicenseRef-webpki", + # https://github.com/rustls/webpki/blob/main/LICENSE ISC Style + "LicenseRef-rustls-webpki", ] # Allow 1 or more licenses on a per-crate basis, so that particular licenses @@ -77,6 +79,11 @@ name = "webpki" expression = "LicenseRef-webpki" license-files = [{ path = "LICENSE", hash = 0x001c7e6c }] +[[licenses.clarify]] +name = "rustls-webpki" +expression = "LicenseRef-rustls-webpki" +license-files = [{ path = "LICENSE", hash = 0x001c7e6c }] + # This section is considered when running `cargo deny check sources`. # More documentation about the 'sources' section can be found here: # https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html