From a746ec87a3d4f9d304da558288e823c794bef706 Mon Sep 17 00:00:00 2001 From: stevencartavia Date: Fri, 1 Nov 2024 16:44:47 -0600 Subject: [PATCH 1/4] Use Arc in SystemCaller --- crates/engine/util/src/reorg.rs | 7 ++++--- crates/ethereum/evm/src/execute.rs | 2 +- crates/evm/src/system_calls/mod.rs | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/engine/util/src/reorg.rs b/crates/engine/util/src/reorg.rs index 0d51d2dfab6f..ed5cf9688ec6 100644 --- a/crates/engine/util/src/reorg.rs +++ b/crates/engine/util/src/reorg.rs @@ -32,6 +32,7 @@ use std::{ collections::VecDeque, future::Future, pin::Pin, + sync::Arc, task::{ready, Context, Poll}, }; use tokio::sync::oneshot; @@ -258,7 +259,7 @@ where Evm: ConfigureEvm
, Spec: EthereumHardforks, { - let chain_spec = payload_validator.chain_spec(); + let chain_spec = Arc::new(payload_validator.chain_spec()); // Ensure next payload is valid. let next_block = payload_validator @@ -303,7 +304,7 @@ where let mut evm = evm_config.evm_with_env(&mut state, env); // apply eip-4788 pre block contract call - let mut system_caller = SystemCaller::new(evm_config.clone(), chain_spec); + let mut system_caller = SystemCaller::new(evm_config.clone(), chain_spec.clone()); system_caller.apply_beacon_root_contract_call( reorg_target.timestamp, @@ -365,7 +366,7 @@ where if let Some(withdrawals) = &reorg_target.body.withdrawals { state.increment_balances(post_block_withdrawals_balance_increments( - chain_spec, + &chain_spec, reorg_target.timestamp, withdrawals, ))?; diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index f082a3a707ea..fa14e260d651 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -95,7 +95,7 @@ where { /// Creates a new [`EthExecutionStrategy`] pub fn new(state: State, chain_spec: Arc, evm_config: EvmConfig) -> Self { - let system_caller = SystemCaller::new(evm_config.clone(), (*chain_spec).clone()); + let system_caller = SystemCaller::new(evm_config.clone(), chain_spec.clone()); Self { state, chain_spec, evm_config, system_caller } } } diff --git a/crates/evm/src/system_calls/mod.rs b/crates/evm/src/system_calls/mod.rs index daaf1d1414f7..f1c5627d623c 100644 --- a/crates/evm/src/system_calls/mod.rs +++ b/crates/evm/src/system_calls/mod.rs @@ -10,6 +10,7 @@ use reth_execution_errors::BlockExecutionError; use reth_primitives::{Block, Header}; use revm::{Database, DatabaseCommit, Evm}; use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState, B256}; +use std::sync::Arc; mod eip2935; mod eip4788; @@ -46,7 +47,7 @@ impl OnStateHook for NoopHook { #[allow(missing_debug_implementations)] pub struct SystemCaller { evm_config: EvmConfig, - chain_spec: Chainspec, + chain_spec: Arc, /// Optional hook to be called after each state change. hook: Option>, } @@ -54,7 +55,7 @@ pub struct SystemCaller { impl SystemCaller { /// Create a new system caller with the given EVM config, database, and chain spec, and creates /// the EVM with the given initialized config and block environment. - pub const fn new(evm_config: EvmConfig, chain_spec: Chainspec) -> Self { + pub const fn new(evm_config: EvmConfig, chain_spec: Arc) -> Self { Self { evm_config, chain_spec, hook: None } } From 7493d63feb00cc3a5a74b39b96a6c609269e4820 Mon Sep 17 00:00:00 2001 From: stevencartavia Date: Fri, 1 Nov 2024 16:50:55 -0600 Subject: [PATCH 2/4] fix --- crates/optimism/evm/src/execute.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 9c5db9d4b614..c2b006144369 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -90,7 +90,7 @@ where { /// Creates a new [`OpExecutionStrategy`] pub fn new(state: State, chain_spec: Arc, evm_config: EvmConfig) -> Self { - let system_caller = SystemCaller::new(evm_config.clone(), (*chain_spec).clone()); + let system_caller = SystemCaller::new(evm_config.clone(), chain_spec.clone()); Self { state, chain_spec, evm_config, system_caller } } } From a6bcd56823b6b10c08794d627e16d16d290ff2d3 Mon Sep 17 00:00:00 2001 From: stevencartavia Date: Fri, 1 Nov 2024 18:02:02 -0600 Subject: [PATCH 3/4] update --- crates/optimism/payload/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index cae2d34bd499..0cf45835a239 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -197,7 +197,7 @@ where chain_spec.is_regolith_active_at_timestamp(attributes.payload_attributes.timestamp); // apply eip-4788 pre block contract call - let mut system_caller = SystemCaller::new(evm_config.clone(), &chain_spec); + let mut system_caller = SystemCaller::new(evm_config.clone(), chain_spec.clone()); system_caller .pre_block_beacon_root_contract_call( From 1fc5063d5a030ce7c50d4a8d91dc43d9dd5d09d0 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 2 Nov 2024 08:22:12 +0100 Subject: [PATCH 4/4] touchups --- crates/engine/util/src/reorg.rs | 5 ++--- crates/evm/src/system_calls/mod.rs | 3 +-- crates/payload/validator/src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/engine/util/src/reorg.rs b/crates/engine/util/src/reorg.rs index ed5cf9688ec6..69831389a658 100644 --- a/crates/engine/util/src/reorg.rs +++ b/crates/engine/util/src/reorg.rs @@ -32,7 +32,6 @@ use std::{ collections::VecDeque, future::Future, pin::Pin, - sync::Arc, task::{ready, Context, Poll}, }; use tokio::sync::oneshot; @@ -259,7 +258,7 @@ where Evm: ConfigureEvm
, Spec: EthereumHardforks, { - let chain_spec = Arc::new(payload_validator.chain_spec()); + let chain_spec = payload_validator.chain_spec(); // Ensure next payload is valid. let next_block = payload_validator @@ -366,7 +365,7 @@ where if let Some(withdrawals) = &reorg_target.body.withdrawals { state.increment_balances(post_block_withdrawals_balance_increments( - &chain_spec, + chain_spec, reorg_target.timestamp, withdrawals, ))?; diff --git a/crates/evm/src/system_calls/mod.rs b/crates/evm/src/system_calls/mod.rs index f1c5627d623c..7fdb31d967dd 100644 --- a/crates/evm/src/system_calls/mod.rs +++ b/crates/evm/src/system_calls/mod.rs @@ -1,7 +1,7 @@ //! System contract call functions. use crate::ConfigureEvm; -use alloc::{boxed::Box, vec}; +use alloc::{boxed::Box, sync::Arc, vec}; use alloy_eips::eip7685::Requests; use alloy_primitives::Bytes; use core::fmt::Display; @@ -10,7 +10,6 @@ use reth_execution_errors::BlockExecutionError; use reth_primitives::{Block, Header}; use revm::{Database, DatabaseCommit, Evm}; use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState, B256}; -use std::sync::Arc; mod eip2935; mod eip4788; diff --git a/crates/payload/validator/src/lib.rs b/crates/payload/validator/src/lib.rs index 38e53bac42a5..e74b5f48d40f 100644 --- a/crates/payload/validator/src/lib.rs +++ b/crates/payload/validator/src/lib.rs @@ -31,7 +31,7 @@ impl ExecutionPayloadValidator { /// Returns the chain spec used by the validator. #[inline] - pub fn chain_spec(&self) -> &ChainSpec { + pub const fn chain_spec(&self) -> &Arc { &self.chain_spec } }