From 4649d6f041b2b9eb9868ea7c29a98e057e0941a2 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sun, 29 Dec 2024 14:23:47 +0100 Subject: [PATCH] chore: move payload builder types to standalone mod (#13593) --- crates/ethereum/node/src/lib.rs | 2 + crates/ethereum/node/src/node.rs | 89 ++------------------------- crates/ethereum/node/src/payload.rs | 93 +++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 84 deletions(-) create mode 100644 crates/ethereum/node/src/payload.rs diff --git a/crates/ethereum/node/src/lib.rs b/crates/ethereum/node/src/lib.rs index 8dae6031577c..a51886dd1c41 100644 --- a/crates/ethereum/node/src/lib.rs +++ b/crates/ethereum/node/src/lib.rs @@ -23,3 +23,5 @@ pub use evm::{ pub mod node; pub use node::EthereumNode; + +pub mod payload; diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index 492d1cfac7cf..f1a1f56ec048 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -1,26 +1,23 @@ //! Ethereum Node types config. -use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; +use crate::{EthEngineTypes, EthEvmConfig}; use reth_beacon_consensus::EthBeaconConsensus; use reth_chainspec::ChainSpec; use reth_ethereum_engine_primitives::{ EthBuiltPayload, EthPayloadAttributes, EthPayloadBuilderAttributes, }; -use reth_ethereum_payload_builder::EthereumBuilderConfig; use reth_evm::execute::BasicBlockExecutorProvider; use reth_evm_ethereum::execute::EthExecutionStrategyFactory; use reth_network::{EthNetworkPrimitives, NetworkHandle, PeersInfo}; -use reth_node_api::{AddOnsContext, ConfigureEvm, FullNodeComponents, HeaderTy, TxTy}; +use reth_node_api::{AddOnsContext, FullNodeComponents, TxTy}; use reth_node_builder::{ components::{ - ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder, - PayloadServiceBuilder, PoolBuilder, + ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder, PoolBuilder, }, node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine}, rpc::{EngineValidatorBuilder, RpcAddOns}, - BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig, PayloadTypes, + BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadTypes, }; -use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; use reth_primitives::{EthPrimitives, PooledTransaction}; use reth_provider::{CanonStateSubscriptions, EthStorage}; use reth_rpc::EthApi; @@ -32,8 +29,7 @@ use reth_transaction_pool::{ use reth_trie_db::MerklePatriciaTrie; use std::sync::Arc; -use crate::{EthEngineTypes, EthEvmConfig}; - +pub use crate::payload::EthereumPayloadBuilder; pub use reth_ethereum_engine_primitives::EthereumEngineValidator; /// Type configuration for a regular Ethereum node. @@ -218,81 +214,6 @@ where } } -/// A basic ethereum payload service. -#[derive(Clone, Default, Debug)] -#[non_exhaustive] -pub struct EthereumPayloadBuilder; - -impl EthereumPayloadBuilder { - /// A helper method initializing [`PayloadBuilderService`] with the given EVM config. - pub fn spawn( - self, - evm_config: Evm, - ctx: &BuilderContext, - pool: Pool, - ) -> eyre::Result> - where - Types: NodeTypesWithEngine, - Node: FullNodeTypes, - Evm: ConfigureEvm
, Transaction = TxTy>, - Pool: TransactionPool>> - + Unpin - + 'static, - Types::Engine: PayloadTypes< - BuiltPayload = EthBuiltPayload, - PayloadAttributes = EthPayloadAttributes, - PayloadBuilderAttributes = EthPayloadBuilderAttributes, - >, - { - let conf = ctx.payload_builder_config(); - let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new( - evm_config, - EthereumBuilderConfig::new(conf.extra_data_bytes()).with_gas_limit(conf.gas_limit()), - ); - - let payload_job_config = BasicPayloadJobGeneratorConfig::default() - .interval(conf.interval()) - .deadline(conf.deadline()) - .max_payload_tasks(conf.max_payload_tasks()); - - let payload_generator = BasicPayloadJobGenerator::with_builder( - ctx.provider().clone(), - pool, - ctx.task_executor().clone(), - payload_job_config, - payload_builder, - ); - let (payload_service, payload_builder) = - PayloadBuilderService::new(payload_generator, ctx.provider().canonical_state_stream()); - - ctx.task_executor().spawn_critical("payload builder service", Box::pin(payload_service)); - - Ok(payload_builder) - } -} - -impl PayloadServiceBuilder for EthereumPayloadBuilder -where - Types: NodeTypesWithEngine, - Node: FullNodeTypes, - Pool: TransactionPool>> - + Unpin - + 'static, - Types::Engine: PayloadTypes< - BuiltPayload = EthBuiltPayload, - PayloadAttributes = EthPayloadAttributes, - PayloadBuilderAttributes = EthPayloadBuilderAttributes, - >, -{ - async fn spawn_payload_service( - self, - ctx: &BuilderContext, - pool: Pool, - ) -> eyre::Result> { - self.spawn(EthEvmConfig::new(ctx.chain_spec()), ctx, pool) - } -} - /// A basic ethereum payload service. #[derive(Debug, Default, Clone, Copy)] pub struct EthereumNetworkBuilder { diff --git a/crates/ethereum/node/src/payload.rs b/crates/ethereum/node/src/payload.rs new file mode 100644 index 000000000000..84df93c0bab4 --- /dev/null +++ b/crates/ethereum/node/src/payload.rs @@ -0,0 +1,93 @@ +//! Payload component configuration for the Ethereum node. + +use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; +use reth_chainspec::ChainSpec; +use reth_ethereum_engine_primitives::{ + EthBuiltPayload, EthPayloadAttributes, EthPayloadBuilderAttributes, +}; +use reth_ethereum_payload_builder::EthereumBuilderConfig; +use reth_evm::ConfigureEvm; +use reth_evm_ethereum::EthEvmConfig; +use reth_node_api::{FullNodeTypes, HeaderTy, NodeTypesWithEngine, TxTy}; +use reth_node_builder::{ + components::PayloadServiceBuilder, BuilderContext, PayloadBuilderConfig, PayloadTypes, +}; +use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; +use reth_primitives::EthPrimitives; +use reth_provider::CanonStateSubscriptions; +use reth_transaction_pool::{PoolTransaction, TransactionPool}; + +/// A basic ethereum payload service. +#[derive(Clone, Default, Debug)] +#[non_exhaustive] +pub struct EthereumPayloadBuilder; + +impl EthereumPayloadBuilder { + /// A helper method initializing [`PayloadBuilderService`] with the given EVM config. + pub fn spawn( + self, + evm_config: Evm, + ctx: &BuilderContext, + pool: Pool, + ) -> eyre::Result> + where + Types: NodeTypesWithEngine, + Node: FullNodeTypes, + Evm: ConfigureEvm
, Transaction = TxTy>, + Pool: TransactionPool>> + + Unpin + + 'static, + Types::Engine: PayloadTypes< + BuiltPayload = EthBuiltPayload, + PayloadAttributes = EthPayloadAttributes, + PayloadBuilderAttributes = EthPayloadBuilderAttributes, + >, + { + let conf = ctx.payload_builder_config(); + let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new( + evm_config, + EthereumBuilderConfig::new(conf.extra_data_bytes()).with_gas_limit(conf.gas_limit()), + ); + + let payload_job_config = BasicPayloadJobGeneratorConfig::default() + .interval(conf.interval()) + .deadline(conf.deadline()) + .max_payload_tasks(conf.max_payload_tasks()); + + let payload_generator = BasicPayloadJobGenerator::with_builder( + ctx.provider().clone(), + pool, + ctx.task_executor().clone(), + payload_job_config, + payload_builder, + ); + let (payload_service, payload_builder) = + PayloadBuilderService::new(payload_generator, ctx.provider().canonical_state_stream()); + + ctx.task_executor().spawn_critical("payload builder service", Box::pin(payload_service)); + + Ok(payload_builder) + } +} + +impl PayloadServiceBuilder for EthereumPayloadBuilder +where + Types: NodeTypesWithEngine, + Node: FullNodeTypes, + Pool: TransactionPool>> + + Unpin + + 'static, + Types::Engine: PayloadTypes< + BuiltPayload = EthBuiltPayload, + PayloadAttributes = EthPayloadAttributes, + PayloadBuilderAttributes = EthPayloadBuilderAttributes, + >, +{ + async fn spawn_payload_service( + self, + ctx: &BuilderContext, + pool: Pool, + ) -> eyre::Result> { + self.spawn(EthEvmConfig::new(ctx.chain_spec()), ctx, pool) + } +}