mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(node_builder): allow borrowing self in ConfigureEvm::evm (#8024)
This commit is contained in:
@ -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,
|
||||
|
||||
@ -145,7 +145,7 @@ where
|
||||
withdrawals.clone(),
|
||||
&client,
|
||||
chain_spec,
|
||||
evm_config,
|
||||
&evm_config,
|
||||
) {
|
||||
Ok((new_header, bundle_state)) => {
|
||||
// clear all transactions from pool
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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>,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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>,
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -298,7 +298,8 @@ fn execute_block(
|
||||
)
|
||||
.with_bundle_update()
|
||||
.build();
|
||||
let mut evm = EthEvmConfig::default().evm(state);
|
||||
let evm_config = EthEvmConfig::default();
|
||||
let mut evm = evm_config.evm(state);
|
||||
|
||||
// Set state clear flag.
|
||||
evm.db_mut().set_state_clear_flag(
|
||||
|
||||
Reference in New Issue
Block a user