Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Arc<ChainSpec> in SystemCaller #12268

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 4 additions & 3 deletions crates/engine/util/src/reorg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use std::{
collections::VecDeque,
future::Future,
pin::Pin,
sync::Arc,
task::{ready, Context, Poll},
};
use tokio::sync::oneshot;
Expand Down Expand Up @@ -258,7 +259,7 @@ where
Evm: ConfigureEvm<Header = Header>,
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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
))?;
Expand Down
2 changes: 1 addition & 1 deletion crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ where
{
/// Creates a new [`EthExecutionStrategy`]
pub fn new(state: State<DB>, chain_spec: Arc<ChainSpec>, 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 }
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/evm/src/system_calls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,15 +47,15 @@ impl OnStateHook for NoopHook {
#[allow(missing_debug_implementations)]
pub struct SystemCaller<EvmConfig, Chainspec> {
evm_config: EvmConfig,
chain_spec: Chainspec,
chain_spec: Arc<Chainspec>,
/// Optional hook to be called after each state change.
hook: Option<Box<dyn OnStateHook>>,
}

impl<EvmConfig, Chainspec> SystemCaller<EvmConfig, Chainspec> {
/// 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<Chainspec>) -> Self {
Self { evm_config, chain_spec, hook: None }
}

Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ where
{
/// Creates a new [`OpExecutionStrategy`]
pub fn new(state: State<DB>, chain_spec: Arc<OpChainSpec>, 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 }
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading