feat(rpc): rename Client generics to Provider (#3126)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Thomas Coratger
2023-06-13 19:17:16 +02:00
committed by GitHub
parent 225e05267b
commit 39c6b22829
22 changed files with 330 additions and 311 deletions

View File

@ -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<Client, Pool, Network, Tasks, Events, Engine>(
pub async fn start_servers<Provider, Pool, Network, Tasks, Events, Engine>(
&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<Client, Pool, Network, Tasks, Events>(
pub async fn start_rpc_server<Provider, Pool, Network, Tasks, Events>(
&self,
client: Client,
provider: Provider,
pool: Pool,
network: Network,
executor: Tasks,
events: Events,
) -> Result<RpcServerHandle, RpcError>
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<Client, Pool, Network, Tasks>(
pub async fn start_auth_server<Provider, Pool, Network, Tasks>(
&self,
client: Client,
provider: Provider,
pool: Pool,
network: Network,
executor: Tasks,
engine_api: EngineApi<Client>,
engine_api: EngineApi<Provider>,
jwt_secret: JwtSecret,
) -> Result<AuthServerHandle, RpcError>
where
Client: BlockProviderIdExt
Provider: BlockProviderIdExt
+ HeaderProvider
+ StateProviderFactory
+ EvmEnvProvider
@ -358,7 +358,7 @@ impl RpcServerArgs {
);
reth_rpc_builder::auth::launch(
client,
provider,
pool,
network,
executor,

View File

@ -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<ExecutionPayload>;
@ -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<ExecutionPayloadEnvelope>;

View File

@ -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, Pool, Network, Tasks, EngineApi>(
client: Client,
pub async fn launch<Provider, Pool, Network, Tasks, EngineApi>(
provider: Provider,
pool: Pool,
network: Network,
executor: Tasks,
@ -37,7 +37,7 @@ pub async fn launch<Client, Pool, Network, Tasks, EngineApi>(
secret: JwtSecret,
) -> Result<AuthServerHandle, RpcError>
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<Client, Pool, Network, EngineApi>(
eth_api: EthApi<Client, Pool, Network>,
eth_filter: EthFilter<Client, Pool>,
pub async fn launch_with_eth_api<Provider, Pool, Network, EngineApi>(
eth_api: EthApi<Provider, Pool, Network>,
eth_filter: EthFilter<Provider, Pool>,
engine_api: EngineApi,
socket_addr: SocketAddr,
secret: JwtSecret,
) -> Result<AuthServerHandle, RpcError>
where
Client: BlockProviderIdExt
Provider: BlockProviderIdExt
+ HeaderProvider
+ StateProviderFactory
+ EvmEnvProvider

View File

@ -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<Client, Pool, Network, Events> {
pub struct EthHandlers<Provider, Pool, Network, Events> {
/// Main `eth_` request handler
pub api: EthApi<Client, Pool, Network>,
pub api: EthApi<Provider, Pool, Network>,
/// The async caching layer used by the eth handlers
pub cache: EthStateCache,
/// Polling based filter handler available on all transports
pub filter: EthFilter<Client, Pool>,
pub filter: EthFilter<Provider, Pool>,
/// Handler for subscriptions only available for transports that support it (ws, ipc)
pub pubsub: EthPubSub<Client, Pool, Events, Network>,
pub pubsub: EthPubSub<Provider, Pool, Events, Network>,
}
/// Additional config values for the eth namespace

View File

@ -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, Pool, Network, Events>(client: Client, pool: Pool, network: Network, events: Events)
//! pub async fn launch<Provider, Pool, Network, Events>(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, Pool, Network, Events, EngineApi>(client: Client, pool: Pool, network: Network, events: Events, engine_api: EngineApi)
//! pub async fn launch<Provider, Pool, Network, Events, EngineApi>(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, Pool, Network, Tasks, Events>(
client: Client,
pub async fn launch<Provider, Pool, Network, Tasks, Events>(
provider: Provider,
pool: Pool,
network: Network,
module_config: impl Into<TransportRpcModuleConfig>,
@ -164,7 +164,7 @@ pub async fn launch<Client, Pool, Network, Tasks, Events>(
events: Events,
) -> Result<RpcServerHandle, RpcError>
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<Client, Pool, Network, Tasks, Events> {
/// The Client type to when creating all rpc handlers
client: Client,
pub struct RpcModuleBuilder<Provider, Pool, Network, Tasks, Events> {
/// 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<Client, Pool, Network, Tasks, Events> {
// === impl RpcBuilder ===
impl<Client, Pool, Network, Tasks, Events> RpcModuleBuilder<Client, Pool, Network, Tasks, Events> {
impl<Provider, Pool, Network, Tasks, Events>
RpcModuleBuilder<Provider, Pool, Network, Tasks, Events>
{
/// 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<C>(self, client: C) -> RpcModuleBuilder<C, Pool, Network, Tasks, Events>
/// Configure the provider instance.
pub fn with_provider<P>(self, provider: P) -> RpcModuleBuilder<P, Pool, Network, Tasks, Events>
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<P>(self, pool: P) -> RpcModuleBuilder<Client, P, Network, Tasks, Events>
pub fn with_pool<P>(self, pool: P) -> RpcModuleBuilder<Provider, P, Network, Tasks, Events>
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<N>(self, network: N) -> RpcModuleBuilder<Client, Pool, N, Tasks, Events>
pub fn with_network<N>(self, network: N) -> RpcModuleBuilder<Provider, Pool, N, Tasks, Events>
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<T>(self, executor: T) -> RpcModuleBuilder<Client, Pool, Network, T, Events>
pub fn with_executor<T>(
self,
executor: T,
) -> RpcModuleBuilder<Provider, Pool, Network, T, Events>
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<E>(self, events: E) -> RpcModuleBuilder<Client, Pool, Network, Tasks, E>
pub fn with_events<E>(self, events: E) -> RpcModuleBuilder<Provider, Pool, Network, Tasks, E>
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<Client, Pool, Network, Tasks, Events> RpcModuleBuilder<Client, Pool, Network, Tasks, Events>
impl<Provider, Pool, Network, Tasks, Events>
RpcModuleBuilder<Provider, Pool, Network, Tasks, 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,
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<Client, Pool, Network, Tasks, Events>(
pub fn standalone_module<Provider, Pool, Network, Tasks, Events>(
&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, Pool, Network, Tasks, Events> {
client: Client,
pub struct RethModuleRegistry<Provider, Pool, Network, Tasks, Events> {
provider: Provider,
pool: Pool,
network: Network,
executor: Tasks,
@ -608,7 +615,7 @@ pub struct RethModuleRegistry<Client, Pool, Network, Tasks, Events> {
/// Additional settings for handlers.
config: RpcModuleConfig,
/// Holds a clone of all the eth namespace handlers
eth: Option<EthHandlers<Client, Pool, Network, Events>>,
eth: Option<EthHandlers<Provider, Pool, Network, Events>>,
/// to put trace calls behind semaphore
tracing_call_guard: TracingCallGuard,
/// Contains the [Methods] of a module
@ -617,12 +624,12 @@ pub struct RethModuleRegistry<Client, Pool, Network, Tasks, Events> {
// === impl RethModuleRegistry ===
impl<Client, Pool, Network, Tasks, Events>
RethModuleRegistry<Client, Pool, Network, Tasks, Events>
impl<Provider, Pool, Network, Tasks, Events>
RethModuleRegistry<Provider, Pool, Network, Tasks, Events>
{
/// Creates a new, empty instance.
pub fn new(
client: Client,
provider: Provider,
pool: Pool,
network: Network,
executor: Tasks,
@ -630,7 +637,7 @@ impl<Client, Pool, Network, Tasks, Events>
config: RpcModuleConfig,
) -> Self {
Self {
client,
provider,
pool,
network,
eth: None,
@ -657,7 +664,8 @@ impl<Client, Pool, Network, Tasks, Events>
}
}
impl<Client, Pool, Network, Tasks, Events> RethModuleRegistry<Client, Pool, Network, Tasks, Events>
impl<Provider, Pool, Network, Tasks, Events>
RethModuleRegistry<Provider, Pool, Network, Tasks, Events>
where
Network: NetworkInfo + Peers + Clone + 'static,
{
@ -676,9 +684,10 @@ where
}
}
impl<Client, Pool, Network, Tasks, Events> RethModuleRegistry<Client, Pool, Network, Tasks, Events>
impl<Provider, Pool, Network, Tasks, Events>
RethModuleRegistry<Provider, Pool, Network, Tasks, 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,
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<F, R>(&mut self, f: F) -> R
where
F: FnOnce(&EthHandlers<Client, Pool, Network, Events>) -> R,
F: FnOnce(&EthHandlers<Provider, Pool, Network, Events>) -> 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<Client, Pool, Network, Events> {
fn eth_handlers(&mut self) -> EthHandlers<Provider, Pool, Network, Events> {
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<Client, Pool, Network> {
fn eth_api(&mut self) -> EthApi<Provider, Pool, Network> {
self.with_eth(|handlers| handlers.api.clone())
}
}

View File

@ -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())

View File

@ -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<Client> {
/// The client to interact with the chain.
client: Client,
pub struct EngineApi<Provider> {
/// The provider to interact with the chain.
provider: Provider,
/// Consensus configuration
chain_spec: Arc<ChainSpec>,
/// The channel to send messages to the beacon consensus engine.
@ -34,18 +34,18 @@ pub struct EngineApi<Client> {
payload_store: PayloadStore,
}
impl<Client> EngineApi<Client>
impl<Provider> EngineApi<Provider>
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<ChainSpec>,
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 <https://github.com/ethereum/execution-apis/blob/3d627c95a4d3510a8187dd02e0250ecb4331d27e/src/engine/paris.md#engine_newpayloadv1>
@ -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<ExecutionPayload> {
Ok(self
.payload_store
@ -139,7 +139,7 @@ where
/// See also <https://github.com/ethereum/execution-apis/blob/3d627c95a4d3510a8187dd02e0250ecb4331d27e/src/engine/shanghai.md#engine_getpayloadv2>
///
/// 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<Client> EngineApiServer for EngineApi<Client>
impl<Provider> EngineApiServer for EngineApi<Provider>
where
Client: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvider + 'static,
Provider: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvider + 'static,
{
/// Handler for `engine_newPayloadV1`
/// See also <https://github.com/ethereum/execution-apis/blob/3d627c95a4d3510a8187dd02e0250ecb4331d27e/src/engine/paris.md#engine_newpayloadv1>
@ -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<ExecutionPayload> {
trace!(target: "rpc::engine", "Serving engine_getPayloadV1");
Ok(EngineApi::get_payload_v1(self, payload_id).await?)
@ -369,7 +369,7 @@ where
/// See also <https://github.com/ethereum/execution-apis/blob/3d627c95a4d3510a8187dd02e0250ecb4331d27e/src/engine/shanghai.md#engine_getpayloadv2>
///
/// 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<ExecutionPayloadEnvelope> {
trace!(target: "rpc::engine", "Serving engine_getPayloadV2");
Ok(EngineApi::get_payload_v2(self, payload_id).await?)
@ -424,7 +424,7 @@ where
}
}
impl<Client> std::fmt::Debug for EngineApi<Client> {
impl<Provider> std::fmt::Debug for EngineApi<Provider> {
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<Arc<MockEthProvider>>) {
let chain_spec: Arc<ChainSpec> = 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<ChainSpec>,
client: Arc<MockEthProvider>,
provider: Arc<MockEthProvider>,
from_api: UnboundedReceiver<BeaconEngineMessage>,
}
@ -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::<Vec<_>>();
@ -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();

View File

@ -17,8 +17,8 @@ pub type TraceBlockResult = Result<(Vec<LocalizedTransactionTrace>, 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<T: TraceApiClient + Sync> TraceApiExt for T {
type Client = T;
type Provider = T;
fn trace_block_buffered<I, B>(&self, params: I, n: usize) -> TraceBlockStream<'_>
where

View File

@ -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<Client, Eth> {
inner: Arc<DebugApiInner<Client, Eth>>,
pub struct DebugApi<Provider, Eth> {
inner: Arc<DebugApiInner<Provider, Eth>>,
}
// === impl DebugApi ===
impl<Client, Eth> DebugApi<Client, Eth> {
impl<Provider, Eth> DebugApi<Provider, Eth> {
/// Create a new instance of the [DebugApi]
pub fn new(
client: Client,
provider: Provider,
eth: Eth,
task_spawner: Box<dyn TaskSpawner>,
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<Client, Eth> DebugApi<Client, Eth>
impl<Provider, Eth> DebugApi<Provider, Eth>
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<Vec<TraceResult>> {
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<Client, Eth> DebugApiServer for DebugApi<Client, Eth>
impl<Provider, Eth> DebugApiServer for DebugApi<Provider, Eth>
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<Bytes> {
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<Bytes> {
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<Vec<Bytes>> {
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<Client, Eth> std::fmt::Debug for DebugApi<Client, Eth> {
impl<Provider, Eth> std::fmt::Debug for DebugApi<Provider, Eth> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DebugApi").finish_non_exhaustive()
}
}
impl<Client, Eth> Clone for DebugApi<Client, Eth> {
impl<Provider, Eth> Clone for DebugApi<Provider, Eth> {
fn clone(&self) -> Self {
Self { inner: Arc::clone(&self.inner) }
}
}
struct DebugApiInner<Client, Eth> {
/// The client that can interact with the chain.
client: Client,
struct DebugApiInner<Provider, Eth> {
/// 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

View File

@ -8,9 +8,9 @@ use reth_primitives::BlockId;
use reth_provider::{BlockProviderIdExt, EvmEnvProvider, StateProviderFactory};
use reth_rpc_types::{Block, Index, RichBlock};
impl<Client, Pool, Network> EthApi<Client, Pool, Network>
impl<Provider, Pool, Network> EthApi<Provider, Pool, Network>
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<BlockId>,
) -> EthResult<Option<Vec<reth_primitives::Header>>> {
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()))

View File

@ -31,10 +31,10 @@ use tracing::trace;
const MIN_TRANSACTION_GAS: u64 = 21_000u64;
const MIN_CREATE_GAS: u64 = 53_000u64;
impl<Client, Pool, Network> EthApi<Client, Pool, Network>
impl<Provider, Pool, Network> EthApi<Provider, Pool, Network>
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].

View File

@ -11,10 +11,10 @@ use reth_rpc_types::{FeeHistory, FeeHistoryCacheItem, TxGasAndReward};
use reth_transaction_pool::TransactionPool;
use std::collections::BTreeMap;
impl<Client, Pool, Network> EthApi<Client, Pool, Network>
impl<Provider, Pool, Network> EthApi<Provider, Pool, Network>
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) {

View File

@ -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<ChainInfo>;
/// Returns a list of addresses owned by client.
/// Returns a list of addresses owned by provider.
fn accounts(&self) -> Vec<Address>;
/// 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<Client, Pool, Network> {
pub struct EthApi<Provider, Pool, Network> {
/// All nested fields bundled together.
inner: Arc<EthApiInner<Client, Pool, Network>>,
inner: Arc<EthApiInner<Provider, Pool, Network>>,
}
impl<Client, Pool, Network> EthApi<Client, Pool, Network>
impl<Provider, Pool, Network> EthApi<Provider, Pool, Network>
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<Client>,
gas_oracle: GasPriceOracle<Provider>,
) -> 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<Client>,
gas_oracle: GasPriceOracle<Provider>,
task_spawner: Box<dyn TaskSpawner>,
) -> 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<Client> {
pub(crate) fn gas_oracle(&self) -> &GasPriceOracle<Provider> {
&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<Client, Pool, Network> EthApi<Client, Pool, Network>
impl<Provider, Pool, Network> EthApi<Provider, Pool, Network>
where
Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static,
Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static,
{
fn convert_block_number(&self, num: BlockNumberOrTag) -> Result<Option<u64>> {
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<StateProviderBox<'_>> {
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<StateProviderBox<'_>> {
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<StateProviderBox<'_>> {
self.client().latest()
self.provider().latest()
}
}
impl<Client, Pool, Events> std::fmt::Debug for EthApi<Client, Pool, Events> {
impl<Provider, Pool, Events> std::fmt::Debug for EthApi<Provider, Pool, Events> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EthApi").finish_non_exhaustive()
}
}
impl<Client, Pool, Events> Clone for EthApi<Client, Pool, Events> {
impl<Provider, Pool, Events> Clone for EthApi<Provider, Pool, Events> {
fn clone(&self) -> Self {
Self { inner: Arc::clone(&self.inner) }
}
}
#[async_trait]
impl<Client, Pool, Network> EthApiSpec for EthApi<Client, Pool, Network>
impl<Provider, Pool, Network> EthApiSpec for EthApi<Provider, Pool, Network>
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<ChainInfo> {
self.client().chain_info()
self.provider().chain_info()
}
fn accounts(&self) -> Vec<Address> {
@ -285,7 +285,7 @@ where
fn sync_status(&self) -> Result<SyncStatus> {
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<Client, Pool, Network> {
struct EthApiInner<Provider, Pool, Network> {
/// 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<Client, Pool, Network> {
/// The async cache frontend for eth related data
eth_cache: EthStateCache,
/// The async gas oracle frontend for gas price suggestions
gas_oracle: GasPriceOracle<Client>,
gas_oracle: GasPriceOracle<Provider>,
/// The block number at which the node started
starting_block: U256,
/// The type that can spawn tasks which would otherwise block.

View File

@ -29,11 +29,11 @@ use serde_json::Value;
use tracing::trace;
#[async_trait::async_trait]
impl<Client, Pool, Network> EthApiServer for EthApi<Client, Pool, Network>
impl<Provider, Pool, Network> EthApiServer for EthApi<Provider, Pool, Network>
where
Self: EthApiSpec + EthTransactions,
Pool: TransactionPool + 'static,
Client: BlockProvider
Provider: BlockProvider
+ BlockIdProvider
+ BlockProviderIdExt
+ HeaderProvider

View File

@ -11,7 +11,7 @@ use reth_primitives::{Address, Bytes};
use serde_json::Value;
use std::ops::Deref;
impl<Client, Pool, Network> EthApi<Client, Pool, Network> {
impl<Provider, Pool, Network> EthApi<Provider, Pool, Network> {
pub(crate) async fn sign(&self, account: Address, message: Bytes) -> EthResult<Bytes> {
let signer = self.find_signer(&account)?;
let signature = signer.sign(account, &message).await?;

View File

@ -14,9 +14,9 @@ use reth_provider::{
use reth_rpc_types::{EIP1186AccountProofResponse, StorageProof};
use reth_transaction_pool::{PoolTransaction, TransactionPool};
impl<Client, Pool, Network> EthApi<Client, Pool, Network>
impl<Provider, Pool, Network> EthApi<Provider, Pool, Network>
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<JsonStorageKey>,
block_id: Option<BlockId>,
) -> EthResult<EIP1186AccountProofResponse> {
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

View File

@ -179,10 +179,10 @@ pub trait EthTransactions: Send + Sync {
}
#[async_trait]
impl<Client, Pool, Network> EthTransactions for EthApi<Client, Pool, Network>
impl<Provider, Pool, Network> EthTransactions for EthApi<Provider, Pool, Network>
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<StateProviderBox<'_>> {
@ -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<Option<TransactionReceipt>> {
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<Client, Pool, Network> EthApi<Client, Pool, Network>
impl<Provider, Pool, Network> EthApi<Provider, Pool, Network>
where
Pool: TransactionPool + 'static,
Client: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static,
Provider: BlockProviderIdExt + StateProviderFactory + EvmEnvProvider + 'static,
Network: 'static,
{
pub(crate) fn sign_request(

View File

@ -94,16 +94,16 @@ pub struct EthStateCache {
impl EthStateCache {
/// Creates and returns both [EthStateCache] frontend and the memory bound service.
fn create<Client, Tasks>(
client: Client,
fn create<Provider, Tasks>(
provider: Provider,
action_task_spawner: Tasks,
max_block_bytes: usize,
max_receipt_bytes: usize,
max_env_bytes: usize,
) -> (Self, EthStateCacheService<Client, Tasks>) {
) -> (Self, EthStateCacheService<Provider, Tasks>) {
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: Client, config: EthStateCacheConfig) -> Self
pub fn spawn<Provider>(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, Tasks>(
client: Client,
pub fn spawn_with<Provider, Tasks>(
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<H256, (CfgEnv, BlockEnv)>,
{
/// 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<LimitBlocks>,
/// The LRU cache for full blocks grouped by their hash.
@ -242,9 +242,9 @@ pub(crate) struct EthStateCacheService<
action_task_spawner: Tasks,
}
impl<Client, Tasks> EthStateCacheService<Client, Tasks>
impl<Provider, Tasks> EthStateCacheService<Provider, Tasks>
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<Option<Block>>) {
@ -285,9 +285,9 @@ where
}
}
impl<Client, Tasks> Future for EthStateCacheService<Client, Tasks>
impl<Provider, Tasks> Future for EthStateCacheService<Provider, Tasks>
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 {

View File

@ -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<Client, Pool> {
pub struct EthFilter<Provider, Pool> {
/// All nested fields bundled together.
inner: Arc<EthFilterInner<Client, Pool>>,
inner: Arc<EthFilterInner<Provider, Pool>>,
}
impl<Client, Pool> EthFilter<Client, Pool> {
impl<Provider, Pool> EthFilter<Provider, Pool> {
/// 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<dyn TaskSpawner>,
) -> Self {
let inner = EthFilterInner {
client,
provider,
active_filters: Default::default(),
pool,
id_provider: Arc::new(EthSubscriptionIdProvider::default()),
@ -64,9 +64,9 @@ impl<Client, Pool> EthFilter<Client, Pool> {
}
}
impl<Client, Pool> EthFilter<Client, Pool>
impl<Provider, Pool> EthFilter<Provider, Pool>
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<FilterChanges, FilterError> {
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<Client, Pool> EthFilterApiServer for EthFilter<Client, Pool>
impl<Provider, Pool> EthFilterApiServer for EthFilter<Provider, Pool>
where
Client: BlockProvider + BlockIdProvider + EvmEnvProvider + 'static,
Provider: BlockProvider + BlockIdProvider + EvmEnvProvider + 'static,
Pool: TransactionPool + 'static,
{
/// Handler for `eth_newFilter`
@ -238,13 +238,13 @@ where
}
}
impl<Client, Pool> std::fmt::Debug for EthFilter<Client, Pool> {
impl<Provider, Pool> std::fmt::Debug for EthFilter<Provider, Pool> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EthFilter").finish_non_exhaustive()
}
}
impl<Client, Pool> Clone for EthFilter<Client, Pool> {
impl<Provider, Pool> Clone for EthFilter<Provider, Pool> {
fn clone(&self) -> Self {
Self { inner: Arc::clone(&self.inner) }
}
@ -252,12 +252,12 @@ impl<Client, Pool> Clone for EthFilter<Client, Pool> {
/// Container type `EthFilter`
#[derive(Debug)]
struct EthFilterInner<Client, Pool> {
struct EthFilterInner<Provider, Pool> {
/// 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<Client, Pool> {
task_spawner: Box<dyn TaskSpawner>,
}
impl<Client, Pool> EthFilterInner<Client, Pool>
impl<Provider, Pool> EthFilterInner<Provider, Pool>
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<FilterId> {
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<Option<(SealedBlock, Vec<Receipt>)>> {
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

View File

@ -81,9 +81,9 @@ impl GasPriceOracleConfig {
/// Calculates a gas price depending on recent blocks.
#[derive(Debug)]
pub struct GasPriceOracle<Client> {
pub struct GasPriceOracle<Provider> {
/// 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<Client> {
last_price: Mutex<GasPriceOracleResult>,
}
impl<Client> GasPriceOracle<Client>
impl<Provider> GasPriceOracle<Provider>
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<U256> {
let header = self
.client
.provider
.sealed_header_by_number_or_tag(BlockNumberOrTag::Latest)?
.ok_or(EthApiError::UnknownBlockNumber)?;

View File

@ -27,40 +27,47 @@ use tokio_stream::{
///
/// This handles `eth_subscribe` RPC calls.
#[derive(Clone)]
pub struct EthPubSub<Client, Pool, Events, Network> {
pub struct EthPubSub<Provider, Pool, Events, Network> {
/// All nested fields bundled together.
inner: EthPubSubInner<Client, Pool, Events, Network>,
inner: EthPubSubInner<Provider, Pool, Events, Network>,
/// The type that's used to spawn subscription tasks.
subscription_task_spawner: Box<dyn TaskSpawner>,
}
// === impl EthPubSub ===
impl<Client, Pool, Events, Network> EthPubSub<Client, Pool, Events, Network> {
impl<Provider, Pool, Events, Network> EthPubSub<Provider, Pool, Events, Network> {
/// 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::<TokioTaskExecutor>::default())
pub fn new(provider: Provider, pool: Pool, chain_events: Events, network: Network) -> Self {
Self::with_spawner(
provider,
pool,
chain_events,
network,
Box::<TokioTaskExecutor>::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<dyn TaskSpawner>,
) -> 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<Client, Pool, Events, Network> EthPubSubApiServer for EthPubSub<Client, Pool, Events, Network>
impl<Provider, Pool, Events, Network> EthPubSubApiServer
for EthPubSub<Provider, Pool, Events, Network>
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<Client, Pool, Events, Network>(
pubsub: EthPubSubInner<Client, Pool, Events, Network>,
async fn handle_accepted<Provider, Pool, Events, Network>(
pubsub: EthPubSubInner<Provider, Pool, Events, Network>,
accepted_sink: SubscriptionSink,
kind: SubscriptionKind,
params: Option<Params>,
) -> 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<Client, Pool, Events, Network> std::fmt::Debug for EthPubSub<Client, Pool, Events, Network> {
impl<Provider, Pool, Events, Network> std::fmt::Debug
for EthPubSub<Provider, Pool, Events, Network>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EthPubSub").finish_non_exhaustive()
}
@ -193,11 +202,11 @@ impl<Client, Pool, Events, Network> std::fmt::Debug for EthPubSub<Client, Pool,
/// Container type `EthPubSub`
#[derive(Clone)]
struct EthPubSubInner<Client, Pool, Events, Network> {
struct EthPubSubInner<Provider, Pool, Events, Network> {
/// 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<Client, Pool, Events, Network> {
// == impl EthPubSubInner ===
impl<Client, Pool, Events, Network> EthPubSubInner<Client, Pool, Events, Network>
impl<Provider, Pool, Events, Network> EthPubSubInner<Provider, Pool, Events, Network>
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<Client, Pool, Events, Network> EthPubSubInner<Client, Pool, Events, Network>
impl<Provider, Pool, Events, Network> EthPubSubInner<Provider, Pool, Events, Network>
where
Pool: TransactionPool + 'static,
{
@ -237,9 +246,9 @@ where
}
}
impl<Client, Pool, Events, Network> EthPubSubInner<Client, Pool, Events, Network>
impl<Provider, Pool, Events, Network> EthPubSubInner<Provider, Pool, Events, Network>
where
Client: BlockProvider + EvmEnvProvider + 'static,
Provider: BlockProvider + EvmEnvProvider + 'static,
Events: CanonStateSubscriptions + 'static,
Network: NetworkInfo + 'static,
Pool: 'static,

View File

@ -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<Client, Eth> {
inner: Arc<TraceApiInner<Client, Eth>>,
pub struct TraceApi<Provider, Eth> {
inner: Arc<TraceApiInner<Provider, Eth>>,
}
// === impl TraceApi ===
impl<Client, Eth> TraceApi<Client, Eth> {
/// The client that can interact with the chain.
pub fn client(&self) -> &Client {
&self.inner.client
impl<Provider, Eth> TraceApi<Provider, Eth> {
/// 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<dyn TaskSpawner>,
tracing_call_guard: TracingCallGuard,
) -> Self {
let inner = Arc::new(TraceApiInner {
client,
provider,
eth_api,
eth_cache,
task_spawner,
@ -73,9 +73,9 @@ impl<Client, Eth> TraceApi<Client, Eth> {
// === impl TraceApi ===
impl<Client, Eth> TraceApi<Client, Eth>
impl<Provider, Eth> TraceApi<Provider, Eth>
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<Client, Eth> TraceApiServer for TraceApi<Client, Eth>
impl<Provider, Eth> TraceApiServer for TraceApi<Provider, Eth>
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<Client, Eth> std::fmt::Debug for TraceApi<Client, Eth> {
impl<Provider, Eth> std::fmt::Debug for TraceApi<Provider, Eth> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TraceApi").finish_non_exhaustive()
}
}
impl<Client, Eth> Clone for TraceApi<Client, Eth> {
impl<Provider, Eth> Clone for TraceApi<Provider, Eth> {
fn clone(&self) -> Self {
Self { inner: Arc::clone(&self.inner) }
}
}
struct TraceApiInner<Client, Eth> {
/// The client that can interact with the chain.
client: Client,
struct TraceApiInner<Provider, Eth> {
/// 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