Skip to content

Commit

Permalink
Use Arc<ChainSpec> in SystemCaller (#12268)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
stevencartavia and mattsse authored Nov 2, 2024
1 parent d7ead13 commit 962fa66
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/engine/util/src/reorg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,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
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
6 changes: 3 additions & 3 deletions crates/evm/src/system_calls/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -46,15 +46,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
2 changes: 1 addition & 1 deletion crates/payload/validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<ChainSpec> ExecutionPayloadValidator<ChainSpec> {

/// Returns the chain spec used by the validator.
#[inline]
pub fn chain_spec(&self) -> &ChainSpec {
pub const fn chain_spec(&self) -> &Arc<ChainSpec> {
&self.chain_spec
}
}
Expand Down

0 comments on commit 962fa66

Please sign in to comment.