reth_evm/
noop.rs

1//! A no operation block executor implementation.
2
3use alloy_primitives::BlockNumber;
4use core::fmt::Display;
5use reth_execution_errors::BlockExecutionError;
6use reth_execution_types::{BlockExecutionInput, BlockExecutionOutput, ExecutionOutcome};
7use reth_primitives::{BlockWithSenders, NodePrimitives};
8use reth_prune_types::PruneModes;
9use reth_storage_errors::provider::ProviderError;
10use revm::State;
11use revm_primitives::db::Database;
12
13use crate::{
14    execute::{BatchExecutor, BlockExecutorProvider, Executor},
15    system_calls::OnStateHook,
16};
17
18const UNAVAILABLE_FOR_NOOP: &str = "execution unavailable for noop";
19
20/// A [`BlockExecutorProvider`] implementation that does nothing.
21#[derive(Debug, Default, Clone)]
22#[non_exhaustive]
23pub struct NoopBlockExecutorProvider<P>(core::marker::PhantomData<P>);
24
25impl<P: NodePrimitives> BlockExecutorProvider for NoopBlockExecutorProvider<P> {
26    type Primitives = P;
27
28    type Executor<DB: Database<Error: Into<ProviderError> + Display>> = Self;
29
30    type BatchExecutor<DB: Database<Error: Into<ProviderError> + Display>> = Self;
31
32    fn executor<DB>(&self, _: DB) -> Self::Executor<DB>
33    where
34        DB: Database<Error: Into<ProviderError> + Display>,
35    {
36        Self::default()
37    }
38
39    fn batch_executor<DB>(&self, _: DB) -> Self::BatchExecutor<DB>
40    where
41        DB: Database<Error: Into<ProviderError> + Display>,
42    {
43        Self::default()
44    }
45}
46
47impl<DB, P: NodePrimitives> Executor<DB> for NoopBlockExecutorProvider<P> {
48    type Input<'a> = BlockExecutionInput<'a, BlockWithSenders<P::Block>>;
49    type Output = BlockExecutionOutput<P::Receipt>;
50    type Error = BlockExecutionError;
51
52    fn execute(self, _: Self::Input<'_>) -> Result<Self::Output, Self::Error> {
53        Err(BlockExecutionError::msg(UNAVAILABLE_FOR_NOOP))
54    }
55
56    fn execute_with_state_closure<F>(
57        self,
58        _: Self::Input<'_>,
59        _: F,
60    ) -> Result<Self::Output, Self::Error>
61    where
62        F: FnMut(&State<DB>),
63    {
64        Err(BlockExecutionError::msg(UNAVAILABLE_FOR_NOOP))
65    }
66
67    fn execute_with_state_hook<F>(
68        self,
69        _: Self::Input<'_>,
70        _: F,
71    ) -> Result<Self::Output, Self::Error>
72    where
73        F: OnStateHook,
74    {
75        Err(BlockExecutionError::msg(UNAVAILABLE_FOR_NOOP))
76    }
77}
78
79impl<DB, P: NodePrimitives> BatchExecutor<DB> for NoopBlockExecutorProvider<P> {
80    type Input<'a> = BlockExecutionInput<'a, BlockWithSenders<P::Block>>;
81    type Output = ExecutionOutcome<P::Receipt>;
82    type Error = BlockExecutionError;
83
84    fn execute_and_verify_one(&mut self, _: Self::Input<'_>) -> Result<(), Self::Error> {
85        Err(BlockExecutionError::msg(UNAVAILABLE_FOR_NOOP))
86    }
87
88    fn finalize(self) -> Self::Output {
89        unreachable!()
90    }
91
92    fn set_tip(&mut self, _: BlockNumber) {}
93
94    fn set_prune_modes(&mut self, _: PruneModes) {}
95
96    fn size_hint(&self) -> Option<usize> {
97        None
98    }
99}