refactor: simplify engine Api (#2240)

This commit is contained in:
Matthias Seitz
2023-04-14 18:59:18 +02:00
committed by GitHub
parent 3779a225fb
commit 08eae76bec
16 changed files with 405 additions and 554 deletions

View File

@@ -2,16 +2,15 @@ use crate::error::{RpcError, ServerKind};
pub use jsonrpsee::server::ServerBuilder;
use jsonrpsee::server::{RpcModule, ServerHandle};
use reth_network_api::{NetworkInfo, Peers};
use reth_primitives::ChainSpec;
use reth_provider::{BlockProvider, EvmEnvProvider, HeaderProvider, StateProviderFactory};
use reth_rpc::{
eth::cache::EthStateCache, AuthLayer, EngineApi, EthApi, EthFilter, JwtAuthValidator, JwtSecret,
};
use reth_rpc_api::servers::*;
use reth_rpc_engine_api::EngineApiHandle;
use reth_tasks::TaskSpawner;
use reth_transaction_pool::TransactionPool;
use std::{net::SocketAddr, sync::Arc};
use std::net::SocketAddr;
/// Configure and launch an auth server with `engine` and a _new_ `eth` namespace.
#[allow(clippy::too_many_arguments)]
@@ -20,8 +19,7 @@ pub async fn launch<Client, Pool, Network, Tasks>(
pool: Pool,
network: Network,
executor: Tasks,
chain_spec: Arc<ChainSpec>,
handle: EngineApiHandle,
engine_api: EngineApi<Client>,
socket_addr: SocketAddr,
secret: JwtSecret,
) -> Result<ServerHandle, RpcError>
@@ -41,15 +39,14 @@ where
let eth_cache = EthStateCache::spawn_with(client.clone(), Default::default(), executor);
let eth_api = EthApi::new(client.clone(), pool.clone(), network, eth_cache);
let eth_filter = EthFilter::new(client, pool);
launch_with_eth_api(eth_api, chain_spec, eth_filter, handle, socket_addr, secret).await
launch_with_eth_api(eth_api, eth_filter, engine_api, socket_addr, secret).await
}
/// Configure and launch an auth server with existing EthApi implementation.
pub async fn launch_with_eth_api<Client, Pool, Network>(
eth_api: EthApi<Client, Pool, Network>,
chain_spec: Arc<ChainSpec>,
eth_filter: EthFilter<Client, Pool>,
handle: EngineApiHandle,
engine_api: EngineApi<Client>,
socket_addr: SocketAddr,
secret: JwtSecret,
) -> Result<ServerHandle, RpcError>
@@ -66,7 +63,7 @@ where
{
// Configure the module and start the server.
let mut module = RpcModule::new(());
module.merge(EngineApi::new(chain_spec, handle).into_rpc()).expect("No conflicting methods");
module.merge(engine_api.into_rpc()).expect("No conflicting methods");
module.merge(eth_api.into_rpc()).expect("No conflicting methods");
module.merge(eth_filter.into_rpc()).expect("No conflicting methods");