Use Arc<ChainSpec> in SystemCaller (#12268)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Steven
2024-11-02 01:41:11 -06:00
committed by GitHub
parent d7ead13bda
commit 962fa6685b
6 changed files with 8 additions and 8 deletions

View File

@ -303,7 +303,7 @@ where
let mut evm = evm_config.evm_with_env(&mut state, env); let mut evm = evm_config.evm_with_env(&mut state, env);
// apply eip-4788 pre block contract call // 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( system_caller.apply_beacon_root_contract_call(
reorg_target.timestamp, reorg_target.timestamp,

View File

@ -95,7 +95,7 @@ where
{ {
/// Creates a new [`EthExecutionStrategy`] /// Creates a new [`EthExecutionStrategy`]
pub fn new(state: State<DB>, chain_spec: Arc<ChainSpec>, evm_config: EvmConfig) -> Self { 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 } Self { state, chain_spec, evm_config, system_caller }
} }
} }

View File

@ -1,7 +1,7 @@
//! System contract call functions. //! System contract call functions.
use crate::ConfigureEvm; use crate::ConfigureEvm;
use alloc::{boxed::Box, vec}; use alloc::{boxed::Box, sync::Arc, vec};
use alloy_eips::eip7685::Requests; use alloy_eips::eip7685::Requests;
use alloy_primitives::Bytes; use alloy_primitives::Bytes;
use core::fmt::Display; use core::fmt::Display;
@ -46,7 +46,7 @@ impl OnStateHook for NoopHook {
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct SystemCaller<EvmConfig, Chainspec> { pub struct SystemCaller<EvmConfig, Chainspec> {
evm_config: EvmConfig, evm_config: EvmConfig,
chain_spec: Chainspec, chain_spec: Arc<Chainspec>,
/// Optional hook to be called after each state change. /// Optional hook to be called after each state change.
hook: Option<Box<dyn OnStateHook>>, hook: Option<Box<dyn OnStateHook>>,
} }
@ -54,7 +54,7 @@ pub struct SystemCaller<EvmConfig, Chainspec> {
impl<EvmConfig, Chainspec> SystemCaller<EvmConfig, Chainspec> { impl<EvmConfig, Chainspec> SystemCaller<EvmConfig, Chainspec> {
/// Create a new system caller with the given EVM config, database, and chain spec, and creates /// 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. /// 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 } Self { evm_config, chain_spec, hook: None }
} }

View File

@ -90,7 +90,7 @@ where
{ {
/// Creates a new [`OpExecutionStrategy`] /// Creates a new [`OpExecutionStrategy`]
pub fn new(state: State<DB>, chain_spec: Arc<OpChainSpec>, evm_config: EvmConfig) -> Self { 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 } Self { state, chain_spec, evm_config, system_caller }
} }
} }

View File

@ -197,7 +197,7 @@ where
chain_spec.is_regolith_active_at_timestamp(attributes.payload_attributes.timestamp); chain_spec.is_regolith_active_at_timestamp(attributes.payload_attributes.timestamp);
// apply eip-4788 pre block contract call // 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 system_caller
.pre_block_beacon_root_contract_call( .pre_block_beacon_root_contract_call(

View File

@ -31,7 +31,7 @@ impl<ChainSpec> ExecutionPayloadValidator<ChainSpec> {
/// Returns the chain spec used by the validator. /// Returns the chain spec used by the validator.
#[inline] #[inline]
pub fn chain_spec(&self) -> &ChainSpec { pub const fn chain_spec(&self) -> &Arc<ChainSpec> {
&self.chain_spec &self.chain_spec
} }
} }