reth_consensus/
noop.rs

1use crate::{Consensus, ConsensusError, FullConsensus, HeaderValidator};
2use alloc::sync::Arc;
3use alloy_primitives::U256;
4use reth_execution_types::BlockExecutionResult;
5use reth_primitives_traits::{Block, NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader};
6
7/// A Consensus implementation that does nothing.
8#[derive(Debug, Copy, Clone, Default)]
9#[non_exhaustive]
10pub struct NoopConsensus;
11
12impl NoopConsensus {
13    /// Creates an Arc instance of Self.
14    pub fn arc() -> Arc<Self> {
15        Arc::new(Self::default())
16    }
17}
18
19impl<H> HeaderValidator<H> for NoopConsensus {
20    fn validate_header(&self, _header: &SealedHeader<H>) -> Result<(), ConsensusError> {
21        Ok(())
22    }
23
24    fn validate_header_against_parent(
25        &self,
26        _header: &SealedHeader<H>,
27        _parent: &SealedHeader<H>,
28    ) -> Result<(), ConsensusError> {
29        Ok(())
30    }
31
32    fn validate_header_with_total_difficulty(
33        &self,
34        _header: &H,
35        _total_difficulty: U256,
36    ) -> Result<(), ConsensusError> {
37        Ok(())
38    }
39}
40
41impl<B: Block> Consensus<B> for NoopConsensus {
42    type Error = ConsensusError;
43
44    fn validate_body_against_header(
45        &self,
46        _body: &B::Body,
47        _header: &SealedHeader<B::Header>,
48    ) -> Result<(), Self::Error> {
49        Ok(())
50    }
51
52    fn validate_block_pre_execution(&self, _block: &SealedBlock<B>) -> Result<(), Self::Error> {
53        Ok(())
54    }
55}
56
57impl<N: NodePrimitives> FullConsensus<N> for NoopConsensus {
58    fn validate_block_post_execution(
59        &self,
60        _block: &RecoveredBlock<N::Block>,
61        _result: &BlockExecutionResult<N::Receipt>,
62    ) -> Result<(), ConsensusError> {
63        Ok(())
64    }
65}