mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: move ValidationApi setup to EthereumAddOns (#14342)
This commit is contained in:
@ -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
|
||||
|
||||
@ -31,14 +31,13 @@
|
||||
//! use reth_transaction_pool::{PoolTransaction, TransactionPool};
|
||||
//! use std::sync::Arc;
|
||||
//!
|
||||
//! pub async fn launch<Provider, Pool, Network, BlockExecutor, Consensus, Validator>(
|
||||
//! pub async fn launch<Provider, Pool, Network, BlockExecutor, Consensus>(
|
||||
//! 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<Primitives = Provider::Primitives>,
|
||||
//! Consensus: FullConsensus<Provider::Primitives, Error = ConsensusError> + Clone + 'static,
|
||||
//! Validator: PayloadValidator<Block = reth_primitives::Block, ExecutionData = ExecutionData>,
|
||||
//! {
|
||||
//! // 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, Pool, Network, EngineApi, EngineT, BlockExecutor, Consensus>(
|
||||
//! 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<Primitives = Provider::Primitives>,
|
||||
//! Consensus: FullConsensus<Provider::Primitives, Error = ConsensusError> + Clone + 'static,
|
||||
//! Validator: PayloadValidator<Block = reth_primitives::Block, ExecutionData = ExecutionData>,
|
||||
//! {
|
||||
//! // 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<Provider, Pool, Network, Tasks, EvmConfig, EthApi, BlockExec
|
||||
eth: DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, EthApi>,
|
||||
block_executor: BlockExecutor,
|
||||
consensus: Arc<dyn FullConsensus<BlockExecutor::Primitives, Error = ConsensusError>>,
|
||||
payload_validator: Arc<
|
||||
dyn PayloadValidator<Block = Provider::Block, ExecutionData = ExecutionData>,
|
||||
>,
|
||||
) -> Result<RpcServerHandle, RpcError>
|
||||
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<Provider, Pool, EvmConfig, Network, Tasks, EthApi>,
|
||||
payload_validator: Arc<
|
||||
dyn PayloadValidator<Block = Provider::Block, ExecutionData = ExecutionData>,
|
||||
>,
|
||||
) -> (
|
||||
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, Validator>(evm: Evm, validator: Validator)
|
||||
/// fn init<Evm>(evm: Evm)
|
||||
/// where
|
||||
/// Evm: ConfigureEvm<Header = Header, Transaction = TransactionSigned> + 'static,
|
||||
/// Validator: PayloadValidator<Block = reth_primitives::Block, ExecutionData = ExecutionData>
|
||||
/// + '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<Provider, Pool, EvmConfig, Network, Tasks, EthApi>,
|
||||
payload_validator: Arc<
|
||||
dyn PayloadValidator<Block = Provider::Block, ExecutionData = ExecutionData>,
|
||||
>,
|
||||
) -> RpcRegistryInner<Provider, Pool, Network, Tasks, EthApi, BlockExecutor, Consensus>
|
||||
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<Provider, Pool, EvmConfig, Network, Tasks, EthApi>,
|
||||
payload_validator: Arc<
|
||||
dyn PayloadValidator<Block = Provider::Block, ExecutionData = ExecutionData>,
|
||||
>,
|
||||
) -> 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<dyn PayloadValidator<Block = Provider::Block, ExecutionData = ExecutionData>>,
|
||||
/// Holds the configuration for the RPC modules
|
||||
config: RpcModuleConfig,
|
||||
/// Holds a all `eth_` namespace handlers
|
||||
eth: EthHandlers<Provider, EthApi>,
|
||||
/// to put trace calls behind semaphore
|
||||
@ -916,9 +878,6 @@ where
|
||||
evm_config: EvmConfig,
|
||||
eth_api_builder: DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, EthApi>,
|
||||
block_executor: BlockExecutor,
|
||||
payload_validator: Arc<
|
||||
dyn PayloadValidator<Block = Provider::Block, ExecutionData = ExecutionData>,
|
||||
>,
|
||||
) -> Self
|
||||
where
|
||||
EvmConfig: ConfigureEvm<Header = Provider::Header>,
|
||||
@ -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<Provider> {
|
||||
RethApi::new(self.provider.clone(), Box::new(self.executor.clone()))
|
||||
}
|
||||
|
||||
/// Instantiates `ValidationApi`
|
||||
pub fn validation_api(&self) -> ValidationApi<Provider, BlockExecutor>
|
||||
where
|
||||
Consensus:
|
||||
FullConsensus<BlockExecutor::Primitives, Error = ConsensusError> + Clone + 'static,
|
||||
Provider: BlockReader<Block = <BlockExecutor::Primitives as NodePrimitives>::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<Provider, Pool, Network, Tasks, EthApi, BlockExecutor, Consensus>
|
||||
@ -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()
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -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<RpcModuleSelection>) -> 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<RpcModuleSelection>) -> RpcServerHan
|
||||
/// Launches a new server with ws only with the given modules
|
||||
pub async fn launch_ws(modules: impl Into<RpcModuleSelection>) -> 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<RpcModuleSelection>) -> 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<RpcModuleSelection>) ->
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user