Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use noop consensus for op import #8462

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions bin/reth/src/commands/import_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::{
version::SHORT_VERSION,
};
use clap::Parser;
use reth_beacon_consensus::EthBeaconConsensus;
use reth_config::{config::EtlConfig, Config};
use reth_consensus::noop::NoopConsensus;
use reth_db::{init_db, tables, transaction::DbTx};
use reth_db_common::init::init_genesis;
use reth_downloaders::file_client::{
Expand Down Expand Up @@ -98,8 +98,8 @@ impl ImportOpCommand {

init_genesis(provider_factory.clone())?;

let consensus = Arc::new(EthBeaconConsensus::new(chain_spec.clone()));
info!(target: "reth::cli", "Consensus engine initialized");
// we use noop here because we expect the inputs to be valid
let consensus = Arc::new(NoopConsensus::default());

// open file
let mut reader = ChunkedFileReader::new(&self.path, self.chunk_len).await?;
Expand Down
1 change: 0 additions & 1 deletion crates/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ workspace = true
[dependencies]
# reth
reth-primitives.workspace = true
reth-optimism-primitives.workspace = true
reth-consensus.workspace = true

[dev-dependencies]
Expand Down
7 changes: 2 additions & 5 deletions crates/consensus/common/src/validation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Collection of methods for block validation.

use reth_consensus::ConsensusError;
use reth_optimism_primitives::bedrock_import::is_dup_tx;
use reth_primitives::{
constants::{
eip4844::{DATA_GAS_PER_BLOB, MAX_DATA_GAS_PER_BLOCK},
Expand Down Expand Up @@ -82,10 +81,8 @@ pub fn validate_block_pre_execution(
}

// Check transaction root
if !chain_spec.is_optimism_mainnet() || !is_dup_tx(block.number) {
if let Err(error) = block.ensure_transaction_root_valid() {
return Err(ConsensusError::BodyTransactionRootDiff(error.into()))
}
if let Err(error) = block.ensure_transaction_root_valid() {
return Err(ConsensusError::BodyTransactionRootDiff(error.into()))
}

// EIP-4895: Beacon chain push withdrawals as operations
Expand Down
3 changes: 3 additions & 0 deletions crates/consensus/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ use reth_primitives::{
};
use std::fmt::Debug;

/// A consensus implementation that does nothing.
pub mod noop;

#[cfg(any(test, feature = "test-utils"))]
/// test helpers for mocking consensus
pub mod test_utils;
Expand Down
41 changes: 41 additions & 0 deletions crates/consensus/consensus/src/noop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::{Consensus, ConsensusError, PostExecutionInput};
use reth_primitives::{BlockWithSenders, Header, SealedBlock, SealedHeader, U256};

/// A Consensus implementation that does nothing.
#[derive(Debug, Copy, Clone, Default)]
#[non_exhaustive]
pub struct NoopConsensus;

impl Consensus for NoopConsensus {
fn validate_header(&self, _header: &SealedHeader) -> Result<(), ConsensusError> {
Ok(())
}

fn validate_header_against_parent(
&self,
_header: &SealedHeader,
_parent: &SealedHeader,
) -> Result<(), ConsensusError> {
Ok(())
}

fn validate_header_with_total_difficulty(
&self,
_header: &Header,
_total_difficulty: U256,
) -> Result<(), ConsensusError> {
Ok(())
}

fn validate_block_pre_execution(&self, _block: &SealedBlock) -> Result<(), ConsensusError> {
Ok(())
}

fn validate_block_post_execution(
&self,
_block: &BlockWithSenders,
_input: PostExecutionInput<'_>,
) -> Result<(), ConsensusError> {
Ok(())
}
}
Loading