reth_evm/
noop.rs

1//! A no operation block executor implementation.
2
3use crate::{
4    execute::{BlockExecutorProvider, Executor},
5    Database, OnStateHook,
6};
7use reth_execution_errors::BlockExecutionError;
8use reth_execution_types::BlockExecutionResult;
9use reth_primitives_traits::{NodePrimitives, RecoveredBlock};
10
11const UNAVAILABLE_FOR_NOOP: &str = "execution unavailable for noop";
12
13/// A [`BlockExecutorProvider`] implementation that does nothing.
14#[derive(Debug, Default, Clone)]
15#[non_exhaustive]
16pub struct NoopBlockExecutorProvider<P>(core::marker::PhantomData<P>);
17
18impl<P: NodePrimitives> BlockExecutorProvider for NoopBlockExecutorProvider<P> {
19    type Primitives = P;
20
21    type Executor<DB: Database> = Self;
22
23    fn executor<DB>(&self, _: DB) -> Self::Executor<DB>
24    where
25        DB: Database,
26    {
27        Self::default()
28    }
29}
30
31impl<DB: Database, P: NodePrimitives> Executor<DB> for NoopBlockExecutorProvider<P> {
32    type Primitives = P;
33    type Error = BlockExecutionError;
34
35    fn execute_one(
36        &mut self,
37        _block: &RecoveredBlock<<Self::Primitives as NodePrimitives>::Block>,
38    ) -> Result<BlockExecutionResult<<Self::Primitives as NodePrimitives>::Receipt>, Self::Error>
39    {
40        Err(BlockExecutionError::msg(UNAVAILABLE_FOR_NOOP))
41    }
42
43    fn execute_one_with_state_hook<F>(
44        &mut self,
45        _block: &RecoveredBlock<<Self::Primitives as NodePrimitives>::Block>,
46        _state_hook: F,
47    ) -> Result<BlockExecutionResult<<Self::Primitives as NodePrimitives>::Receipt>, Self::Error>
48    where
49        F: OnStateHook + 'static,
50    {
51        Err(BlockExecutionError::msg(UNAVAILABLE_FOR_NOOP))
52    }
53
54    fn into_state(self) -> revm_database::State<DB> {
55        unreachable!()
56    }
57
58    fn size_hint(&self) -> usize {
59        0
60    }
61}