mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat: introduce evm config trait (#6461)
Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com> Co-authored-by: Oliver Nordbjerg <onbjerg@users.noreply.github.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
bundle_state::BundleStateWithReceipts, BlockExecutor, BlockExecutorStats, ExecutorFactory,
|
||||
PrunableBlockExecutor, StateProvider,
|
||||
bundle_state::BundleStateWithReceipts, BlockExecutor, ExecutorFactory, PrunableBlockExecutor,
|
||||
StateProvider,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use reth_interfaces::executor::BlockExecutionError;
|
||||
@ -11,6 +11,8 @@ use std::sync::Arc;
|
||||
pub struct TestExecutor(pub Option<BundleStateWithReceipts>);
|
||||
|
||||
impl BlockExecutor for TestExecutor {
|
||||
type Error = BlockExecutionError;
|
||||
|
||||
fn execute(
|
||||
&mut self,
|
||||
_block: &BlockWithSenders,
|
||||
@ -45,10 +47,6 @@ impl BlockExecutor for TestExecutor {
|
||||
self.0.clone().unwrap_or_default()
|
||||
}
|
||||
|
||||
fn stats(&self) -> BlockExecutorStats {
|
||||
BlockExecutorStats::default()
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
@ -77,7 +75,7 @@ impl ExecutorFactory for TestExecutorFactory {
|
||||
fn with_state<'a, SP: StateProvider + 'a>(
|
||||
&'a self,
|
||||
_sp: SP,
|
||||
) -> Box<dyn PrunableBlockExecutor + 'a> {
|
||||
) -> Box<dyn PrunableBlockExecutor<Error = <TestExecutor as BlockExecutor>::Error> + 'a> {
|
||||
let exec_res = self.exec_results.lock().pop();
|
||||
Box::new(TestExecutor(exec_res))
|
||||
}
|
||||
|
||||
@ -14,17 +14,20 @@ pub trait ExecutorFactory: Send + Sync + 'static {
|
||||
fn with_state<'a, SP: StateProvider + 'a>(
|
||||
&'a self,
|
||||
_sp: SP,
|
||||
) -> Box<dyn PrunableBlockExecutor + 'a>;
|
||||
) -> Box<dyn PrunableBlockExecutor<Error = BlockExecutionError> + 'a>;
|
||||
}
|
||||
|
||||
/// An executor capable of executing a block.
|
||||
pub trait BlockExecutor {
|
||||
/// The error type returned by the executor.
|
||||
type Error;
|
||||
|
||||
/// Execute a block.
|
||||
fn execute(
|
||||
&mut self,
|
||||
block: &BlockWithSenders,
|
||||
total_difficulty: U256,
|
||||
) -> Result<(), BlockExecutionError>;
|
||||
) -> Result<(), Self::Error>;
|
||||
|
||||
/// Executes the block and checks receipts.
|
||||
///
|
||||
@ -33,7 +36,7 @@ pub trait BlockExecutor {
|
||||
&mut self,
|
||||
block: &BlockWithSenders,
|
||||
total_difficulty: U256,
|
||||
) -> Result<(), BlockExecutionError>;
|
||||
) -> Result<(), Self::Error>;
|
||||
|
||||
/// Runs the provided transactions and commits their state to the run-time database.
|
||||
///
|
||||
@ -51,14 +54,11 @@ pub trait BlockExecutor {
|
||||
&mut self,
|
||||
block: &BlockWithSenders,
|
||||
total_difficulty: U256,
|
||||
) -> Result<(Vec<Receipt>, u64), BlockExecutionError>;
|
||||
) -> Result<(Vec<Receipt>, u64), Self::Error>;
|
||||
|
||||
/// Return bundle state. This is output of executed blocks.
|
||||
fn take_output_state(&mut self) -> BundleStateWithReceipts;
|
||||
|
||||
/// Internal statistics of execution.
|
||||
fn stats(&self) -> BlockExecutorStats;
|
||||
|
||||
/// Returns the size hint of current in-memory changes.
|
||||
fn size_hint(&self) -> Option<usize>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user