Expand description
Configure reth RPC.
This crate contains several builder and config types that allow to configure the selection of
RethRpcModule
specific to transports (ws, http, ipc).
The RpcModuleBuilder
is the main entrypoint for configuring all reth modules. It takes
instances of components required to start the servers, such as provider impls, network and
transaction pool. RpcModuleBuilder::build
returns a TransportRpcModules
which contains
the transport specific config (what APIs are available via this transport).
The RpcServerConfig
is used to assemble and start the http server, ws server, ipc servers,
it requires the TransportRpcModules
so it can start the servers with the configured modules.
§Examples
Configure only an http server with a selection of RethRpcModule
s
use alloy_consensus::Header;
use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm};
use reth_network_api::{NetworkInfo, Peers};
use reth_provider::{AccountReader, CanonStateSubscriptions, ChangeSetReader, FullRpcProvider};
use reth_rpc::EthApi;
use reth_rpc_builder::{
RethRpcModule, RpcModuleBuilder, RpcServerConfig, ServerBuilder, TransportRpcModuleConfig,
};
use reth_tasks::TokioTaskExecutor;
use reth_transaction_pool::TransactionPool;
pub async fn launch<Provider, Pool, Network, Events, EvmConfig, BlockExecutor, Consensus>(
provider: Provider,
pool: Pool,
network: Network,
events: Events,
evm_config: EvmConfig,
block_executor: BlockExecutor,
consensus: Consensus,
) where
Provider: FullRpcProvider + AccountReader + ChangeSetReader,
Pool: TransactionPool + Unpin + 'static,
Network: NetworkInfo + Peers + Clone + 'static,
Events: CanonStateSubscriptions + Clone + 'static,
EvmConfig: ConfigureEvm<Header = Header>,
BlockExecutor: BlockExecutorProvider,
Consensus: reth_consensus::Consensus + Clone + 'static,
{
// configure the rpc module per transport
let transports = TransportRpcModuleConfig::default().with_http(vec![
RethRpcModule::Admin,
RethRpcModule::Debug,
RethRpcModule::Eth,
RethRpcModule::Web3,
]);
let transport_modules = RpcModuleBuilder::new(
provider,
pool,
network,
TokioTaskExecutor::default(),
events,
evm_config,
block_executor,
consensus,
)
.build(transports, Box::new(EthApi::with_spawner));
let handle = RpcServerConfig::default()
.with_http(ServerBuilder::default())
.start(&transport_modules)
.await;
}
Configure a http and ws server with a separate auth server that handles the engine_
API
use alloy_consensus::Header;
use reth_engine_primitives::EngineTypes;
use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm};
use reth_network_api::{NetworkInfo, Peers};
use reth_provider::{AccountReader, CanonStateSubscriptions, ChangeSetReader, FullRpcProvider};
use reth_rpc::EthApi;
use reth_rpc_api::EngineApiServer;
use reth_rpc_builder::{
auth::AuthServerConfig, RethRpcModule, RpcModuleBuilder, RpcServerConfig,
TransportRpcModuleConfig,
};
use reth_rpc_layer::JwtSecret;
use reth_tasks::TokioTaskExecutor;
use reth_transaction_pool::TransactionPool;
use tokio::try_join;
pub async fn launch<
Provider,
Pool,
Network,
Events,
EngineApi,
EngineT,
EvmConfig,
BlockExecutor,
Consensus,
>(
provider: Provider,
pool: Pool,
network: Network,
events: Events,
engine_api: EngineApi,
evm_config: EvmConfig,
block_executor: BlockExecutor,
consensus: Consensus,
) where
Provider: FullRpcProvider + AccountReader + ChangeSetReader,
Pool: TransactionPool + Unpin + 'static,
Network: NetworkInfo + Peers + Clone + 'static,
Events: CanonStateSubscriptions + Clone + 'static,
EngineApi: EngineApiServer<EngineT>,
EngineT: EngineTypes,
EvmConfig: ConfigureEvm<Header = Header>,
BlockExecutor: BlockExecutorProvider,
Consensus: reth_consensus::Consensus + Clone + 'static,
{
// configure the rpc module per transport
let transports = TransportRpcModuleConfig::default().with_http(vec![
RethRpcModule::Admin,
RethRpcModule::Debug,
RethRpcModule::Eth,
RethRpcModule::Web3,
]);
let builder = RpcModuleBuilder::new(
provider,
pool,
network,
TokioTaskExecutor::default(),
events,
evm_config,
block_executor,
consensus,
);
// configure the server modules
let (modules, auth_module, _registry) =
builder.build_with_auth_server(transports, engine_api, Box::new(EthApi::with_spawner));
// start the servers
let auth_config = AuthServerConfig::builder(JwtSecret::random()).build();
let config = RpcServerConfig::default();
let (_rpc_handle, _auth_handle) =
try_join!(config.start(&modules), auth_module.start_server(auth_config),).unwrap();
}
Re-exports§
pub use eth::EthHandlers;
Modules§
- Auth server utilities.
- RPC server utilities.
- Common RPC constants.
- Rpc error utilities.
- Eth utils
- [
jsonrpsee
] helper layer for rate limiting certain methods.
Structs§
- A no-op middleware.
- Similar to [
tower::ServiceBuilder
] but doesn’t support any tower middleware implementations. - Builder to configure and create a JSON-RPC server
- Response future to update the metrics for a single request/response pair.
- A builder type to configure the RPC module: See [
RpcModule
] - Bundles settings for modules
- Configures
RpcModuleConfig
- A Helper type the holds instances of the configured modules.
- A [
RpcServiceT
] middleware that captures RPC metrics for the server. - A builder type for configuring and launching the servers that will handle RPC requests.
- A handle to the spawned servers.
- Builder to configure and create a JSON-RPC server
- Two middlewares chained together.
- Holds modules to be installed per transport type
- Holds installed modules per transport type.
Enums§
- Error thrown when parsing cors domains went wrong
- Represents RPC modules that are supported by reth
- Describes the modules that should be installed.
Functions§
- Convenience function for starting a server in one step.