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 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 /// Validates body against header (no-op implementation).
59 fn validate_body_against_header(
60 &self,
61 _body: &B::Body,
62 _header: &SealedHeader<B::Header>,
63 ) -> Result<(), ConsensusError> {
64 Ok(())
65 }
66
67 /// Validates block before execution (no-op implementation).
68 fn validate_block_pre_execution(&self, _block: &SealedBlock<B>) -> Result<(), ConsensusError> {
69 Ok(())
70 }
71}
72
73impl<N: NodePrimitives> FullConsensus<N> for NoopConsensus {
74 /// Validates block after execution (no-op implementation).
75 fn validate_block_post_execution(
76 &self,
77 _block: &RecoveredBlock<N::Block>,
78 _result: &BlockExecutionResult<N::Receipt>,
79 _receipt_root_bloom: Option<ReceiptRootBloom>,
80 ) -> Result<(), ConsensusError> {
81 Ok(())
82 }
83}