feat: update SystemCaller (#11718)

This commit is contained in:
Federico Gimenez
2024-10-14 17:52:34 +02:00
committed by GitHub
parent f684dd4c4c
commit 600a394571
11 changed files with 36 additions and 34 deletions

View File

@ -97,7 +97,7 @@ where
state_hook: F,
) -> Result<Self::Output, Self::Error>
where
F: OnStateHook,
F: OnStateHook + 'static,
{
match self {
Self::Left(a) => a.execute_with_state_hook(input, state_hook),

View File

@ -56,7 +56,7 @@ pub trait Executor<DB> {
state_hook: F,
) -> Result<Self::Output, Self::Error>
where
F: OnStateHook;
F: OnStateHook + 'static;
}
/// A general purpose executor that can execute multiple inputs in sequence, validate the outputs,

View File

@ -1,7 +1,7 @@
//! System contract call functions.
use crate::ConfigureEvm;
use alloc::vec::Vec;
use alloc::{boxed::Box, vec::Vec};
use core::fmt::Display;
use reth_chainspec::EthereumHardforks;
use reth_execution_errors::BlockExecutionError;
@ -42,27 +42,26 @@ impl OnStateHook for NoopHook {
///
/// This can be used to chain system transaction calls.
#[allow(missing_debug_implementations)]
pub struct SystemCaller<'a, EvmConfig, Chainspec, Hook = NoopHook> {
evm_config: &'a EvmConfig,
pub struct SystemCaller<EvmConfig, Chainspec> {
evm_config: EvmConfig,
chain_spec: Chainspec,
/// Optional hook to be called after each state change.
hook: Option<Hook>,
hook: Option<Box<dyn OnStateHook>>,
}
impl<'a, EvmConfig, Chainspec> SystemCaller<'a, EvmConfig, Chainspec, NoopHook> {
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: &'a EvmConfig, chain_spec: Chainspec) -> Self {
pub const fn new(evm_config: EvmConfig, chain_spec: Chainspec) -> Self {
Self { evm_config, chain_spec, hook: None }
}
/// Installs a custom hook to be called after each state change.
pub fn with_state_hook<H: OnStateHook>(
self,
hook: Option<H>,
) -> SystemCaller<'a, EvmConfig, Chainspec, H> {
let Self { evm_config, chain_spec, .. } = self;
SystemCaller { evm_config, chain_spec, hook }
pub fn with_state_hook(&mut self, hook: Option<Box<dyn OnStateHook>>) -> &mut Self {
self.hook = hook;
self
}
/// Convenience method to consume the type and drop borrowed fields
pub fn finish(self) {}
}
@ -85,11 +84,10 @@ where
.build()
}
impl<EvmConfig, Chainspec, Hook> SystemCaller<'_, EvmConfig, Chainspec, Hook>
impl<EvmConfig, Chainspec> SystemCaller<EvmConfig, Chainspec>
where
EvmConfig: ConfigureEvm<Header = Header>,
Chainspec: EthereumHardforks,
Hook: OnStateHook,
{
/// Apply pre execution changes.
pub fn apply_pre_execution_changes<DB, Ext>(