From 104bd6e03951c0c51d8518a4255ad4476441ac72 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Sun, 9 Feb 2025 18:14:53 +0400 Subject: [PATCH] refactor: move `ValidationApi` setup to `EthereumAddOns` (#14342) --- Cargo.lock | 5 + crates/ethereum/node/Cargo.toml | 4 + crates/ethereum/node/src/node.rs | 107 +++++++++++++++--- crates/node/builder/src/rpc.rs | 17 +-- crates/rpc/rpc-builder/Cargo.toml | 2 +- crates/rpc/rpc-builder/src/lib.rs | 94 +++------------ crates/rpc/rpc-builder/tests/it/middleware.rs | 3 - crates/rpc/rpc-builder/tests/it/startup.rs | 9 +- crates/rpc/rpc-builder/tests/it/utils.rs | 21 +--- crates/rpc/rpc/Cargo.toml | 1 + crates/rpc/rpc/src/eth/core.rs | 9 ++ examples/rpc-db/src/main.rs | 10 +- 12 files changed, 139 insertions(+), 143 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 164719a63..c0fca41c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8231,7 +8231,11 @@ dependencies = [ "reth-provider", "reth-revm", "reth-rpc", + "reth-rpc-api", + "reth-rpc-builder", "reth-rpc-eth-api", + "reth-rpc-eth-types", + "reth-rpc-server-types", "reth-tasks", "reth-tracing", "reth-transaction-pool", @@ -8929,6 +8933,7 @@ dependencies = [ "reth-network-api", "reth-network-peers", "reth-network-types", + "reth-node-api", "reth-primitives", "reth-primitives-traits", "reth-provider", diff --git a/crates/ethereum/node/Cargo.toml b/crates/ethereum/node/Cargo.toml index 609a5a122..61492f246 100644 --- a/crates/ethereum/node/Cargo.toml +++ b/crates/ethereum/node/Cargo.toml @@ -25,10 +25,14 @@ reth-evm.workspace = true reth-evm-ethereum.workspace = true reth-consensus.workspace = true reth-rpc.workspace = true +reth-rpc-builder.workspace = true +reth-rpc-api.workspace = true +reth-rpc-server-types.workspace = true reth-node-api.workspace = true reth-chainspec.workspace = true reth-revm = { workspace = true, features = ["std"] } reth-trie-db.workspace = true +reth-rpc-eth-types.workspace = true # revm with required ethereum features revm = { workspace = true, features = ["secp256k1", "blst", "c-kzg"] } diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index e0b09e65e..40ac74dee 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -10,26 +10,31 @@ use reth_ethereum_engine_primitives::{ EthBuiltPayload, EthPayloadAttributes, EthPayloadBuilderAttributes, }; use reth_ethereum_primitives::{EthPrimitives, PooledTransaction}; -use reth_evm::execute::BasicBlockExecutorProvider; +use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm}; use reth_evm_ethereum::execute::EthExecutionStrategyFactory; use reth_network::{EthNetworkPrimitives, NetworkHandle, PeersInfo}; -use reth_node_api::{AddOnsContext, FullNodeComponents, TxTy}; +use reth_node_api::{AddOnsContext, FullNodeComponents, NodeAddOns, TxTy}; use reth_node_builder::{ components::{ ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder, PoolBuilder, }, node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine}, - rpc::{EngineValidatorBuilder, RpcAddOns}, + rpc::{EngineValidatorAddOn, EngineValidatorBuilder, RethRpcAddOns, RpcAddOns, RpcHandle}, BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadTypes, }; use reth_provider::{providers::ProviderFactoryBuilder, CanonStateSubscriptions, EthStorage}; -use reth_rpc::EthApi; +use reth_rpc::{eth::core::EthApiFor, ValidationApi}; +use reth_rpc_api::servers::BlockSubmissionValidationApiServer; +use reth_rpc_builder::config::RethRpcServerConfig; +use reth_rpc_eth_types::{error::FromEvmError, EthApiError}; +use reth_rpc_server_types::RethRpcModule; use reth_tracing::tracing::{debug, info}; use reth_transaction_pool::{ blobstore::DiskFileBlobStore, EthTransactionPool, PoolTransaction, TransactionPool, TransactionValidationTaskExecutor, }; use reth_trie_db::MerklePatriciaTrie; +use revm::primitives::TxEnv; use std::sync::Arc; /// Type configuration for a regular Ethereum node. @@ -112,16 +117,92 @@ impl NodeTypesWithEngine for EthereumNode { } /// Add-ons w.r.t. l1 ethereum. -pub type EthereumAddOns = RpcAddOns< - N, - EthApi< - ::Provider, - ::Pool, - NetworkHandle, - ::Evm, +#[derive(Debug)] +pub struct EthereumAddOns { + inner: RpcAddOns, EthereumEngineValidatorBuilder>, +} + +impl Default for EthereumAddOns { + fn default() -> Self { + Self { inner: Default::default() } + } +} + +impl NodeAddOns for EthereumAddOns +where + N: FullNodeComponents< + Types: NodeTypesWithEngine< + ChainSpec = ChainSpec, + Primitives = EthPrimitives, + Engine = EthEngineTypes, + >, + Evm: ConfigureEvm, >, - EthereumEngineValidatorBuilder, ->; + EthApiError: FromEvmError, +{ + type Handle = RpcHandle>; + + async fn launch_add_ons( + self, + ctx: reth_node_api::AddOnsContext<'_, N>, + ) -> eyre::Result { + let validation_api = ValidationApi::new( + ctx.node.provider().clone(), + Arc::new(ctx.node.consensus().clone()), + ctx.node.block_executor().clone(), + ctx.config.rpc.flashbots_config(), + Box::new(ctx.node.task_executor().clone()), + Arc::new(EthereumEngineValidator::new(ctx.config.chain.clone())), + ); + + self.inner + .launch_add_ons_with(ctx, move |modules, _| { + modules.merge_if_module_configured( + RethRpcModule::Flashbots, + validation_api.into_rpc(), + )?; + + Ok(()) + }) + .await + } +} + +impl RethRpcAddOns for EthereumAddOns +where + N: FullNodeComponents< + Types: NodeTypesWithEngine< + ChainSpec = ChainSpec, + Primitives = EthPrimitives, + Engine = EthEngineTypes, + >, + Evm: ConfigureEvm, + >, + EthApiError: FromEvmError, +{ + type EthApi = EthApiFor; + + fn hooks_mut(&mut self) -> &mut reth_node_builder::rpc::RpcHooks { + self.inner.hooks_mut() + } +} + +impl EngineValidatorAddOn for EthereumAddOns +where + N: FullNodeComponents< + Types: NodeTypesWithEngine< + ChainSpec = ChainSpec, + Primitives = EthPrimitives, + Engine = EthEngineTypes, + >, + >, +{ + type Validator = EthereumEngineValidator; + + async fn engine_validator(&self, ctx: &AddOnsContext<'_, N>) -> eyre::Result { + EthereumEngineValidatorBuilder::default().build(ctx).await + } +} impl Node for EthereumNode where diff --git a/crates/node/builder/src/rpc.rs b/crates/node/builder/src/rpc.rs index f5ac2eb93..9319ab775 100644 --- a/crates/node/builder/src/rpc.rs +++ b/crates/node/builder/src/rpc.rs @@ -19,7 +19,6 @@ use reth_node_core::{ version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA}, }; use reth_payload_builder::PayloadStore; -use reth_primitives::EthPrimitives; use reth_provider::ChainSpecProvider; use reth_rpc::{ eth::{EthApiTypes, FullEthApiServer}, @@ -35,7 +34,6 @@ use reth_rpc_engine_api::{capabilities::EngineCapabilities, EngineApi}; use reth_tasks::TaskExecutor; use reth_tokio_util::EventSender; use reth_tracing::tracing::{debug, info}; -use std::sync::Arc; /// Contains the handles to the spawned RPC servers. /// @@ -473,12 +471,7 @@ where .with_evm_config(node.evm_config().clone()) .with_block_executor(node.block_executor().clone()) .with_consensus(node.consensus().clone()) - .build_with_auth_server( - module_config, - engine_api, - eth_api_builder, - Arc::new(engine_validator), - ); + .build_with_auth_server(module_config, engine_api, eth_api_builder); // in dev mode we generate 20 random dev-signer accounts if config.dev.dev { @@ -591,12 +584,8 @@ pub trait EthApiBuilder: 'static { fn build(ctx: &EthApiBuilderCtx) -> Self; } -impl< - N: FullNodeComponents< - Provider: ChainSpecProvider, - Types: NodeTypes, - >, - > EthApiBuilder for EthApi +impl> EthApiBuilder + for EthApi { fn build(ctx: &EthApiBuilderCtx) -> Self { Self::with_spawner(ctx) diff --git a/crates/rpc/rpc-builder/Cargo.toml b/crates/rpc/rpc-builder/Cargo.toml index 4ed304937..16caf4d79 100644 --- a/crates/rpc/rpc-builder/Cargo.toml +++ b/crates/rpc/rpc-builder/Cargo.toml @@ -29,7 +29,6 @@ reth-rpc-server-types.workspace = true reth-tasks = { workspace = true, features = ["rayon"] } reth-transaction-pool.workspace = true reth-evm.workspace = true -reth-engine-primitives.workspace = true # rpc/net jsonrpsee = { workspace = true, features = ["server"] } @@ -66,6 +65,7 @@ reth-tracing.workspace = true reth-transaction-pool = { workspace = true, features = ["test-utils"] } reth-rpc-types-compat.workspace = true reth-primitives.workspace = true +reth-engine-primitives.workspace = true alloy-primitives.workspace = true alloy-rpc-types-eth.workspace = true diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 0886da8d4..50e43d8aa 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -31,14 +31,13 @@ //! use reth_transaction_pool::{PoolTransaction, TransactionPool}; //! use std::sync::Arc; //! -//! pub async fn launch( +//! pub async fn launch( //! provider: Provider, //! pool: Pool, //! network: Network, //! evm_config: EthEvmConfig, //! block_executor: BlockExecutor, //! consensus: Consensus, -//! validator: Validator, //! ) where //! Provider: FullRpcProvider< //! Transaction = TransactionSigned, @@ -58,7 +57,6 @@ //! Network: NetworkInfo + Peers + Clone + 'static, //! BlockExecutor: BlockExecutorProvider, //! Consensus: FullConsensus + Clone + 'static, -//! Validator: PayloadValidator, //! { //! // configure the rpc module per transport //! let transports = TransportRpcModuleConfig::default().with_http(vec![ @@ -76,7 +74,7 @@ //! block_executor, //! consensus, //! ) -//! .build(transports, Box::new(EthApi::with_spawner), Arc::new(validator)); +//! .build(transports, Box::new(EthApi::with_spawner)); //! let handle = RpcServerConfig::default() //! .with_http(ServerBuilder::default()) //! .start(&transport_modules) @@ -107,16 +105,7 @@ //! use std::sync::Arc; //! use tokio::try_join; //! -//! pub async fn launch< -//! Provider, -//! Pool, -//! Network, -//! EngineApi, -//! EngineT, -//! BlockExecutor, -//! Consensus, -//! Validator, -//! >( +//! pub async fn launch( //! provider: Provider, //! pool: Pool, //! network: Network, @@ -124,7 +113,6 @@ //! evm_config: EthEvmConfig, //! block_executor: BlockExecutor, //! consensus: Consensus, -//! validator: Validator, //! ) where //! Provider: FullRpcProvider< //! Transaction = TransactionSigned, @@ -144,7 +132,6 @@ //! Network: NetworkInfo + Peers + Clone + 'static, //! BlockExecutor: BlockExecutorProvider, //! Consensus: FullConsensus + Clone + 'static, -//! Validator: PayloadValidator, //! { //! // configure the rpc module per transport //! let transports = TransportRpcModuleConfig::default().with_http(vec![ @@ -164,12 +151,8 @@ //! ); //! //! // 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), -//! ); +//! 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(); @@ -211,7 +194,6 @@ use jsonrpsee::{ }; use reth_chainspec::EthereumHardforks; use reth_consensus::{ConsensusError, FullConsensus}; -use reth_engine_primitives::{ExecutionData, PayloadValidator}; use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm}; use reth_network_api::{noop::NoopNetwork, NetworkInfo, Peers}; use reth_primitives::NodePrimitives; @@ -221,7 +203,7 @@ use reth_provider::{ }; use reth_rpc::{ AdminApi, DebugApi, EngineEthApi, EthBundle, MinerApi, NetApi, OtterscanApi, RPCApi, RethApi, - TraceApi, TxPoolApi, ValidationApi, ValidationApiConfig, Web3Api, + TraceApi, TxPoolApi, ValidationApiConfig, Web3Api, }; use reth_rpc_api::servers::*; use reth_rpc_eth_api::{ @@ -282,9 +264,6 @@ pub async fn launch, block_executor: BlockExecutor, consensus: Arc>, - payload_validator: Arc< - dyn PayloadValidator, - >, ) -> Result where Provider: FullRpcProvider< @@ -323,7 +302,7 @@ where block_executor, consensus, ) - .build(module_config, eth, payload_validator), + .build(module_config, eth), ) .await } @@ -614,9 +593,6 @@ where module_config: TransportRpcModuleConfig, engine: impl IntoEngineApiRpcModule, eth: DynEthApiBuilder, - payload_validator: Arc< - dyn PayloadValidator, - >, ) -> ( TransportRpcModules, AuthRpcModule, @@ -646,7 +622,6 @@ where evm_config, eth, block_executor, - payload_validator, ); let modules = registry.create_transport_rpc_modules(module_config); @@ -677,11 +652,9 @@ where /// use reth_transaction_pool::noop::NoopTransactionPool; /// use std::sync::Arc; /// - /// fn init(evm: Evm, validator: Validator) + /// fn init(evm: Evm) /// where /// Evm: ConfigureEvm
+ 'static, - /// Validator: PayloadValidator - /// + 'static, /// { /// let mut registry = RpcModuleBuilder::default() /// .with_provider(NoopProvider::default()) @@ -691,7 +664,7 @@ where /// .with_evm_config(evm) /// .with_block_executor(EthExecutorProvider::mainnet()) /// .with_consensus(NoopConsensus::default()) - /// .into_registry(Default::default(), Box::new(EthApi::with_spawner), Arc::new(validator)); + /// .into_registry(Default::default(), Box::new(EthApi::with_spawner)); /// /// let eth_api = registry.eth_api(); /// } @@ -700,9 +673,6 @@ where self, config: RpcModuleConfig, eth: DynEthApiBuilder, - payload_validator: Arc< - dyn PayloadValidator, - >, ) -> RpcRegistryInner where EthApi: EthApiTypes + 'static, @@ -719,7 +689,6 @@ where evm_config, eth, block_executor, - payload_validator, ) } @@ -729,9 +698,6 @@ where self, module_config: TransportRpcModuleConfig, eth: DynEthApiBuilder, - payload_validator: Arc< - dyn PayloadValidator, - >, ) -> TransportRpcModules<()> where EthApi: FullEthApiServer< @@ -761,7 +727,6 @@ where evm_config, eth, block_executor, - payload_validator, ); modules.config = module_config; @@ -859,6 +824,7 @@ impl RpcModuleConfigBuilder { /// A Helper type the holds instances of the configured modules. #[derive(Debug, Clone)] +#[expect(dead_code)] // Consensus generic, might be useful in the future pub struct RpcRegistryInner< Provider: BlockReader, Pool, @@ -874,10 +840,6 @@ pub struct RpcRegistryInner< executor: Tasks, block_executor: BlockExecutor, consensus: Consensus, - payload_validator: - Arc>, - /// Holds the configuration for the RPC modules - config: RpcModuleConfig, /// Holds a all `eth_` namespace handlers eth: EthHandlers, /// to put trace calls behind semaphore @@ -916,9 +878,6 @@ where evm_config: EvmConfig, eth_api_builder: DynEthApiBuilder, block_executor: BlockExecutor, - payload_validator: Arc< - dyn PayloadValidator, - >, ) -> Self where EvmConfig: ConfigureEvm
, @@ -942,11 +901,9 @@ where eth, executor, consensus, - config, modules: Default::default(), blocking_pool_guard, block_executor, - payload_validator, } } } @@ -1220,23 +1177,6 @@ where pub fn reth_api(&self) -> RethApi { RethApi::new(self.provider.clone(), Box::new(self.executor.clone())) } - - /// Instantiates `ValidationApi` - pub fn validation_api(&self) -> ValidationApi - where - Consensus: - FullConsensus + Clone + 'static, - Provider: BlockReader::Block>, - { - ValidationApi::new( - self.provider.clone(), - Arc::new(self.consensus.clone()), - self.block_executor.clone(), - self.config.flashbots.clone(), - Box::new(self.executor.clone()), - self.payload_validator.clone(), - ) - } } impl @@ -1393,16 +1333,10 @@ where .into_rpc() .into() } - RethRpcModule::Flashbots => ValidationApi::new( - eth_api.provider().clone(), - Arc::new(self.consensus.clone()), - self.block_executor.clone(), - self.config.flashbots.clone(), - Box::new(self.executor.clone()), - self.payload_validator.clone(), - ) - .into_rpc() - .into(), + // only relevant for Ethereum and configured in `EthereumAddOns` + // implementation + // TODO: can we get rid of this here? + RethRpcModule::Flashbots => Default::default(), RethRpcModule::Miner => MinerApi::default().into_rpc().into(), }) .clone() diff --git a/crates/rpc/rpc-builder/tests/it/middleware.rs b/crates/rpc/rpc-builder/tests/it/middleware.rs index 0e0bb80c0..96d818ed4 100644 --- a/crates/rpc/rpc-builder/tests/it/middleware.rs +++ b/crates/rpc/rpc-builder/tests/it/middleware.rs @@ -5,8 +5,6 @@ use jsonrpsee::{ types::Request, MethodResponse, }; -use reth_chainspec::MAINNET; -use reth_ethereum_engine_primitives::EthereumEngineValidator; use reth_rpc::EthApi; use reth_rpc_builder::{RpcServerConfig, TransportRpcModuleConfig}; use reth_rpc_eth_api::EthApiClient; @@ -65,7 +63,6 @@ async fn test_rpc_middleware() { let modules = builder.build( TransportRpcModuleConfig::set_http(RpcModuleSelection::All), Box::new(EthApi::with_spawner), - Arc::new(EthereumEngineValidator::new(MAINNET.clone())), ); let mylayer = MyMiddlewareLayer::default(); diff --git a/crates/rpc/rpc-builder/tests/it/startup.rs b/crates/rpc/rpc-builder/tests/it/startup.rs index ac53b0149..9f6961fbb 100644 --- a/crates/rpc/rpc-builder/tests/it/startup.rs +++ b/crates/rpc/rpc-builder/tests/it/startup.rs @@ -1,9 +1,7 @@ //! Startup tests -use std::{io, sync::Arc}; +use std::io; -use reth_chainspec::MAINNET; -use reth_ethereum_engine_primitives::EthereumEngineValidator; use reth_rpc::EthApi; use reth_rpc_builder::{ error::{RpcError, ServerKind, WsHttpSamePortError}, @@ -32,7 +30,6 @@ async fn test_http_addr_in_use() { let server = builder.build( TransportRpcModuleConfig::set_http(vec![RethRpcModule::Admin]), Box::new(EthApi::with_spawner), - Arc::new(EthereumEngineValidator::new(MAINNET.clone())), ); let result = RpcServerConfig::http(Default::default()).with_http_address(addr).start(&server).await; @@ -48,7 +45,6 @@ async fn test_ws_addr_in_use() { let server = builder.build( TransportRpcModuleConfig::set_ws(vec![RethRpcModule::Admin]), Box::new(EthApi::with_spawner), - Arc::new(EthereumEngineValidator::new(MAINNET.clone())), ); let result = RpcServerConfig::ws(Default::default()).with_ws_address(addr).start(&server).await; let err = result.unwrap_err(); @@ -70,7 +66,6 @@ async fn test_launch_same_port_different_modules() { TransportRpcModuleConfig::set_ws(vec![RethRpcModule::Admin]) .with_http(vec![RethRpcModule::Eth]), Box::new(EthApi::with_spawner), - Arc::new(EthereumEngineValidator::new(MAINNET.clone())), ); let addr = test_address(); let res = RpcServerConfig::ws(Default::default()) @@ -93,7 +88,6 @@ async fn test_launch_same_port_same_cors() { TransportRpcModuleConfig::set_ws(vec![RethRpcModule::Eth]) .with_http(vec![RethRpcModule::Eth]), Box::new(EthApi::with_spawner), - Arc::new(EthereumEngineValidator::new(MAINNET.clone())), ); let addr = test_address(); let res = RpcServerConfig::ws(Default::default()) @@ -114,7 +108,6 @@ async fn test_launch_same_port_different_cors() { TransportRpcModuleConfig::set_ws(vec![RethRpcModule::Eth]) .with_http(vec![RethRpcModule::Eth]), Box::new(EthApi::with_spawner), - Arc::new(EthereumEngineValidator::new(MAINNET.clone())), ); let addr = test_address(); let res = RpcServerConfig::ws(Default::default()) diff --git a/crates/rpc/rpc-builder/tests/it/utils.rs b/crates/rpc/rpc-builder/tests/it/utils.rs index 21251628e..67b845970 100644 --- a/crates/rpc/rpc-builder/tests/it/utils.rs +++ b/crates/rpc/rpc-builder/tests/it/utils.rs @@ -1,7 +1,4 @@ -use std::{ - net::{Ipv4Addr, SocketAddr, SocketAddrV4}, - sync::Arc, -}; +use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use alloy_rpc_types_engine::{ClientCode, ClientVersionV1}; use reth_chainspec::MAINNET; @@ -63,11 +60,8 @@ pub async fn launch_auth(secret: JwtSecret) -> AuthServerHandle { /// Launches a new server with http only with the given modules pub async fn launch_http(modules: impl Into) -> RpcServerHandle { let builder = test_rpc_builder(); - let server = builder.build( - TransportRpcModuleConfig::set_http(modules), - Box::new(EthApi::with_spawner), - Arc::new(EthereumEngineValidator::new(MAINNET.clone())), - ); + let server = + builder.build(TransportRpcModuleConfig::set_http(modules), Box::new(EthApi::with_spawner)); RpcServerConfig::http(Default::default()) .with_http_address(test_address()) .start(&server) @@ -78,11 +72,8 @@ pub async fn launch_http(modules: impl Into) -> RpcServerHan /// Launches a new server with ws only with the given modules pub async fn launch_ws(modules: impl Into) -> RpcServerHandle { let builder = test_rpc_builder(); - let server = builder.build( - TransportRpcModuleConfig::set_ws(modules), - Box::new(EthApi::with_spawner), - Arc::new(EthereumEngineValidator::new(MAINNET.clone())), - ); + let server = + builder.build(TransportRpcModuleConfig::set_ws(modules), Box::new(EthApi::with_spawner)); RpcServerConfig::ws(Default::default()) .with_ws_address(test_address()) .start(&server) @@ -97,7 +88,6 @@ pub async fn launch_http_ws(modules: impl Into) -> RpcServer let server = builder.build( TransportRpcModuleConfig::set_ws(modules.clone()).with_http(modules), Box::new(EthApi::with_spawner), - Arc::new(EthereumEngineValidator::new(MAINNET.clone())), ); RpcServerConfig::ws(Default::default()) .with_ws_address(test_address()) @@ -116,7 +106,6 @@ pub async fn launch_http_ws_same_port(modules: impl Into) -> let server = builder.build( TransportRpcModuleConfig::set_ws(modules.clone()).with_http(modules), Box::new(EthApi::with_spawner), - Arc::new(EthereumEngineValidator::new(MAINNET.clone())), ); let addr = test_address(); RpcServerConfig::ws(Default::default()) diff --git a/crates/rpc/rpc/Cargo.toml b/crates/rpc/rpc/Cargo.toml index 255656a9c..40e975d66 100644 --- a/crates/rpc/rpc/Cargo.toml +++ b/crates/rpc/rpc/Cargo.toml @@ -36,6 +36,7 @@ reth-rpc-eth-types.workspace = true reth-rpc-server-types.workspace = true reth-network-types.workspace = true reth-consensus.workspace = true +reth-node-api.workspace = true # ethereum alloy-consensus.workspace = true diff --git a/crates/rpc/rpc/src/eth/core.rs b/crates/rpc/rpc/src/eth/core.rs index 7eb85e264..3adcf9e5b 100644 --- a/crates/rpc/rpc/src/eth/core.rs +++ b/crates/rpc/rpc/src/eth/core.rs @@ -9,6 +9,7 @@ use alloy_eips::BlockNumberOrTag; use alloy_network::Ethereum; use alloy_primitives::{Bytes, U256}; use derive_more::Deref; +use reth_node_api::{FullNodeComponents, FullNodeTypes}; use reth_primitives::NodePrimitives; use reth_provider::{ BlockReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, ProviderBlock, @@ -31,6 +32,14 @@ use tokio::sync::{broadcast, Mutex}; const DEFAULT_BROADCAST_CAPACITY: usize = 2000; +/// Helper type alias for [`EthApi`] with components from the given [`FullNodeComponents`]. +pub type EthApiFor = EthApi< + ::Provider, + ::Pool, + ::Network, + ::Evm, +>; + /// `Eth` API implementation. /// /// This type provides the functionality for handling `eth_` related requests. diff --git a/examples/rpc-db/src/main.rs b/examples/rpc-db/src/main.rs index 1bf98c8c0..67c40035f 100644 --- a/examples/rpc-db/src/main.rs +++ b/examples/rpc-db/src/main.rs @@ -34,9 +34,7 @@ use reth::rpc::builder::{ // Configuring the network parts, ideally also wouldn't need to think about this. use myrpc_ext::{MyRpcExt, MyRpcExtApiServer}; use reth::tasks::TokioTaskExecutor; -use reth_node_ethereum::{ - node::EthereumEngineValidator, EthEvmConfig, EthExecutorProvider, EthereumNode, -}; +use reth_node_ethereum::{EthEvmConfig, EthExecutorProvider, EthereumNode}; use reth_provider::ChainSpecProvider; // Custom rpc extension @@ -75,11 +73,7 @@ async fn main() -> eyre::Result<()> { // Pick which namespaces to expose. let config = TransportRpcModuleConfig::default().with_http([RethRpcModule::Eth]); - let mut server = rpc_builder.build( - config, - Box::new(EthApi::with_spawner), - Arc::new(EthereumEngineValidator::new(spec)), - ); + let mut server = rpc_builder.build(config, Box::new(EthApi::with_spawner)); // Add a custom rpc namespace let custom_rpc = MyRpcExt { provider };