Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_execution_types::ExecutionOutcome;
use reth_fs_util as fs;
use reth_node_api::{NodeTypesWithDB, NodeTypesWithEngine, PayloadBuilderAttributes};
use reth_node_ethereum::EthExecutorProvider;
use reth_node_ethereum::{EthEvmConfig, EthExecutorProvider};
use reth_payload_builder::database::CachedReads;
use reth_primitives::{
revm_primitives::KzgSettings, Address, BlobTransaction, BlobTransactionSidecar, Bytes,
Expand Down Expand Up @@ -243,7 +243,9 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
None,
);

let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::default();
let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
EthEvmConfig::new(provider_factory.chain_spec()),
);

match payload_builder.try_build(args)? {
BuildOutcome::Better { payload, .. } => {
Expand Down
6 changes: 4 additions & 2 deletions bin/reth/src/commands/debug_cmd/replay_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use reth_fs_util as fs;
use reth_network::{BlockDownloaderProvider, NetworkHandle};
use reth_network_api::NetworkInfo;
use reth_node_api::{NodeTypesWithDB, NodeTypesWithDBAdapter, NodeTypesWithEngine};
use reth_node_ethereum::{EthEngineTypes, EthExecutorProvider};
use reth_node_ethereum::{EthEngineTypes, EthEvmConfig, EthExecutorProvider};
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use reth_provider::{
providers::BlockchainProvider, CanonStateSubscriptions, ChainSpecProvider, ProviderFactory,
Expand Down Expand Up @@ -117,7 +117,9 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
.await?;

// Set up payload builder
let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::default();
let payload_builder = reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
EthEvmConfig::new(provider_factory.chain_spec()),
);

let payload_generator = BasicPayloadJobGenerator::with_builder(
blockchain_db.clone(),
Expand Down
8 changes: 1 addition & 7 deletions crates/engine/invalid-block-hooks/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@ where
// Setup environment for the execution.
let mut cfg = CfgEnvWithHandlerCfg::new(Default::default(), Default::default());
let mut block_env = BlockEnv::default();
self.evm_config.fill_cfg_and_block_env(
&mut cfg,
&mut block_env,
&self.provider.chain_spec(),
block.header(),
U256::MAX,
);
self.evm_config.fill_cfg_and_block_env(&mut cfg, &mut block_env, block.header(), U256::MAX);

// Setup EVM
let mut evm = self.evm_config.evm_with_env(
Expand Down
8 changes: 1 addition & 7 deletions crates/engine/util/src/reorg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,7 @@ where
// Configure environments
let mut cfg = CfgEnvWithHandlerCfg::new(Default::default(), Default::default());
let mut block_env = BlockEnv::default();
evm_config.fill_cfg_and_block_env(
&mut cfg,
&mut block_env,
chain_spec,
&reorg_target.header,
U256::MAX,
);
evm_config.fill_cfg_and_block_env(&mut cfg, &mut block_env, &reorg_target.header, U256::MAX);
let env = EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, Default::default());
let mut evm = evm_config.evm_with_env(&mut state, env);

Expand Down
5 changes: 2 additions & 3 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct EthExecutorProvider<EvmConfig = EthEvmConfig> {
impl EthExecutorProvider {
/// Creates a new default ethereum executor provider.
pub fn ethereum(chain_spec: Arc<ChainSpec>) -> Self {
Self::new(chain_spec, Default::default())
Self::new(chain_spec.clone(), EthEvmConfig::new(chain_spec))
}

/// Returns a new provider for the mainnet.
Expand Down Expand Up @@ -285,7 +285,6 @@ where
self.executor.evm_config.fill_cfg_and_block_env(
&mut cfg,
&mut block_env,
self.chain_spec(),
header,
total_difficulty,
);
Expand Down Expand Up @@ -522,7 +521,7 @@ mod tests {
}

fn executor_provider(chain_spec: Arc<ChainSpec>) -> EthExecutorProvider<EthEvmConfig> {
EthExecutorProvider { chain_spec, evm_config: Default::default() }
EthExecutorProvider { evm_config: EthEvmConfig::new(chain_spec.clone()), chain_spec }
}

#[test]
Expand Down
45 changes: 27 additions & 18 deletions crates/ethereum/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#[cfg(not(feature = "std"))]
extern crate alloc;

use std::sync::Arc;

use reth_chainspec::{ChainSpec, Head};
use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::{transaction::FillTxEnv, Address, Header, TransactionSigned, U256};
Expand All @@ -32,20 +34,28 @@ pub mod dao_fork;
pub mod eip6110;

/// Ethereum-related EVM configuration.
#[derive(Debug, Clone, Copy, Default)]
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct EthEvmConfig;
pub struct EthEvmConfig {
chain_spec: Arc<ChainSpec>,
}

impl EthEvmConfig {
/// Create a new `EthEvmConfig` with the given `chain_spec`.
pub const fn new(chain_spec: Arc<ChainSpec>) -> Self {
Self { chain_spec }
}
}

impl ConfigureEvmEnv for EthEvmConfig {
fn fill_cfg_env(
&self,
cfg_env: &mut CfgEnvWithHandlerCfg,
chain_spec: &ChainSpec,
header: &Header,
total_difficulty: U256,
) {
let spec_id = config::revm_spec(
chain_spec,
&self.chain_spec,
&Head {
number: header.number,
timestamp: header.timestamp,
Expand All @@ -55,7 +65,7 @@ impl ConfigureEvmEnv for EthEvmConfig {
},
);

cfg_env.chain_id = chain_spec.chain().id();
cfg_env.chain_id = self.chain_spec.chain().id();
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;

cfg_env.handler_cfg.spec_id = spec_id;
Expand Down Expand Up @@ -115,7 +125,7 @@ impl ConfigureEvm for EthEvmConfig {
#[cfg(test)]
mod tests {
use super::*;
use reth_chainspec::{Chain, ChainSpec};
use reth_chainspec::{Chain, ChainSpec, MAINNET};
use reth_evm::execute::ProviderError;
use reth_primitives::{
revm_primitives::{BlockEnv, CfgEnv, SpecId},
Expand Down Expand Up @@ -155,10 +165,9 @@ mod tests {

// Use the `EthEvmConfig` to fill the `cfg_env` and `block_env` based on the ChainSpec,
// Header, and total difficulty
EthEvmConfig::default().fill_cfg_and_block_env(
EthEvmConfig::new(Arc::new(chain_spec.clone())).fill_cfg_and_block_env(
&mut cfg_env,
&mut block_env,
&chain_spec,
&header,
total_difficulty,
);
Expand All @@ -172,7 +181,7 @@ mod tests {
#[allow(clippy::needless_update)]
fn test_evm_configure() {
// Create a default `EthEvmConfig`
let evm_config = EthEvmConfig::default();
let evm_config = EthEvmConfig::new(MAINNET.clone());

// Initialize an empty database wrapped in CacheDB
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();
Expand Down Expand Up @@ -210,7 +219,7 @@ mod tests {
#[test]
#[allow(clippy::needless_update)]
fn test_evm_with_env_default_spec() {
let evm_config = EthEvmConfig::default();
let evm_config = EthEvmConfig::new(MAINNET.clone());

let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();

Expand All @@ -231,7 +240,7 @@ mod tests {
#[test]
#[allow(clippy::needless_update)]
fn test_evm_with_env_custom_cfg() {
let evm_config = EthEvmConfig::default();
let evm_config = EthEvmConfig::new(MAINNET.clone());

let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();

Expand Down Expand Up @@ -262,7 +271,7 @@ mod tests {
#[test]
#[allow(clippy::needless_update)]
fn test_evm_with_env_custom_block_and_tx() {
let evm_config = EthEvmConfig::default();
let evm_config = EthEvmConfig::new(MAINNET.clone());

let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();

Expand Down Expand Up @@ -296,7 +305,7 @@ mod tests {
#[test]
#[allow(clippy::needless_update)]
fn test_evm_with_spec_id() {
let evm_config = EthEvmConfig::default();
let evm_config = EthEvmConfig::new(MAINNET.clone());

let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();

Expand All @@ -319,7 +328,7 @@ mod tests {
#[test]
#[allow(clippy::needless_update)]
fn test_evm_with_inspector() {
let evm_config = EthEvmConfig::default();
let evm_config = EthEvmConfig::new(MAINNET.clone());

let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();

Expand Down Expand Up @@ -361,7 +370,7 @@ mod tests {
#[test]
#[allow(clippy::needless_update)]
fn test_evm_with_env_and_default_inspector() {
let evm_config = EthEvmConfig::default();
let evm_config = EthEvmConfig::new(MAINNET.clone());
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();

let env_with_handler = EnvWithHandlerCfg::default();
Expand All @@ -381,7 +390,7 @@ mod tests {
#[test]
#[allow(clippy::needless_update)]
fn test_evm_with_env_inspector_and_custom_cfg() {
let evm_config = EthEvmConfig::default();
let evm_config = EthEvmConfig::new(MAINNET.clone());
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();

let cfg = CfgEnv::default().with_chain_id(111);
Expand All @@ -406,7 +415,7 @@ mod tests {
#[test]
#[allow(clippy::needless_update)]
fn test_evm_with_env_inspector_and_custom_block_tx() {
let evm_config = EthEvmConfig::default();
let evm_config = EthEvmConfig::new(MAINNET.clone());
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();

// Create custom block and tx environment
Expand Down Expand Up @@ -438,7 +447,7 @@ mod tests {
#[test]
#[allow(clippy::needless_update)]
fn test_evm_with_env_inspector_and_spec_id() {
let evm_config = EthEvmConfig::default();
let evm_config = EthEvmConfig::new(MAINNET.clone());
let db = CacheDB::<EmptyDBTyped<ProviderError>>::default();

let handler_cfg = HandlerCfg { spec_id: SpecId::CONSTANTINOPLE, ..Default::default() };
Expand Down
74 changes: 43 additions & 31 deletions crates/ethereum/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use reth_ethereum_engine_primitives::{
};
use reth_evm_ethereum::execute::EthExecutorProvider;
use reth_network::NetworkHandle;
use reth_node_api::{FullNodeComponents, NodeAddOns};
use reth_node_api::{ConfigureEvm, FullNodeComponents, NodeAddOns};
use reth_node_builder::{
components::{
ComponentsBuilder, ConsensusBuilder, ExecutorBuilder, NetworkBuilder,
PayloadServiceBuilder, PoolBuilder,
},
node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine},
BuilderContext, ConfigureEvm, Node, PayloadBuilderConfig, PayloadTypes,
BuilderContext, Node, PayloadBuilderConfig, PayloadTypes,
};
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
use reth_provider::CanonStateSubscriptions;
Expand Down Expand Up @@ -57,7 +57,7 @@ impl EthereumNode {
ComponentsBuilder::default()
.node_types::<Node>()
.pool(EthereumPoolBuilder::default())
.payload(EthereumPayloadBuilder::new(EthEvmConfig::default()))
.payload(EthereumPayloadBuilder::default())
.network(EthereumNetworkBuilder::default())
.executor(EthereumExecutorBuilder::default())
.consensus(EthereumConsensusBuilder::default())
Expand Down Expand Up @@ -120,8 +120,8 @@ where
ctx: &BuilderContext<Node>,
) -> eyre::Result<(Self::EVM, Self::Executor)> {
let chain_spec = ctx.chain_spec();
let evm_config = EthEvmConfig::default();
let executor = EthExecutorProvider::new(chain_spec, evm_config);
let evm_config = EthEvmConfig::new(ctx.chain_spec());
let executor = EthExecutorProvider::new(chain_spec, evm_config.clone());

Ok((evm_config, executor))
}
Expand Down Expand Up @@ -204,37 +204,29 @@ where
/// A basic ethereum payload service.
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub struct EthereumPayloadBuilder<Evm = EthEvmConfig> {
/// The EVM configuration to use for the payload builder.
pub evm_config: Evm,
}
pub struct EthereumPayloadBuilder;

impl<EVM> EthereumPayloadBuilder<EVM> {
/// Create a new instance with the given evm config.
pub const fn new(evm_config: EVM) -> Self {
Self { evm_config }
}
}

impl<Types, Node, Evm, Pool> PayloadServiceBuilder<Node, Pool> for EthereumPayloadBuilder<Evm>
where
Types: NodeTypesWithEngine<ChainSpec = ChainSpec>,
Node: FullNodeTypes<Types = Types>,
Evm: ConfigureEvm,
Pool: TransactionPool + Unpin + 'static,
Types::Engine: PayloadTypes<
BuiltPayload = EthBuiltPayload,
PayloadAttributes = EthPayloadAttributes,
PayloadBuilderAttributes = EthPayloadBuilderAttributes,
>,
{
async fn spawn_payload_service(
impl EthereumPayloadBuilder {
/// A helper method initializing [`PayloadBuilderService`] with the given EVM config.
pub fn spawn<Types, Node, Evm, Pool>(
self,
evm_config: Evm,
ctx: &BuilderContext<Node>,
pool: Pool,
) -> eyre::Result<PayloadBuilderHandle<Types::Engine>> {
) -> eyre::Result<PayloadBuilderHandle<Types::Engine>>
where
Types: NodeTypesWithEngine<ChainSpec = ChainSpec>,
Node: FullNodeTypes<Types = Types>,
Evm: ConfigureEvm,
Pool: TransactionPool + Unpin + 'static,
Types::Engine: PayloadTypes<
BuiltPayload = EthBuiltPayload,
PayloadAttributes = EthPayloadAttributes,
PayloadBuilderAttributes = EthPayloadBuilderAttributes,
>,
{
let payload_builder =
reth_ethereum_payload_builder::EthereumPayloadBuilder::new(self.evm_config);
reth_ethereum_payload_builder::EthereumPayloadBuilder::new(evm_config);
let conf = ctx.payload_builder_config();

let payload_job_config = BasicPayloadJobGeneratorConfig::default()
Expand All @@ -260,6 +252,26 @@ where
}
}

impl<Types, Node, Pool> PayloadServiceBuilder<Node, Pool> for EthereumPayloadBuilder
where
Types: NodeTypesWithEngine<ChainSpec = ChainSpec>,
Node: FullNodeTypes<Types = Types>,
Pool: TransactionPool + Unpin + 'static,
Types::Engine: PayloadTypes<
BuiltPayload = EthBuiltPayload,
PayloadAttributes = EthPayloadAttributes,
PayloadBuilderAttributes = EthPayloadBuilderAttributes,
>,
{
async fn spawn_payload_service(
self,
ctx: &BuilderContext<Node>,
pool: Pool,
) -> eyre::Result<PayloadBuilderHandle<Types::Engine>> {
self.spawn(EthEvmConfig::new(ctx.chain_spec()), ctx, pool)
}
}

/// A basic ethereum payload service.
#[derive(Debug, Default, Clone, Copy)]
pub struct EthereumNetworkBuilder {
Expand Down
6 changes: 0 additions & 6 deletions crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ impl<EvmConfig> EthereumPayloadBuilder<EvmConfig> {
}
}

impl Default for EthereumPayloadBuilder {
fn default() -> Self {
Self::new(EthEvmConfig::default())
}
}

// Default implementation of [PayloadBuilder] for unit type
impl<EvmConfig, Pool, Client> PayloadBuilder<Pool, Client> for EthereumPayloadBuilder<EvmConfig>
where
Expand Down
Loading