Skip to content
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
6 changes: 2 additions & 4 deletions crates/cli/commands/src/import_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ pub async fn import_blocks_from_file<N>(
provider_factory: ProviderFactory<N>,
config: &Config,
executor: impl ConfigureEvm<Primitives = N::Primitives> + 'static,
consensus: Arc<
impl FullConsensus<N::Primitives, Error = reth_consensus::ConsensusError> + 'static,
>,
consensus: Arc<impl FullConsensus<N::Primitives> + 'static>,
) -> eyre::Result<ImportResult>
where
N: ProviderNodeTypes,
Expand Down Expand Up @@ -198,7 +196,7 @@ pub fn build_import_pipeline_impl<N, C, E>(
) -> eyre::Result<(Pipeline<N>, impl futures::Stream<Item = NodeEvent<N::Primitives>> + use<N, C, E>)>
where
N: ProviderNodeTypes,
C: FullConsensus<N::Primitives, Error = reth_consensus::ConsensusError> + 'static,
C: FullConsensus<N::Primitives> + 'static,
E: ConfigureEvm<Primitives = N::Primitives> + 'static,
{
if !file_client.has_canonical_blocks() {
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/commands/src/stage/dump/execution.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::setup;
use reth_consensus::{noop::NoopConsensus, ConsensusError, FullConsensus};
use reth_consensus::{noop::NoopConsensus, FullConsensus};
use reth_db::DatabaseEnv;
use reth_db_api::{
cursor::DbCursorRO, database::Database, table::TableImporter, tables, transaction::DbTx,
Expand Down Expand Up @@ -28,7 +28,7 @@ pub(crate) async fn dump_execution_stage<N, E, C>(
where
N: ProviderNodeTypes<DB = Arc<DatabaseEnv>>,
E: ConfigureEvm<Primitives = N::Primitives> + 'static,
C: FullConsensus<E::Primitives, Error = ConsensusError> + 'static,
C: FullConsensus<E::Primitives> + 'static,
{
let (output_db, tip_block_number) = setup(from, to, &output_datadir.db(), db_tool)?;

Expand Down Expand Up @@ -169,7 +169,7 @@ fn dry_run<N, E, C>(
where
N: ProviderNodeTypes,
E: ConfigureEvm<Primitives = N::Primitives> + 'static,
C: FullConsensus<E::Primitives, Error = ConsensusError> + 'static,
C: FullConsensus<E::Primitives> + 'static,
{
info!(target: "reth::cli", "Executing stage. [dry-run]");

Expand Down
6 changes: 3 additions & 3 deletions crates/cli/commands/src/stage/dump/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::setup;
use alloy_primitives::{Address, BlockNumber};
use eyre::Result;
use reth_config::config::EtlConfig;
use reth_consensus::{ConsensusError, FullConsensus};
use reth_consensus::FullConsensus;
use reth_db::DatabaseEnv;
use reth_db_api::{database::Database, models::BlockNumberAddress, table::TableImporter, tables};
use reth_db_common::DbTool;
Expand All @@ -31,7 +31,7 @@ pub(crate) async fn dump_merkle_stage<N>(
output_datadir: ChainPath<DataDirPath>,
should_run: bool,
evm_config: impl ConfigureEvm<Primitives = N::Primitives>,
consensus: impl FullConsensus<N::Primitives, Error = ConsensusError> + 'static,
consensus: impl FullConsensus<N::Primitives> + 'static,
) -> Result<()>
where
N: ProviderNodeTypes<DB = Arc<DatabaseEnv>>,
Expand Down Expand Up @@ -79,7 +79,7 @@ fn unwind_and_copy<N: ProviderNodeTypes>(
tip_block_number: u64,
output_db: &DatabaseEnv,
evm_config: impl ConfigureEvm<Primitives = N::Primitives>,
consensus: impl FullConsensus<N::Primitives, Error = ConsensusError> + 'static,
consensus: impl FullConsensus<N::Primitives> + 'static,
) -> eyre::Result<()> {
let (from, to) = range;
let provider = db_tool.provider_factory.database_provider_rw()?;
Expand Down
7 changes: 2 additions & 5 deletions crates/consensus/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,12 @@ pub trait FullConsensus<N: NodePrimitives>: Consensus<N::Block> {
/// Consensus is a protocol that chooses canonical chain.
#[auto_impl::auto_impl(&, Arc)]
pub trait Consensus<B: Block>: HeaderValidator<B::Header> {
/// The error type related to consensus.
type Error;

/// Ensures that body field values match the header.
fn validate_body_against_header(
&self,
body: &B::Body,
header: &SealedHeader<B::Header>,
) -> Result<(), Self::Error>;
) -> Result<(), ConsensusError>;

/// Validate a block disregarding world state, i.e. things that can be checked before sender
/// recovery and execution.
Expand All @@ -70,7 +67,7 @@ pub trait Consensus<B: Block>: HeaderValidator<B::Header> {
/// **This should not be called for the genesis block**.
///
/// Note: validating blocks does not include other validations of the Consensus
fn validate_block_pre_execution(&self, block: &SealedBlock<B>) -> Result<(), Self::Error>;
fn validate_block_pre_execution(&self, block: &SealedBlock<B>) -> Result<(), ConsensusError>;
}

/// `HeaderValidator` is a protocol that validates headers and their relationships.
Expand Down
6 changes: 2 additions & 4 deletions crates/consensus/consensus/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,17 @@ impl<H> HeaderValidator<H> for NoopConsensus {
}

impl<B: Block> Consensus<B> for NoopConsensus {
type Error = ConsensusError;

/// Validates body against header (no-op implementation).
fn validate_body_against_header(
&self,
_body: &B::Body,
_header: &SealedHeader<B::Header>,
) -> Result<(), Self::Error> {
) -> Result<(), ConsensusError> {
Ok(())
}

/// Validates block before execution (no-op implementation).
fn validate_block_pre_execution(&self, _block: &SealedBlock<B>) -> Result<(), Self::Error> {
fn validate_block_pre_execution(&self, _block: &SealedBlock<B>) -> Result<(), ConsensusError> {
Ok(())
}
}
Expand Down
6 changes: 2 additions & 4 deletions crates/consensus/consensus/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,19 @@ impl<N: NodePrimitives> FullConsensus<N> for TestConsensus {
}

impl<B: Block> Consensus<B> for TestConsensus {
type Error = ConsensusError;

fn validate_body_against_header(
&self,
_body: &B::Body,
_header: &SealedHeader<B::Header>,
) -> Result<(), Self::Error> {
) -> Result<(), ConsensusError> {
if self.fail_body_against_header() {
Err(ConsensusError::BaseFeeMissing)
} else {
Ok(())
}
}

fn validate_block_pre_execution(&self, _block: &SealedBlock<B>) -> Result<(), Self::Error> {
fn validate_block_pre_execution(&self, _block: &SealedBlock<B>) -> Result<(), ConsensusError> {
if self.fail_validation() {
Err(ConsensusError::BaseFeeMissing)
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/service/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use futures::{Stream, StreamExt};
use pin_project::pin_project;
use reth_chainspec::EthChainSpec;
use reth_consensus::{ConsensusError, FullConsensus};
use reth_consensus::FullConsensus;
use reth_engine_primitives::{BeaconEngineMessage, ConsensusEngineEvent};
use reth_engine_tree::{
backfill::PipelineSync,
Expand Down Expand Up @@ -70,7 +70,7 @@ where
/// Constructor for `EngineService`.
#[expect(clippy::too_many_arguments)]
pub fn new<V, C>(
consensus: Arc<dyn FullConsensus<N::Primitives, Error = ConsensusError>>,
consensus: Arc<dyn FullConsensus<N::Primitives>>,
chain_spec: Arc<N::ChainSpec>,
client: Client,
incoming_requests: EngineMessageStream<N::Payload>,
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/tree/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{engine::DownloadRequest, metrics::BlockDownloaderMetrics};
use alloy_consensus::BlockHeader;
use alloy_primitives::B256;
use futures::FutureExt;
use reth_consensus::{Consensus, ConsensusError};
use reth_consensus::Consensus;
use reth_network_p2p::{
full_block::{FetchFullBlockFuture, FetchFullBlockRangeFuture, FullBlockClient},
BlockClient,
Expand Down Expand Up @@ -81,7 +81,7 @@ where
B: Block,
{
/// Create a new instance
pub fn new(client: Client, consensus: Arc<dyn Consensus<B, Error = ConsensusError>>) -> Self {
pub fn new(client: Client, consensus: Arc<dyn Consensus<B>>) -> Self {
Self {
full_block_client: FullBlockClient::new(client, consensus),
inflight_full_block_requests: Vec::new(),
Expand Down
6 changes: 3 additions & 3 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ where
C: ConfigureEvm<Primitives = N> + 'static,
{
provider: P,
consensus: Arc<dyn FullConsensus<N, Error = ConsensusError>>,
consensus: Arc<dyn FullConsensus<N>>,
payload_validator: V,
/// Keeps track of internals such as executed and buffered blocks.
state: EngineApiTreeState<N>,
Expand Down Expand Up @@ -326,7 +326,7 @@ where
#[expect(clippy::too_many_arguments)]
pub fn new(
provider: P,
consensus: Arc<dyn FullConsensus<N, Error = ConsensusError>>,
consensus: Arc<dyn FullConsensus<N>>,
payload_validator: V,
outgoing: UnboundedSender<EngineApiEvent<N>>,
state: EngineApiTreeState<N>,
Expand Down Expand Up @@ -368,7 +368,7 @@ where
#[expect(clippy::complexity)]
pub fn spawn_new(
provider: P,
consensus: Arc<dyn FullConsensus<N, Error = ConsensusError>>,
consensus: Arc<dyn FullConsensus<N>>,
payload_validator: V,
persistence: PersistenceHandle<N>,
payload_builder: PayloadBuilderHandle<T>,
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/tree/src/tree/payload_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where
/// Provider for database access.
provider: P,
/// Consensus implementation for validation.
consensus: Arc<dyn FullConsensus<Evm::Primitives, Error = ConsensusError>>,
consensus: Arc<dyn FullConsensus<Evm::Primitives>>,
/// EVM configuration.
evm_config: Evm,
/// Configuration for the tree.
Expand Down Expand Up @@ -149,7 +149,7 @@ where
#[allow(clippy::too_many_arguments)]
pub fn new(
provider: P,
consensus: Arc<dyn FullConsensus<N, Error = ConsensusError>>,
consensus: Arc<dyn FullConsensus<N>>,
evm_config: Evm,
validator: V,
config: TreeConfig,
Expand Down
6 changes: 2 additions & 4 deletions crates/ethereum/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,15 @@ where
B: Block,
ChainSpec: EthChainSpec<Header = B::Header> + EthereumHardforks + Debug + Send + Sync,
{
type Error = ConsensusError;

fn validate_body_against_header(
&self,
body: &B::Body,
header: &SealedHeader<B::Header>,
) -> Result<(), Self::Error> {
) -> Result<(), ConsensusError> {
validate_body_against_header(body, header.header())
}

fn validate_block_pre_execution(&self, block: &SealedBlock<B>) -> Result<(), Self::Error> {
fn validate_block_pre_execution(&self, block: &SealedBlock<B>) -> Result<(), ConsensusError> {
validate_block_pre_execution(block, &self.chain_spec)
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/net/downloaders/src/bodies/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use alloy_primitives::BlockNumber;
use futures::Stream;
use futures_util::StreamExt;
use reth_config::BodiesConfig;
use reth_consensus::{Consensus, ConsensusError};
use reth_consensus::Consensus;
use reth_network_p2p::{
bodies::{
client::BodiesClient,
Expand Down Expand Up @@ -41,7 +41,7 @@ pub struct BodiesDownloader<
/// The bodies client
client: Arc<C>,
/// The consensus client
consensus: Arc<dyn Consensus<B, Error = ConsensusError>>,
consensus: Arc<dyn Consensus<B>>,
/// The database handle
provider: Provider,
/// The maximum number of non-empty blocks per one request
Expand Down Expand Up @@ -577,7 +577,7 @@ impl BodiesDownloaderBuilder {
pub fn build<B, C, Provider>(
self,
client: C,
consensus: Arc<dyn Consensus<B, Error = ConsensusError>>,
consensus: Arc<dyn Consensus<B>>,
provider: Provider,
) -> BodiesDownloader<B, C, Provider>
where
Expand Down
4 changes: 2 additions & 2 deletions crates/net/downloaders/src/bodies/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy_consensus::BlockHeader;
use alloy_primitives::BlockNumber;
use futures::{stream::FuturesUnordered, Stream};
use futures_util::StreamExt;
use reth_consensus::{Consensus, ConsensusError};
use reth_consensus::Consensus;
use reth_network_p2p::{
bodies::{client::BodiesClient, response::BlockResponse},
error::DownloadResult,
Expand Down Expand Up @@ -58,7 +58,7 @@ where
pub(crate) fn push_new_request(
&mut self,
client: Arc<C>,
consensus: Arc<dyn Consensus<B, Error = ConsensusError>>,
consensus: Arc<dyn Consensus<B>>,
request: Vec<SealedHeader<B::Header>>,
) {
// Set last max requested block number
Expand Down
6 changes: 3 additions & 3 deletions crates/net/downloaders/src/bodies/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::metrics::{BodyDownloaderMetrics, ResponseMetrics};
use alloy_consensus::BlockHeader;
use alloy_primitives::B256;
use futures::{Future, FutureExt};
use reth_consensus::{Consensus, ConsensusError};
use reth_consensus::Consensus;
use reth_network_p2p::{
bodies::{client::BodiesClient, response::BlockResponse},
error::{DownloadError, DownloadResult},
Expand Down Expand Up @@ -38,7 +38,7 @@ use std::{
/// and eventually disconnected.
pub(crate) struct BodiesRequestFuture<B: Block, C: BodiesClient<Body = B::Body>> {
client: Arc<C>,
consensus: Arc<dyn Consensus<B, Error = ConsensusError>>,
consensus: Arc<dyn Consensus<B>>,
metrics: BodyDownloaderMetrics,
/// Metrics for individual responses. This can be used to observe how the size (in bytes) of
/// responses change while bodies are being downloaded.
Expand All @@ -60,7 +60,7 @@ where
/// Returns an empty future. Use [`BodiesRequestFuture::with_headers`] to set the request.
pub(crate) fn new(
client: Arc<C>,
consensus: Arc<dyn Consensus<B, Error = ConsensusError>>,
consensus: Arc<dyn Consensus<B>>,
metrics: BodyDownloaderMetrics,
) -> Self {
Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/net/downloaders/src/bodies/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<B: Block + 'static> TaskDownloader<B> {
/// # Example
///
/// ```
/// use reth_consensus::{Consensus, ConsensusError};
/// use reth_consensus::Consensus;
/// use reth_downloaders::bodies::{bodies::BodiesDownloaderBuilder, task::TaskDownloader};
/// use reth_network_p2p::bodies::client::BodiesClient;
/// use reth_primitives_traits::{Block, InMemorySize};
Expand All @@ -55,7 +55,7 @@ impl<B: Block + 'static> TaskDownloader<B> {
/// Provider: HeaderProvider<Header = B::Header> + Unpin + 'static,
/// >(
/// client: Arc<C>,
/// consensus: Arc<dyn Consensus<B, Error = ConsensusError>>,
/// consensus: Arc<dyn Consensus<B>>,
/// provider: Provider,
/// ) {
/// let downloader =
Expand Down
8 changes: 4 additions & 4 deletions crates/net/downloaders/src/file_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<B: FullBlock> FileClient<B> {
/// Create a new file client from a file path.
pub async fn new<P: AsRef<Path>>(
path: P,
consensus: Arc<dyn Consensus<B, Error = ConsensusError>>,
consensus: Arc<dyn Consensus<B>>,
) -> Result<Self, FileClientError> {
let file = File::open(path).await?;
Self::from_file(file, consensus).await
Expand All @@ -95,7 +95,7 @@ impl<B: FullBlock> FileClient<B> {
/// Initialize the [`FileClient`] with a file directly.
pub(crate) async fn from_file(
mut file: File,
consensus: Arc<dyn Consensus<B, Error = ConsensusError>>,
consensus: Arc<dyn Consensus<B>>,
) -> Result<Self, FileClientError> {
// get file len from metadata before reading
let metadata = file.metadata().await?;
Expand Down Expand Up @@ -200,7 +200,7 @@ impl<B: FullBlock> FileClient<B> {
}

struct FileClientBuilder<B: Block> {
pub consensus: Arc<dyn Consensus<B, Error = ConsensusError>>,
pub consensus: Arc<dyn Consensus<B>>,
pub parent_header: Option<SealedHeader<B::Header>>,
}

Expand Down Expand Up @@ -562,7 +562,7 @@ impl ChunkedFileReader {
/// are available before processing. For plain files, it uses the original chunking logic.
pub async fn next_chunk<B: FullBlock>(
&mut self,
consensus: Arc<dyn Consensus<B, Error = ConsensusError>>,
consensus: Arc<dyn Consensus<B>>,
parent_header: Option<SealedHeader<B::Header>>,
) -> Result<Option<FileClient<B>>, FileClientError> {
let Some(chunk_len) = self.read_next_chunk().await? else { return Ok(None) };
Expand Down
Loading
Loading