experiment with different designs

This commit is contained in:
Dan Cline
2024-02-21 00:37:24 -05:00
parent 2eef0dc1a5
commit c9f9a61758
3 changed files with 61 additions and 2 deletions

View File

@@ -5,7 +5,7 @@ use crate::{
};
use reth_node_api::ConfigureEvmEnv;
use reth_primitives::ChainSpec;
use reth_provider::{ExecutorFactory, PrunableBlockExecutor, StateProvider};
use reth_provider::{ExecutorFactory, PrunableBlockExecutor, StateProvider, ExecutorFactoryLifetime, ExecutorFactoryGat};
use std::sync::Arc;
/// Factory for creating [EVMProcessor].
@@ -36,6 +36,46 @@ impl<EvmConfig> EvmProcessorFactory<EvmConfig> {
}
}
impl<'a, EvmConfig> ExecutorFactoryLifetime<'a> for EvmProcessorFactory<EvmConfig>
where
EvmConfig: ConfigureEvmEnv + Send + Sync + Clone + 'static,
{
type Executor = EVMProcessor<'a, EvmConfig>;
fn with_state<SP: StateProvider + 'a>(&self, sp: SP) -> Self::Executor {
let database_state = StateProviderDatabase::new(sp);
let mut evm = EVMProcessor::new_with_db(
self.chain_spec.clone(),
database_state,
self.evm_config.clone(),
);
if let Some(ref stack) = self.stack {
evm.set_stack(stack.clone());
}
evm
}
}
impl<EvmConfig> ExecutorFactoryGat for EvmProcessorFactory<EvmConfig>
where
EvmConfig: ConfigureEvmEnv + Send + Sync + Clone + 'static,
{
type Executor<'a> = EVMProcessor<'a, EvmConfig>;
fn with_state<'a, SP: StateProvider + 'a>(&self, sp: SP) -> Self::Executor<'a> {
let database_state = StateProviderDatabase::new(sp);
let mut evm = EVMProcessor::new_with_db(
self.chain_spec.clone(),
database_state,
self.evm_config.clone(),
);
if let Some(ref stack) = self.stack {
evm.set_stack(stack.clone());
}
evm
}
}
impl<EvmConfig> ExecutorFactory for EvmProcessorFactory<EvmConfig>
where
EvmConfig: ConfigureEvmEnv + Send + Sync + Clone + 'static,

View File

@@ -17,6 +17,22 @@ pub trait ExecutorFactory: Send + Sync + 'static {
) -> Box<dyn PrunableBlockExecutor + 'a>;
}
/// ExecutorFactory that is generic over a lifetime.
pub trait ExecutorFactoryLifetime<'a>: Send + Sync + 'static {
type Executor: PrunableBlockExecutor;
/// Executor with [`StateProvider`]
fn with_state<SP: StateProvider + 'a>(&self, sp: SP) -> Self::Executor;
}
/// ExecutorFactoryGat uses a GAT
pub trait ExecutorFactoryGat: Send + Sync + 'static {
type Executor<'a>: PrunableBlockExecutor;
/// Executor with [`StateProvider`]
fn with_state<'a, SP: StateProvider + 'a>(&self, sp: SP) -> Self::Executor<'a>;
}
/// An executor capable of executing a block.
pub trait BlockExecutor {
/// Execute a block.

View File

@@ -46,7 +46,10 @@ mod withdrawals;
pub use withdrawals::WithdrawalsProvider;
mod executor;
pub use executor::{BlockExecutor, BlockExecutorStats, ExecutorFactory, PrunableBlockExecutor};
pub use executor::{
BlockExecutor, BlockExecutorStats, ExecutorFactory, ExecutorFactoryLifetime, ExecutorFactoryGat,
PrunableBlockExecutor,
};
mod chain;
pub use chain::{