From 21217cbed3d70d4901ad7e110ace29a72fb4b53b Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 9 May 2023 16:41:53 +0200 Subject: [PATCH] chore: remove allow unused in rpc (#2617) --- crates/rpc/rpc-builder/src/lib.rs | 4 ++-- crates/rpc/rpc/src/debug.rs | 13 ++++++++++++- crates/rpc/rpc/src/eth/api/block.rs | 8 -------- crates/rpc/rpc/src/eth/api/mod.rs | 8 ++++++-- crates/rpc/rpc/src/eth/api/state.rs | 1 + crates/rpc/rpc/src/eth/filter.rs | 1 + crates/rpc/rpc/src/eth/pubsub.rs | 26 +++++--------------------- crates/rpc/rpc/src/lib.rs | 2 -- crates/rpc/rpc/src/result.rs | 5 ----- crates/rpc/rpc/src/trace.rs | 8 +++++++- 10 files changed, 34 insertions(+), 42 deletions(-) diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 0b0aa7f389..eb95dda994 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -820,12 +820,12 @@ where self.config.eth.max_logs_per_response, ); - let pubsub = EthPubSub::new( + let pubsub = EthPubSub::with_spawner( self.client.clone(), self.pool.clone(), self.events.clone(), self.network.clone(), - cache.clone(), + Box::new(self.executor.clone()), ); let eth = EthHandlers { api, cache, filter, pubsub }; diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index bac7a0b781..f70c09831b 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -28,6 +28,7 @@ use reth_rpc_types::{ }; use revm::primitives::Env; use revm_primitives::{db::DatabaseCommit, BlockEnv, CfgEnv}; +use tokio::sync::{AcquireError, OwnedSemaphorePermit}; /// `debug` API implementation. /// @@ -38,7 +39,7 @@ pub struct DebugApi { client: Client, /// The implementation of `eth` API eth_api: Eth, - // restrict the number of concurrent calls to `debug_traceTransaction` + // restrict the number of concurrent calls to tracing calls tracing_call_guard: TracingCallGuard, } @@ -58,6 +59,11 @@ where Client: BlockProvider + HeaderProvider + 'static, Eth: EthTransactions + 'static, { + /// Acquires a permit to execute a tracing call. + async fn acquire_trace_permit(&self) -> Result { + self.tracing_call_guard.clone().acquire_owned().await + } + /// Trace the entire block fn trace_block_with( &self, @@ -288,6 +294,7 @@ where rlp_block: Bytes, opts: GethDebugTracingOptions, ) -> RpcResult> { + let _permit = self.acquire_trace_permit().await; Ok(DebugApi::debug_trace_raw_block(self, rlp_block, opts).await?) } @@ -297,6 +304,7 @@ where block: H256, opts: GethDebugTracingOptions, ) -> RpcResult> { + let _permit = self.acquire_trace_permit().await; Ok(DebugApi::debug_trace_block(self, block.into(), opts).await?) } @@ -306,6 +314,7 @@ where block: BlockNumberOrTag, opts: GethDebugTracingOptions, ) -> RpcResult> { + let _permit = self.acquire_trace_permit().await; Ok(DebugApi::debug_trace_block(self, block.into(), opts).await?) } @@ -315,6 +324,7 @@ where tx_hash: H256, opts: GethDebugTracingOptions, ) -> RpcResult { + let _permit = self.acquire_trace_permit().await; Ok(DebugApi::debug_trace_transaction(self, tx_hash, opts).await?) } @@ -325,6 +335,7 @@ where block_number: Option, opts: GethDebugTracingCallOptions, ) -> RpcResult { + let _permit = self.acquire_trace_permit().await; Ok(DebugApi::debug_trace_call(self, request, block_number, opts).await?) } } diff --git a/crates/rpc/rpc/src/eth/api/block.rs b/crates/rpc/rpc/src/eth/api/block.rs index 475950bb75..0c8b3ea3f4 100644 --- a/crates/rpc/rpc/src/eth/api/block.rs +++ b/crates/rpc/rpc/src/eth/api/block.rs @@ -68,14 +68,6 @@ where Ok(self.cache().get_block_transactions(block_hash).await?.map(|txs| txs.len())) } - /// Returns the block header for the given block id. - pub(crate) async fn header( - &self, - block_id: impl Into, - ) -> EthResult> { - Ok(self.block(block_id).await?.map(|block| block.header)) - } - /// Returns the block object for the given block id. pub(crate) async fn block( &self, diff --git a/crates/rpc/rpc/src/eth/api/mod.rs b/crates/rpc/rpc/src/eth/api/mod.rs index 4c3930fee3..6e37e94800 100644 --- a/crates/rpc/rpc/src/eth/api/mod.rs +++ b/crates/rpc/rpc/src/eth/api/mod.rs @@ -3,7 +3,11 @@ //! The entire implementation of the namespace is quite large, hence it is divided across several //! files. -use crate::eth::{cache::EthStateCache, signer::EthSigner}; +use crate::eth::{ + cache::EthStateCache, + error::{EthApiError, EthResult}, + signer::EthSigner, +}; use async_trait::async_trait; use reth_interfaces::Result; use reth_network_api::NetworkInfo; @@ -20,7 +24,7 @@ mod server; mod sign; mod state; mod transactions; -use crate::eth::error::{EthApiError, EthResult}; + pub use transactions::{EthTransactions, TransactionSource}; /// Cache limit of block-level fee history for `eth_feeHistory` RPC method. diff --git a/crates/rpc/rpc/src/eth/api/state.rs b/crates/rpc/rpc/src/eth/api/state.rs index a424060461..ff4a7f7b32 100644 --- a/crates/rpc/rpc/src/eth/api/state.rs +++ b/crates/rpc/rpc/src/eth/api/state.rs @@ -81,6 +81,7 @@ where Ok(H256(value.to_be_bytes())) } + #[allow(unused)] pub(crate) fn get_proof( &self, address: Address, diff --git a/crates/rpc/rpc/src/eth/filter.rs b/crates/rpc/rpc/src/eth/filter.rs index 57322c4759..4aff2cb3f8 100644 --- a/crates/rpc/rpc/src/eth/filter.rs +++ b/crates/rpc/rpc/src/eth/filter.rs @@ -187,6 +187,7 @@ where #[derive(Debug)] struct EthFilterInner { /// The transaction pool. + #[allow(unused)] // we need this for non standard full transactions eventually pool: Pool, /// The client that can interact with the chain. client: Client, diff --git a/crates/rpc/rpc/src/eth/pubsub.rs b/crates/rpc/rpc/src/eth/pubsub.rs index 0a191b5df1..984cfa4ea0 100644 --- a/crates/rpc/rpc/src/eth/pubsub.rs +++ b/crates/rpc/rpc/src/eth/pubsub.rs @@ -1,5 +1,5 @@ //! `eth_` PubSub RPC handler implementation -use crate::eth::{cache::EthStateCache, logs_utils}; +use crate::eth::logs_utils; use futures::StreamExt; use jsonrpsee::{types::SubscriptionResult, SubscriptionSink}; use reth_network_api::NetworkInfo; @@ -37,21 +37,8 @@ impl EthPubSub { /// Creates a new, shareable instance. /// /// Subscription tasks are spawned via [tokio::task::spawn] - pub fn new( - client: Client, - pool: Pool, - chain_events: Events, - network: Network, - eth_cache: EthStateCache, - ) -> Self { - Self::with_spawner( - client, - pool, - chain_events, - network, - eth_cache, - Box::::default(), - ) + pub fn new(client: Client, pool: Pool, chain_events: Events, network: Network) -> Self { + Self::with_spawner(client, pool, chain_events, network, Box::::default()) } /// Creates a new, shareable instance. @@ -60,10 +47,9 @@ impl EthPubSub { pool: Pool, chain_events: Events, network: Network, - eth_cache: EthStateCache, subscription_task_spawner: Box, ) -> Self { - let inner = EthPubSubInner { client, pool, chain_events, network, eth_cache }; + let inner = EthPubSubInner { client, pool, chain_events, network }; Self { inner, subscription_task_spawner } } } @@ -168,12 +154,10 @@ struct EthPubSubInner { pool: Pool, /// The client that can interact with the chain. client: Client, - /// A type that allows to create new event subscriptions, + /// A type that allows to create new event subscriptions. chain_events: Events, /// The network. network: Network, - /// The async cache frontend for eth related data - eth_cache: EthStateCache, } // == impl EthPubSubInner === diff --git a/crates/rpc/rpc/src/lib.rs b/crates/rpc/rpc/src/lib.rs index 82d16c4eea..0c4d47e57a 100644 --- a/crates/rpc/rpc/src/lib.rs +++ b/crates/rpc/rpc/src/lib.rs @@ -4,8 +4,6 @@ no_crate_inject, attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) ))] -// TODO remove later -#![allow(dead_code)] //! Reth RPC implementation //! diff --git a/crates/rpc/rpc/src/result.rs b/crates/rpc/rpc/src/result.rs index 7ca707ab07..a3e1d458dd 100644 --- a/crates/rpc/rpc/src/result.rs +++ b/crates/rpc/rpc/src/result.rs @@ -164,7 +164,6 @@ pub(crate) fn rpc_err(code: i32, msg: impl Into, data: Option<&[u8]>) -> #[cfg(test)] mod tests { - use super::*; fn assert_rpc_result>() {} @@ -173,10 +172,6 @@ mod tests { Ok(o) } - fn to_optional_reth_err(o: Ok) -> reth_interfaces::Result> { - Ok(Some(o)) - } - #[test] fn can_convert_rpc() { assert_rpc_result::<(), reth_interfaces::Error, reth_interfaces::Result<()>>(); diff --git a/crates/rpc/rpc/src/trace.rs b/crates/rpc/rpc/src/trace.rs index d85eb7fe55..3ea15f9649 100644 --- a/crates/rpc/rpc/src/trace.rs +++ b/crates/rpc/rpc/src/trace.rs @@ -37,7 +37,8 @@ pub struct TraceApi { client: Client, /// Access to commonly used code of the `eth` namespace eth_api: Eth, - /// The async cache frontend for eth related data + /// The async cache frontend for eth-related data + #[allow(unused)] // we need this for trace_filter eventually eth_cache: EthStateCache, // restrict the number of concurrent calls to `trace_*` tracing_call_guard: TracingCallGuard, @@ -46,6 +47,11 @@ pub struct TraceApi { // === impl TraceApi === impl TraceApi { + /// The client that can interact with the chain. + pub fn client(&self) -> &Client { + &self.client + } + /// Create a new instance of the [TraceApi] pub fn new( client: Client,