From 4d9a98780fbc75014f8a833c08abf0be7765c6c1 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Mon, 10 Feb 2025 22:00:24 +0400 Subject: [PATCH] chore: abstract `OpPayloadBuilder` over `ChainSpec` (#14374) --- Cargo.lock | 1 - crates/optimism/payload/Cargo.toml | 1 - crates/optimism/payload/src/builder.rs | 38 ++++++++++++++++---------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e4e62abe..7db01fdd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8536,7 +8536,6 @@ dependencies = [ "reth-chainspec", "reth-evm", "reth-execution-types", - "reth-optimism-chainspec", "reth-optimism-consensus", "reth-optimism-evm", "reth-optimism-forks", diff --git a/crates/optimism/payload/Cargo.toml b/crates/optimism/payload/Cargo.toml index 435a6fc0a..4921e3f80 100644 --- a/crates/optimism/payload/Cargo.toml +++ b/crates/optimism/payload/Cargo.toml @@ -29,7 +29,6 @@ reth-basic-payload-builder.workspace = true reth-chain-state.workspace = true # op-reth -reth-optimism-chainspec.workspace = true reth-optimism-consensus.workspace = true reth-optimism-evm.workspace = true reth-optimism-forks.workspace = true diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index df0f52d85..de45db85f 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -19,13 +19,12 @@ use op_alloy_consensus::OpDepositReceipt; use op_alloy_rpc_types_engine::OpPayloadAttributes; use reth_basic_payload_builder::*; use reth_chain_state::{ExecutedBlock, ExecutedBlockWithTrieUpdates}; -use reth_chainspec::{ChainSpecProvider, EthereumHardforks}; +use reth_chainspec::{ChainSpecProvider, EthChainSpec, EthereumHardforks}; use reth_evm::{ env::EvmEnv, system_calls::SystemCaller, ConfigureEvmEnv, ConfigureEvmFor, Database, Evm, EvmError, InvalidTxError, NextBlockEnvAttributes, }; use reth_execution_types::ExecutionOutcome; -use reth_optimism_chainspec::OpChainSpec; use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism; use reth_optimism_evm::{OpReceiptBuilder, ReceiptBuilderCtx}; use reth_optimism_forks::OpHardforks; @@ -152,7 +151,7 @@ impl impl OpPayloadBuilder where Pool: TransactionPool>, - Client: StateProviderFactory + ChainSpecProvider, + Client: StateProviderFactory + ChainSpecProvider, N: OpPayloadPrimitives, EvmConfig: ConfigureEvmFor, { @@ -236,7 +235,7 @@ where let evm_env = self.evm_env(&attributes, &parent).map_err(PayloadBuilderError::other)?; let config = PayloadConfig { parent_header: Arc::new(parent), attributes }; - let ctx: OpPayloadBuilderCtx = OpPayloadBuilderCtx { + let ctx: OpPayloadBuilderCtx = OpPayloadBuilderCtx { evm_config: self.evm_config.clone(), da_config: self.config.da_config.clone(), chain_spec: self.client.chain_spec(), @@ -260,7 +259,7 @@ where impl PayloadBuilder for OpPayloadBuilder where - Client: StateProviderFactory + ChainSpecProvider + Clone, + Client: StateProviderFactory + ChainSpecProvider + Clone, N: OpPayloadPrimitives, Pool: TransactionPool>, EvmConfig: ConfigureEvmFor, @@ -334,15 +333,16 @@ impl<'a, Txs> OpBuilder<'a, Txs> { impl OpBuilder<'_, Txs> { /// Executes the payload and returns the outcome. - pub fn execute( + pub fn execute( self, state: &mut State, - ctx: &OpPayloadBuilderCtx, + ctx: &OpPayloadBuilderCtx, ) -> Result>, PayloadBuilderError> where N: OpPayloadPrimitives, Txs: PayloadTransactions>, EvmConfig: ConfigureEvmFor, + ChainSpec: EthChainSpec + OpHardforks, DB: Database + AsRef

, P: StorageRootProvider, { @@ -397,13 +397,14 @@ impl OpBuilder<'_, Txs> { } /// Builds the payload on top of the state. - pub fn build( + pub fn build( self, mut state: State, - ctx: OpPayloadBuilderCtx, + ctx: OpPayloadBuilderCtx, ) -> Result>, PayloadBuilderError> where EvmConfig: ConfigureEvmFor, + ChainSpec: EthChainSpec + OpHardforks, N: OpPayloadPrimitives, Txs: PayloadTransactions>, DB: Database + AsRef

, @@ -522,13 +523,14 @@ impl OpBuilder<'_, Txs> { } /// Builds the payload and returns its [`ExecutionWitness`] based on the state after execution. - pub fn witness( + pub fn witness( self, state: &mut State, - ctx: &OpPayloadBuilderCtx, + ctx: &OpPayloadBuilderCtx, ) -> Result where EvmConfig: ConfigureEvmFor, + ChainSpec: EthChainSpec + OpHardforks, N: OpPayloadPrimitives, Txs: PayloadTransactions>, DB: Database + AsRef

, @@ -631,13 +633,13 @@ impl ExecutionInfo { /// Container type that holds all necessities to build a new payload. #[derive(Debug)] -pub struct OpPayloadBuilderCtx { +pub struct OpPayloadBuilderCtx { /// The type that knows how to perform system calls and configure the evm. pub evm_config: EvmConfig, /// The DA config for the payload builder pub da_config: OpDAConfig, /// The chainspec - pub chain_spec: Arc, + pub chain_spec: Arc, /// How to build the payload. pub config: PayloadConfig>, /// Evm Settings @@ -650,7 +652,12 @@ pub struct OpPayloadBuilderCtx { pub receipt_builder: Arc>, } -impl OpPayloadBuilderCtx { +impl OpPayloadBuilderCtx +where + EvmConfig: ConfigureEvmEnv, + ChainSpec: EthChainSpec + OpHardforks, + N: NodePrimitives, +{ /// Returns the parent block the payload will be build on. pub fn parent(&self) -> &SealedHeader { &self.config.parent_header @@ -782,9 +789,10 @@ impl OpPayloadBuilderCtx OpPayloadBuilderCtx +impl OpPayloadBuilderCtx where EvmConfig: ConfigureEvmFor, + ChainSpec: EthChainSpec + OpHardforks, N: OpPayloadPrimitives, { /// apply eip-4788 pre block contract call