feat(node_builder): allow borrowing self in ConfigureEvm::evm (#8024)

This commit is contained in:
DaniPopes
2024-05-01 17:22:49 +02:00
committed by GitHub
parent f157ec83b6
commit 399afd802c
11 changed files with 46 additions and 51 deletions

View File

@ -426,7 +426,7 @@ impl StorageInner {
withdrawals: Option<Withdrawals>,
client: &impl StateProviderFactory,
chain_spec: Arc<ChainSpec>,
evm_config: EvmConfig,
evm_config: &EvmConfig,
) -> Result<(SealedHeader, BundleStateWithReceipts), BlockExecutionError>
where
EvmConfig: ConfigureEvm,

View File

@ -145,7 +145,7 @@ where
withdrawals.clone(),
&client,
chain_spec,
evm_config,
&evm_config,
) {
Ok((new_header, bundle_state)) => {
// clear all transactions from pool

View File

@ -137,7 +137,7 @@ where
///
/// It does __not__ apply post-execution changes.
fn execute_pre_and_transactions<Ext, DB>(
&mut self,
&self,
block: &BlockWithSenders,
mut evm: Evm<'_, Ext, &mut State<DB>>,
) -> Result<(Vec<Receipt>, u64), BlockExecutionError>

View File

@ -24,14 +24,17 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
/// This does not automatically configure the EVM with [ConfigureEvmEnv] methods. It is up to
/// the caller to call an appropriate method to fill the transaction and block environment
/// before executing any transactions using the provided EVM.
fn evm<'a, DB: Database + 'a>(&self, db: DB) -> Evm<'a, Self::DefaultExternalContext<'a>, DB>;
fn evm<'a, DB: Database + 'a>(
&'a self,
db: DB,
) -> Evm<'a, Self::DefaultExternalContext<'a>, DB>;
/// Returns a new EVM with the given database configured with the given environment settings,
/// including the spec id.
///
/// This will preserve any handler modifications
fn evm_with_env<'a, DB: Database + 'a>(
&self,
&'a self,
db: DB,
env: EnvWithHandlerCfg,
) -> Evm<'a, Self::DefaultExternalContext<'a>, DB> {
@ -48,7 +51,7 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
///
/// This will preserve any handler modifications
fn evm_with_env_and_inspector<'a, DB, I>(
&self,
&'a self,
db: DB,
env: EnvWithHandlerCfg,
inspector: I,
@ -68,7 +71,7 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
/// Caution: This does not automatically configure the EVM with [ConfigureEvmEnv] methods. It is
/// up to the caller to call an appropriate method to fill the transaction and block
/// environment before executing any transactions using the provided EVM.
fn evm_with_inspector<'a, DB, I>(&self, db: DB, inspector: I) -> Evm<'a, I, DB>
fn evm_with_inspector<'a, DB, I>(&'a self, db: DB, inspector: I) -> Evm<'a, I, DB>
where
DB: Database + 'a,
I: GetInspector<DB>,

View File

@ -235,6 +235,11 @@ impl<DB> WithLaunchContext<NodeBuilder<DB>>
where
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
{
/// Returns a reference to the node builder's config.
pub fn config(&self) -> &NodeConfig {
self.builder.config()
}
/// Configures the types of the node.
pub fn with_types<T>(self) -> WithLaunchContext<NodeBuilderWithTypes<RethFullAdapter<DB, T>>>
where

View File

@ -9,7 +9,7 @@ pub trait ExecutorBuilder<Node: FullNodeTypes>: Send {
type EVM: ConfigureEvm;
// TODO(mattsse): integrate `Executor`
/// Creates the transaction pool.
/// Creates the EVM config.
fn build_evm(
self,
ctx: &BuilderContext<Node>,

View File

@ -137,7 +137,7 @@ where
///
/// It does __not__ apply post-execution changes.
fn execute_pre_and_transactions<Ext, DB>(
&mut self,
&self,
block: &BlockWithSenders,
mut evm: Evm<'_, Ext, &mut State<DB>>,
) -> Result<(Vec<Receipt>, u64), BlockExecutionError>

View File

@ -46,11 +46,8 @@ where
sp: SP,
) -> Box<dyn PrunableBlockExecutor<Error = BlockExecutionError> + 'a> {
let database_state = StateProviderDatabase::new(sp);
let mut evm = EVMProcessor::new_with_db(
self.chain_spec.clone(),
database_state,
self.evm_config.clone(),
);
let mut evm =
EVMProcessor::new_with_db(self.chain_spec.clone(), database_state, &self.evm_config);
if let Some(stack) = &self.stack {
evm.set_stack(stack.clone());
}

View File

@ -242,10 +242,11 @@ mod tests {
chain_spec: Arc<ChainSpec>,
db: StateProviderTest,
) -> EVMProcessor<'a, TestEvmConfig> {
static CONFIG: std::sync::OnceLock<TestEvmConfig> = std::sync::OnceLock::new();
let mut executor = EVMProcessor::new_with_db(
chain_spec,
StateProviderDatabase::new(db),
TestEvmConfig::default(),
CONFIG.get_or_init(TestEvmConfig::default),
);
executor.evm.context.evm.db.load_cache_account(L1_BLOCK_CONTRACT).unwrap();
executor

View File

@ -7,7 +7,7 @@ use revm::{
primitives::{CfgEnvWithHandlerCfg, ResultAndState},
Evm, State,
};
use std::{sync::Arc, time::Instant};
use std::{marker::PhantomData, sync::Arc, time::Instant};
#[cfg(not(feature = "optimism"))]
use tracing::{debug, trace};
@ -59,7 +59,7 @@ pub struct EVMProcessor<'a, EvmConfig> {
/// Execution stats
pub(crate) stats: BlockExecutorStats,
/// The type that is able to configure the EVM environment.
_evm_config: EvmConfig,
_phantom: PhantomData<EvmConfig>,
}
impl<'a, EvmConfig> EVMProcessor<'a, EvmConfig>
@ -75,7 +75,7 @@ where
pub fn new_with_db<DB: StateProvider + 'a>(
chain_spec: Arc<ChainSpec>,
db: StateProviderDatabase<DB>,
evm_config: EvmConfig,
evm_config: &'a EvmConfig,
) -> Self {
let state = State::builder()
.with_database_boxed(Box::new(db))
@ -89,7 +89,7 @@ where
pub fn new_with_state(
chain_spec: Arc<ChainSpec>,
revm_state: StateDBBox<'a, ProviderError>,
evm_config: EvmConfig,
evm_config: &'a EvmConfig,
) -> Self {
let stack = InspectorStack::new(InspectorStackConfig::default());
let evm = evm_config.evm_with_inspector(revm_state, stack);
@ -98,7 +98,7 @@ where
evm,
batch_record: BlockBatchRecord::default(),
stats: BlockExecutorStats::default(),
_evm_config: evm_config,
_phantom: PhantomData,
}
}
@ -507,11 +507,9 @@ mod tests {
);
// execute invalid header (no parent beacon block root)
let mut executor = EVMProcessor::new_with_db(
chain_spec,
StateProviderDatabase::new(db),
TestEvmConfig::default(),
);
let evm_config = TestEvmConfig::default();
let mut executor =
EVMProcessor::new_with_db(chain_spec, StateProviderDatabase::new(db), &evm_config);
// attempt to execute a block without parent beacon block root, expect err
let err = executor
@ -599,11 +597,9 @@ mod tests {
.build(),
);
let mut executor = EVMProcessor::new_with_db(
chain_spec,
StateProviderDatabase::new(db),
TestEvmConfig::default(),
);
let evm_config = TestEvmConfig::default();
let mut executor =
EVMProcessor::new_with_db(chain_spec, StateProviderDatabase::new(db), &evm_config);
executor.init_env(&header, U256::ZERO);
// get the env
@ -648,11 +644,9 @@ mod tests {
.build(),
);
let mut executor = EVMProcessor::new_with_db(
chain_spec,
StateProviderDatabase::new(db),
TestEvmConfig::default(),
);
let evm_config = TestEvmConfig::default();
let mut executor =
EVMProcessor::new_with_db(chain_spec, StateProviderDatabase::new(db), &evm_config);
// construct the header for block one
let header = Header {
@ -702,11 +696,9 @@ mod tests {
let mut header = chain_spec.genesis_header();
let mut executor = EVMProcessor::new_with_db(
chain_spec,
StateProviderDatabase::new(db),
TestEvmConfig::default(),
);
let evm_config = TestEvmConfig::default();
let mut executor =
EVMProcessor::new_with_db(chain_spec, StateProviderDatabase::new(db), &evm_config);
executor.init_env(&header, U256::ZERO);
// attempt to execute the genesis block with non-zero parent beacon block root, expect err
@ -781,11 +773,9 @@ mod tests {
);
// execute header
let mut executor = EVMProcessor::new_with_db(
chain_spec,
StateProviderDatabase::new(db),
TestEvmConfig::default(),
);
let evm_config = TestEvmConfig::default();
let mut executor =
EVMProcessor::new_with_db(chain_spec, StateProviderDatabase::new(db), &evm_config);
executor.init_env(&header, U256::ZERO);
// ensure that the env is configured with a base fee
@ -843,11 +833,9 @@ mod tests {
let chain_id = chain_spec.chain.id();
// execute header
let mut executor = EVMProcessor::new_with_db(
chain_spec,
StateProviderDatabase::new(db),
TestEvmConfig::default(),
);
let evm_config = TestEvmConfig::default();
let mut executor =
EVMProcessor::new_with_db(chain_spec, StateProviderDatabase::new(db), &evm_config);
// Create a test transaction that gonna fail
let transaction = TransactionSigned::from_transaction_and_signature(