diff --git a/bin/reth/src/args/rpc_server_args.rs b/bin/reth/src/args/rpc_server_args.rs index d1bb2f9c01..fa16ee3588 100644 --- a/bin/reth/src/args/rpc_server_args.rs +++ b/bin/reth/src/args/rpc_server_args.rs @@ -237,9 +237,9 @@ impl RpcServerArgs { /// for the auth server that handles the `engine_` API that's accessed by the consensus /// layer. #[allow(clippy::too_many_arguments)] - pub async fn start_servers( + pub async fn start_servers( &self, - client: Client, + provider: Provider, pool: Pool, network: Network, executor: Tasks, @@ -248,7 +248,7 @@ impl RpcServerArgs { jwt_secret: JwtSecret, ) -> Result<(RpcServerHandle, AuthServerHandle), RpcError> where - Client: BlockProviderIdExt + Provider: BlockProviderIdExt + HeaderProvider + StateProviderFactory + EvmEnvProvider @@ -267,7 +267,7 @@ impl RpcServerArgs { debug!(target: "reth::cli", http=?module_config.http(), ws=?module_config.ws(), "Using RPC module config"); let (rpc_modules, auth_module) = RpcModuleBuilder::default() - .with_client(client) + .with_provider(provider) .with_pool(pool) .with_network(network) .with_events(events) @@ -297,16 +297,16 @@ impl RpcServerArgs { } /// Convenience function for starting a rpc server with configs which extracted from cli args. - pub async fn start_rpc_server( + pub async fn start_rpc_server( &self, - client: Client, + provider: Provider, pool: Pool, network: Network, executor: Tasks, events: Events, ) -> Result where - Client: BlockProviderIdExt + Provider: BlockProviderIdExt + HeaderProvider + StateProviderFactory + EvmEnvProvider @@ -319,7 +319,7 @@ impl RpcServerArgs { Events: CanonStateSubscriptions + Clone + 'static, { reth_rpc_builder::launch( - client, + provider, pool, network, self.transport_rpc_module_config(), @@ -331,17 +331,17 @@ impl RpcServerArgs { } /// Create Engine API server. - pub async fn start_auth_server( + pub async fn start_auth_server( &self, - client: Client, + provider: Provider, pool: Pool, network: Network, executor: Tasks, - engine_api: EngineApi, + engine_api: EngineApi, jwt_secret: JwtSecret, ) -> Result where - Client: BlockProviderIdExt + Provider: BlockProviderIdExt + HeaderProvider + StateProviderFactory + EvmEnvProvider @@ -358,7 +358,7 @@ impl RpcServerArgs { ); reth_rpc_builder::auth::launch( - client, + provider, pool, network, executor, diff --git a/crates/rpc/rpc-api/src/engine.rs b/crates/rpc/rpc-api/src/engine.rs index 857e5634a4..be4825a5b6 100644 --- a/crates/rpc/rpc-api/src/engine.rs +++ b/crates/rpc/rpc-api/src/engine.rs @@ -47,7 +47,7 @@ pub trait EngineApi { /// Caution: This should not return the `withdrawals` field /// /// Note: - /// > Client software MAY stop the corresponding build process after serving this call. + /// > Provider software MAY stop the corresponding build process after serving this call. #[method(name = "getPayloadV1")] async fn get_payload_v1(&self, payload_id: PayloadId) -> RpcResult; @@ -55,7 +55,7 @@ pub trait EngineApi { /// /// Returns the most recent version of the payload that is available in the corresponding /// payload build process at the time of receiving this call. Note: - /// > Client software MAY stop the corresponding build process after serving this call. + /// > Provider software MAY stop the corresponding build process after serving this call. #[method(name = "getPayloadV2")] async fn get_payload_v2(&self, payload_id: PayloadId) -> RpcResult; diff --git a/crates/rpc/rpc-builder/src/auth.rs b/crates/rpc/rpc-builder/src/auth.rs index ac9bf3df78..11fb8185c8 100644 --- a/crates/rpc/rpc-builder/src/auth.rs +++ b/crates/rpc/rpc-builder/src/auth.rs @@ -27,8 +27,8 @@ use std::{ /// Configure and launch a _standalone_ auth server with `engine` and a _new_ `eth` namespace. #[allow(clippy::too_many_arguments)] -pub async fn launch( - client: Client, +pub async fn launch( + provider: Provider, pool: Pool, network: Network, executor: Tasks, @@ -37,7 +37,7 @@ pub async fn launch( secret: JwtSecret, ) -> Result where - Client: BlockProviderIdExt + Provider: BlockProviderIdExt + ReceiptProviderIdExt + HeaderProvider + StateProviderFactory @@ -51,10 +51,11 @@ where EngineApi: EngineApiServer, { // spawn a new cache task - let eth_cache = EthStateCache::spawn_with(client.clone(), Default::default(), executor.clone()); - let gas_oracle = GasPriceOracle::new(client.clone(), Default::default(), eth_cache.clone()); + let eth_cache = + EthStateCache::spawn_with(provider.clone(), Default::default(), executor.clone()); + let gas_oracle = GasPriceOracle::new(provider.clone(), Default::default(), eth_cache.clone()); let eth_api = EthApi::with_spawner( - client.clone(), + provider.clone(), pool.clone(), network, eth_cache.clone(), @@ -62,7 +63,7 @@ where Box::new(executor.clone()), ); let eth_filter = EthFilter::new( - client, + provider, pool, eth_cache.clone(), DEFAULT_MAX_LOGS_IN_RESPONSE, @@ -72,15 +73,15 @@ where } /// Configure and launch a _standalone_ auth server with existing EthApi implementation. -pub async fn launch_with_eth_api( - eth_api: EthApi, - eth_filter: EthFilter, +pub async fn launch_with_eth_api( + eth_api: EthApi, + eth_filter: EthFilter, engine_api: EngineApi, socket_addr: SocketAddr, secret: JwtSecret, ) -> Result where - Client: BlockProviderIdExt + Provider: BlockProviderIdExt + HeaderProvider + StateProviderFactory + EvmEnvProvider diff --git a/crates/rpc/rpc-builder/src/eth.rs b/crates/rpc/rpc-builder/src/eth.rs index 1f62fd2a12..907740b769 100644 --- a/crates/rpc/rpc-builder/src/eth.rs +++ b/crates/rpc/rpc-builder/src/eth.rs @@ -15,15 +15,15 @@ pub(crate) const DEFAULT_MAX_TRACING_REQUESTS: u32 = 25; /// All handlers for the `eth` namespace #[derive(Debug, Clone)] -pub struct EthHandlers { +pub struct EthHandlers { /// Main `eth_` request handler - pub api: EthApi, + pub api: EthApi, /// The async caching layer used by the eth handlers pub cache: EthStateCache, /// Polling based filter handler available on all transports - pub filter: EthFilter, + pub filter: EthFilter, /// Handler for subscriptions only available for transports that support it (ws, ipc) - pub pubsub: EthPubSub, + pub pubsub: EthPubSub, } /// Additional config values for the eth namespace diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index a3e6b6b28e..c82573e7a5 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -29,9 +29,9 @@ //! use reth_rpc_builder::{RethRpcModule, RpcModuleBuilder, RpcServerConfig, ServerBuilder, TransportRpcModuleConfig}; //! use reth_tasks::TokioTaskExecutor; //! use reth_transaction_pool::TransactionPool; -//! pub async fn launch(client: Client, pool: Pool, network: Network, events: Events) +//! pub async fn launch(provider: Provider, pool: Pool, network: Network, events: Events) //! where -//! Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + Clone + Unpin + 'static, +//! Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + Clone + Unpin + 'static, //! Pool: TransactionPool + Clone + 'static, //! Network: NetworkInfo + Peers + Clone + 'static, //! Events: CanonStateSubscriptions + Clone + 'static, @@ -43,7 +43,7 @@ //! RethRpcModule::Eth, //! RethRpcModule::Web3, //! ]); -//! let transport_modules = RpcModuleBuilder::new(client, pool, network, TokioTaskExecutor::default(), events).build(transports); +//! let transport_modules = RpcModuleBuilder::new(provider, pool, network, TokioTaskExecutor::default(), events).build(transports); //! let handle = RpcServerConfig::default() //! .with_http(ServerBuilder::default()) //! .start(transport_modules) @@ -65,9 +65,9 @@ //! use reth_transaction_pool::TransactionPool; //! use reth_rpc_api::EngineApiServer; //! use reth_rpc_builder::auth::AuthServerConfig; -//! pub async fn launch(client: Client, pool: Pool, network: Network, events: Events, engine_api: EngineApi) +//! pub async fn launch(provider: Provider, pool: Pool, network: Network, events: Events, engine_api: EngineApi) //! where -//! Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + Clone + Unpin + 'static, +//! Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + Clone + Unpin + 'static, //! Pool: TransactionPool + Clone + 'static, //! Network: NetworkInfo + Peers + Clone + 'static, //! Events: CanonStateSubscriptions + Clone + 'static, @@ -80,7 +80,7 @@ //! RethRpcModule::Eth, //! RethRpcModule::Web3, //! ]); -//! let builder = RpcModuleBuilder::new(client, pool, network, TokioTaskExecutor::default(), events); +//! let builder = RpcModuleBuilder::new(provider, pool, network, TokioTaskExecutor::default(), events); //! //! // configure the server modules //! let (modules, auth_module) = builder.build_with_auth_server(transports, engine_api); @@ -154,8 +154,8 @@ pub use jsonrpsee::server::ServerBuilder; pub use reth_ipc::server::{Builder as IpcServerBuilder, Endpoint}; /// Convenience function for starting a server in one step. -pub async fn launch( - client: Client, +pub async fn launch( + provider: Provider, pool: Pool, network: Network, module_config: impl Into, @@ -164,7 +164,7 @@ pub async fn launch( events: Events, ) -> Result where - Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + Clone + Unpin + 'static, + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + Clone + Unpin + 'static, Pool: TransactionPool + Clone + 'static, Network: NetworkInfo + Peers + Clone + 'static, Tasks: TaskSpawner + Clone + 'static, @@ -172,7 +172,7 @@ where { let module_config = module_config.into(); let server_config = server_config.into(); - RpcModuleBuilder::new(client, pool, network, executor, events) + RpcModuleBuilder::new(provider, pool, network, executor, events) .build(module_config) .start_server(server_config) .await @@ -182,9 +182,9 @@ where /// /// This is the main entrypoint for up RPC servers. #[derive(Debug, Clone)] -pub struct RpcModuleBuilder { - /// The Client type to when creating all rpc handlers - client: Client, +pub struct RpcModuleBuilder { + /// The Provider type to when creating all rpc handlers + provider: Provider, /// The Pool type to when creating all rpc handlers pool: Pool, /// The Network type to when creating all rpc handlers @@ -197,67 +197,73 @@ pub struct RpcModuleBuilder { // === impl RpcBuilder === -impl RpcModuleBuilder { +impl + RpcModuleBuilder +{ /// Create a new instance of the builder pub fn new( - client: Client, + provider: Provider, pool: Pool, network: Network, executor: Tasks, events: Events, ) -> Self { - Self { client, pool, network, executor, events } + Self { provider, pool, network, executor, events } } - /// Configure the client instance. - pub fn with_client(self, client: C) -> RpcModuleBuilder + /// Configure the provider instance. + pub fn with_provider

(self, provider: P) -> RpcModuleBuilder where - C: BlockProvider + StateProviderFactory + EvmEnvProvider + 'static, + P: BlockProvider + StateProviderFactory + EvmEnvProvider + 'static, { let Self { pool, network, executor, events, .. } = self; - RpcModuleBuilder { client, network, pool, executor, events } + RpcModuleBuilder { provider, network, pool, executor, events } } /// Configure the transaction pool instance. - pub fn with_pool

(self, pool: P) -> RpcModuleBuilder + pub fn with_pool

(self, pool: P) -> RpcModuleBuilder where P: TransactionPool + 'static, { - let Self { client, network, executor, events, .. } = self; - RpcModuleBuilder { client, network, pool, executor, events } + let Self { provider, network, executor, events, .. } = self; + RpcModuleBuilder { provider, network, pool, executor, events } } /// Configure the network instance. - pub fn with_network(self, network: N) -> RpcModuleBuilder + pub fn with_network(self, network: N) -> RpcModuleBuilder where N: NetworkInfo + Peers + 'static, { - let Self { client, pool, executor, events, .. } = self; - RpcModuleBuilder { client, network, pool, executor, events } + let Self { provider, pool, executor, events, .. } = self; + RpcModuleBuilder { provider, network, pool, executor, events } } /// Configure the task executor to use for additional tasks. - pub fn with_executor(self, executor: T) -> RpcModuleBuilder + pub fn with_executor( + self, + executor: T, + ) -> RpcModuleBuilder where T: TaskSpawner + 'static, { - let Self { pool, network, client, events, .. } = self; - RpcModuleBuilder { client, network, pool, executor, events } + let Self { pool, network, provider, events, .. } = self; + RpcModuleBuilder { provider, network, pool, executor, events } } /// Configure the event subscriber instance - pub fn with_events(self, events: E) -> RpcModuleBuilder + pub fn with_events(self, events: E) -> RpcModuleBuilder where E: CanonStateSubscriptions + 'static, { - let Self { client, pool, executor, network, .. } = self; - RpcModuleBuilder { client, network, pool, executor, events } + let Self { provider, pool, executor, network, .. } = self; + RpcModuleBuilder { provider, network, pool, executor, events } } } -impl RpcModuleBuilder +impl + RpcModuleBuilder where - Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + Clone + Unpin + 'static, + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + Clone + Unpin + 'static, Pool: TransactionPool + Clone + 'static, Network: NetworkInfo + Peers + Clone + 'static, Tasks: TaskSpawner + Clone + 'static, @@ -278,12 +284,12 @@ where { let mut modules = TransportRpcModules::default(); - let Self { client, pool, network, executor, events } = self; + let Self { provider, pool, network, executor, events } = self; let TransportRpcModuleConfig { http, ws, ipc, config } = module_config.clone(); let mut registry = RethModuleRegistry::new( - client, + provider, pool, network, executor, @@ -308,13 +314,13 @@ where pub fn build(self, module_config: TransportRpcModuleConfig) -> TransportRpcModules<()> { let mut modules = TransportRpcModules::default(); - let Self { client, pool, network, executor, events } = self; + let Self { provider, pool, network, executor, events } = self; if !module_config.is_empty() { let TransportRpcModuleConfig { http, ws, ipc, config } = module_config.clone(); let mut registry = RethModuleRegistry::new( - client, + provider, pool, network, executor, @@ -464,9 +470,9 @@ impl RpcModuleSelection { /// Note: This will always create new instance of the module handlers and is therefor only /// recommended for launching standalone transports. If multiple transports need to be /// configured it's recommended to use the [RpcModuleBuilder]. - pub fn standalone_module( + pub fn standalone_module( &self, - client: Client, + provider: Provider, pool: Pool, network: Network, executor: Tasks, @@ -474,14 +480,15 @@ impl RpcModuleSelection { config: RpcModuleConfig, ) -> RpcModule<()> where - Client: + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + Clone + Unpin + 'static, Pool: TransactionPool + Clone + 'static, Network: NetworkInfo + Peers + Clone + 'static, Tasks: TaskSpawner + Clone + 'static, Events: CanonStateSubscriptions + Clone + 'static, { - let mut registry = RethModuleRegistry::new(client, pool, network, executor, events, config); + let mut registry = + RethModuleRegistry::new(provider, pool, network, executor, events, config); registry.module_for(self) } @@ -599,8 +606,8 @@ impl Serialize for RethRpcModule { } /// A Helper type the holds instances of the configured modules. -pub struct RethModuleRegistry { - client: Client, +pub struct RethModuleRegistry { + provider: Provider, pool: Pool, network: Network, executor: Tasks, @@ -608,7 +615,7 @@ pub struct RethModuleRegistry { /// Additional settings for handlers. config: RpcModuleConfig, /// Holds a clone of all the eth namespace handlers - eth: Option>, + eth: Option>, /// to put trace calls behind semaphore tracing_call_guard: TracingCallGuard, /// Contains the [Methods] of a module @@ -617,12 +624,12 @@ pub struct RethModuleRegistry { // === impl RethModuleRegistry === -impl - RethModuleRegistry +impl + RethModuleRegistry { /// Creates a new, empty instance. pub fn new( - client: Client, + provider: Provider, pool: Pool, network: Network, executor: Tasks, @@ -630,7 +637,7 @@ impl config: RpcModuleConfig, ) -> Self { Self { - client, + provider, pool, network, eth: None, @@ -657,7 +664,8 @@ impl } } -impl RethModuleRegistry +impl + RethModuleRegistry where Network: NetworkInfo + Peers + Clone + 'static, { @@ -676,9 +684,10 @@ where } } -impl RethModuleRegistry +impl + RethModuleRegistry where - Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + Clone + Unpin + 'static, + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + Clone + Unpin + 'static, Pool: TransactionPool + Clone + 'static, Network: NetworkInfo + Peers + Clone + 'static, Tasks: TaskSpawner + Clone + 'static, @@ -697,7 +706,7 @@ where self.modules.insert( RethRpcModule::Debug, DebugApi::new( - self.client.clone(), + self.provider.clone(), eth_api, Box::new(self.executor.clone()), self.tracing_call_guard.clone(), @@ -714,7 +723,7 @@ where self.modules.insert( RethRpcModule::Trace, TraceApi::new( - self.client.clone(), + self.provider.clone(), eth.api.clone(), eth.cache, Box::new(self.executor.clone()), @@ -800,7 +809,7 @@ where AdminApi::new(self.network.clone()).into_rpc().into() } RethRpcModule::Debug => DebugApi::new( - self.client.clone(), + self.provider.clone(), eth_api.clone(), Box::new(self.executor.clone()), self.tracing_call_guard.clone(), @@ -819,7 +828,7 @@ where NetApi::new(self.network.clone(), eth_api.clone()).into_rpc().into() } RethRpcModule::Trace => TraceApi::new( - self.client.clone(), + self.provider.clone(), eth_api.clone(), eth_cache.clone(), Box::new(self.executor.clone()), @@ -856,16 +865,16 @@ where /// Creates the [EthHandlers] type the first time this is called. fn with_eth(&mut self, f: F) -> R where - F: FnOnce(&EthHandlers) -> R, + F: FnOnce(&EthHandlers) -> R, { if self.eth.is_none() { let cache = EthStateCache::spawn_with( - self.client.clone(), + self.provider.clone(), self.config.eth.cache.clone(), self.executor.clone(), ); let gas_oracle = GasPriceOracle::new( - self.client.clone(), + self.provider.clone(), self.config.eth.gas_oracle.clone(), cache.clone(), ); @@ -880,7 +889,7 @@ where let executor = Box::new(self.executor.clone()); let api = EthApi::with_spawner( - self.client.clone(), + self.provider.clone(), self.pool.clone(), self.network.clone(), cache.clone(), @@ -888,7 +897,7 @@ where executor.clone(), ); let filter = EthFilter::new( - self.client.clone(), + self.provider.clone(), self.pool.clone(), cache.clone(), self.config.eth.max_logs_per_response, @@ -896,7 +905,7 @@ where ); let pubsub = EthPubSub::with_spawner( - self.client.clone(), + self.provider.clone(), self.pool.clone(), self.events.clone(), self.network.clone(), @@ -910,12 +919,12 @@ where } /// Returns the configured [EthHandlers] or creates it if it does not exist yet - fn eth_handlers(&mut self) -> EthHandlers { + fn eth_handlers(&mut self) -> EthHandlers { self.with_eth(|handlers| handlers.clone()) } /// Returns the configured [EthApi] or creates it if it does not exist yet - fn eth_api(&mut self) -> EthApi { + fn eth_api(&mut self) -> EthApi { self.with_eth(|handlers| handlers.api.clone()) } } diff --git a/crates/rpc/rpc-builder/tests/it/utils.rs b/crates/rpc/rpc-builder/tests/it/utils.rs index 9773d32132..1281a8ae07 100644 --- a/crates/rpc/rpc-builder/tests/it/utils.rs +++ b/crates/rpc/rpc-builder/tests/it/utils.rs @@ -99,7 +99,7 @@ pub fn test_rpc_builder() -> RpcModuleBuilder< TestCanonStateSubscriptions, > { RpcModuleBuilder::default() - .with_client(NoopProvider::default()) + .with_provider(NoopProvider::default()) .with_pool(testing_pool()) .with_network(NoopNetwork) .with_executor(TokioTaskExecutor::default()) diff --git a/crates/rpc/rpc-engine-api/src/engine_api.rs b/crates/rpc/rpc-engine-api/src/engine_api.rs index 424658972a..20a085f0aa 100644 --- a/crates/rpc/rpc-engine-api/src/engine_api.rs +++ b/crates/rpc/rpc-engine-api/src/engine_api.rs @@ -23,9 +23,9 @@ const MAX_PAYLOAD_BODIES_LIMIT: u64 = 1024; /// The Engine API implementation that grants the Consensus layer access to data and /// functions in the Execution layer that are crucial for the consensus process. -pub struct EngineApi { - /// The client to interact with the chain. - client: Client, +pub struct EngineApi { + /// The provider to interact with the chain. + provider: Provider, /// Consensus configuration chain_spec: Arc, /// The channel to send messages to the beacon consensus engine. @@ -34,18 +34,18 @@ pub struct EngineApi { payload_store: PayloadStore, } -impl EngineApi +impl EngineApi where - Client: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvider + 'static, + Provider: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvider + 'static, { /// Create new instance of [EngineApi]. pub fn new( - client: Client, + provider: Provider, chain_spec: Arc, beacon_consensus: BeaconConsensusEngineHandle, payload_store: PayloadStore, ) -> Self { - Self { client, chain_spec, beacon_consensus, payload_store } + Self { provider, chain_spec, beacon_consensus, payload_store } } /// See also @@ -123,7 +123,7 @@ where /// Caution: This should not return the `withdrawals` field /// /// Note: - /// > Client software MAY stop the corresponding build process after serving this call. + /// > Provider software MAY stop the corresponding build process after serving this call. pub async fn get_payload_v1(&self, payload_id: PayloadId) -> EngineApiResult { Ok(self .payload_store @@ -139,7 +139,7 @@ where /// See also /// /// Note: - /// > Client software MAY stop the corresponding build process after serving this call. + /// > Provider software MAY stop the corresponding build process after serving this call. async fn get_payload_v2( &self, payload_id: PayloadId, @@ -180,7 +180,7 @@ where let end = start.saturating_add(count); for num in start..end { let block = self - .client + .provider .block(BlockHashOrNumber::Number(num)) .map_err(|err| EngineApiError::Internal(Box::new(err)))?; result.push(block.map(Into::into)); @@ -202,7 +202,7 @@ where let mut result = Vec::with_capacity(hashes.len()); for hash in hashes { let block = self - .client + .provider .block(BlockHashOrNumber::Hash(hash)) .map_err(|err| EngineApiError::Internal(Box::new(err)))?; result.push(block.map(Into::into)); @@ -249,7 +249,7 @@ where // Attempt to look up terminal block hash let local_hash = self - .client + .provider .block_hash(terminal_block_number.as_u64()) .map_err(|err| EngineApiError::Internal(Box::new(err)))?; @@ -302,9 +302,9 @@ where } #[async_trait] -impl EngineApiServer for EngineApi +impl EngineApiServer for EngineApi where - Client: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvider + 'static, + Provider: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvider + 'static, { /// Handler for `engine_newPayloadV1` /// See also @@ -355,7 +355,7 @@ where /// Caution: This should not return the `withdrawals` field /// /// Note: - /// > Client software MAY stop the corresponding build process after serving this call. + /// > Provider software MAY stop the corresponding build process after serving this call. async fn get_payload_v1(&self, payload_id: PayloadId) -> RpcResult { trace!(target: "rpc::engine", "Serving engine_getPayloadV1"); Ok(EngineApi::get_payload_v1(self, payload_id).await?) @@ -369,7 +369,7 @@ where /// See also /// /// Note: - /// > Client software MAY stop the corresponding build process after serving this call. + /// > Provider software MAY stop the corresponding build process after serving this call. async fn get_payload_v2(&self, payload_id: PayloadId) -> RpcResult { trace!(target: "rpc::engine", "Serving engine_getPayloadV2"); Ok(EngineApi::get_payload_v2(self, payload_id).await?) @@ -424,7 +424,7 @@ where } } -impl std::fmt::Debug for EngineApi { +impl std::fmt::Debug for EngineApi { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("EngineApi").finish_non_exhaustive() } @@ -444,22 +444,22 @@ mod tests { fn setup_engine_api() -> (EngineApiTestHandle, EngineApi>) { let chain_spec: Arc = MAINNET.clone(); - let client = Arc::new(MockEthProvider::default()); + let provider = Arc::new(MockEthProvider::default()); let payload_store = spawn_test_payload_service(); let (to_engine, engine_rx) = unbounded_channel(); let api = EngineApi::new( - client.clone(), + provider.clone(), chain_spec.clone(), BeaconConsensusEngineHandle::new(to_engine), payload_store.into(), ); - let handle = EngineApiTestHandle { chain_spec, client, from_api: engine_rx }; + let handle = EngineApiTestHandle { chain_spec, provider, from_api: engine_rx }; (handle, api) } struct EngineApiTestHandle { chain_spec: Arc, - client: Arc, + provider: Arc, from_api: UnboundedReceiver, } @@ -511,7 +511,7 @@ mod tests { let (start, count) = (1, 10); let blocks = random_block_range(start..=start + count - 1, H256::default(), 0..2); - handle.client.extend_blocks(blocks.iter().cloned().map(|b| (b.hash(), b.unseal()))); + handle.provider.extend_blocks(blocks.iter().cloned().map(|b| (b.hash(), b.unseal()))); let expected = blocks.iter().cloned().map(|b| Some(b.unseal().into())).collect::>(); @@ -530,7 +530,7 @@ mod tests { // Insert only blocks in ranges 1-25 and 50-75 let first_missing_range = 26..=50; let second_missing_range = 76..=100; - handle.client.extend_blocks( + handle.provider.extend_blocks( blocks .iter() .filter(|b| { @@ -611,7 +611,7 @@ mod tests { ); // Add block and to provider local store and test for mismatch - handle.client.add_block( + handle.provider.add_block( execution_terminal_block.hash(), execution_terminal_block.clone().unseal(), ); @@ -638,7 +638,7 @@ mod tests { terminal_block_number: terminal_block_number.into(), }; - handle.client.add_block(terminal_block.hash(), terminal_block.unseal()); + handle.provider.add_block(terminal_block.hash(), terminal_block.unseal()); let config = api.exchange_transition_configuration(transition_config.clone()).await.unwrap(); diff --git a/crates/rpc/rpc-testing-util/src/trace.rs b/crates/rpc/rpc-testing-util/src/trace.rs index cdf6ad81a8..d13a55971c 100644 --- a/crates/rpc/rpc-testing-util/src/trace.rs +++ b/crates/rpc/rpc-testing-util/src/trace.rs @@ -17,8 +17,8 @@ pub type TraceBlockResult = Result<(Vec, BlockId), (R /// An extension trait for the Trace API. #[async_trait::async_trait] pub trait TraceApiExt { - /// The client type that is used to make the requests. - type Client; + /// The provider type that is used to make the requests. + type Provider; /// Returns a new stream that yields the traces for the given blocks. /// @@ -39,7 +39,7 @@ pub trait TraceApiExt { #[async_trait::async_trait] impl TraceApiExt for T { - type Client = T; + type Provider = T; fn trace_block_buffered(&self, params: I, n: usize) -> TraceBlockStream<'_> where diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 6d0f845483..a3116a2655 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -35,31 +35,31 @@ use tokio::sync::{oneshot, AcquireError, OwnedSemaphorePermit}; /// `debug` API implementation. /// /// This type provides the functionality for handling `debug` related requests. -pub struct DebugApi { - inner: Arc>, +pub struct DebugApi { + inner: Arc>, } // === impl DebugApi === -impl DebugApi { +impl DebugApi { /// Create a new instance of the [DebugApi] pub fn new( - client: Client, + provider: Provider, eth: Eth, task_spawner: Box, tracing_call_guard: TracingCallGuard, ) -> Self { let inner = - Arc::new(DebugApiInner { client, eth_api: eth, task_spawner, tracing_call_guard }); + Arc::new(DebugApiInner { provider, eth_api: eth, task_spawner, tracing_call_guard }); Self { inner } } } // === impl DebugApi === -impl DebugApi +impl DebugApi where - Client: BlockProviderIdExt + HeaderProvider + 'static, + Provider: BlockProviderIdExt + HeaderProvider + 'static, Eth: EthTransactions + 'static, { /// Executes the future on a new blocking task. @@ -171,7 +171,7 @@ where ) -> EthResult> { let block_hash = self .inner - .client + .provider .block_hash_for_id(block_id)? .ok_or_else(|| EthApiError::UnknownBlockNumber)?; @@ -324,23 +324,23 @@ where } #[async_trait] -impl DebugApiServer for DebugApi +impl DebugApiServer for DebugApi where - Client: BlockProviderIdExt + HeaderProvider + 'static, + Provider: BlockProviderIdExt + HeaderProvider + 'static, Eth: EthApiSpec + 'static, { /// Handler for `debug_getRawHeader` async fn raw_header(&self, block_id: BlockId) -> RpcResult { let header = match block_id { - BlockId::Hash(hash) => self.inner.client.header(&hash.into()).to_rpc_result()?, + BlockId::Hash(hash) => self.inner.provider.header(&hash.into()).to_rpc_result()?, BlockId::Number(number_or_tag) => { let number = self .inner - .client + .provider .convert_block_number(number_or_tag) .to_rpc_result()? .ok_or_else(|| internal_rpc_err("Pending block not supported".to_string()))?; - self.inner.client.header_by_number(number).to_rpc_result()? + self.inner.provider.header_by_number(number).to_rpc_result()? } }; @@ -354,7 +354,7 @@ where /// Handler for `debug_getRawBlock` async fn raw_block(&self, block_id: BlockId) -> RpcResult { - let block = self.inner.client.block_by_id(block_id).to_rpc_result()?; + let block = self.inner.provider.block_by_id(block_id).to_rpc_result()?; let mut res = Vec::new(); if let Some(mut block) = block { @@ -384,7 +384,7 @@ where /// Handler for `debug_getRawReceipts` async fn raw_receipts(&self, block_id: BlockId) -> RpcResult> { let receipts = - self.inner.client.receipts_by_block_id(block_id).to_rpc_result()?.unwrap_or_default(); + self.inner.provider.receipts_by_block_id(block_id).to_rpc_result()?.unwrap_or_default(); let mut all_receipts = Vec::with_capacity(receipts.len()); for receipt in receipts { @@ -464,21 +464,21 @@ where } } -impl std::fmt::Debug for DebugApi { +impl std::fmt::Debug for DebugApi { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("DebugApi").finish_non_exhaustive() } } -impl Clone for DebugApi { +impl Clone for DebugApi { fn clone(&self) -> Self { Self { inner: Arc::clone(&self.inner) } } } -struct DebugApiInner { - /// The client that can interact with the chain. - client: Client, +struct DebugApiInner { + /// The provider that can interact with the chain. + provider: Provider, /// The implementation of `eth` API eth_api: Eth, // restrict the number of concurrent calls to tracing calls diff --git a/crates/rpc/rpc/src/eth/api/block.rs b/crates/rpc/rpc/src/eth/api/block.rs index 218e180fa4..4c48c8e674 100644 --- a/crates/rpc/rpc/src/eth/api/block.rs +++ b/crates/rpc/rpc/src/eth/api/block.rs @@ -8,9 +8,9 @@ use reth_primitives::BlockId; use reth_provider::{BlockProviderIdExt, EvmEnvProvider, StateProviderFactory}; use reth_rpc_types::{Block, Index, RichBlock}; -impl EthApi +impl EthApi where - Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, { /// Returns the uncle headers of the given block /// @@ -20,7 +20,7 @@ where block_id: impl Into, ) -> EthResult>> { let block_id = block_id.into(); - Ok(self.client().ommers_by_id(block_id)?) + Ok(self.provider().ommers_by_id(block_id)?) } pub(crate) async fn ommer_by_block_and_index( @@ -32,9 +32,9 @@ where let uncles = if block_id.is_pending() { // Pending block can be fetched directly without need for caching - self.client().pending_block()?.map(|block| block.ommers) + self.provider().pending_block()?.map(|block| block.ommers) } else { - self.client().ommers_by_id(block_id)? + self.provider().ommers_by_id(block_id)? } .unwrap_or_default(); @@ -57,10 +57,10 @@ where if block_id.is_pending() { // Pending block can be fetched directly without need for caching - return Ok(self.client().pending_block()?.map(|block| block.body.len())) + return Ok(self.provider().pending_block()?.map(|block| block.body.len())) } - let block_hash = match self.client().block_hash_for_id(block_id)? { + let block_hash = match self.provider().block_hash_for_id(block_id)? { Some(block_hash) => block_hash, None => return Ok(None), }; @@ -77,10 +77,10 @@ where if block_id.is_pending() { // Pending block can be fetched directly without need for caching - return Ok(self.client().pending_block()?) + return Ok(self.provider().pending_block()?) } - let block_hash = match self.client().block_hash_for_id(block_id)? { + let block_hash = match self.provider().block_hash_for_id(block_id)? { Some(block_hash) => block_hash, None => return Ok(None), }; @@ -103,7 +103,7 @@ where }; let block_hash = block.hash; let total_difficulty = - self.client().header_td(&block_hash)?.ok_or(EthApiError::UnknownBlockNumber)?; + self.provider().header_td(&block_hash)?.ok_or(EthApiError::UnknownBlockNumber)?; let block = Block::from_block(block.into(), total_difficulty, full.into(), Some(block_hash))?; Ok(Some(block.into())) diff --git a/crates/rpc/rpc/src/eth/api/call.rs b/crates/rpc/rpc/src/eth/api/call.rs index bf1af26dd7..63d8d1d3d6 100644 --- a/crates/rpc/rpc/src/eth/api/call.rs +++ b/crates/rpc/rpc/src/eth/api/call.rs @@ -31,10 +31,10 @@ use tracing::trace; const MIN_TRANSACTION_GAS: u64 = 21_000u64; const MIN_CREATE_GAS: u64 = 53_000u64; -impl EthApi +impl EthApi where Pool: TransactionPool + Clone + 'static, - Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, Network: NetworkInfo + Send + Sync + 'static, { /// Estimate gas needed for execution of the `request` at the [BlockId]. diff --git a/crates/rpc/rpc/src/eth/api/fees.rs b/crates/rpc/rpc/src/eth/api/fees.rs index 980961e738..ebed8a30c1 100644 --- a/crates/rpc/rpc/src/eth/api/fees.rs +++ b/crates/rpc/rpc/src/eth/api/fees.rs @@ -11,10 +11,10 @@ use reth_rpc_types::{FeeHistory, FeeHistoryCacheItem, TxGasAndReward}; use reth_transaction_pool::TransactionPool; use std::collections::BTreeMap; -impl EthApi +impl EthApi where Pool: TransactionPool + Clone + 'static, - Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, Network: NetworkInfo + Send + Sync + 'static, { /// Returns a suggestion for a gas price for legacy transactions. @@ -45,7 +45,7 @@ where return Ok(FeeHistory::default()) } - let Some(previous_to_end_block) = self.inner.client.block_number_for_id(newest_block)? else { return Err(EthApiError::UnknownBlockNumber)}; + let Some(previous_to_end_block) = self.inner.provider.block_number_for_id(newest_block)? else { return Err(EthApiError::UnknownBlockNumber)}; let end_block = previous_to_end_block + 1; if end_block < block_count { @@ -103,9 +103,9 @@ where { let header_range = start_block..=end_block; - let headers = self.inner.client.headers_range(header_range.clone())?; + let headers = self.inner.provider.headers_range(header_range.clone())?; let transactions_by_block = - self.inner.client.transactions_by_block_range(header_range)?; + self.inner.provider.transactions_by_block_range(header_range)?; let header_tx = headers.iter().zip(&transactions_by_block); @@ -168,7 +168,7 @@ where // get the first block in the range from the db let oldest_block_hash = - self.inner.client.block_hash(start_block)?.ok_or(EthApiError::UnknownBlockNumber)?; + self.inner.provider.block_hash(start_block)?.ok_or(EthApiError::UnknownBlockNumber)?; // Set the hash in cache items if the block is present in the cache if let Some(cache_item) = fee_history_cache_items.get_mut(&start_block) { diff --git a/crates/rpc/rpc/src/eth/api/mod.rs b/crates/rpc/rpc/src/eth/api/mod.rs index 9c16099983..4e50bb2f70 100644 --- a/crates/rpc/rpc/src/eth/api/mod.rs +++ b/crates/rpc/rpc/src/eth/api/mod.rs @@ -44,10 +44,10 @@ pub trait EthApiSpec: EthTransactions + Send + Sync { /// Returns the chain id fn chain_id(&self) -> U64; - /// Returns client chain info + /// Returns provider chain info fn chain_info(&self) -> Result; - /// Returns a list of addresses owned by client. + /// Returns a list of addresses owned by provider. fn accounts(&self) -> Vec

; /// Returns `true` if the network is undergoing sync. @@ -65,25 +65,25 @@ pub trait EthApiSpec: EthTransactions + Send + Sync { /// are implemented separately in submodules. The rpc handler implementation can then delegate to /// the main impls. This way [`EthApi`] is not limited to [`jsonrpsee`] and can be used standalone /// or in other network handlers (for example ipc). -pub struct EthApi { +pub struct EthApi { /// All nested fields bundled together. - inner: Arc>, + inner: Arc>, } -impl EthApi +impl EthApi where - Client: BlockProviderIdExt, + Provider: BlockProviderIdExt, { /// Creates a new, shareable instance using the default tokio task spawner. pub fn new( - client: Client, + provider: Provider, pool: Pool, network: Network, eth_cache: EthStateCache, - gas_oracle: GasPriceOracle, + gas_oracle: GasPriceOracle, ) -> Self { Self::with_spawner( - client, + provider, pool, network, eth_cache, @@ -94,15 +94,15 @@ where /// Creates a new, shareable instance. pub fn with_spawner( - client: Client, + provider: Provider, pool: Pool, network: Network, eth_cache: EthStateCache, - gas_oracle: GasPriceOracle, + gas_oracle: GasPriceOracle, task_spawner: Box, ) -> Self { // get the block number of the latest block - let latest_block = client + let latest_block = provider .header_by_number_or_tag(BlockNumberOrTag::Latest) .ok() .flatten() @@ -110,7 +110,7 @@ where .unwrap_or_default(); let inner = EthApiInner { - client, + provider, pool, network, signers: Default::default(), @@ -151,13 +151,13 @@ where } /// Returns the gas oracle frontend - pub(crate) fn gas_oracle(&self) -> &GasPriceOracle { + pub(crate) fn gas_oracle(&self) -> &GasPriceOracle { &self.inner.gas_oracle } - /// Returns the inner `Client` - pub fn client(&self) -> &Client { - &self.inner.client + /// Returns the inner `Provider` + pub fn provider(&self) -> &Provider { + &self.inner.provider } /// Returns the inner `Network` @@ -173,12 +173,12 @@ where // === State access helpers === -impl EthApi +impl EthApi where - Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, { fn convert_block_number(&self, num: BlockNumberOrTag) -> Result> { - self.client().convert_block_number(num) + self.provider().convert_block_number(num) } /// Returns the state at the given [BlockId] enum. @@ -219,40 +219,40 @@ where /// Returns the state at the given block number pub fn state_at_hash(&self, block_hash: H256) -> Result> { - self.client().history_by_block_hash(block_hash) + self.provider().history_by_block_hash(block_hash) } /// Returns the state at the given block number pub fn state_at_number(&self, block_number: u64) -> Result> { match self.convert_block_number(BlockNumberOrTag::Latest)? { Some(num) if num == block_number => self.latest_state(), - _ => self.client().history_by_block_number(block_number), + _ => self.provider().history_by_block_number(block_number), } } /// Returns the _latest_ state pub fn latest_state(&self) -> Result> { - self.client().latest() + self.provider().latest() } } -impl std::fmt::Debug for EthApi { +impl std::fmt::Debug for EthApi { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("EthApi").finish_non_exhaustive() } } -impl Clone for EthApi { +impl Clone for EthApi { fn clone(&self) -> Self { Self { inner: Arc::clone(&self.inner) } } } #[async_trait] -impl EthApiSpec for EthApi +impl EthApiSpec for EthApi where Pool: TransactionPool + Clone + 'static, - Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, Network: NetworkInfo + 'static, { /// Returns the current ethereum protocol version. @@ -270,7 +270,7 @@ where /// Returns the current info for the chain fn chain_info(&self) -> Result { - self.client().chain_info() + self.provider().chain_info() } fn accounts(&self) -> Vec
{ @@ -285,7 +285,7 @@ where fn sync_status(&self) -> Result { let status = if self.is_syncing() { let current_block = U256::from( - self.client().chain_info().map(|info| info.best_number).unwrap_or_default(), + self.provider().chain_info().map(|info| info.best_number).unwrap_or_default(), ); SyncStatus::Info(SyncInfo { starting_block: self.inner.starting_block, @@ -302,11 +302,11 @@ where } /// Container type `EthApi` -struct EthApiInner { +struct EthApiInner { /// The transaction pool. pool: Pool, - /// The client that can interact with the chain. - client: Client, + /// The provider that can interact with the chain. + provider: Provider, /// An interface to interact with the network network: Network, /// All configured Signers @@ -314,7 +314,7 @@ struct EthApiInner { /// The async cache frontend for eth related data eth_cache: EthStateCache, /// The async gas oracle frontend for gas price suggestions - gas_oracle: GasPriceOracle, + gas_oracle: GasPriceOracle, /// The block number at which the node started starting_block: U256, /// The type that can spawn tasks which would otherwise block. diff --git a/crates/rpc/rpc/src/eth/api/server.rs b/crates/rpc/rpc/src/eth/api/server.rs index 315a900963..6d093cb01f 100644 --- a/crates/rpc/rpc/src/eth/api/server.rs +++ b/crates/rpc/rpc/src/eth/api/server.rs @@ -29,11 +29,11 @@ use serde_json::Value; use tracing::trace; #[async_trait::async_trait] -impl EthApiServer for EthApi +impl EthApiServer for EthApi where Self: EthApiSpec + EthTransactions, Pool: TransactionPool + 'static, - Client: BlockProvider + Provider: BlockProvider + BlockIdProvider + BlockProviderIdExt + HeaderProvider diff --git a/crates/rpc/rpc/src/eth/api/sign.rs b/crates/rpc/rpc/src/eth/api/sign.rs index edd03e4655..48164a6007 100644 --- a/crates/rpc/rpc/src/eth/api/sign.rs +++ b/crates/rpc/rpc/src/eth/api/sign.rs @@ -11,7 +11,7 @@ use reth_primitives::{Address, Bytes}; use serde_json::Value; use std::ops::Deref; -impl EthApi { +impl EthApi { pub(crate) async fn sign(&self, account: Address, message: Bytes) -> EthResult { let signer = self.find_signer(&account)?; let signature = signer.sign(account, &message).await?; diff --git a/crates/rpc/rpc/src/eth/api/state.rs b/crates/rpc/rpc/src/eth/api/state.rs index 92f1caa9a5..9a9669c3fb 100644 --- a/crates/rpc/rpc/src/eth/api/state.rs +++ b/crates/rpc/rpc/src/eth/api/state.rs @@ -14,9 +14,9 @@ use reth_provider::{ use reth_rpc_types::{EIP1186AccountProofResponse, StorageProof}; use reth_transaction_pool::{PoolTransaction, TransactionPool}; -impl EthApi +impl EthApi where - Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, Pool: TransactionPool + Clone + 'static, Network: Send + Sync + 'static, { @@ -89,7 +89,7 @@ where keys: Vec, block_id: Option, ) -> EthResult { - let chain_info = self.client().chain_info()?; + let chain_info = self.provider().chain_info()?; let block_id = block_id.unwrap_or(BlockId::Number(BlockNumberOrTag::Latest)); // if we are trying to create a proof for the latest block, but have a BlockId as input diff --git a/crates/rpc/rpc/src/eth/api/transactions.rs b/crates/rpc/rpc/src/eth/api/transactions.rs index 2612b48287..2669066797 100644 --- a/crates/rpc/rpc/src/eth/api/transactions.rs +++ b/crates/rpc/rpc/src/eth/api/transactions.rs @@ -179,10 +179,10 @@ pub trait EthTransactions: Send + Sync { } #[async_trait] -impl EthTransactions for EthApi +impl EthTransactions for EthApi where Pool: TransactionPool + Clone + 'static, - Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, Network: NetworkInfo + Send + Sync + 'static, { fn state_at(&self, at: BlockId) -> EthResult> { @@ -199,13 +199,13 @@ where async fn evm_env_at(&self, at: BlockId) -> EthResult<(CfgEnv, BlockEnv, BlockId)> { if at.is_pending() { - let header = if let Some(pending) = self.client().pending_header()? { + let header = if let Some(pending) = self.provider().pending_header()? { pending } else { // no pending block from the CL yet, so we use the latest block and modify the env // values that we can let mut latest = self - .client() + .provider() .latest_header()? .ok_or_else(|| EthApiError::UnknownBlockNumber)?; @@ -221,13 +221,13 @@ where let mut cfg = CfgEnv::default(); let mut block_env = BlockEnv::default(); - self.client().fill_block_env_with_header(&mut block_env, &header)?; - self.client().fill_cfg_env_with_header(&mut cfg, &header)?; + self.provider().fill_block_env_with_header(&mut block_env, &header)?; + self.provider().fill_cfg_env_with_header(&mut cfg, &header)?; return Ok((cfg, block_env, header.hash.into())) } else { // Use cached values if there is no pending block let block_hash = self - .client() + .provider() .block_hash_for_id(at)? .ok_or_else(|| EthApiError::UnknownBlockNumber)?; let (cfg, env) = self.cache().get_evm_env(block_hash).await?; @@ -267,7 +267,7 @@ where // Try to find the transaction on disk let mut resp = self .on_blocking_task(|this| async move { - match this.client().transaction_by_hash_with_meta(hash)? { + match this.provider().transaction_by_hash_with_meta(hash)? { None => Ok(None), Some((tx, meta)) => { let transaction = tx @@ -345,12 +345,12 @@ where async fn transaction_receipt(&self, hash: H256) -> EthResult> { self.on_blocking_task(|this| async move { - let (tx, meta) = match this.client().transaction_by_hash_with_meta(hash)? { + let (tx, meta) = match this.provider().transaction_by_hash_with_meta(hash)? { Some((tx, meta)) => (tx, meta), None => return Ok(None), }; - let receipt = match this.client().receipt_by_hash(hash)? { + let receipt = match this.provider().receipt_by_hash(hash)? { Some(recpt) => recpt, None => return Ok(None), }; @@ -566,10 +566,10 @@ where // === impl EthApi === -impl EthApi +impl EthApi where Pool: TransactionPool + 'static, - Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, + Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static, Network: 'static, { pub(crate) fn sign_request( diff --git a/crates/rpc/rpc/src/eth/cache.rs b/crates/rpc/rpc/src/eth/cache.rs index 55f50103a1..717ef54025 100644 --- a/crates/rpc/rpc/src/eth/cache.rs +++ b/crates/rpc/rpc/src/eth/cache.rs @@ -94,16 +94,16 @@ pub struct EthStateCache { impl EthStateCache { /// Creates and returns both [EthStateCache] frontend and the memory bound service. - fn create( - client: Client, + fn create( + provider: Provider, action_task_spawner: Tasks, max_block_bytes: usize, max_receipt_bytes: usize, max_env_bytes: usize, - ) -> (Self, EthStateCacheService) { + ) -> (Self, EthStateCacheService) { let (to_service, rx) = unbounded_channel(); let service = EthStateCacheService { - client, + provider, full_block_cache: BlockLruCache::with_memory_budget(max_block_bytes), receipts_cache: ReceiptsLruCache::with_memory_budget(max_receipt_bytes), evm_env_cache: EnvLruCache::with_memory_budget(max_env_bytes), @@ -119,29 +119,29 @@ impl EthStateCache { /// [tokio::spawn]. /// /// See also [Self::spawn_with] - pub fn spawn(client: Client, config: EthStateCacheConfig) -> Self + pub fn spawn(provider: Provider, config: EthStateCacheConfig) -> Self where - Client: StateProviderFactory + BlockProvider + EvmEnvProvider + Clone + Unpin + 'static, + Provider: StateProviderFactory + BlockProvider + EvmEnvProvider + Clone + Unpin + 'static, { - Self::spawn_with(client, config, TokioTaskExecutor::default()) + Self::spawn_with(provider, config, TokioTaskExecutor::default()) } /// Creates a new async LRU backed cache service task and spawns it to a new task via the given /// spawner. /// /// The cache is memory limited by the given max bytes values. - pub fn spawn_with( - client: Client, + pub fn spawn_with( + provider: Provider, config: EthStateCacheConfig, executor: Tasks, ) -> Self where - Client: StateProviderFactory + BlockProvider + EvmEnvProvider + Clone + Unpin + 'static, + Provider: StateProviderFactory + BlockProvider + EvmEnvProvider + Clone + Unpin + 'static, Tasks: TaskSpawner + Clone + 'static, { let EthStateCacheConfig { max_block_bytes, max_receipt_bytes, max_env_bytes } = config; let (this, service) = Self::create( - client, + provider, executor.clone(), max_block_bytes, max_receipt_bytes, @@ -216,7 +216,7 @@ impl EthStateCache { /// to limit concurrent requests. #[must_use = "Type does nothing unless spawned"] pub(crate) struct EthStateCacheService< - Client, + Provider, Tasks, LimitBlocks = ByMemoryUsage, LimitReceipts = ByMemoryUsage, @@ -227,7 +227,7 @@ pub(crate) struct EthStateCacheService< LimitEnvs: Limiter, { /// The type used to lookup data from disk - client: Client, + provider: Provider, /// The LRU cache for full blocks grouped by their hash. full_block_cache: BlockLruCache, /// The LRU cache for full blocks grouped by their hash. @@ -242,9 +242,9 @@ pub(crate) struct EthStateCacheService< action_task_spawner: Tasks, } -impl EthStateCacheService +impl EthStateCacheService where - Client: StateProviderFactory + BlockProvider + EvmEnvProvider + Clone + Unpin + 'static, + Provider: StateProviderFactory + BlockProvider + EvmEnvProvider + Clone + Unpin + 'static, Tasks: TaskSpawner + Clone + 'static, { fn on_new_block(&mut self, block_hash: H256, res: Result>) { @@ -285,9 +285,9 @@ where } } -impl Future for EthStateCacheService +impl Future for EthStateCacheService where - Client: StateProviderFactory + BlockProvider + EvmEnvProvider + Clone + Unpin + 'static, + Provider: StateProviderFactory + BlockProvider + EvmEnvProvider + Clone + Unpin + 'static, Tasks: TaskSpawner + Clone + 'static, { type Output = (); @@ -313,10 +313,10 @@ where // block is not in the cache, request it if this is the first consumer if this.full_block_cache.queue(block_hash, Either::Left(response_tx)) { - let client = this.client.clone(); + let provider = this.provider.clone(); let action_tx = this.action_tx.clone(); this.action_task_spawner.spawn_blocking(Box::pin(async move { - let res = client.block_by_hash(block_hash); + let res = provider.block_by_hash(block_hash); let _ = action_tx .send(CacheAction::BlockResult { block_hash, res }); })); @@ -331,10 +331,10 @@ where // block is not in the cache, request it if this is the first consumer if this.full_block_cache.queue(block_hash, Either::Right(response_tx)) { - let client = this.client.clone(); + let provider = this.provider.clone(); let action_tx = this.action_tx.clone(); this.action_task_spawner.spawn_blocking(Box::pin(async move { - let res = client.block_by_hash(block_hash); + let res = provider.block_by_hash(block_hash); let _ = action_tx .send(CacheAction::BlockResult { block_hash, res }); })); @@ -351,10 +351,10 @@ where // block is not in the cache, request it if this is the first consumer if this.receipts_cache.queue(block_hash, response_tx) { - let client = this.client.clone(); + let provider = this.provider.clone(); let action_tx = this.action_tx.clone(); this.action_task_spawner.spawn_blocking(Box::pin(async move { - let res = client.receipts_by_block(block_hash.into()); + let res = provider.receipts_by_block(block_hash.into()); let _ = action_tx .send(CacheAction::ReceiptsResult { block_hash, res }); })); @@ -370,12 +370,12 @@ where // env data is not in the cache, request it if this is the first // consumer if this.evm_env_cache.queue(block_hash, response_tx) { - let client = this.client.clone(); + let provider = this.provider.clone(); let action_tx = this.action_tx.clone(); this.action_task_spawner.spawn_blocking(Box::pin(async move { let mut cfg = CfgEnv::default(); let mut block_env = BlockEnv::default(); - let res = client + let res = provider .fill_env_at(&mut cfg, &mut block_env, block_hash.into()) .map(|_| (cfg, block_env)); let _ = action_tx.send(CacheAction::EnvResult { diff --git a/crates/rpc/rpc/src/eth/filter.rs b/crates/rpc/rpc/src/eth/filter.rs index cfd61e0f05..c6eea1fbe1 100644 --- a/crates/rpc/rpc/src/eth/filter.rs +++ b/crates/rpc/rpc/src/eth/filter.rs @@ -26,27 +26,27 @@ use tracing::trace; const MAX_HEADERS_RANGE: u64 = 1_000; // with ~530bytes per header this is ~500kb /// `Eth` filter RPC implementation. -pub struct EthFilter { +pub struct EthFilter { /// All nested fields bundled together. - inner: Arc>, + inner: Arc>, } -impl EthFilter { +impl EthFilter { /// Creates a new, shareable instance. /// - /// This uses the given pool to get notified about new transactions, the client to interact with - /// the blockchain, the cache to fetch cacheable data, like the logs and the + /// This uses the given pool to get notified about new transactions, the provider to interact + /// with the blockchain, the cache to fetch cacheable data, like the logs and the /// max_logs_per_response to limit the amount of logs returned in a single response /// `eth_getLogs` pub fn new( - client: Client, + provider: Provider, pool: Pool, eth_cache: EthStateCache, max_logs_per_response: usize, task_spawner: Box, ) -> Self { let inner = EthFilterInner { - client, + provider, active_filters: Default::default(), pool, id_provider: Arc::new(EthSubscriptionIdProvider::default()), @@ -64,9 +64,9 @@ impl EthFilter { } } -impl EthFilter +impl EthFilter where - Client: BlockProvider + BlockIdProvider + EvmEnvProvider + 'static, + Provider: BlockProvider + BlockIdProvider + EvmEnvProvider + 'static, Pool: TransactionPool + 'static, { /// Executes the given filter on a new task. @@ -91,7 +91,7 @@ where /// Returns all the filter changes for the given id, if any pub async fn filter_changes(&self, id: FilterId) -> Result { - let info = self.inner.client.chain_info()?; + let info = self.inner.provider.chain_info()?; let best_number = info.best_number; let (start_block, kind) = { @@ -117,7 +117,7 @@ where for block_num in start_block..best_number { let block_hash = self .inner - .client + .provider .block_hash(block_num)? .ok_or(EthApiError::UnknownBlockNumber)?; block_hashes.push(block_hash); @@ -128,11 +128,11 @@ where let (from_block_number, to_block_number) = match filter.block_option { FilterBlockOption::Range { from_block, to_block } => { let from = from_block - .map(|num| self.inner.client.convert_block_number(num)) + .map(|num| self.inner.provider.convert_block_number(num)) .transpose()? .flatten(); let to = to_block - .map(|num| self.inner.client.convert_block_number(num)) + .map(|num| self.inner.provider.convert_block_number(num)) .transpose()? .flatten(); logs_utils::get_filter_block_range(from, to, start_block, info) @@ -176,9 +176,9 @@ where } #[async_trait] -impl EthFilterApiServer for EthFilter +impl EthFilterApiServer for EthFilter where - Client: BlockProvider + BlockIdProvider + EvmEnvProvider + 'static, + Provider: BlockProvider + BlockIdProvider + EvmEnvProvider + 'static, Pool: TransactionPool + 'static, { /// Handler for `eth_newFilter` @@ -238,13 +238,13 @@ where } } -impl std::fmt::Debug for EthFilter { +impl std::fmt::Debug for EthFilter { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("EthFilter").finish_non_exhaustive() } } -impl Clone for EthFilter { +impl Clone for EthFilter { fn clone(&self) -> Self { Self { inner: Arc::clone(&self.inner) } } @@ -252,12 +252,12 @@ impl Clone for EthFilter { /// Container type `EthFilter` #[derive(Debug)] -struct EthFilterInner { +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, + /// The provider that can interact with the chain. + provider: Provider, /// All currently installed filters. active_filters: ActiveFilters, /// Provides ids to identify filters @@ -272,9 +272,9 @@ struct EthFilterInner { task_spawner: Box, } -impl EthFilterInner +impl EthFilterInner where - Client: BlockProvider + BlockIdProvider + EvmEnvProvider + 'static, + Provider: BlockProvider + BlockIdProvider + EvmEnvProvider + 'static, Pool: TransactionPool + 'static, { /// Returns logs matching given filter object. @@ -298,16 +298,16 @@ where } FilterBlockOption::Range { from_block, to_block } => { // compute the range - let info = self.client.chain_info()?; + let info = self.provider.chain_info()?; // we start at the most recent block if unset in filter let start_block = info.best_number; let from = from_block - .map(|num| self.client.convert_block_number(num)) + .map(|num| self.provider.convert_block_number(num)) .transpose()? .flatten(); let to = to_block - .map(|num| self.client.convert_block_number(num)) + .map(|num| self.provider.convert_block_number(num)) .transpose()? .flatten(); let (from_block_number, to_block_number) = @@ -319,7 +319,7 @@ where /// Installs a new filter and returns the new identifier. async fn install_filter(&self, kind: FilterKind) -> RpcResult { - let last_poll_block_number = self.client.best_block_number().to_rpc_result()?; + let last_poll_block_number = self.provider.best_block_number().to_rpc_result()?; let id = FilterId::from(self.id_provider.next_id()); let mut filters = self.active_filters.inner.lock().await; filters.insert( @@ -338,7 +338,7 @@ where &self, hash_or_number: BlockHashOrNumber, ) -> EthResult)>> { - let block_hash = match self.client.convert_block_hash(hash_or_number)? { + let block_hash = match self.provider.convert_block_hash(hash_or_number)? { Some(hash) => hash, None => return Ok(None), }; @@ -386,7 +386,7 @@ where for (from, to) in BlockRangeInclusiveIter::new(from_block..=to_block, self.max_headers_range) { - let headers = self.client.headers_range(from..=to)?; + let headers = self.provider.headers_range(from..=to)?; for (idx, header) in headers.iter().enumerate() { // these are consecutive headers, so we can use the parent hash of the next block to diff --git a/crates/rpc/rpc/src/eth/gas_oracle.rs b/crates/rpc/rpc/src/eth/gas_oracle.rs index 98cf756d7a..fd5ab19428 100644 --- a/crates/rpc/rpc/src/eth/gas_oracle.rs +++ b/crates/rpc/rpc/src/eth/gas_oracle.rs @@ -81,9 +81,9 @@ impl GasPriceOracleConfig { /// Calculates a gas price depending on recent blocks. #[derive(Debug)] -pub struct GasPriceOracle { +pub struct GasPriceOracle { /// The type used to subscribe to block events and get block info - client: Client, + provider: Provider, /// The cache for blocks cache: EthStateCache, /// The config for the oracle @@ -92,13 +92,13 @@ pub struct GasPriceOracle { last_price: Mutex, } -impl GasPriceOracle +impl GasPriceOracle where - Client: BlockProviderIdExt + 'static, + Provider: BlockProviderIdExt + 'static, { /// Creates and returns the [GasPriceOracle]. pub fn new( - client: Client, + provider: Provider, mut oracle_config: GasPriceOracleConfig, cache: EthStateCache, ) -> Self { @@ -108,13 +108,13 @@ where oracle_config.percentile = 100; } - Self { client, oracle_config, last_price: Default::default(), cache } + Self { provider, oracle_config, last_price: Default::default(), cache } } /// Suggests a gas price estimate based on recent blocks, using the configured percentile. pub async fn suggest_tip_cap(&self) -> EthResult { let header = self - .client + .provider .sealed_header_by_number_or_tag(BlockNumberOrTag::Latest)? .ok_or(EthApiError::UnknownBlockNumber)?; diff --git a/crates/rpc/rpc/src/eth/pubsub.rs b/crates/rpc/rpc/src/eth/pubsub.rs index 4fe9db4d20..f4a4ccebb1 100644 --- a/crates/rpc/rpc/src/eth/pubsub.rs +++ b/crates/rpc/rpc/src/eth/pubsub.rs @@ -27,40 +27,47 @@ use tokio_stream::{ /// /// This handles `eth_subscribe` RPC calls. #[derive(Clone)] -pub struct EthPubSub { +pub struct EthPubSub { /// All nested fields bundled together. - inner: EthPubSubInner, + inner: EthPubSubInner, /// The type that's used to spawn subscription tasks. subscription_task_spawner: Box, } // === impl EthPubSub === -impl EthPubSub { +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) -> Self { - Self::with_spawner(client, pool, chain_events, network, Box::::default()) + pub fn new(provider: Provider, pool: Pool, chain_events: Events, network: Network) -> Self { + Self::with_spawner( + provider, + pool, + chain_events, + network, + Box::::default(), + ) } /// Creates a new, shareable instance. pub fn with_spawner( - client: Client, + provider: Provider, pool: Pool, chain_events: Events, network: Network, subscription_task_spawner: Box, ) -> Self { - let inner = EthPubSubInner { client, pool, chain_events, network }; + let inner = EthPubSubInner { provider, pool, chain_events, network }; Self { inner, subscription_task_spawner } } } #[async_trait::async_trait] -impl EthPubSubApiServer for EthPubSub +impl EthPubSubApiServer + for EthPubSub where - Client: BlockProvider + EvmEnvProvider + Clone + 'static, + Provider: BlockProvider + EvmEnvProvider + Clone + 'static, Pool: TransactionPool + 'static, Events: CanonStateSubscriptions + Clone + 'static, Network: NetworkInfo + Clone + 'static, @@ -83,14 +90,14 @@ where } /// The actual handler for and accepted [`EthPubSub::subscribe`] call. -async fn handle_accepted( - pubsub: EthPubSubInner, +async fn handle_accepted( + pubsub: EthPubSubInner, accepted_sink: SubscriptionSink, kind: SubscriptionKind, params: Option, ) -> Result<(), jsonrpsee::core::Error> where - Client: BlockProvider + EvmEnvProvider + Clone + 'static, + Provider: BlockProvider + EvmEnvProvider + Clone + 'static, Pool: TransactionPool + 'static, Events: CanonStateSubscriptions + Clone + 'static, Network: NetworkInfo + Clone + 'static, @@ -185,7 +192,9 @@ where } } -impl std::fmt::Debug for EthPubSub { +impl std::fmt::Debug + for EthPubSub +{ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("EthPubSub").finish_non_exhaustive() } @@ -193,11 +202,11 @@ impl std::fmt::Debug for EthPubSub { +struct EthPubSubInner { /// The transaction pool. pool: Pool, - /// The client that can interact with the chain. - client: Client, + /// The provider that can interact with the chain. + provider: Provider, /// A type that allows to create new event subscriptions. chain_events: Events, /// The network. @@ -206,15 +215,15 @@ struct EthPubSubInner { // == impl EthPubSubInner === -impl EthPubSubInner +impl EthPubSubInner where - Client: BlockProvider + 'static, + Provider: BlockProvider + 'static, { /// Returns the current sync status for the `syncing` subscription async fn sync_status(&self, is_syncing: bool) -> EthSubscriptionResult { if is_syncing { let current_block = - self.client.chain_info().map(|info| info.best_number).unwrap_or_default(); + self.provider.chain_info().map(|info| info.best_number).unwrap_or_default(); EthSubscriptionResult::SyncState(PubSubSyncStatus::Detailed(SyncStatusMetadata { syncing: true, starting_block: 0, @@ -227,7 +236,7 @@ where } } -impl EthPubSubInner +impl EthPubSubInner where Pool: TransactionPool + 'static, { @@ -237,9 +246,9 @@ where } } -impl EthPubSubInner +impl EthPubSubInner where - Client: BlockProvider + EvmEnvProvider + 'static, + Provider: BlockProvider + EvmEnvProvider + 'static, Events: CanonStateSubscriptions + 'static, Network: NetworkInfo + 'static, Pool: 'static, diff --git a/crates/rpc/rpc/src/trace.rs b/crates/rpc/rpc/src/trace.rs index 81d0e39e52..45ff282eb6 100644 --- a/crates/rpc/rpc/src/trace.rs +++ b/crates/rpc/rpc/src/trace.rs @@ -33,28 +33,28 @@ use tokio::sync::{oneshot, AcquireError, OwnedSemaphorePermit}; /// `trace` API implementation. /// /// This type provides the functionality for handling `trace` related requests. -pub struct TraceApi { - inner: Arc>, +pub struct TraceApi { + inner: Arc>, } // === impl TraceApi === -impl TraceApi { - /// The client that can interact with the chain. - pub fn client(&self) -> &Client { - &self.inner.client +impl TraceApi { + /// The provider that can interact with the chain. + pub fn provider(&self) -> &Provider { + &self.inner.provider } /// Create a new instance of the [TraceApi] pub fn new( - client: Client, + provider: Provider, eth_api: Eth, eth_cache: EthStateCache, task_spawner: Box, tracing_call_guard: TracingCallGuard, ) -> Self { let inner = Arc::new(TraceApiInner { - client, + provider, eth_api, eth_cache, task_spawner, @@ -73,9 +73,9 @@ impl TraceApi { // === impl TraceApi === -impl TraceApi +impl TraceApi where - Client: BlockProvider + StateProviderFactory + EvmEnvProvider + 'static, + Provider: BlockProvider + StateProviderFactory + EvmEnvProvider + 'static, Eth: EthTransactions + 'static, { /// Executes the future on a new blocking task. @@ -382,9 +382,9 @@ where } #[async_trait] -impl TraceApiServer for TraceApi +impl TraceApiServer for TraceApi where - Client: BlockProvider + StateProviderFactory + EvmEnvProvider + 'static, + Provider: BlockProvider + StateProviderFactory + EvmEnvProvider + 'static, Eth: EthTransactions + 'static, { /// Executes the given call and returns a number of possible traces for it. @@ -486,20 +486,20 @@ where } } -impl std::fmt::Debug for TraceApi { +impl std::fmt::Debug for TraceApi { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("TraceApi").finish_non_exhaustive() } } -impl Clone for TraceApi { +impl Clone for TraceApi { fn clone(&self) -> Self { Self { inner: Arc::clone(&self.inner) } } } -struct TraceApiInner { - /// The client that can interact with the chain. - client: Client, +struct TraceApiInner { + /// The provider that can interact with the chain. + provider: Provider, /// Access to commonly used code of the `eth` namespace eth_api: Eth, /// The async cache frontend for eth-related data