diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index 36559061d69f..fbc61eabb9e3 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -21,7 +21,7 @@ use reth_cli::chainspec::ChainSpecParser; use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs}; use reth_cli_runner::CliContext; use reth_consensus::{Consensus, FullConsensus}; -use reth_errors::RethResult; +use reth_errors::{ConsensusError, RethResult}; use reth_ethereum_payload_builder::EthereumBuilderConfig; use reth_evm::execute::{BlockExecutorProvider, Executor}; use reth_execution_types::ExecutionOutcome; @@ -128,7 +128,7 @@ impl> Command { ) -> eyre::Result<()> { let Environment { provider_factory, .. } = self.env.init::(AccessRights::RW)?; - let consensus: Arc = + let consensus: Arc> = Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec())); let executor = EthExecutorProvider::ethereum(provider_factory.chain_spec()); diff --git a/bin/reth/src/commands/debug_cmd/execution.rs b/bin/reth/src/commands/debug_cmd/execution.rs index e25bb6afff66..a7af54d573b7 100644 --- a/bin/reth/src/commands/debug_cmd/execution.rs +++ b/bin/reth/src/commands/debug_cmd/execution.rs @@ -18,6 +18,7 @@ use reth_downloaders::{ bodies::bodies::BodiesDownloaderBuilder, headers::reverse_headers::ReverseHeadersDownloaderBuilder, }; +use reth_errors::ConsensusError; use reth_exex::ExExManagerHandle; use reth_network::{BlockDownloaderProvider, NetworkHandle}; use reth_network_api::NetworkInfo; @@ -64,7 +65,7 @@ impl> Command { &self, config: &Config, client: Client, - consensus: Arc, + consensus: Arc>, provider_factory: ProviderFactory, task_executor: &TaskExecutor, static_file_producer: StaticFileProducer>, @@ -172,7 +173,7 @@ impl> Command { let Environment { provider_factory, config, data_dir } = self.env.init::(AccessRights::RW)?; - let consensus: Arc = + let consensus: Arc> = Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec())); // Configure and build network diff --git a/bin/reth/src/commands/debug_cmd/merkle.rs b/bin/reth/src/commands/debug_cmd/merkle.rs index 59fe2bafaf6c..bb79068bd547 100644 --- a/bin/reth/src/commands/debug_cmd/merkle.rs +++ b/bin/reth/src/commands/debug_cmd/merkle.rs @@ -10,7 +10,7 @@ use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, Environ use reth_cli_runner::CliContext; use reth_cli_util::get_secret_key; use reth_config::Config; -use reth_consensus::Consensus; +use reth_consensus::{Consensus, ConsensusError}; use reth_db::tables; use reth_db_api::{cursor::DbCursorRO, transaction::DbTx}; use reth_evm::execute::{BatchExecutor, BlockExecutorProvider}; @@ -129,7 +129,7 @@ impl> Command { info!(target: "reth::cli", target_block_number=self.to, "Finished downloading tip of block range"); // build the full block client - let consensus: Arc = + let consensus: Arc> = Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec())); let block_range_client = FullBlockClient::new(fetch_client, consensus); diff --git a/bin/reth/src/commands/debug_cmd/replay_engine.rs b/bin/reth/src/commands/debug_cmd/replay_engine.rs index 3d17ea456526..80d60cfb39be 100644 --- a/bin/reth/src/commands/debug_cmd/replay_engine.rs +++ b/bin/reth/src/commands/debug_cmd/replay_engine.rs @@ -12,7 +12,7 @@ use reth_cli_commands::common::{AccessRights, CliNodeTypes, Environment, Environ use reth_cli_runner::CliContext; use reth_cli_util::get_secret_key; use reth_config::Config; -use reth_consensus::FullConsensus; +use reth_consensus::{ConsensusError, FullConsensus}; use reth_db::DatabaseEnv; use reth_engine_util::engine_store::{EngineMessageStore, StoredEngineApiMessage}; use reth_ethereum_payload_builder::EthereumBuilderConfig; @@ -97,7 +97,7 @@ impl> Command { let Environment { provider_factory, config, data_dir } = self.env.init::(AccessRights::RW)?; - let consensus: Arc = + let consensus: Arc> = Arc::new(EthBeaconConsensus::new(provider_factory.chain_spec())); let executor = EthExecutorProvider::ethereum(provider_factory.chain_spec()); diff --git a/crates/blockchain-tree/src/externals.rs b/crates/blockchain-tree/src/externals.rs index 9e72008e838f..ad22417a91d7 100644 --- a/crates/blockchain-tree/src/externals.rs +++ b/crates/blockchain-tree/src/externals.rs @@ -1,7 +1,7 @@ //! Blockchain tree externals. use alloy_primitives::{BlockHash, BlockNumber}; -use reth_consensus::FullConsensus; +use reth_consensus::{ConsensusError, FullConsensus}; use reth_db::{static_file::BlockHashMask, tables}; use reth_db_api::{cursor::DbCursorRO, transaction::DbTx}; use reth_node_types::NodeTypesWithDB; @@ -28,7 +28,7 @@ pub struct TreeExternals { /// The provider factory, used to commit the canonical chain, or unwind it. pub(crate) provider_factory: ProviderFactory, /// The consensus engine. - pub(crate) consensus: Arc, + pub(crate) consensus: Arc>, /// The executor factory to execute blocks with. pub(crate) executor_factory: E, } @@ -37,7 +37,7 @@ impl TreeExternals { /// Create new tree externals. pub fn new( provider_factory: ProviderFactory, - consensus: Arc, + consensus: Arc>, executor_factory: E, ) -> Self { Self { provider_factory, consensus, executor_factory } diff --git a/crates/cli/commands/src/import.rs b/crates/cli/commands/src/import.rs index adb973815731..a73322a903f4 100644 --- a/crates/cli/commands/src/import.rs +++ b/crates/cli/commands/src/import.rs @@ -7,7 +7,7 @@ use reth_beacon_consensus::EthBeaconConsensus; use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_cli::chainspec::ChainSpecParser; use reth_config::Config; -use reth_consensus::Consensus; +use reth_consensus::{Consensus, ConsensusError}; use reth_db::tables; use reth_db_api::transaction::DbTx; use reth_downloaders::{ @@ -169,7 +169,7 @@ pub fn build_import_pipeline( ) -> eyre::Result<(Pipeline, impl Stream>)> where N: ProviderNodeTypes + CliNodeTypes, - C: Consensus, BodyTy> + 'static, + C: Consensus, BodyTy, Error = ConsensusError> + 'static, E: BlockExecutorProvider, { if !file_client.has_canonical_blocks() { diff --git a/crates/consensus/beacon/src/engine/test_utils.rs b/crates/consensus/beacon/src/engine/test_utils.rs index ae627cae6961..56de724aded2 100644 --- a/crates/consensus/beacon/src/engine/test_utils.rs +++ b/crates/consensus/beacon/src/engine/test_utils.rs @@ -13,7 +13,7 @@ use reth_blockchain_tree::{ }; use reth_chainspec::ChainSpec; use reth_config::config::StageConfig; -use reth_consensus::{test_utils::TestConsensus, FullConsensus}; +use reth_consensus::{test_utils::TestConsensus, ConsensusError, FullConsensus}; use reth_db::{test_utils::TempDatabase, DatabaseEnv as DE}; use reth_downloaders::{ bodies::bodies::BodiesDownloaderBuilder, @@ -332,12 +332,13 @@ where let provider_factory = create_test_provider_factory_with_chain_spec(self.base_config.chain_spec.clone()); - let consensus: Arc = match self.base_config.consensus { - TestConsensusConfig::Real => { - Arc::new(EthBeaconConsensus::new(Arc::clone(&self.base_config.chain_spec))) - } - TestConsensusConfig::Test => Arc::new(TestConsensus::default()), - }; + let consensus: Arc> = + match self.base_config.consensus { + TestConsensusConfig::Real => { + Arc::new(EthBeaconConsensus::new(Arc::clone(&self.base_config.chain_spec))) + } + TestConsensusConfig::Test => Arc::new(TestConsensus::default()), + }; let payload_builder = spawn_test_payload_service::(); // use either noop client or a user provided client (for example TestFullBlockClient) diff --git a/crates/consensus/consensus/src/lib.rs b/crates/consensus/consensus/src/lib.rs index ba1b1321e776..1de99d8278f5 100644 --- a/crates/consensus/consensus/src/lib.rs +++ b/crates/consensus/consensus/src/lib.rs @@ -66,12 +66,15 @@ pub trait FullConsensus: /// Consensus is a protocol that chooses canonical chain. #[auto_impl::auto_impl(&, Arc)] pub trait Consensus: AsHeaderValidator { + /// The error type related to consensus. + type Error; + /// Ensures that body field values match the header. fn validate_body_against_header( &self, body: &B, header: &SealedHeader, - ) -> Result<(), ConsensusError>; + ) -> Result<(), Self::Error>; /// Validate a block disregarding world state, i.e. things that can be checked before sender /// recovery and execution. @@ -82,8 +85,7 @@ pub trait Consensus: AsHeaderValidator { /// **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) - -> Result<(), ConsensusError>; + fn validate_block_pre_execution(&self, block: &SealedBlock) -> Result<(), Self::Error>; } /// HeaderValidator is a protocol that validates headers and their relationships. @@ -170,13 +172,13 @@ impl, H> AsHeaderValidator for T { /// Helper trait to cast `Arc` to `Arc` pub trait AsConsensus: Consensus { /// Converts the [`Arc`] of self to [`Arc`] of [`HeaderValidator`] - fn as_consensus<'a>(self: Arc) -> Arc + 'a> + fn as_consensus<'a>(self: Arc) -> Arc + 'a> where Self: 'a; } impl, H, B> AsConsensus for T { - fn as_consensus<'a>(self: Arc) -> Arc + 'a> + fn as_consensus<'a>(self: Arc) -> Arc + 'a> where Self: 'a, { diff --git a/crates/consensus/consensus/src/noop.rs b/crates/consensus/consensus/src/noop.rs index c56e9867a256..ea269c07dada 100644 --- a/crates/consensus/consensus/src/noop.rs +++ b/crates/consensus/consensus/src/noop.rs @@ -30,18 +30,17 @@ impl HeaderValidator for NoopConsensus { } impl Consensus for NoopConsensus { + type Error = ConsensusError; + fn validate_body_against_header( &self, _body: &B, _header: &SealedHeader, - ) -> Result<(), ConsensusError> { + ) -> Result<(), Self::Error> { Ok(()) } - fn validate_block_pre_execution( - &self, - _block: &SealedBlock, - ) -> Result<(), ConsensusError> { + fn validate_block_pre_execution(&self, _block: &SealedBlock) -> Result<(), Self::Error> { Ok(()) } } @@ -51,7 +50,7 @@ impl FullConsensus for NoopConsensus { &self, _block: &BlockWithSenders, _input: PostExecutionInput<'_, N::Receipt>, - ) -> Result<(), ConsensusError> { + ) -> Result<(), Self::Error> { Ok(()) } } diff --git a/crates/consensus/consensus/src/test_utils.rs b/crates/consensus/consensus/src/test_utils.rs index 082c8ca8bb5a..3f26222c4b90 100644 --- a/crates/consensus/consensus/src/test_utils.rs +++ b/crates/consensus/consensus/src/test_utils.rs @@ -61,11 +61,13 @@ impl FullConsensus for TestConsensus { } impl Consensus for TestConsensus { + type Error = ConsensusError; + fn validate_body_against_header( &self, _body: &B, _header: &SealedHeader, - ) -> Result<(), ConsensusError> { + ) -> Result<(), Self::Error> { if self.fail_body_against_header() { Err(ConsensusError::BaseFeeMissing) } else { @@ -73,10 +75,7 @@ impl Consensus for TestConsensus { } } - fn validate_block_pre_execution( - &self, - _block: &SealedBlock, - ) -> Result<(), ConsensusError> { + fn validate_block_pre_execution(&self, _block: &SealedBlock) -> Result<(), Self::Error> { if self.fail_validation() { Err(ConsensusError::BaseFeeMissing) } else { diff --git a/crates/engine/local/src/service.rs b/crates/engine/local/src/service.rs index 3c7bc72baed5..12c24bd6816a 100644 --- a/crates/engine/local/src/service.rs +++ b/crates/engine/local/src/service.rs @@ -18,7 +18,7 @@ use crate::miner::{LocalMiner, MiningMode}; use futures_util::{Stream, StreamExt}; use reth_beacon_consensus::{BeaconConsensusEngineEvent, EngineNodeTypes}; use reth_chainspec::EthChainSpec; -use reth_consensus::FullConsensus; +use reth_consensus::{ConsensusError, FullConsensus}; use reth_engine_primitives::{BeaconEngineMessage, EngineValidator}; use reth_engine_service::service::EngineMessageStream; use reth_engine_tree::{ @@ -64,7 +64,7 @@ where /// Constructor for [`LocalEngineService`]. #[allow(clippy::too_many_arguments)] pub fn new( - consensus: Arc>, + consensus: Arc>, executor_factory: impl BlockExecutorProvider, provider: ProviderFactory, blockchain_db: BlockchainProvider2, diff --git a/crates/engine/service/src/service.rs b/crates/engine/service/src/service.rs index aeaf364a8cdc..5d60182b6e99 100644 --- a/crates/engine/service/src/service.rs +++ b/crates/engine/service/src/service.rs @@ -2,7 +2,7 @@ use futures::{Stream, StreamExt}; use pin_project::pin_project; use reth_beacon_consensus::{BeaconConsensusEngineEvent, EngineNodeTypes}; use reth_chainspec::EthChainSpec; -use reth_consensus::FullConsensus; +use reth_consensus::{ConsensusError, FullConsensus}; use reth_engine_primitives::{BeaconEngineMessage, EngineValidator}; use reth_engine_tree::{ backfill::PipelineSync, @@ -69,7 +69,7 @@ where /// Constructor for `EngineService`. #[allow(clippy::too_many_arguments)] pub fn new( - consensus: Arc>, + consensus: Arc>, executor_factory: E, chain_spec: Arc, client: Client, diff --git a/crates/engine/tree/src/download.rs b/crates/engine/tree/src/download.rs index 1e42e25477b1..262c642f0a87 100644 --- a/crates/engine/tree/src/download.rs +++ b/crates/engine/tree/src/download.rs @@ -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; +use reth_consensus::{Consensus, ConsensusError}; use reth_network_p2p::{ full_block::{FetchFullBlockFuture, FetchFullBlockRangeFuture, FullBlockClient}, BlockClient, @@ -84,7 +84,7 @@ where /// Create a new instance pub fn new( client: Client, - consensus: Arc>, + consensus: Arc>, ) -> Self { Self { full_block_client: FullBlockClient::new(client, consensus), diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 645106c57277..16a86c33f41e 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -474,7 +474,7 @@ where { provider: P, executor_provider: E, - consensus: Arc>, + consensus: Arc>, payload_validator: V, /// Keeps track of internals such as executed and buffered blocks. state: EngineApiTreeState, @@ -561,7 +561,7 @@ where pub fn new( provider: P, executor_provider: E, - consensus: Arc>, + consensus: Arc>, payload_validator: V, outgoing: UnboundedSender>, state: EngineApiTreeState, @@ -609,7 +609,7 @@ where pub fn spawn_new( provider: P, executor_provider: E, - consensus: Arc>, + consensus: Arc>, payload_validator: V, persistence: PersistenceHandle, payload_builder: PayloadBuilderHandle, diff --git a/crates/ethereum/consensus/src/lib.rs b/crates/ethereum/consensus/src/lib.rs index c1ba56b8c624..c31be45e2210 100644 --- a/crates/ethereum/consensus/src/lib.rs +++ b/crates/ethereum/consensus/src/lib.rs @@ -116,18 +116,17 @@ where H: BlockHeader, B: BlockBody, { + type Error = ConsensusError; + fn validate_body_against_header( &self, body: &B, header: &SealedHeader, - ) -> Result<(), ConsensusError> { + ) -> Result<(), Self::Error> { validate_body_against_header(body, header.header()) } - fn validate_block_pre_execution( - &self, - block: &SealedBlock, - ) -> Result<(), ConsensusError> { + fn validate_block_pre_execution(&self, block: &SealedBlock) -> Result<(), Self::Error> { validate_block_pre_execution(block, &self.chain_spec) } } diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index f1a1f56ec048..f37e08ef553f 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -3,6 +3,7 @@ use crate::{EthEngineTypes, EthEvmConfig}; use reth_beacon_consensus::EthBeaconConsensus; use reth_chainspec::ChainSpec; +use reth_consensus::{ConsensusError, FullConsensus}; use reth_ethereum_engine_primitives::{ EthBuiltPayload, EthPayloadAttributes, EthPayloadBuilderAttributes, }; @@ -252,7 +253,7 @@ impl ConsensusBuilder for EthereumConsensusBuilder where Node: FullNodeTypes>, { - type Consensus = Arc; + type Consensus = Arc>; async fn build_consensus(self, ctx: &BuilderContext) -> eyre::Result { Ok(Arc::new(EthBeaconConsensus::new(ctx.chain_spec()))) diff --git a/crates/net/downloaders/src/bodies/bodies.rs b/crates/net/downloaders/src/bodies/bodies.rs index 47a816f4ce6b..454f6bffc562 100644 --- a/crates/net/downloaders/src/bodies/bodies.rs +++ b/crates/net/downloaders/src/bodies/bodies.rs @@ -5,7 +5,7 @@ use alloy_primitives::BlockNumber; use futures::Stream; use futures_util::StreamExt; use reth_config::BodiesConfig; -use reth_consensus::Consensus; +use reth_consensus::{Consensus, ConsensusError}; use reth_network_p2p::{ bodies::{ client::BodiesClient, @@ -39,7 +39,7 @@ pub struct BodiesDownloader { /// The bodies client client: Arc, /// The consensus client - consensus: Arc>, + consensus: Arc>, /// The database handle provider: Provider, /// The maximum number of non-empty blocks per one request @@ -579,7 +579,7 @@ impl BodiesDownloaderBuilder { pub fn build( self, client: B, - consensus: Arc>, + consensus: Arc>, provider: Provider, ) -> BodiesDownloader where diff --git a/crates/net/downloaders/src/bodies/queue.rs b/crates/net/downloaders/src/bodies/queue.rs index 892eae14cbb1..b9f63b143ac2 100644 --- a/crates/net/downloaders/src/bodies/queue.rs +++ b/crates/net/downloaders/src/bodies/queue.rs @@ -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; +use reth_consensus::{Consensus, ConsensusError}; use reth_network_p2p::{ bodies::{client::BodiesClient, response::BlockResponse}, error::DownloadResult, @@ -59,7 +59,7 @@ where pub(crate) fn push_new_request( &mut self, client: Arc, - consensus: Arc>, + consensus: Arc>, request: Vec>, ) { // Set last max requested block number diff --git a/crates/net/downloaders/src/bodies/request.rs b/crates/net/downloaders/src/bodies/request.rs index a3ad1f3b9dc2..79b76f2dbf58 100644 --- a/crates/net/downloaders/src/bodies/request.rs +++ b/crates/net/downloaders/src/bodies/request.rs @@ -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; +use reth_consensus::{Consensus, ConsensusError}; use reth_network_p2p::{ bodies::{client::BodiesClient, response::BlockResponse}, error::{DownloadError, DownloadResult}, @@ -40,7 +40,7 @@ use std::{ /// and eventually disconnected. pub(crate) struct BodiesRequestFuture { client: Arc, - consensus: Arc>, + consensus: Arc>, 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. @@ -62,7 +62,7 @@ where /// Returns an empty future. Use [`BodiesRequestFuture::with_headers`] to set the request. pub(crate) fn new( client: Arc, - consensus: Arc>, + consensus: Arc>, metrics: BodyDownloaderMetrics, ) -> Self { Self { diff --git a/crates/net/downloaders/src/bodies/task.rs b/crates/net/downloaders/src/bodies/task.rs index 9377be78676c..863c889532c3 100644 --- a/crates/net/downloaders/src/bodies/task.rs +++ b/crates/net/downloaders/src/bodies/task.rs @@ -43,7 +43,7 @@ impl TaskDow /// # Example /// /// ``` - /// use reth_consensus::Consensus; + /// use reth_consensus::{Consensus, ConsensusError}; /// use reth_downloaders::bodies::{bodies::BodiesDownloaderBuilder, task::TaskDownloader}; /// use reth_network_p2p::bodies::client::BodiesClient; /// use reth_primitives_traits::InMemorySize; @@ -55,7 +55,7 @@ impl TaskDow /// Provider: HeaderProvider
+ Unpin + 'static, /// >( /// client: Arc, - /// consensus: Arc>, + /// consensus: Arc>, /// provider: Provider, /// ) { /// let downloader = BodiesDownloaderBuilder::default().build(client, consensus, provider); diff --git a/crates/net/p2p/src/full_block.rs b/crates/net/p2p/src/full_block.rs index 62981ad5d9ab..fdee01ab9988 100644 --- a/crates/net/p2p/src/full_block.rs +++ b/crates/net/p2p/src/full_block.rs @@ -7,7 +7,7 @@ use crate::{ }; use alloy_consensus::BlockHeader; use alloy_primitives::{Sealable, B256}; -use reth_consensus::Consensus; +use reth_consensus::{Consensus, ConsensusError}; use reth_eth_wire_types::HeadersDirection; use reth_network_peers::WithPeerId; use reth_primitives::{SealedBlock, SealedHeader}; @@ -30,7 +30,7 @@ where Client: BlockClient, { client: Client, - consensus: Arc>, + consensus: Arc>, } impl FullBlockClient @@ -40,7 +40,7 @@ where /// Creates a new instance of `FullBlockClient`. pub fn new( client: Client, - consensus: Arc>, + consensus: Arc>, ) -> Self { Self { client, consensus } } @@ -118,7 +118,7 @@ where Client: BlockClient, { client: Client, - consensus: Arc>, + consensus: Arc>, hash: B256, request: FullBlockRequest, header: Option>, @@ -330,7 +330,7 @@ where /// The client used to fetch headers and bodies. client: Client, /// The consensus instance used to validate the blocks. - consensus: Arc>, + consensus: Arc>, /// The block hash to start fetching from (inclusive). start_hash: B256, /// How many blocks to fetch: `len([start_hash, ..]) == count` diff --git a/crates/net/p2p/src/test_utils/headers.rs b/crates/net/p2p/src/test_utils/headers.rs index 5809ad6bdd40..6e20b335a107 100644 --- a/crates/net/p2p/src/test_utils/headers.rs +++ b/crates/net/p2p/src/test_utils/headers.rs @@ -12,7 +12,7 @@ use crate::{ }; use alloy_consensus::Header; use futures::{Future, FutureExt, Stream, StreamExt}; -use reth_consensus::{test_utils::TestConsensus, Consensus}; +use reth_consensus::{test_utils::TestConsensus, Consensus, ConsensusError}; use reth_eth_wire_types::HeadersDirection; use reth_network_peers::{PeerId, WithPeerId}; use reth_primitives::SealedHeader; @@ -147,7 +147,11 @@ impl Stream for TestDownload { let empty: SealedHeader = SealedHeader::default(); if let Err(error) = - >::validate_header_against_parent(&this.consensus, &empty, &empty) + >::validate_header_against_parent( + &this.consensus, + &empty, + &empty, + ) { this.done = true; return Poll::Ready(Some(Err(DownloadError::HeaderValidation { diff --git a/crates/node/api/src/node.rs b/crates/node/api/src/node.rs index 8db75480d11a..66c131581892 100644 --- a/crates/node/api/src/node.rs +++ b/crates/node/api/src/node.rs @@ -3,7 +3,7 @@ use crate::ConfigureEvm; use alloy_rpc_types_engine::JwtSecret; use reth_beacon_consensus::BeaconConsensusEngineHandle; -use reth_consensus::FullConsensus; +use reth_consensus::{ConsensusError, FullConsensus}; use reth_db_api::{ database_metrics::{DatabaseMetadata, DatabaseMetrics}, Database, @@ -58,7 +58,10 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static { type Executor: BlockExecutorProvider::Primitives>; /// The consensus type of the node. - type Consensus: FullConsensus<::Primitives> + Clone + Unpin + 'static; + type Consensus: FullConsensus<::Primitives, Error = ConsensusError> + + Clone + + Unpin + + 'static; /// Network API. type Network: FullNetwork; diff --git a/crates/node/builder/src/components/builder.rs b/crates/node/builder/src/components/builder.rs index ce24c8bff8df..977381b6582b 100644 --- a/crates/node/builder/src/components/builder.rs +++ b/crates/node/builder/src/components/builder.rs @@ -7,7 +7,7 @@ use crate::{ }, BuilderContext, ConfigureEvm, FullNodeTypes, }; -use reth_consensus::FullConsensus; +use reth_consensus::{ConsensusError, FullConsensus}; use reth_evm::execute::BlockExecutorProvider; use reth_network::NetworkPrimitives; use reth_node_api::{BodyTy, HeaderTy, NodeTypes, NodeTypesWithEngine, TxTy}; @@ -402,7 +402,10 @@ where + 'static, EVM: ConfigureEvm
, Transaction = TxTy>, Executor: BlockExecutorProvider::Primitives>, - Cons: FullConsensus<::Primitives> + Clone + Unpin + 'static, + Cons: FullConsensus<::Primitives, Error = ConsensusError> + + Clone + + Unpin + + 'static, { type Components = Components; diff --git a/crates/node/builder/src/components/consensus.rs b/crates/node/builder/src/components/consensus.rs index 074080d337b1..0620b2507d2a 100644 --- a/crates/node/builder/src/components/consensus.rs +++ b/crates/node/builder/src/components/consensus.rs @@ -1,4 +1,5 @@ //! Consensus component for the node builder. +use reth_consensus::{ConsensusError, FullConsensus}; use reth_node_api::NodeTypes; use crate::{BuilderContext, FullNodeTypes}; @@ -7,7 +8,7 @@ use std::future::Future; /// A type that knows how to build the consensus implementation. pub trait ConsensusBuilder: Send { /// The consensus implementation to build. - type Consensus: reth_consensus::FullConsensus<::Primitives> + type Consensus: FullConsensus<::Primitives, Error = ConsensusError> + Clone + Unpin + 'static; @@ -22,7 +23,7 @@ pub trait ConsensusBuilder: Send { impl ConsensusBuilder for F where Node: FullNodeTypes, - Consensus: reth_consensus::FullConsensus<::Primitives> + Consensus: FullConsensus<::Primitives, Error = ConsensusError> + Clone + Unpin + 'static, diff --git a/crates/node/builder/src/components/mod.rs b/crates/node/builder/src/components/mod.rs index 892380a4c6ca..c5ac67e5cbc7 100644 --- a/crates/node/builder/src/components/mod.rs +++ b/crates/node/builder/src/components/mod.rs @@ -23,7 +23,7 @@ pub use pool::*; use reth_network_p2p::BlockClient; use crate::{ConfigureEvm, FullNodeTypes}; -use reth_consensus::FullConsensus; +use reth_consensus::{ConsensusError, FullConsensus}; use reth_evm::execute::BlockExecutorProvider; use reth_network::{NetworkHandle, NetworkPrimitives}; use reth_network_api::FullNetwork; @@ -47,7 +47,10 @@ pub trait NodeComponents: Clone + Unpin + Send + Sync + 'stati type Executor: BlockExecutorProvider::Primitives>; /// The consensus type of the node. - type Consensus: FullConsensus<::Primitives> + Clone + Unpin + 'static; + type Consensus: FullConsensus<::Primitives, Error = ConsensusError> + + Clone + + Unpin + + 'static; /// Network API. type Network: FullNetwork< @@ -106,7 +109,10 @@ where + 'static, EVM: ConfigureEvm
, Transaction = TxTy>, Executor: BlockExecutorProvider::Primitives>, - Cons: FullConsensus<::Primitives> + Clone + Unpin + 'static, + Cons: FullConsensus<::Primitives, Error = ConsensusError> + + Clone + + Unpin + + 'static, { type Pool = Pool; type Evm = EVM; diff --git a/crates/node/builder/src/setup.rs b/crates/node/builder/src/setup.rs index 62cfbac9bea8..610ca7bbc799 100644 --- a/crates/node/builder/src/setup.rs +++ b/crates/node/builder/src/setup.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use alloy_primitives::{BlockNumber, B256}; use reth_config::{config::StageConfig, PruneConfig}; -use reth_consensus::Consensus; +use reth_consensus::{Consensus, ConsensusError}; use reth_downloaders::{ bodies::bodies::BodiesDownloaderBuilder, headers::reverse_headers::ReverseHeadersDownloaderBuilder, @@ -27,7 +27,7 @@ use tokio::sync::watch; pub fn build_networked_pipeline( config: &StageConfig, client: Client, - consensus: Arc>, + consensus: Arc>, provider_factory: ProviderFactory, task_executor: &TaskExecutor, metrics_tx: reth_stages::MetricEventsSender, @@ -75,7 +75,7 @@ pub fn build_pipeline( stage_config: &StageConfig, header_downloader: H, body_downloader: B, - consensus: Arc>, + consensus: Arc>, max_block: Option, metrics_tx: reth_stages::MetricEventsSender, prune_config: Option, diff --git a/crates/node/core/src/utils.rs b/crates/node/core/src/utils.rs index 1db9c1f6b9ff..31d847da7fbd 100644 --- a/crates/node/core/src/utils.rs +++ b/crates/node/core/src/utils.rs @@ -5,7 +5,7 @@ use alloy_consensus::BlockHeader; use alloy_eips::BlockHashOrNumber; use alloy_rpc_types_engine::{JwtError, JwtSecret}; use eyre::Result; -use reth_consensus::Consensus; +use reth_consensus::{Consensus, ConsensusError}; use reth_network_p2p::{ bodies::client::BodiesClient, headers::client::HeadersClient, priority::Priority, }; @@ -72,7 +72,7 @@ where pub async fn get_single_body( client: Client, header: SealedHeader, - consensus: impl Consensus, + consensus: impl Consensus, ) -> Result> where Client: BodiesClient, diff --git a/crates/optimism/consensus/src/lib.rs b/crates/optimism/consensus/src/lib.rs index 01f8f9a72f50..7d54b8a049bb 100644 --- a/crates/optimism/consensus/src/lib.rs +++ b/crates/optimism/consensus/src/lib.rs @@ -61,6 +61,8 @@ impl FullConsensus for OpBeaconConsensus { } impl Consensus for OpBeaconConsensus { + type Error = ConsensusError; + fn validate_body_against_header( &self, body: &OpBlockBody, diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 10dab2ab5b31..1e758522e486 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -16,6 +16,7 @@ //! Configure only an http server with a selection of [`RethRpcModule`]s //! //! ``` +//! use reth_consensus::{ConsensusError, FullConsensus}; //! use reth_engine_primitives::PayloadValidator; //! use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm}; //! use reth_network_api::{NetworkInfo, Peers}; @@ -67,7 +68,7 @@ //! CanonStateSubscriptions + Clone + 'static, //! EvmConfig: ConfigureEvm
, //! BlockExecutor: BlockExecutorProvider, -//! Consensus: reth_consensus::FullConsensus + Clone + 'static, +//! Consensus: FullConsensus + Clone + 'static, //! Validator: PayloadValidator, //! { //! // configure the rpc module per transport @@ -99,6 +100,7 @@ //! //! //! ``` +//! use reth_consensus::{ConsensusError, FullConsensus}; //! use reth_engine_primitives::{EngineTypes, PayloadValidator}; //! use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm}; //! use reth_network_api::{NetworkInfo, Peers}; @@ -159,7 +161,7 @@ //! EngineT: EngineTypes, //! EvmConfig: ConfigureEvm
, //! BlockExecutor: BlockExecutorProvider, -//! Consensus: reth_consensus::FullConsensus + Clone + 'static, +//! Consensus: FullConsensus + Clone + 'static, //! Validator: PayloadValidator, //! { //! // configure the rpc module per transport @@ -226,7 +228,7 @@ use jsonrpsee::{ Methods, RpcModule, }; use reth_chainspec::EthereumHardforks; -use reth_consensus::FullConsensus; +use reth_consensus::{ConsensusError, FullConsensus}; use reth_engine_primitives::{EngineTypes, PayloadValidator}; use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm}; use reth_network_api::{noop::NoopNetwork, NetworkInfo, Peers}; @@ -298,7 +300,7 @@ pub async fn launch, block_executor: BlockExecutor, - consensus: Arc>, + consensus: Arc>, payload_validator: Arc>, ) -> Result where @@ -684,7 +686,7 @@ where Transaction = ::SignedTx, >, BlockExecutor: BlockExecutorProvider, - Consensus: reth_consensus::FullConsensus + Clone + 'static, + Consensus: FullConsensus + Clone + 'static, { /// Configures all [`RpcModule`]s specific to the given [`TransportRpcModuleConfig`] which can /// be used to start the transport server(s). @@ -1347,7 +1349,8 @@ where /// Instantiates `ValidationApi` pub fn validation_api(&self) -> ValidationApi where - Consensus: reth_consensus::FullConsensus + Clone + 'static, + Consensus: + FullConsensus + Clone + 'static, Provider: BlockReader::Block>, { ValidationApi::new( @@ -1379,7 +1382,7 @@ where >, >, BlockExecutor: BlockExecutorProvider, - Consensus: reth_consensus::FullConsensus + Clone + 'static, + Consensus: FullConsensus + Clone + 'static, { /// Configures the auth module that includes the /// * `engine_` namespace diff --git a/crates/rpc/rpc/src/validation.rs b/crates/rpc/rpc/src/validation.rs index cb3ab4f296cf..3e65db5a2c96 100644 --- a/crates/rpc/rpc/src/validation.rs +++ b/crates/rpc/rpc/src/validation.rs @@ -43,7 +43,7 @@ where /// Create a new instance of the [`ValidationApi`] pub fn new( provider: Provider, - consensus: Arc>, + consensus: Arc>, executor_provider: E, config: ValidationApiConfig, task_spawner: Box, @@ -461,7 +461,7 @@ pub struct ValidationApiInner { /// The provider that can interact with the chain. provider: Provider, /// Consensus implementation. - consensus: Arc>, + consensus: Arc>, /// Execution payload validator. payload_validator: Arc::Block>>, /// Block executor factory. diff --git a/crates/stages/stages/src/lib.rs b/crates/stages/stages/src/lib.rs index ce6a96cf3496..20c780e24c61 100644 --- a/crates/stages/stages/src/lib.rs +++ b/crates/stages/stages/src/lib.rs @@ -30,11 +30,11 @@ //! # use reth_provider::test_utils::{create_test_provider_factory, MockNodeTypesWithDB}; //! # use reth_static_file::StaticFileProducer; //! # use reth_config::config::StageConfig; -//! # use reth_consensus::Consensus; +//! # use reth_consensus::{Consensus, ConsensusError}; //! # use reth_consensus::test_utils::TestConsensus; //! # //! # let chain_spec = MAINNET.clone(); -//! # let consensus: Arc = Arc::new(TestConsensus::default()); +//! # let consensus: Arc> = Arc::new(TestConsensus::default()); //! # let headers_downloader = ReverseHeadersDownloaderBuilder::default().build( //! # Arc::new(TestHeadersClient::default()), //! # consensus.clone().as_header_validator() diff --git a/crates/stages/stages/src/sets.rs b/crates/stages/stages/src/sets.rs index 53eb23379646..7b8205e25e17 100644 --- a/crates/stages/stages/src/sets.rs +++ b/crates/stages/stages/src/sets.rs @@ -44,7 +44,7 @@ use crate::{ }; use alloy_primitives::B256; use reth_config::config::StageConfig; -use reth_consensus::Consensus; +use reth_consensus::{Consensus, ConsensusError}; use reth_evm::execute::BlockExecutorProvider; use reth_network_p2p::{bodies::downloader::BodyDownloader, headers::downloader::HeaderDownloader}; use reth_provider::HeaderSyncGapProvider; @@ -102,7 +102,7 @@ where pub fn new( provider: Provider, tip: watch::Receiver, - consensus: Arc>, + consensus: Arc>, header_downloader: H, body_downloader: B, executor_factory: E, @@ -185,7 +185,7 @@ where /// The tip for the headers stage. tip: watch::Receiver, /// The consensus engine used to validate incoming data. - consensus: Arc>, + consensus: Arc>, /// The block header downloader header_downloader: H, /// The block body downloader @@ -203,7 +203,7 @@ where pub fn new( provider: Provider, tip: watch::Receiver, - consensus: Arc>, + consensus: Arc>, header_downloader: H, body_downloader: B, stages_config: StageConfig, @@ -236,7 +236,7 @@ where provider: P, tip: watch::Receiver, header_downloader: H, - consensus: Arc>, + consensus: Arc>, stages_config: StageConfig, ) -> StageSetBuilder where