reth_consensus/
noop.rs

1//! A consensus implementation that does nothing.
2//!
3//! This module provides `NoopConsensus`, a consensus implementation that performs no validation
4//! and always returns `Ok(())` for all validation methods. Useful for testing and scenarios
5//! where consensus validation is not required.
6//!
7//! # Examples
8//!
9//! ```rust
10//! use reth_consensus::noop::NoopConsensus;
11//! use std::sync::Arc;
12//!
13//! let consensus = NoopConsensus::default();
14//! let consensus_arc = NoopConsensus::arc();
15//! ```
16//!
17//! # Warning
18//!
19//! **Not for production use** - provides no security guarantees or consensus validation.
20
21use crate::{Consensus, ConsensusError, FullConsensus, HeaderValidator};
22use alloc::sync::Arc;
23use reth_execution_types::BlockExecutionResult;
24use reth_primitives_traits::{Block, NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader};
25
26/// A Consensus implementation that does nothing.
27///
28/// Always returns `Ok(())` for all validation methods. Suitable for testing and scenarios
29/// where consensus validation is not required.
30#[derive(Debug, Copy, Clone, Default)]
31#[non_exhaustive]
32pub struct NoopConsensus;
33
34impl NoopConsensus {
35    /// Creates an Arc instance of Self.
36    pub fn arc() -> Arc<Self> {
37        Arc::new(Self::default())
38    }
39}
40
41impl<H> HeaderValidator<H> for NoopConsensus {
42    /// Validates a header (no-op implementation).
43    fn validate_header(&self, _header: &SealedHeader<H>) -> Result<(), ConsensusError> {
44        Ok(())
45    }
46
47    /// Validates a header against its parent (no-op implementation).
48    fn validate_header_against_parent(
49        &self,
50        _header: &SealedHeader<H>,
51        _parent: &SealedHeader<H>,
52    ) -> Result<(), ConsensusError> {
53        Ok(())
54    }
55}
56
57impl<B: Block> Consensus<B> for NoopConsensus {
58    type Error = ConsensusError;
59
60    /// Validates body against header (no-op implementation).
61    fn validate_body_against_header(
62        &self,
63        _body: &B::Body,
64        _header: &SealedHeader<B::Header>,
65    ) -> Result<(), Self::Error> {
66        Ok(())
67    }
68
69    /// Validates block before execution (no-op implementation).
70    fn validate_block_pre_execution(&self, _block: &SealedBlock<B>) -> Result<(), Self::Error> {
71        Ok(())
72    }
73}
74
75impl<N: NodePrimitives> FullConsensus<N> for NoopConsensus {
76    /// Validates block after execution (no-op implementation).
77    fn validate_block_post_execution(
78        &self,
79        _block: &RecoveredBlock<N::Block>,
80        _result: &BlockExecutionResult<N::Receipt>,
81    ) -> Result<(), ConsensusError> {
82        Ok(())
83    }
84}