mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: move EngineValidator setup to RpcAddOns (#11850)
This commit is contained in:
@ -12,15 +12,16 @@ use reth_ethereum_engine_primitives::{
|
||||
use reth_evm_ethereum::execute::EthExecutorProvider;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_node_api::{
|
||||
ConfigureEvm, EngineValidator, FullNodeComponents, NodePrimitives, NodeTypesWithDB,
|
||||
AddOnsContext, ConfigureEvm, EngineValidator, FullNodeComponents, NodePrimitives,
|
||||
NodeTypesWithDB,
|
||||
};
|
||||
use reth_node_builder::{
|
||||
components::{
|
||||
ComponentsBuilder, ConsensusBuilder, EngineValidatorBuilder, ExecutorBuilder,
|
||||
NetworkBuilder, PayloadServiceBuilder, PoolBuilder,
|
||||
ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder,
|
||||
PayloadServiceBuilder, PoolBuilder,
|
||||
},
|
||||
node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine},
|
||||
rpc::RpcAddOns,
|
||||
rpc::{EngineValidatorBuilder, RpcAddOns},
|
||||
BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig, PayloadTypes,
|
||||
};
|
||||
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
||||
@ -57,7 +58,6 @@ impl EthereumNode {
|
||||
EthereumNetworkBuilder,
|
||||
EthereumExecutorBuilder,
|
||||
EthereumConsensusBuilder,
|
||||
EthereumEngineValidatorBuilder,
|
||||
>
|
||||
where
|
||||
Node: FullNodeTypes<Types: NodeTypes<ChainSpec = ChainSpec>>,
|
||||
@ -74,7 +74,6 @@ impl EthereumNode {
|
||||
.network(EthereumNetworkBuilder::default())
|
||||
.executor(EthereumExecutorBuilder::default())
|
||||
.consensus(EthereumConsensusBuilder::default())
|
||||
.engine_validator(EthereumEngineValidatorBuilder::default())
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,6 +95,7 @@ pub type EthereumAddOns<N> = RpcAddOns<
|
||||
NetworkHandle,
|
||||
<N as FullNodeComponents>::Evm,
|
||||
>,
|
||||
EthereumEngineValidatorBuilder,
|
||||
>;
|
||||
|
||||
impl<Types, N> Node<N> for EthereumNode
|
||||
@ -110,7 +110,6 @@ where
|
||||
EthereumNetworkBuilder,
|
||||
EthereumExecutorBuilder,
|
||||
EthereumConsensusBuilder,
|
||||
EthereumEngineValidatorBuilder,
|
||||
>;
|
||||
|
||||
type AddOns = EthereumAddOns<
|
||||
@ -347,12 +346,12 @@ pub struct EthereumEngineValidatorBuilder;
|
||||
impl<Node, Types> EngineValidatorBuilder<Node> for EthereumEngineValidatorBuilder
|
||||
where
|
||||
Types: NodeTypesWithEngine<ChainSpec = ChainSpec>,
|
||||
Node: FullNodeTypes<Types = Types>,
|
||||
Node: FullNodeComponents<Types = Types>,
|
||||
EthereumEngineValidator: EngineValidator<Types::Engine>,
|
||||
{
|
||||
type Validator = EthereumEngineValidator;
|
||||
|
||||
async fn build_validator(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::Validator> {
|
||||
Ok(EthereumEngineValidator::new(ctx.chain_spec()))
|
||||
async fn build(self, ctx: &AddOnsContext<'_, Node>) -> eyre::Result<Self::Validator> {
|
||||
Ok(EthereumEngineValidator::new(ctx.config.chain.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,6 @@ reth-primitives.workspace = true
|
||||
reth-provider = { workspace = true, features = ["test-utils"] }
|
||||
reth-tasks.workspace = true
|
||||
reth-transaction-pool = { workspace = true, features = ["test-utils"] }
|
||||
reth-ethereum-engine-primitives.workspace = true
|
||||
|
||||
## async
|
||||
futures-util.workspace = true
|
||||
|
||||
@ -24,7 +24,6 @@ use reth_db::{
|
||||
DatabaseEnv,
|
||||
};
|
||||
use reth_db_common::init::init_genesis;
|
||||
use reth_ethereum_engine_primitives::EthereumEngineValidator;
|
||||
use reth_evm::test_utils::MockExecutorProvider;
|
||||
use reth_execution_types::Chain;
|
||||
use reth_exex::{ExExContext, ExExEvent, ExExNotification, ExExNotifications, Wal};
|
||||
@ -41,10 +40,7 @@ use reth_node_builder::{
|
||||
};
|
||||
use reth_node_core::node_config::NodeConfig;
|
||||
use reth_node_ethereum::{
|
||||
node::{
|
||||
EthereumAddOns, EthereumEngineValidatorBuilder, EthereumNetworkBuilder,
|
||||
EthereumPayloadBuilder,
|
||||
},
|
||||
node::{EthereumAddOns, EthereumNetworkBuilder, EthereumPayloadBuilder},
|
||||
EthEngineTypes, EthEvmConfig,
|
||||
};
|
||||
use reth_payload_builder::noop::NoopPayloadBuilderService;
|
||||
@ -140,7 +136,6 @@ where
|
||||
EthereumNetworkBuilder,
|
||||
TestExecutorBuilder,
|
||||
TestConsensusBuilder,
|
||||
EthereumEngineValidatorBuilder,
|
||||
>;
|
||||
type AddOns = EthereumAddOns<
|
||||
NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>,
|
||||
@ -154,7 +149,6 @@ where
|
||||
.network(EthereumNetworkBuilder::default())
|
||||
.executor(TestExecutorBuilder::default())
|
||||
.consensus(TestConsensusBuilder::default())
|
||||
.engine_validator(EthereumEngineValidatorBuilder::default())
|
||||
}
|
||||
|
||||
fn add_ons(&self) -> Self::AddOns {
|
||||
@ -284,8 +278,6 @@ pub async fn test_exex_context_with_chain_spec(
|
||||
let tasks = TaskManager::current();
|
||||
let task_executor = tasks.executor();
|
||||
|
||||
let engine_validator = EthereumEngineValidator::new(chain_spec.clone());
|
||||
|
||||
let components = NodeAdapter::<FullNodeTypesAdapter<NodeTypesWithDBAdapter<TestNode, _>, _>, _> {
|
||||
components: Components {
|
||||
transaction_pool,
|
||||
@ -294,7 +286,6 @@ pub async fn test_exex_context_with_chain_spec(
|
||||
consensus,
|
||||
network,
|
||||
payload_builder,
|
||||
engine_validator,
|
||||
},
|
||||
task_executor,
|
||||
provider,
|
||||
|
||||
@ -5,7 +5,6 @@ use std::{future::Future, marker::PhantomData};
|
||||
use alloy_rpc_types_engine::JwtSecret;
|
||||
use reth_beacon_consensus::BeaconConsensusEngineHandle;
|
||||
use reth_consensus::Consensus;
|
||||
use reth_engine_primitives::EngineValidator;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network_api::FullNetwork;
|
||||
use reth_node_core::node_config::NodeConfig;
|
||||
@ -64,9 +63,6 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
|
||||
/// Network API.
|
||||
type Network: FullNetwork;
|
||||
|
||||
/// Validator for the engine API.
|
||||
type EngineValidator: EngineValidator<<Self::Types as NodeTypesWithEngine>::Engine>;
|
||||
|
||||
/// Returns the transaction pool of the node.
|
||||
fn pool(&self) -> &Self::Pool;
|
||||
|
||||
@ -87,9 +83,6 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
|
||||
&self,
|
||||
) -> &PayloadBuilderHandle<<Self::Types as NodeTypesWithEngine>::Engine>;
|
||||
|
||||
/// Returns the engine validator.
|
||||
fn engine_validator(&self) -> &Self::EngineValidator;
|
||||
|
||||
/// Returns the provider of the node.
|
||||
fn provider(&self) -> &Self::Provider;
|
||||
|
||||
|
||||
@ -97,7 +97,6 @@ impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<
|
||||
type Executor = C::Executor;
|
||||
type Network = C::Network;
|
||||
type Consensus = C::Consensus;
|
||||
type EngineValidator = C::EngineValidator;
|
||||
|
||||
fn pool(&self) -> &Self::Pool {
|
||||
self.components.pool()
|
||||
@ -130,10 +129,6 @@ impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<
|
||||
fn consensus(&self) -> &Self::Consensus {
|
||||
self.components.consensus()
|
||||
}
|
||||
|
||||
fn engine_validator(&self) -> &Self::EngineValidator {
|
||||
self.components.engine_validator()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FullNodeTypes, C: NodeComponents<T>> Clone for NodeAdapter<T, C> {
|
||||
|
||||
@ -4,7 +4,6 @@ use std::{future::Future, marker::PhantomData};
|
||||
|
||||
use reth_consensus::Consensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_node_api::{EngineValidator, NodeTypesWithEngine};
|
||||
use reth_primitives::Header;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
@ -16,8 +15,6 @@ use crate::{
|
||||
BuilderContext, ConfigureEvm, FullNodeTypes,
|
||||
};
|
||||
|
||||
use super::EngineValidatorBuilder;
|
||||
|
||||
/// A generic, general purpose and customizable [`NodeComponentsBuilder`] implementation.
|
||||
///
|
||||
/// This type is stateful and captures the configuration of the node's components.
|
||||
@ -38,23 +35,22 @@ use super::EngineValidatorBuilder;
|
||||
/// All component builders are captured in the builder state and will be consumed once the node is
|
||||
/// launched.
|
||||
#[derive(Debug)]
|
||||
pub struct ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> {
|
||||
pub struct ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB> {
|
||||
pool_builder: PoolB,
|
||||
payload_builder: PayloadB,
|
||||
network_builder: NetworkB,
|
||||
executor_builder: ExecB,
|
||||
consensus_builder: ConsB,
|
||||
engine_validator_builder: EVB,
|
||||
_marker: PhantomData<Node>,
|
||||
}
|
||||
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
{
|
||||
/// Configures the node types.
|
||||
pub fn node_types<Types>(
|
||||
self,
|
||||
) -> ComponentsBuilder<Types, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
) -> ComponentsBuilder<Types, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
Types: FullNodeTypes,
|
||||
{
|
||||
@ -64,7 +60,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
@ -73,7 +68,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
payload_builder,
|
||||
network_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker: Default::default(),
|
||||
}
|
||||
}
|
||||
@ -86,7 +80,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
network_builder: self.network_builder,
|
||||
executor_builder: self.executor_builder,
|
||||
consensus_builder: self.consensus_builder,
|
||||
engine_validator_builder: self.engine_validator_builder,
|
||||
_marker: self._marker,
|
||||
}
|
||||
}
|
||||
@ -99,7 +92,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
network_builder: self.network_builder,
|
||||
executor_builder: self.executor_builder,
|
||||
consensus_builder: self.consensus_builder,
|
||||
engine_validator_builder: self.engine_validator_builder,
|
||||
_marker: self._marker,
|
||||
}
|
||||
}
|
||||
@ -112,7 +104,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
network_builder: f(self.network_builder),
|
||||
executor_builder: self.executor_builder,
|
||||
consensus_builder: self.consensus_builder,
|
||||
engine_validator_builder: self.engine_validator_builder,
|
||||
_marker: self._marker,
|
||||
}
|
||||
}
|
||||
@ -125,7 +116,6 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
network_builder: self.network_builder,
|
||||
executor_builder: f(self.executor_builder),
|
||||
consensus_builder: self.consensus_builder,
|
||||
engine_validator_builder: self.engine_validator_builder,
|
||||
_marker: self._marker,
|
||||
}
|
||||
}
|
||||
@ -138,14 +128,13 @@ impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
network_builder: self.network_builder,
|
||||
executor_builder: self.executor_builder,
|
||||
consensus_builder: f(self.consensus_builder),
|
||||
engine_validator_builder: self.engine_validator_builder,
|
||||
_marker: self._marker,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
{
|
||||
@ -156,7 +145,7 @@ where
|
||||
pub fn pool<PB>(
|
||||
self,
|
||||
pool_builder: PB,
|
||||
) -> ComponentsBuilder<Node, PB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
) -> ComponentsBuilder<Node, PB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
PB: PoolBuilder<Node>,
|
||||
{
|
||||
@ -166,7 +155,6 @@ where
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
@ -175,14 +163,13 @@ where
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
PoolB: PoolBuilder<Node>,
|
||||
@ -194,7 +181,7 @@ where
|
||||
pub fn network<NB>(
|
||||
self,
|
||||
network_builder: NB,
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NB, ExecB, ConsB, EVB>
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NB, ExecB, ConsB>
|
||||
where
|
||||
NB: NetworkBuilder<Node, PoolB::Pool>,
|
||||
{
|
||||
@ -204,7 +191,6 @@ where
|
||||
network_builder: _,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
@ -213,7 +199,6 @@ where
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
}
|
||||
}
|
||||
@ -225,7 +210,7 @@ where
|
||||
pub fn payload<PB>(
|
||||
self,
|
||||
payload_builder: PB,
|
||||
) -> ComponentsBuilder<Node, PoolB, PB, NetworkB, ExecB, ConsB, EVB>
|
||||
) -> ComponentsBuilder<Node, PoolB, PB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
PB: PayloadServiceBuilder<Node, PoolB::Pool>,
|
||||
{
|
||||
@ -235,7 +220,6 @@ where
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
@ -244,7 +228,6 @@ where
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
}
|
||||
}
|
||||
@ -256,7 +239,7 @@ where
|
||||
pub fn executor<EB>(
|
||||
self,
|
||||
executor_builder: EB,
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, EB, ConsB, EVB>
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, EB, ConsB>
|
||||
where
|
||||
EB: ExecutorBuilder<Node>,
|
||||
{
|
||||
@ -266,7 +249,6 @@ where
|
||||
network_builder,
|
||||
executor_builder: _,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
@ -275,7 +257,6 @@ where
|
||||
network_builder,
|
||||
executor_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
}
|
||||
}
|
||||
@ -287,7 +268,7 @@ where
|
||||
pub fn consensus<CB>(
|
||||
self,
|
||||
consensus_builder: CB,
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, CB, EVB>
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, CB>
|
||||
where
|
||||
CB: ConsensusBuilder<Node>,
|
||||
{
|
||||
@ -297,38 +278,7 @@ where
|
||||
network_builder,
|
||||
executor_builder,
|
||||
consensus_builder: _,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
pool_builder,
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
}
|
||||
}
|
||||
|
||||
/// Configures the consensus builder.
|
||||
///
|
||||
/// This accepts a [`ConsensusBuilder`] instance that will be used to create the node's
|
||||
/// components for consensus.
|
||||
pub fn engine_validator<EngineVB>(
|
||||
self,
|
||||
engine_validator_builder: EngineVB,
|
||||
) -> ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EngineVB>
|
||||
where
|
||||
EngineVB: EngineValidatorBuilder<Node>,
|
||||
{
|
||||
let Self {
|
||||
pool_builder,
|
||||
payload_builder,
|
||||
network_builder,
|
||||
executor_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder: _,
|
||||
_marker,
|
||||
} = self;
|
||||
ComponentsBuilder {
|
||||
@ -337,14 +287,13 @@ where
|
||||
network_builder,
|
||||
executor_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB> NodeComponentsBuilder<Node>
|
||||
for ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB, EVB>
|
||||
impl<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB> NodeComponentsBuilder<Node>
|
||||
for ComponentsBuilder<Node, PoolB, PayloadB, NetworkB, ExecB, ConsB>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
PoolB: PoolBuilder<Node>,
|
||||
@ -352,16 +301,8 @@ where
|
||||
PayloadB: PayloadServiceBuilder<Node, PoolB::Pool>,
|
||||
ExecB: ExecutorBuilder<Node>,
|
||||
ConsB: ConsensusBuilder<Node>,
|
||||
EVB: EngineValidatorBuilder<Node>,
|
||||
{
|
||||
type Components = Components<
|
||||
Node,
|
||||
PoolB::Pool,
|
||||
ExecB::EVM,
|
||||
ExecB::Executor,
|
||||
ConsB::Consensus,
|
||||
EVB::Validator,
|
||||
>;
|
||||
type Components = Components<Node, PoolB::Pool, ExecB::EVM, ExecB::Executor, ConsB::Consensus>;
|
||||
|
||||
async fn build_components(
|
||||
self,
|
||||
@ -373,7 +314,6 @@ where
|
||||
network_builder,
|
||||
executor_builder: evm_builder,
|
||||
consensus_builder,
|
||||
engine_validator_builder,
|
||||
_marker,
|
||||
} = self;
|
||||
|
||||
@ -382,7 +322,6 @@ where
|
||||
let network = network_builder.build_network(context, pool.clone()).await?;
|
||||
let payload_builder = payload_builder.spawn_payload_service(context, pool.clone()).await?;
|
||||
let consensus = consensus_builder.build_consensus(context).await?;
|
||||
let engine_validator = engine_validator_builder.build_validator(context).await?;
|
||||
|
||||
Ok(Components {
|
||||
transaction_pool: pool,
|
||||
@ -391,12 +330,11 @@ where
|
||||
payload_builder,
|
||||
executor,
|
||||
consensus,
|
||||
engine_validator,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ComponentsBuilder<(), (), (), (), (), (), ()> {
|
||||
impl Default for ComponentsBuilder<(), (), (), (), (), ()> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pool_builder: (),
|
||||
@ -404,7 +342,6 @@ impl Default for ComponentsBuilder<(), (), (), (), (), (), ()> {
|
||||
network_builder: (),
|
||||
executor_builder: (),
|
||||
consensus_builder: (),
|
||||
engine_validator_builder: (),
|
||||
_marker: Default::default(),
|
||||
}
|
||||
}
|
||||
@ -430,18 +367,17 @@ pub trait NodeComponentsBuilder<Node: FullNodeTypes>: Send {
|
||||
) -> impl Future<Output = eyre::Result<Self::Components>> + Send;
|
||||
}
|
||||
|
||||
impl<Node, F, Fut, Pool, EVM, Executor, Cons, Val> NodeComponentsBuilder<Node> for F
|
||||
impl<Node, F, Fut, Pool, EVM, Executor, Cons> NodeComponentsBuilder<Node> for F
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
|
||||
Fut: Future<Output = eyre::Result<Components<Node, Pool, EVM, Executor, Cons, Val>>> + Send,
|
||||
Fut: Future<Output = eyre::Result<Components<Node, Pool, EVM, Executor, Cons>>> + Send,
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
EVM: ConfigureEvm<Header = Header>,
|
||||
Executor: BlockExecutorProvider,
|
||||
Cons: Consensus + Clone + Unpin + 'static,
|
||||
Val: EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine> + Clone + Unpin + 'static,
|
||||
{
|
||||
type Components = Components<Node, Pool, EVM, Executor, Cons, Val>;
|
||||
type Components = Components<Node, Pool, EVM, Executor, Cons>;
|
||||
|
||||
fn build_components(
|
||||
self,
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
//! Consensus component for the node builder.
|
||||
use reth_node_api::{EngineValidator, NodeTypesWithEngine};
|
||||
|
||||
use crate::{BuilderContext, FullNodeTypes};
|
||||
use std::future::Future;
|
||||
|
||||
/// A type that knows how to build the engine validator.
|
||||
pub trait EngineValidatorBuilder<Node: FullNodeTypes>: Send {
|
||||
/// The consensus implementation to build.
|
||||
type Validator: EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine>
|
||||
+ Clone
|
||||
+ Unpin
|
||||
+ 'static;
|
||||
|
||||
/// Creates the engine validator.
|
||||
fn build_validator(
|
||||
self,
|
||||
ctx: &BuilderContext<Node>,
|
||||
) -> impl Future<Output = eyre::Result<Self::Validator>> + Send;
|
||||
}
|
||||
|
||||
impl<Node, F, Fut, Validator> EngineValidatorBuilder<Node> for F
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Validator:
|
||||
EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine> + Clone + Unpin + 'static,
|
||||
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
|
||||
Fut: Future<Output = eyre::Result<Validator>> + Send,
|
||||
{
|
||||
type Validator = Validator;
|
||||
|
||||
fn build_validator(
|
||||
self,
|
||||
ctx: &BuilderContext<Node>,
|
||||
) -> impl Future<Output = eyre::Result<Self::Validator>> {
|
||||
self(ctx)
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,6 @@
|
||||
|
||||
mod builder;
|
||||
mod consensus;
|
||||
mod engine;
|
||||
mod execute;
|
||||
mod network;
|
||||
mod payload;
|
||||
@ -17,7 +16,6 @@ mod pool;
|
||||
|
||||
pub use builder::*;
|
||||
pub use consensus::*;
|
||||
pub use engine::*;
|
||||
pub use execute::*;
|
||||
pub use network::*;
|
||||
pub use payload::*;
|
||||
@ -27,7 +25,7 @@ use reth_consensus::Consensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_network_api::FullNetwork;
|
||||
use reth_node_api::{EngineValidator, NodeTypesWithEngine};
|
||||
use reth_node_api::NodeTypesWithEngine;
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_primitives::Header;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
@ -55,9 +53,6 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
|
||||
/// Network API.
|
||||
type Network: FullNetwork;
|
||||
|
||||
/// Validator for the engine API.
|
||||
type EngineValidator: EngineValidator<<T::Types as NodeTypesWithEngine>::Engine>;
|
||||
|
||||
/// Returns the transaction pool of the node.
|
||||
fn pool(&self) -> &Self::Pool;
|
||||
|
||||
@ -75,16 +70,13 @@ pub trait NodeComponents<T: FullNodeTypes>: Clone + Unpin + Send + Sync + 'stati
|
||||
|
||||
/// Returns the handle to the payload builder service.
|
||||
fn payload_builder(&self) -> &PayloadBuilderHandle<<T::Types as NodeTypesWithEngine>::Engine>;
|
||||
|
||||
/// Returns the engine validator.
|
||||
fn engine_validator(&self) -> &Self::EngineValidator;
|
||||
}
|
||||
|
||||
/// All the components of the node.
|
||||
///
|
||||
/// This provides access to all the components of the node.
|
||||
#[derive(Debug)]
|
||||
pub struct Components<Node: FullNodeTypes, Pool, EVM, Executor, Consensus, Validator> {
|
||||
pub struct Components<Node: FullNodeTypes, Pool, EVM, Executor, Consensus> {
|
||||
/// The transaction pool of the node.
|
||||
pub transaction_pool: Pool,
|
||||
/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
|
||||
@ -97,26 +89,22 @@ pub struct Components<Node: FullNodeTypes, Pool, EVM, Executor, Consensus, Valid
|
||||
pub network: NetworkHandle,
|
||||
/// The handle to the payload builder service.
|
||||
pub payload_builder: PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine>,
|
||||
/// The validator for the engine API.
|
||||
pub engine_validator: Validator,
|
||||
}
|
||||
|
||||
impl<Node, Pool, EVM, Executor, Cons, Val> NodeComponents<Node>
|
||||
for Components<Node, Pool, EVM, Executor, Cons, Val>
|
||||
impl<Node, Pool, EVM, Executor, Cons> NodeComponents<Node>
|
||||
for Components<Node, Pool, EVM, Executor, Cons>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
EVM: ConfigureEvm<Header = Header>,
|
||||
Executor: BlockExecutorProvider,
|
||||
Cons: Consensus + Clone + Unpin + 'static,
|
||||
Val: EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine> + Clone + Unpin + 'static,
|
||||
{
|
||||
type Pool = Pool;
|
||||
type Evm = EVM;
|
||||
type Executor = Executor;
|
||||
type Consensus = Cons;
|
||||
type Network = NetworkHandle;
|
||||
type EngineValidator = Val;
|
||||
|
||||
fn pool(&self) -> &Self::Pool {
|
||||
&self.transaction_pool
|
||||
@ -143,21 +131,15 @@ where
|
||||
) -> &PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine> {
|
||||
&self.payload_builder
|
||||
}
|
||||
|
||||
fn engine_validator(&self) -> &Self::EngineValidator {
|
||||
&self.engine_validator
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node, Pool, EVM, Executor, Cons, Val> Clone
|
||||
for Components<Node, Pool, EVM, Executor, Cons, Val>
|
||||
impl<Node, Pool, EVM, Executor, Cons> Clone for Components<Node, Pool, EVM, Executor, Cons>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool,
|
||||
EVM: ConfigureEvm<Header = Header>,
|
||||
Executor: BlockExecutorProvider,
|
||||
Cons: Consensus + Clone,
|
||||
Val: EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine>,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
@ -167,7 +149,6 @@ where
|
||||
consensus: self.consensus.clone(),
|
||||
network: self.network.clone(),
|
||||
payload_builder: self.payload_builder.clone(),
|
||||
engine_validator: self.engine_validator.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
use std::{
|
||||
fmt::{self, Debug},
|
||||
future::Future,
|
||||
marker::PhantomData,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
@ -9,7 +10,7 @@ use std::{
|
||||
use alloy_rpc_types::engine::ClientVersionV1;
|
||||
use futures::TryFutureExt;
|
||||
use reth_node_api::{
|
||||
AddOnsContext, FullNodeComponents, NodeAddOns, NodeTypes, NodeTypesWithEngine,
|
||||
AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, NodeTypes, NodeTypesWithEngine,
|
||||
};
|
||||
use reth_node_core::{
|
||||
node_config::NodeConfig,
|
||||
@ -327,31 +328,38 @@ where
|
||||
|
||||
/// Node add-ons containing RPC server configuration, with customizable eth API handler.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub struct RpcAddOns<Node: FullNodeComponents, EthApi: EthApiTypes> {
|
||||
pub struct RpcAddOns<Node: FullNodeComponents, EthApi: EthApiTypes, EV> {
|
||||
/// Additional RPC add-ons.
|
||||
pub hooks: RpcHooks<Node, EthApi>,
|
||||
/// Builder for `EthApi`
|
||||
eth_api_builder: Box<dyn FnOnce(&EthApiBuilderCtx<Node>) -> EthApi + Send + Sync>,
|
||||
/// Engine validator
|
||||
engine_validator_builder: EV,
|
||||
_pd: PhantomData<(Node, EthApi)>,
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents, EthApi: EthApiTypes> Debug for RpcAddOns<Node, EthApi> {
|
||||
impl<Node: FullNodeComponents, EthApi: EthApiTypes, EV: Debug> Debug
|
||||
for RpcAddOns<Node, EthApi, EV>
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("RpcAddOns")
|
||||
.field("hooks", &self.hooks)
|
||||
.field("eth_api_builder", &"...")
|
||||
.field("engine_validator_builder", &self.engine_validator_builder)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents, EthApi: EthApiTypes> RpcAddOns<Node, EthApi> {
|
||||
impl<Node: FullNodeComponents, EthApi: EthApiTypes, EV> RpcAddOns<Node, EthApi, EV> {
|
||||
/// Creates a new instance of the RPC add-ons.
|
||||
pub fn new(
|
||||
eth_api_builder: impl FnOnce(&EthApiBuilderCtx<Node>) -> EthApi + Send + Sync + 'static,
|
||||
engine_validator_builder: EV,
|
||||
) -> Self {
|
||||
Self {
|
||||
hooks: RpcHooks::default(),
|
||||
eth_api_builder: Box::new(eth_api_builder),
|
||||
engine_validator_builder,
|
||||
_pd: PhantomData,
|
||||
}
|
||||
}
|
||||
@ -377,23 +385,28 @@ impl<Node: FullNodeComponents, EthApi: EthApiTypes> RpcAddOns<Node, EthApi> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents, EthApi: EthApiTypes + EthApiBuilder<Node>> Default
|
||||
for RpcAddOns<Node, EthApi>
|
||||
impl<Node, EthApi, EV> Default for RpcAddOns<Node, EthApi, EV>
|
||||
where
|
||||
Node: FullNodeComponents,
|
||||
EthApi: EthApiTypes + EthApiBuilder<Node>,
|
||||
EV: Default,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new(EthApi::build)
|
||||
Self::new(EthApi::build, EV::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<N, EthApi> NodeAddOns<N> for RpcAddOns<N, EthApi>
|
||||
impl<N, EthApi, EV> NodeAddOns<N> for RpcAddOns<N, EthApi, EV>
|
||||
where
|
||||
N: FullNodeComponents<Types: ProviderNodeTypes>,
|
||||
EthApi: EthApiTypes + FullEthApiServer + AddDevSigners + Unpin + 'static,
|
||||
EV: EngineValidatorBuilder<N>,
|
||||
{
|
||||
type Handle = RpcHandle<N, EthApi>;
|
||||
|
||||
async fn launch_add_ons(self, ctx: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> {
|
||||
let AddOnsContext { node, config, beacon_engine_handle, jwt_secret } = ctx;
|
||||
let Self { eth_api_builder, engine_validator_builder, hooks, _pd: _ } = self;
|
||||
|
||||
let client = ClientVersionV1 {
|
||||
code: CLIENT_CODE,
|
||||
@ -411,7 +424,7 @@ where
|
||||
Box::new(node.task_executor().clone()),
|
||||
client,
|
||||
EngineCapabilities::default(),
|
||||
node.engine_validator().clone(),
|
||||
engine_validator_builder.build(&ctx).await?,
|
||||
);
|
||||
info!(target: "reth::cli", "Engine API handler initialized");
|
||||
|
||||
@ -427,7 +440,7 @@ where
|
||||
.with_executor(node.task_executor().clone())
|
||||
.with_evm_config(node.evm_config().clone())
|
||||
.with_block_executor(node.block_executor().clone())
|
||||
.build_with_auth_server(module_config, engine_api, self.eth_api_builder);
|
||||
.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 {
|
||||
@ -443,7 +456,7 @@ where
|
||||
auth_module: &mut auth_module,
|
||||
};
|
||||
|
||||
let RpcHooks { on_rpc_started, extend_rpc_modules } = self.hooks;
|
||||
let RpcHooks { on_rpc_started, extend_rpc_modules } = hooks;
|
||||
|
||||
extend_rpc_modules.extend_rpc_modules(ctx)?;
|
||||
|
||||
@ -503,7 +516,7 @@ pub trait RethRpcAddOns<N: FullNodeComponents>:
|
||||
fn hooks_mut(&mut self) -> &mut RpcHooks<N, Self::EthApi>;
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents, EthApi: EthApiTypes> RethRpcAddOns<N> for RpcAddOns<N, EthApi>
|
||||
impl<N: FullNodeComponents, EthApi: EthApiTypes, EV> RethRpcAddOns<N> for RpcAddOns<N, EthApi, EV>
|
||||
where
|
||||
Self: NodeAddOns<N, Handle = RpcHandle<N, EthApi>>,
|
||||
{
|
||||
@ -525,3 +538,36 @@ impl<N: FullNodeComponents> EthApiBuilder<N> for EthApi<N::Provider, N::Pool, N:
|
||||
Self::with_spawner(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
/// A type that knows how to build the engine validator.
|
||||
pub trait EngineValidatorBuilder<Node: FullNodeComponents>: Send {
|
||||
/// The consensus implementation to build.
|
||||
type Validator: EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine>
|
||||
+ Clone
|
||||
+ Unpin
|
||||
+ 'static;
|
||||
|
||||
/// Creates the engine validator.
|
||||
fn build(
|
||||
self,
|
||||
ctx: &AddOnsContext<'_, Node>,
|
||||
) -> impl Future<Output = eyre::Result<Self::Validator>> + Send;
|
||||
}
|
||||
|
||||
impl<Node, F, Fut, Validator> EngineValidatorBuilder<Node> for F
|
||||
where
|
||||
Node: FullNodeComponents,
|
||||
Validator:
|
||||
EngineValidator<<Node::Types as NodeTypesWithEngine>::Engine> + Clone + Unpin + 'static,
|
||||
F: FnOnce(&AddOnsContext<'_, Node>) -> Fut + Send,
|
||||
Fut: Future<Output = eyre::Result<Validator>> + Send,
|
||||
{
|
||||
type Validator = Validator;
|
||||
|
||||
fn build(
|
||||
self,
|
||||
ctx: &AddOnsContext<'_, Node>,
|
||||
) -> impl Future<Output = eyre::Result<Self::Validator>> {
|
||||
self(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,14 +6,16 @@ use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGenera
|
||||
use reth_chainspec::{EthChainSpec, Hardforks};
|
||||
use reth_evm::ConfigureEvm;
|
||||
use reth_network::{NetworkConfig, NetworkHandle, NetworkManager};
|
||||
use reth_node_api::{EngineValidator, FullNodeComponents, NodeAddOns, NodePrimitives};
|
||||
use reth_node_api::{
|
||||
AddOnsContext, EngineValidator, FullNodeComponents, NodeAddOns, NodePrimitives,
|
||||
};
|
||||
use reth_node_builder::{
|
||||
components::{
|
||||
ComponentsBuilder, ConsensusBuilder, EngineValidatorBuilder, ExecutorBuilder,
|
||||
NetworkBuilder, PayloadServiceBuilder, PoolBuilder, PoolBuilderConfigOverrides,
|
||||
ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder,
|
||||
PayloadServiceBuilder, PoolBuilder, PoolBuilderConfigOverrides,
|
||||
},
|
||||
node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine},
|
||||
rpc::{RethRpcAddOns, RpcAddOns, RpcHandle},
|
||||
rpc::{EngineValidatorBuilder, RethRpcAddOns, RpcAddOns, RpcHandle},
|
||||
BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig,
|
||||
};
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
@ -68,7 +70,6 @@ impl OptimismNode {
|
||||
OptimismNetworkBuilder,
|
||||
OptimismExecutorBuilder,
|
||||
OptimismConsensusBuilder,
|
||||
OptimismEngineValidatorBuilder,
|
||||
>
|
||||
where
|
||||
Node: FullNodeTypes<
|
||||
@ -86,7 +87,6 @@ impl OptimismNode {
|
||||
})
|
||||
.executor(OptimismExecutorBuilder::default())
|
||||
.consensus(OptimismConsensusBuilder::default())
|
||||
.engine_validator(OptimismEngineValidatorBuilder::default())
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +103,6 @@ where
|
||||
OptimismNetworkBuilder,
|
||||
OptimismExecutorBuilder,
|
||||
OptimismConsensusBuilder,
|
||||
OptimismEngineValidatorBuilder,
|
||||
>;
|
||||
|
||||
type AddOns = OptimismAddOns<
|
||||
@ -131,7 +130,9 @@ impl NodeTypesWithEngine for OptimismNode {
|
||||
|
||||
/// Add-ons w.r.t. optimism.
|
||||
#[derive(Debug)]
|
||||
pub struct OptimismAddOns<N: FullNodeComponents>(pub RpcAddOns<N, OpEthApi<N>>);
|
||||
pub struct OptimismAddOns<N: FullNodeComponents>(
|
||||
pub RpcAddOns<N, OpEthApi<N>, OptimismEngineValidatorBuilder>,
|
||||
);
|
||||
|
||||
impl<N: FullNodeComponents> Default for OptimismAddOns<N> {
|
||||
fn default() -> Self {
|
||||
@ -142,12 +143,14 @@ impl<N: FullNodeComponents> Default for OptimismAddOns<N> {
|
||||
impl<N: FullNodeComponents> OptimismAddOns<N> {
|
||||
/// Create a new instance with the given `sequencer_http` URL.
|
||||
pub fn new(sequencer_http: Option<String>) -> Self {
|
||||
Self(RpcAddOns::new(move |ctx| OpEthApi::new(ctx, sequencer_http)))
|
||||
Self(RpcAddOns::new(move |ctx| OpEthApi::new(ctx, sequencer_http), Default::default()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>> NodeAddOns<N>
|
||||
for OptimismAddOns<N>
|
||||
impl<N> NodeAddOns<N> for OptimismAddOns<N>
|
||||
where
|
||||
N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>,
|
||||
OptimismEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
|
||||
{
|
||||
type Handle = RpcHandle<N, OpEthApi<N>>;
|
||||
|
||||
@ -159,8 +162,10 @@ impl<N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>> NodeAddOn
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>> RethRpcAddOns<N>
|
||||
for OptimismAddOns<N>
|
||||
impl<N> RethRpcAddOns<N> for OptimismAddOns<N>
|
||||
where
|
||||
N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>,
|
||||
OptimismEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
|
||||
{
|
||||
type EthApi = OpEthApi<N>;
|
||||
|
||||
@ -458,12 +463,12 @@ pub struct OptimismEngineValidatorBuilder;
|
||||
impl<Node, Types> EngineValidatorBuilder<Node> for OptimismEngineValidatorBuilder
|
||||
where
|
||||
Types: NodeTypesWithEngine<ChainSpec = OpChainSpec>,
|
||||
Node: FullNodeTypes<Types = Types>,
|
||||
Node: FullNodeComponents<Types = Types>,
|
||||
OptimismEngineValidator: EngineValidator<Types::Engine>,
|
||||
{
|
||||
type Validator = OptimismEngineValidator;
|
||||
|
||||
async fn build_validator(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::Validator> {
|
||||
Ok(OptimismEngineValidator::new(ctx.chain_spec()))
|
||||
async fn build(self, ctx: &AddOnsContext<'_, Node>) -> eyre::Result<Self::Validator> {
|
||||
Ok(OptimismEngineValidator::new(ctx.config.chain.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user