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 reth_engine_primitives::PayloadValidator;
use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm};
use reth_network_api::{NetworkInfo, Peers};
use reth_primitives::{Header, PooledTransaction, TransactionSigned};
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::{PoolTransaction, TransactionPool};
use std::sync::Arc;
pub async fn launch<
Provider,
Pool,
Network,
Events,
EvmConfig,
BlockExecutor,
Consensus,
Validator,
>(
provider: Provider,
pool: Pool,
network: Network,
events: Events,
evm_config: EvmConfig,
block_executor: BlockExecutor,
consensus: Consensus,
validator: Validator,
) where
Provider: FullRpcProvider<
Transaction = TransactionSigned,
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
Header = reth_primitives::Header,
> + AccountReader
+ ChangeSetReader,
Pool: TransactionPool<
Transaction: PoolTransaction<
Consensus = TransactionSigned,
Pooled = PooledTransaction,
>,
> + Unpin
+ 'static,
Network: NetworkInfo + Peers + Clone + 'static,
Events:
CanonStateSubscriptions<Primitives = reth_primitives::EthPrimitives> + Clone + 'static,
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
BlockExecutor: BlockExecutorProvider<Primitives = Events::Primitives>,
Consensus: reth_consensus::FullConsensus + Clone + 'static,
Validator: PayloadValidator<Block = reth_primitives::Block>,
{
// 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), Arc::new(validator));
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 reth_engine_primitives::{EngineTypes, PayloadValidator};
use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm};
use reth_network_api::{NetworkInfo, Peers};
use reth_primitives::{Header, PooledTransaction, TransactionSigned};
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::{PoolTransaction, TransactionPool};
use std::sync::Arc;
use tokio::try_join;
pub async fn launch<
Provider,
Pool,
Network,
Events,
EngineApi,
EngineT,
EvmConfig,
BlockExecutor,
Consensus,
Validator,
>(
provider: Provider,
pool: Pool,
network: Network,
events: Events,
engine_api: EngineApi,
evm_config: EvmConfig,
block_executor: BlockExecutor,
consensus: Consensus,
validator: Validator,
) where
Provider: FullRpcProvider<
Transaction = TransactionSigned,
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
Header = reth_primitives::Header,
> + AccountReader
+ ChangeSetReader,
Pool: TransactionPool<
Transaction: PoolTransaction<
Consensus = TransactionSigned,
Pooled = PooledTransaction,
>,
> + Unpin
+ 'static,
Network: NetworkInfo + Peers + Clone + 'static,
Events:
CanonStateSubscriptions<Primitives = reth_primitives::EthPrimitives> + Clone + 'static,
EngineApi: EngineApiServer<EngineT>,
EngineT: EngineTypes,
EvmConfig: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
BlockExecutor: BlockExecutorProvider<Primitives = Events::Primitives>,
Consensus: reth_consensus::FullConsensus + Clone + 'static,
Validator: PayloadValidator<Block = reth_primitives::Block>,
{
// 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),
Arc::new(validator),
);
// 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.