From ab66f58e5cf4f6030621ca3a63fd5a5af1ac89ed Mon Sep 17 00:00:00 2001 From: garwah <14845405+garwahl@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:45:51 +1000 Subject: [PATCH] chore: Remove ChainSpec from PayloadConfig (#11103) Co-authored-by: garwah Co-authored-by: Matthias Seitz --- Cargo.lock | 1 + .../src/commands/debug_cmd/build_block.rs | 1 - .../src/commands/debug_cmd/replay_engine.rs | 1 - crates/ethereum/node/src/node.rs | 1 - crates/ethereum/payload/Cargo.toml | 1 + crates/ethereum/payload/src/lib.rs | 13 ++++++------ crates/optimism/node/src/node.rs | 1 - crates/optimism/payload/src/builder.rs | 9 ++++---- crates/payload/basic/src/lib.rs | 17 +++------------ examples/custom-engine-types/src/main.rs | 21 ++++++++----------- .../custom-payload-builder/src/generator.rs | 13 ++---------- examples/custom-payload-builder/src/main.rs | 1 - 12 files changed, 28 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 938f4bf9e987..2ff1cc46dbd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7244,6 +7244,7 @@ dependencies = [ "alloy-primitives", "reth-basic-payload-builder", "reth-chain-state", + "reth-chainspec", "reth-errors", "reth-evm", "reth-evm-ethereum", diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index 83f7a69cf839..ab613dad6a71 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -226,7 +226,6 @@ impl> Command { best_block.hash(), payload_attrs, )?, - provider_factory.chain_spec(), ); let args = BuildArguments::new( diff --git a/bin/reth/src/commands/debug_cmd/replay_engine.rs b/bin/reth/src/commands/debug_cmd/replay_engine.rs index e6a7663a2b30..cbffa1f0e076 100644 --- a/bin/reth/src/commands/debug_cmd/replay_engine.rs +++ b/bin/reth/src/commands/debug_cmd/replay_engine.rs @@ -122,7 +122,6 @@ impl> Command { NoopTransactionPool::default(), ctx.task_executor.clone(), BasicPayloadJobGeneratorConfig::default(), - provider_factory.chain_spec(), payload_builder, ); diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index 30e32c068617..c1c4653ae6aa 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -244,7 +244,6 @@ impl EthereumPayloadBuilder { pool, ctx.task_executor().clone(), payload_job_config, - ctx.chain_spec(), payload_builder, ); let (payload_service, payload_builder) = diff --git a/crates/ethereum/payload/Cargo.toml b/crates/ethereum/payload/Cargo.toml index d67e39c17d34..5438902b4d5f 100644 --- a/crates/ethereum/payload/Cargo.toml +++ b/crates/ethereum/payload/Cargo.toml @@ -26,6 +26,7 @@ reth-evm-ethereum.workspace = true reth-errors.workspace = true reth-trie.workspace = true reth-chain-state.workspace = true +reth-chainspec.workspace = true # ethereum revm.workspace = true diff --git a/crates/ethereum/payload/src/lib.rs b/crates/ethereum/payload/src/lib.rs index 744ad38b13ab..fcaa6cd5931b 100644 --- a/crates/ethereum/payload/src/lib.rs +++ b/crates/ethereum/payload/src/lib.rs @@ -15,6 +15,7 @@ use reth_basic_payload_builder::{ PayloadConfig, WithdrawalsOutcome, }; use reth_chain_state::ExecutedBlock; +use reth_chainspec::ChainSpec; use reth_errors::RethError; use reth_evm::{ system_calls::{ @@ -36,7 +37,7 @@ use reth_primitives::{ Block, BlockBody, EthereumHardforks, Header, IntoRecoveredTransaction, Receipt, EMPTY_OMMER_ROOT_HASH, }; -use reth_provider::StateProviderFactory; +use reth_provider::{ChainSpecProvider, StateProviderFactory}; use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::{ noop::NoopTransactionPool, BestTransactionsAttributes, TransactionPool, @@ -88,7 +89,7 @@ where impl PayloadBuilder for EthereumPayloadBuilder where EvmConfig: ConfigureEvm
, - Client: StateProviderFactory, + Client: StateProviderFactory + ChainSpecProvider, Pool: TransactionPool, { type Attributes = EthPayloadBuilderAttributes; @@ -137,22 +138,22 @@ pub fn default_ethereum_payload( ) -> Result, PayloadBuilderError> where EvmConfig: ConfigureEvm
, - Client: StateProviderFactory, + Client: StateProviderFactory + ChainSpecProvider, Pool: TransactionPool, { let BuildArguments { client, pool, mut cached_reads, config, cancel, best_payload } = args; + let chain_spec = client.chain_spec(); let state_provider = client.state_by_block_hash(config.parent_block.hash())?; let state = StateProviderDatabase::new(state_provider); let mut db = State::builder().with_database_ref(cached_reads.as_db(state)).with_bundle_update().build(); - let PayloadConfig { parent_block, extra_data, attributes, chain_spec } = config; + let PayloadConfig { parent_block, extra_data, attributes } = config; debug!(target: "payload_builder", id=%attributes.id, parent_hash = ?parent_block.hash(), parent_number = parent_block.number, "building new payload"); let mut cumulative_gas_used = 0; let mut sum_blob_gas_used = 0; - let block_gas_limit: u64 = - initialized_block_env.gas_limit.try_into().unwrap_or(chain_spec.max_gas_limit); + let block_gas_limit: u64 = initialized_block_env.gas_limit.to::(); let base_fee = initialized_block_env.basefee.to::(); let mut executed_txs = Vec::new(); diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index aafdc8aaacfe..8614e8d60db1 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -278,7 +278,6 @@ impl OptimismPayloadBuilder { pool, ctx.task_executor().clone(), payload_job_config, - ctx.chain_spec(), payload_builder, ); let (payload_service, payload_builder) = diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index 447431536d9c..59f1e38d3a66 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use alloy_primitives::U256; use reth_basic_payload_builder::*; use reth_chain_state::ExecutedBlock; -use reth_chainspec::EthereumHardforks; +use reth_chainspec::{ChainSpec, ChainSpecProvider, EthereumHardforks}; use reth_evm::{ system_calls::pre_block_beacon_root_contract_call, ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes, @@ -93,7 +93,7 @@ where /// Implementation of the [`PayloadBuilder`] trait for [`OptimismPayloadBuilder`]. impl PayloadBuilder for OptimismPayloadBuilder where - Client: StateProviderFactory, + Client: StateProviderFactory + ChainSpecProvider, Pool: TransactionPool, EvmConfig: ConfigureEvm
, { @@ -164,16 +164,17 @@ pub(crate) fn optimism_payload( ) -> Result, PayloadBuilderError> where EvmConfig: ConfigureEvm
, - Client: StateProviderFactory, + Client: StateProviderFactory + ChainSpecProvider, Pool: TransactionPool, { let BuildArguments { client, pool, mut cached_reads, config, cancel, best_payload } = args; + let chain_spec = client.chain_spec(); let state_provider = client.state_by_block_hash(config.parent_block.hash())?; let state = StateProviderDatabase::new(state_provider); let mut db = State::builder().with_database_ref(cached_reads.as_db(state)).with_bundle_update().build(); - let PayloadConfig { parent_block, attributes, chain_spec, extra_data } = config; + let PayloadConfig { parent_block, attributes, extra_data } = config; debug!(target: "payload_builder", id=%attributes.payload_attributes.payload_id(), parent_hash = ?parent_block.hash(), parent_number = parent_block.number, "building new payload"); diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index 5117e44e348d..7d1f3fb9eada 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -58,8 +58,6 @@ pub struct BasicPayloadJobGenerator { config: BasicPayloadJobGeneratorConfig, /// Restricts how many generator tasks can be executed at once. payload_task_guard: PayloadTaskGuard, - /// The chain spec. - chain_spec: Arc, /// The type responsible for building payloads. /// /// See [`PayloadBuilder`] @@ -78,7 +76,6 @@ impl BasicPayloadJobGenerator, builder: Builder, ) -> Self { Self { @@ -87,7 +84,6 @@ impl BasicPayloadJobGenerator { pub extra_data: Bytes, /// Requested attributes for the payload. pub attributes: Attributes, - /// The chain spec. - pub chain_spec: Arc, } impl PayloadConfig { @@ -696,9 +686,8 @@ where parent_block: Arc, extra_data: Bytes, attributes: Attributes, - chain_spec: Arc, ) -> Self { - Self { parent_block, extra_data, attributes, chain_spec } + Self { parent_block, extra_data, attributes } } /// Returns the payload id. diff --git a/examples/custom-engine-types/src/main.rs b/examples/custom-engine-types/src/main.rs index a31bf1c341c3..5e0503701ab9 100644 --- a/examples/custom-engine-types/src/main.rs +++ b/examples/custom-engine-types/src/main.rs @@ -45,7 +45,7 @@ use reth_basic_payload_builder::{ BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig, BuildArguments, BuildOutcome, PayloadBuilder, PayloadConfig, }; -use reth_chainspec::{Chain, ChainSpec}; +use reth_chainspec::{Chain, ChainSpec, ChainSpecProvider}; use reth_node_api::{ payload::{EngineApiMessageVersion, EngineObjectValidationError, PayloadOrAttributes}, validate_version_specific_fields, EngineTypes, EngineValidator, PayloadAttributes, @@ -285,7 +285,6 @@ where pool, ctx.task_executor().clone(), payload_job_config, - ctx.chain_spec(), payload_builder, ); let (payload_service, payload_builder) = @@ -304,7 +303,7 @@ pub struct CustomPayloadBuilder; impl PayloadBuilder for CustomPayloadBuilder where - Client: StateProviderFactory, + Client: StateProviderFactory + ChainSpecProvider, Pool: TransactionPool, { type Attributes = CustomPayloadBuilderAttributes; @@ -315,7 +314,9 @@ where args: BuildArguments, ) -> Result, PayloadBuilderError> { let BuildArguments { client, pool, cached_reads, config, cancel, best_payload } = args; - let PayloadConfig { parent_block, extra_data, attributes, chain_spec } = config; + let PayloadConfig { parent_block, extra_data, attributes } = config; + + let chain_spec = client.chain_spec(); // This reuses the default EthereumPayloadBuilder to build the payload // but any custom logic can be implemented here @@ -326,12 +327,7 @@ where client, pool, cached_reads, - config: PayloadConfig { - parent_block, - extra_data, - attributes: attributes.0, - chain_spec, - }, + config: PayloadConfig { parent_block, extra_data, attributes: attributes.0 }, cancel, best_payload, }) @@ -342,9 +338,10 @@ where client: &Client, config: PayloadConfig, ) -> Result { - let PayloadConfig { parent_block, extra_data, attributes, chain_spec } = config; + let PayloadConfig { parent_block, extra_data, attributes } = config; + let chain_spec = client.chain_spec(); >::build_empty_payload(&reth_ethereum_payload_builder::EthereumPayloadBuilder::new(EthEvmConfig::new(chain_spec.clone())),client, - PayloadConfig { parent_block, extra_data, attributes: attributes.0, chain_spec }) + PayloadConfig { parent_block, extra_data, attributes: attributes.0}) } } diff --git a/examples/custom-payload-builder/src/generator.rs b/examples/custom-payload-builder/src/generator.rs index 6531de0bcc76..807cbf6a53bb 100644 --- a/examples/custom-payload-builder/src/generator.rs +++ b/examples/custom-payload-builder/src/generator.rs @@ -5,7 +5,6 @@ use reth::{ transaction_pool::TransactionPool, }; use reth_basic_payload_builder::{BasicPayloadJobGeneratorConfig, PayloadBuilder, PayloadConfig}; -use reth_chainspec::ChainSpec; use reth_node_api::PayloadBuilderAttributes; use reth_payload_builder::{PayloadBuilderError, PayloadJobGenerator}; use reth_primitives::{BlockNumberOrTag, Bytes}; @@ -22,8 +21,6 @@ pub struct EmptyBlockPayloadJobGenerator { executor: Tasks, /// The configuration for the job generator. _config: BasicPayloadJobGeneratorConfig, - /// The chain spec. - chain_spec: Arc, /// The type responsible for building payloads. /// /// See [PayloadBuilder] @@ -40,10 +37,9 @@ impl EmptyBlockPayloadJobGenerator, builder: Builder, ) -> Self { - Self { client, pool, executor, _config: config, builder, chain_spec } + Self { client, pool, executor, _config: config, builder } } } @@ -80,12 +76,7 @@ where // we already know the hash, so we can seal it block.seal(attributes.parent()) }; - let config = PayloadConfig::new( - Arc::new(parent_block), - Bytes::default(), - attributes, - Arc::clone(&self.chain_spec), - ); + let config = PayloadConfig::new(Arc::new(parent_block), Bytes::default(), attributes); Ok(EmptyBlockPayloadJob { client: self.client.clone(), _pool: self.pool.clone(), diff --git a/examples/custom-payload-builder/src/main.rs b/examples/custom-payload-builder/src/main.rs index 4861f8284bad..5ed414eb850b 100644 --- a/examples/custom-payload-builder/src/main.rs +++ b/examples/custom-payload-builder/src/main.rs @@ -56,7 +56,6 @@ where pool, ctx.task_executor().clone(), payload_job_config, - ctx.chain_spec().clone(), reth_ethereum_payload_builder::EthereumPayloadBuilder::new(EthEvmConfig::new( ctx.chain_spec(), )),