Skip to main content

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, ReceiptRootBloom};
22use alloc::sync::Arc;
23use alloy_primitives::B256;
24use reth_execution_types::BlockExecutionResult;
25use reth_primitives_traits::{Block, NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader};
26
27/// A Consensus implementation that does nothing.
28///
29/// Always returns `Ok(())` for all validation methods. Suitable for testing and scenarios
30/// where consensus validation is not required.
31#[derive(Debug, Copy, Clone, Default)]
32#[non_exhaustive]
33pub struct NoopConsensus;
34
35impl NoopConsensus {
36    /// Creates an Arc instance of Self.
37    pub fn arc() -> Arc<Self> {
38        Arc::new(Self::default())
39    }
40}
41
42impl<H> HeaderValidator<H> for NoopConsensus {
43    /// Validates a header (no-op implementation).
44    fn validate_header(&self, _header: &SealedHeader<H>) -> Result<(), ConsensusError> {
45        Ok(())
46    }
47
48    /// Validates a header against its parent (no-op implementation).
49    fn validate_header_against_parent(
50        &self,
51        _header: &SealedHeader<H>,
52        _parent: &SealedHeader<H>,
53    ) -> Result<(), ConsensusError> {
54        Ok(())
55    }
56}
57
58impl<B: Block> Consensus<B> for NoopConsensus {
59    /// Validates body against header (no-op implementation).
60    fn validate_body_against_header(
61        &self,
62        _body: &B::Body,
63        _header: &SealedHeader<B::Header>,
64    ) -> Result<(), ConsensusError> {
65        Ok(())
66    }
67
68    /// Validates block before execution (no-op implementation).
69    fn validate_block_pre_execution(&self, _block: &SealedBlock<B>) -> Result<(), ConsensusError> {
70        Ok(())
71    }
72}
73
74impl<N: NodePrimitives> FullConsensus<N> for NoopConsensus {
75    /// Validates block after execution (no-op implementation).
76    fn validate_block_post_execution(
77        &self,
78        _block: &RecoveredBlock<N::Block>,
79        _result: &BlockExecutionResult<N::Receipt>,
80        _receipt_root_bloom: Option<ReceiptRootBloom>,
81        _block_access_list_hash: Option<B256>,
82    ) -> Result<(), ConsensusError> {
83        Ok(())
84    }
85}