diff --git a/Cargo.lock b/Cargo.lock index d7effc49c..6802524cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6064,6 +6064,7 @@ dependencies = [ "reth-blockchain-tree", "reth-cli-runner", "reth-config", + "reth-consensus", "reth-consensus-common", "reth-db", "reth-discv4", @@ -6114,12 +6115,14 @@ version = "0.2.0-beta.6" dependencies = [ "futures-util", "reth-beacon-consensus", + "reth-consensus", "reth-engine-primitives", "reth-evm", "reth-interfaces", "reth-primitives", "reth-provider", "reth-revm", + "reth-rpc-types", "reth-stages-api", "reth-transaction-pool", "tokio", @@ -6159,6 +6162,7 @@ dependencies = [ "reth-beacon-consensus-core", "reth-blockchain-tree", "reth-config", + "reth-consensus", "reth-db", "reth-downloaders", "reth-engine-primitives", @@ -6191,8 +6195,8 @@ dependencies = [ name = "reth-beacon-consensus-core" version = "0.2.0-beta.6" dependencies = [ + "reth-consensus", "reth-consensus-common", - "reth-interfaces", "reth-primitives", ] @@ -6206,6 +6210,7 @@ dependencies = [ "lru", "metrics", "parking_lot 0.12.1", + "reth-consensus", "reth-db", "reth-interfaces", "reth-metrics", @@ -6274,11 +6279,21 @@ dependencies = [ "toml", ] +[[package]] +name = "reth-consensus" +version = "0.2.0-beta.6" +dependencies = [ + "auto_impl", + "reth-primitives", + "thiserror", +] + [[package]] name = "reth-consensus-common" version = "0.2.0-beta.6" dependencies = [ "mockall", + "reth-consensus", "reth-interfaces", "reth-primitives", "reth-provider", @@ -6405,6 +6420,7 @@ dependencies = [ "rand 0.8.5", "rayon", "reth-config", + "reth-consensus", "reth-db", "reth-interfaces", "reth-metrics", @@ -6649,10 +6665,10 @@ dependencies = [ "futures", "parking_lot 0.12.1", "rand 0.8.5", + "reth-consensus", "reth-eth-wire-types", "reth-network-api", "reth-primitives", - "reth-rpc-types", "secp256k1 0.27.0", "thiserror", "tokio", @@ -6781,6 +6797,7 @@ dependencies = [ "pin-project", "pprof", "rand 0.8.5", + "reth-consensus", "reth-discv4", "reth-discv5", "reth-dns-discovery", @@ -6875,6 +6892,7 @@ dependencies = [ "reth-beacon-consensus", "reth-blockchain-tree", "reth-config", + "reth-consensus", "reth-db", "reth-downloaders", "reth-exex", @@ -6993,12 +7011,12 @@ dependencies = [ "pin-project", "reth-beacon-consensus", "reth-db", - "reth-interfaces", "reth-network", "reth-network-api", "reth-primitives", "reth-provider", "reth-prune", + "reth-rpc-types", "reth-stages", "reth-static-file", "tokio", @@ -7173,6 +7191,7 @@ dependencies = [ "reth-metrics", "reth-nippy-jar", "reth-primitives", + "reth-rpc-types", "reth-trie", "revm", "strum 0.26.2", @@ -7422,6 +7441,7 @@ dependencies = [ "rayon", "reth-codecs", "reth-config", + "reth-consensus", "reth-db", "reth-downloaders", "reth-etl", @@ -7450,6 +7470,7 @@ dependencies = [ "auto_impl", "futures-util", "metrics", + "reth-consensus", "reth-db", "reth-interfaces", "reth-metrics", diff --git a/Cargo.toml b/Cargo.toml index 8cf53ef55..1fb403e1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "crates/consensus/beacon/", "crates/consensus/beacon-core/", "crates/consensus/common/", + "crates/consensus/consensus/", "crates/ethereum-forks/", "crates/e2e-test-utils/", "crates/etl/", @@ -84,7 +85,7 @@ members = [ "examples/custom-inspector/", "examples/exex/minimal/", "examples/exex/op-bridge/", - "testing/ef-tests/", + "testing/ef-tests/" ] default-members = ["bin/reth"] @@ -207,6 +208,7 @@ reth-blockchain-tree = { path = "crates/blockchain-tree" } reth-cli-runner = { path = "crates/cli/runner" } reth-codecs = { path = "crates/storage/codecs" } reth-config = { path = "crates/config" } +reth-consensus = { path = "crates/consensus/consensus" } reth-consensus-common = { path = "crates/consensus/common" } reth-db = { path = "crates/storage/db" } reth-discv4 = { path = "crates/net/discv4" } diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index ea1ee87f0..ff2515464 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -56,6 +56,7 @@ reth-node-optimism = { workspace = true, optional = true, features = [ reth-node-core.workspace = true reth-node-builder.workspace = true reth-node-events.workspace = true +reth-consensus.workspace = true # crypto alloy-rlp.workspace = true diff --git a/bin/reth/src/commands/debug_cmd/build_block.rs b/bin/reth/src/commands/debug_cmd/build_block.rs index 566198ec8..7aaef00fa 100644 --- a/bin/reth/src/commands/debug_cmd/build_block.rs +++ b/bin/reth/src/commands/debug_cmd/build_block.rs @@ -18,8 +18,9 @@ use reth_blockchain_tree::{ BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals, }; use reth_cli_runner::CliContext; +use reth_consensus::Consensus; use reth_db::{init_db, DatabaseEnv}; -use reth_interfaces::{consensus::Consensus, RethResult}; +use reth_interfaces::RethResult; use reth_node_api::PayloadBuilderAttributes; #[cfg(not(feature = "optimism"))] use reth_node_ethereum::EthEvmConfig; diff --git a/bin/reth/src/commands/debug_cmd/execution.rs b/bin/reth/src/commands/debug_cmd/execution.rs index 10f485a73..2384a9af0 100644 --- a/bin/reth/src/commands/debug_cmd/execution.rs +++ b/bin/reth/src/commands/debug_cmd/execution.rs @@ -14,16 +14,14 @@ use futures::{stream::select as stream_select, StreamExt}; use reth_beacon_consensus::BeaconConsensus; use reth_cli_runner::CliContext; use reth_config::{config::EtlConfig, Config}; +use reth_consensus::Consensus; use reth_db::{database::Database, init_db, DatabaseEnv}; use reth_downloaders::{ bodies::bodies::BodiesDownloaderBuilder, headers::reverse_headers::ReverseHeadersDownloaderBuilder, }; use reth_exex::ExExManagerHandle; -use reth_interfaces::{ - consensus::Consensus, - p2p::{bodies::client::BodiesClient, headers::client::HeadersClient}, -}; +use reth_interfaces::p2p::{bodies::client::BodiesClient, headers::client::HeadersClient}; use reth_network::{NetworkEvents, NetworkHandle}; use reth_network_api::NetworkInfo; use reth_node_core::init::init_genesis; diff --git a/bin/reth/src/commands/debug_cmd/merkle.rs b/bin/reth/src/commands/debug_cmd/merkle.rs index ed8783e96..d806306d4 100644 --- a/bin/reth/src/commands/debug_cmd/merkle.rs +++ b/bin/reth/src/commands/debug_cmd/merkle.rs @@ -14,9 +14,10 @@ use clap::Parser; use reth_beacon_consensus::BeaconConsensus; use reth_cli_runner::CliContext; use reth_config::Config; +use reth_consensus::Consensus; use reth_db::{cursor::DbCursorRO, init_db, tables, transaction::DbTx, DatabaseEnv}; use reth_exex::ExExManagerHandle; -use reth_interfaces::{consensus::Consensus, p2p::full_block::FullBlockClient}; +use reth_interfaces::p2p::full_block::FullBlockClient; use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; use reth_node_ethereum::EthEvmConfig; diff --git a/bin/reth/src/commands/debug_cmd/replay_engine.rs b/bin/reth/src/commands/debug_cmd/replay_engine.rs index 0ef866396..841b9e3c6 100644 --- a/bin/reth/src/commands/debug_cmd/replay_engine.rs +++ b/bin/reth/src/commands/debug_cmd/replay_engine.rs @@ -15,8 +15,8 @@ use reth_blockchain_tree::{ }; use reth_cli_runner::CliContext; use reth_config::Config; +use reth_consensus::Consensus; use reth_db::{init_db, DatabaseEnv}; -use reth_interfaces::consensus::Consensus; use reth_network::NetworkHandle; use reth_network_api::NetworkInfo; use reth_node_core::engine_api_store::{EngineApiStore, StoredEngineApiMessage}; diff --git a/bin/reth/src/commands/import.rs b/bin/reth/src/commands/import.rs index dc3140924..4542f10be 100644 --- a/bin/reth/src/commands/import.rs +++ b/bin/reth/src/commands/import.rs @@ -13,6 +13,7 @@ use eyre::Context; use futures::{Stream, StreamExt}; use reth_beacon_consensus::BeaconConsensus; use reth_config::{config::EtlConfig, Config}; +use reth_consensus::Consensus; use reth_db::{database::Database, init_db}; use reth_downloaders::{ bodies::bodies::BodiesDownloaderBuilder, @@ -20,12 +21,9 @@ use reth_downloaders::{ headers::reverse_headers::ReverseHeadersDownloaderBuilder, }; use reth_exex::ExExManagerHandle; -use reth_interfaces::{ - consensus::Consensus, - p2p::{ - bodies::downloader::BodyDownloader, - headers::downloader::{HeaderDownloader, SyncTarget}, - }, +use reth_interfaces::p2p::{ + bodies::downloader::BodyDownloader, + headers::downloader::{HeaderDownloader, SyncTarget}, }; use reth_node_core::init::init_genesis; use reth_node_ethereum::EthEvmConfig; diff --git a/bin/reth/src/commands/stage/unwind.rs b/bin/reth/src/commands/stage/unwind.rs index 7810a4416..a1fe7d8a0 100644 --- a/bin/reth/src/commands/stage/unwind.rs +++ b/bin/reth/src/commands/stage/unwind.rs @@ -10,13 +10,13 @@ use crate::{ use clap::{Parser, Subcommand}; use reth_beacon_consensus::BeaconConsensus; use reth_config::{Config, PruneConfig}; +use reth_consensus::Consensus; use reth_db::{database::Database, open_db}; use reth_downloaders::{ bodies::bodies::BodiesDownloaderBuilder, headers::reverse_headers::ReverseHeadersDownloaderBuilder, }; use reth_exex::ExExManagerHandle; -use reth_interfaces::consensus::Consensus; use reth_node_core::{ args::{get_secret_key, NetworkArgs}, dirs::ChainPath, diff --git a/crates/blockchain-tree/Cargo.toml b/crates/blockchain-tree/Cargo.toml index 3a6ab1439..1757b2939 100644 --- a/crates/blockchain-tree/Cargo.toml +++ b/crates/blockchain-tree/Cargo.toml @@ -19,6 +19,7 @@ reth-provider.workspace = true reth-stages-api.workspace = true reth-trie = { workspace = true, features = ["metrics"] } reth-trie-parallel = { workspace = true, features = ["parallel"] } +reth-consensus.workspace = true # common parking_lot.workspace = true diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 02bae76bb..799e7e343 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -5,13 +5,13 @@ use crate::{ state::{BlockChainId, TreeState}, AppendableChain, BlockIndices, BlockchainTreeConfig, BundleStateData, TreeExternals, }; +use reth_consensus::{Consensus, ConsensusError}; use reth_db::database::Database; use reth_interfaces::{ blockchain_tree::{ error::{BlockchainTreeError, CanonicalError, InsertBlockError, InsertBlockErrorKind}, BlockAttachment, BlockStatus, BlockValidationKind, CanonicalOutcome, InsertPayloadOk, }, - consensus::{Consensus, ConsensusError}, executor::{BlockExecutionError, BlockValidationError}, provider::RootMismatch, RethResult, diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index 2444cf24a..c091b800a 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -5,13 +5,13 @@ use super::externals::TreeExternals; use crate::BundleStateDataRef; +use reth_consensus::{Consensus, ConsensusError}; use reth_db::database::Database; use reth_interfaces::{ blockchain_tree::{ error::{BlockchainTreeError, InsertBlockErrorKind}, BlockAttachment, BlockValidationKind, }, - consensus::{Consensus, ConsensusError}, RethResult, }; use reth_primitives::{ diff --git a/crates/blockchain-tree/src/externals.rs b/crates/blockchain-tree/src/externals.rs index 5a288271e..c3bda1ae2 100644 --- a/crates/blockchain-tree/src/externals.rs +++ b/crates/blockchain-tree/src/externals.rs @@ -1,9 +1,10 @@ //! Blockchain tree externals. +use reth_consensus::Consensus; use reth_db::{ cursor::DbCursorRO, database::Database, static_file::HeaderMask, tables, transaction::DbTx, }; -use reth_interfaces::{consensus::Consensus, RethResult}; +use reth_interfaces::RethResult; use reth_primitives::{BlockHash, BlockNumber, StaticFileSegment}; use reth_provider::{ProviderFactory, StatsReader}; use std::{collections::BTreeMap, sync::Arc}; diff --git a/crates/consensus/auto-seal/Cargo.toml b/crates/consensus/auto-seal/Cargo.toml index 5fbf4f07a..ec96426a4 100644 --- a/crates/consensus/auto-seal/Cargo.toml +++ b/crates/consensus/auto-seal/Cargo.toml @@ -22,6 +22,8 @@ reth-revm.workspace = true reth-transaction-pool.workspace = true reth-evm.workspace = true reth-engine-primitives.workspace = true +reth-consensus.workspace = true +reth-rpc-types.workspace = true # async futures-util.workspace = true diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index 62a293664..f6de63979 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -16,12 +16,10 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] use reth_beacon_consensus::BeaconEngineMessage; +use reth_consensus::{Consensus, ConsensusError}; use reth_engine_primitives::EngineTypes; use reth_evm::ConfigureEvm; -use reth_interfaces::{ - consensus::{Consensus, ConsensusError}, - executor::{BlockExecutionError, BlockValidationError}, -}; +use reth_interfaces::executor::{BlockExecutionError, BlockValidationError}; use reth_primitives::{ constants::{EMPTY_RECEIPTS, EMPTY_TRANSACTIONS, ETHEREUM_BLOCK_GAS_LIMIT}, eip4844::calculate_excess_blob_gas, diff --git a/crates/consensus/auto-seal/src/task.rs b/crates/consensus/auto-seal/src/task.rs index e76b4333e..53bfc6356 100644 --- a/crates/consensus/auto-seal/src/task.rs +++ b/crates/consensus/auto-seal/src/task.rs @@ -3,9 +3,9 @@ use futures_util::{future::BoxFuture, FutureExt}; use reth_beacon_consensus::{BeaconEngineMessage, ForkchoiceStatus}; use reth_engine_primitives::EngineTypes; use reth_evm::ConfigureEvm; -use reth_interfaces::consensus::ForkchoiceState; use reth_primitives::{Block, ChainSpec, IntoRecoveredTransaction, SealedBlockWithSenders}; use reth_provider::{CanonChainTracker, CanonStateNotificationSender, Chain, StateProviderFactory}; +use reth_rpc_types::engine::ForkchoiceState; use reth_stages_api::PipelineEvent; use reth_transaction_pool::{TransactionPool, ValidPoolTransaction}; use std::{ diff --git a/crates/consensus/beacon-core/Cargo.toml b/crates/consensus/beacon-core/Cargo.toml index 232631f73..b5c778b05 100644 --- a/crates/consensus/beacon-core/Cargo.toml +++ b/crates/consensus/beacon-core/Cargo.toml @@ -14,7 +14,7 @@ workspace = true # reth reth-consensus-common.workspace = true reth-primitives.workspace = true -reth-interfaces.workspace = true +reth-consensus.workspace = true [features] optimism = ["reth-primitives/optimism"] \ No newline at end of file diff --git a/crates/consensus/beacon-core/src/lib.rs b/crates/consensus/beacon-core/src/lib.rs index 599e01009..c2a3df6e6 100644 --- a/crates/consensus/beacon-core/src/lib.rs +++ b/crates/consensus/beacon-core/src/lib.rs @@ -8,8 +8,8 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +use reth_consensus::{Consensus, ConsensusError}; use reth_consensus_common::validation; -use reth_interfaces::consensus::{Consensus, ConsensusError}; use reth_primitives::{ constants::MAXIMUM_EXTRA_DATA_SIZE, Chain, ChainSpec, Hardfork, Header, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT_HASH, U256, diff --git a/crates/consensus/beacon/Cargo.toml b/crates/consensus/beacon/Cargo.toml index 439002ec5..0fed12597 100644 --- a/crates/consensus/beacon/Cargo.toml +++ b/crates/consensus/beacon/Cargo.toml @@ -57,6 +57,7 @@ reth-downloaders.workspace = true reth-evm-ethereum.workspace = true reth-ethereum-engine-primitives.workspace = true reth-config.workspace = true +reth-consensus.workspace = true assert_matches.workspace = true diff --git a/crates/consensus/beacon/src/engine/event.rs b/crates/consensus/beacon/src/engine/event.rs index 168130de7..d5cbdee46 100644 --- a/crates/consensus/beacon/src/engine/event.rs +++ b/crates/consensus/beacon/src/engine/event.rs @@ -1,6 +1,6 @@ use crate::engine::forkchoice::ForkchoiceStatus; -use reth_interfaces::consensus::ForkchoiceState; use reth_primitives::{SealedBlock, SealedHeader, B256}; +use reth_rpc_types::engine::ForkchoiceState; use std::{sync::Arc, time::Duration}; /// Events emitted by [crate::BeaconConsensusEngine]. diff --git a/crates/consensus/beacon/src/engine/message.rs b/crates/consensus/beacon/src/engine/message.rs index 464dcedb2..f9f1a84d4 100644 --- a/crates/consensus/beacon/src/engine/message.rs +++ b/crates/consensus/beacon/src/engine/message.rs @@ -4,11 +4,11 @@ use crate::{ }; use futures::{future::Either, FutureExt}; use reth_engine_primitives::EngineTypes; -use reth_interfaces::{consensus::ForkchoiceState, RethResult}; +use reth_interfaces::RethResult; use reth_payload_builder::error::PayloadBuilderError; use reth_rpc_types::engine::{ - CancunPayloadFields, ExecutionPayload, ForkChoiceUpdateResult, ForkchoiceUpdateError, - ForkchoiceUpdated, PayloadId, PayloadStatus, PayloadStatusEnum, + CancunPayloadFields, ExecutionPayload, ForkChoiceUpdateResult, ForkchoiceState, + ForkchoiceUpdateError, ForkchoiceUpdated, PayloadId, PayloadStatus, PayloadStatusEnum, }; use std::{ future::Future, diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index 877e6f450..5e22a4860 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -14,7 +14,6 @@ use reth_interfaces::{ error::{BlockchainTreeError, CanonicalError, InsertBlockError, InsertBlockErrorKind}, BlockStatus, BlockchainTreeEngine, CanonicalOutcome, InsertPayloadOk, }, - consensus::ForkchoiceState, executor::BlockValidationError, p2p::{bodies::client::BodiesClient, headers::client::HeadersClient}, provider::ProviderResult, @@ -31,7 +30,8 @@ use reth_provider::{ StageCheckpointReader, }; use reth_rpc_types::engine::{ - CancunPayloadFields, ExecutionPayload, PayloadStatus, PayloadStatusEnum, PayloadValidationError, + CancunPayloadFields, ExecutionPayload, ForkchoiceState, PayloadStatus, PayloadStatusEnum, + PayloadValidationError, }; use reth_stages_api::{ControlFlow, Pipeline}; use reth_tasks::TaskSpawner; diff --git a/crates/consensus/beacon/src/engine/test_utils.rs b/crates/consensus/beacon/src/engine/test_utils.rs index 329ea6446..297269975 100644 --- a/crates/consensus/beacon/src/engine/test_utils.rs +++ b/crates/consensus/beacon/src/engine/test_utils.rs @@ -7,16 +7,15 @@ use reth_blockchain_tree::{ config::BlockchainTreeConfig, externals::TreeExternals, BlockchainTree, ShareableBlockchainTree, }; use reth_config::config::EtlConfig; +use reth_consensus::Consensus; use reth_db::{test_utils::TempDatabase, DatabaseEnv as DE}; -use reth_ethereum_engine_primitives::EthEngineTypes; -use reth_evm_ethereum::EthEvmConfig; -type DatabaseEnv = TempDatabase; use reth_downloaders::{ bodies::bodies::BodiesDownloaderBuilder, headers::reverse_headers::ReverseHeadersDownloaderBuilder, }; +use reth_ethereum_engine_primitives::EthEngineTypes; +use reth_evm_ethereum::EthEvmConfig; use reth_interfaces::{ - consensus::Consensus, executor::BlockExecutionError, p2p::{bodies::client::BodiesClient, either::EitherDownloader, headers::client::HeadersClient}, sync::NoopSyncStateUpdater, @@ -40,6 +39,8 @@ use reth_tasks::TokioTaskExecutor; use std::{collections::VecDeque, sync::Arc}; use tokio::sync::{oneshot, watch}; +type DatabaseEnv = TempDatabase; + type TestBeaconConsensusEngine = BeaconConsensusEngine< Arc, BlockchainProvider< diff --git a/crates/consensus/common/Cargo.toml b/crates/consensus/common/Cargo.toml index 4659dd3e1..5e5a6ef57 100644 --- a/crates/consensus/common/Cargo.toml +++ b/crates/consensus/common/Cargo.toml @@ -15,6 +15,7 @@ workspace = true reth-primitives.workspace = true reth-interfaces.workspace = true reth-provider.workspace = true +reth-consensus.workspace=true [dev-dependencies] reth-interfaces = { workspace = true, features = ["test-utils"] } diff --git a/crates/consensus/common/src/validation.rs b/crates/consensus/common/src/validation.rs index 1ab466c77..949061882 100644 --- a/crates/consensus/common/src/validation.rs +++ b/crates/consensus/common/src/validation.rs @@ -1,6 +1,7 @@ //! Collection of methods for block validation. -use reth_interfaces::{consensus::ConsensusError, RethResult}; +use reth_consensus::ConsensusError; +use reth_interfaces::RethResult; use reth_primitives::{ constants::eip4844::{DATA_GAS_PER_BLOB, MAX_DATA_GAS_PER_BLOCK}, BlockNumber, ChainSpec, GotExpected, Hardfork, Header, InvalidTransactionError, SealedBlock, diff --git a/crates/consensus/consensus/Cargo.toml b/crates/consensus/consensus/Cargo.toml new file mode 100644 index 000000000..6e4fc7ee9 --- /dev/null +++ b/crates/consensus/consensus/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "reth-consensus" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true + +[lints] +workspace = true + +[dependencies] +reth-primitives.workspace = true + +# misc +auto_impl.workspace = true +thiserror.workspace = true \ No newline at end of file diff --git a/crates/interfaces/src/consensus.rs b/crates/consensus/consensus/src/lib.rs similarity index 95% rename from crates/interfaces/src/consensus.rs rename to crates/consensus/consensus/src/lib.rs index b7d03b72e..ab2453b74 100644 --- a/crates/interfaces/src/consensus.rs +++ b/crates/consensus/consensus/src/lib.rs @@ -1,12 +1,19 @@ +//! Consensus protocol functions + +#![doc( + html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png", + html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", + issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" +)] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + use reth_primitives::{ BlockHash, BlockNumber, GotExpected, GotExpectedBoxed, Header, HeaderValidationError, InvalidTransactionError, SealedBlock, SealedHeader, B256, U256, }; use std::fmt::Debug; -/// Re-export fork choice state -pub use reth_rpc_types::engine::ForkchoiceState; - /// Consensus is a protocol that chooses canonical chain. #[auto_impl::auto_impl(&, Arc)] pub trait Consensus: Debug + Send + Sync { diff --git a/crates/interfaces/Cargo.toml b/crates/interfaces/Cargo.toml index 8f4aa494a..70ac2f942 100644 --- a/crates/interfaces/Cargo.toml +++ b/crates/interfaces/Cargo.toml @@ -12,9 +12,9 @@ workspace = true [dependencies] reth-primitives.workspace = true -reth-rpc-types.workspace = true reth-network-api.workspace = true reth-eth-wire-types.workspace = true +reth-consensus.workspace = true # async futures.workspace = true diff --git a/crates/interfaces/src/blockchain_tree/error.rs b/crates/interfaces/src/blockchain_tree/error.rs index e08211a4f..34e018835 100644 --- a/crates/interfaces/src/blockchain_tree/error.rs +++ b/crates/interfaces/src/blockchain_tree/error.rs @@ -1,11 +1,11 @@ //! Error handling for the blockchain tree use crate::{ - consensus::ConsensusError, executor::{BlockExecutionError, BlockValidationError}, provider::ProviderError, RethError, }; +use reth_consensus::ConsensusError; use reth_primitives::{BlockHash, BlockNumber, SealedBlock}; /// Various error cases that can occur when a block violates tree assumptions. diff --git a/crates/interfaces/src/error.rs b/crates/interfaces/src/error.rs index c49323595..df307ae09 100644 --- a/crates/interfaces/src/error.rs +++ b/crates/interfaces/src/error.rs @@ -1,10 +1,10 @@ use crate::{ blockchain_tree::error::{BlockchainTreeError, CanonicalError}, - consensus::ConsensusError, db::DatabaseError, executor::BlockExecutionError, provider::ProviderError, }; +use reth_consensus::ConsensusError; use reth_network_api::NetworkError; use reth_primitives::fs::FsPathError; diff --git a/crates/interfaces/src/lib.rs b/crates/interfaces/src/lib.rs index b8cfb7b39..e60d4a621 100644 --- a/crates/interfaces/src/lib.rs +++ b/crates/interfaces/src/lib.rs @@ -12,9 +12,6 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -/// Consensus traits. -pub mod consensus; - /// Database error pub mod db; diff --git a/crates/interfaces/src/p2p/error.rs b/crates/interfaces/src/p2p/error.rs index 3c4e351fc..6d822f44c 100644 --- a/crates/interfaces/src/p2p/error.rs +++ b/crates/interfaces/src/p2p/error.rs @@ -1,5 +1,6 @@ use super::headers::client::HeadersRequest; -use crate::{consensus::ConsensusError, db::DatabaseError, provider::ProviderError}; +use crate::{db::DatabaseError, provider::ProviderError}; +use reth_consensus::ConsensusError; use reth_network_api::ReputationChangeKind; use reth_primitives::{ BlockHashOrNumber, BlockNumber, GotExpected, GotExpectedBoxed, Header, WithPeerId, B256, diff --git a/crates/interfaces/src/p2p/full_block.rs b/crates/interfaces/src/p2p/full_block.rs index 3ab8e7644..cb4c66543 100644 --- a/crates/interfaces/src/p2p/full_block.rs +++ b/crates/interfaces/src/p2p/full_block.rs @@ -1,13 +1,11 @@ use super::headers::client::HeadersRequest; -use crate::{ - consensus::{Consensus, ConsensusError}, - p2p::{ - bodies::client::{BodiesClient, SingleBodyRequest}, - error::PeerRequestResult, - headers::client::{HeadersClient, SingleHeaderRequest}, - }, +use crate::p2p::{ + bodies::client::{BodiesClient, SingleBodyRequest}, + error::PeerRequestResult, + headers::client::{HeadersClient, SingleHeaderRequest}, }; use futures::Stream; +use reth_consensus::{Consensus, ConsensusError}; use reth_primitives::{ BlockBody, GotExpected, Header, HeadersDirection, SealedBlock, SealedHeader, WithPeerId, B256, }; diff --git a/crates/interfaces/src/p2p/headers/downloader.rs b/crates/interfaces/src/p2p/headers/downloader.rs index 9eea13aab..500a1a1bc 100644 --- a/crates/interfaces/src/p2p/headers/downloader.rs +++ b/crates/interfaces/src/p2p/headers/downloader.rs @@ -1,11 +1,8 @@ use super::error::HeadersDownloaderResult; -use crate::{ - consensus::Consensus, - p2p::error::{DownloadError, DownloadResult}, -}; +use crate::p2p::error::{DownloadError, DownloadResult}; use futures::Stream; +use reth_consensus::Consensus; use reth_primitives::{BlockHashOrNumber, SealedHeader, B256}; - /// A downloader capable of fetching and yielding block headers. /// /// A downloader represents a distinct strategy for submitting requests to download block headers, diff --git a/crates/interfaces/src/p2p/headers/error.rs b/crates/interfaces/src/p2p/headers/error.rs index 12eab9548..f586aaf74 100644 --- a/crates/interfaces/src/p2p/headers/error.rs +++ b/crates/interfaces/src/p2p/headers/error.rs @@ -1,4 +1,4 @@ -use crate::consensus::ConsensusError; +use reth_consensus::ConsensusError; use reth_primitives::SealedHeader; use thiserror::Error; diff --git a/crates/interfaces/src/p2p/headers/mod.rs b/crates/interfaces/src/p2p/headers/mod.rs index 5746c1b2d..56aabf9d6 100644 --- a/crates/interfaces/src/p2p/headers/mod.rs +++ b/crates/interfaces/src/p2p/headers/mod.rs @@ -6,7 +6,7 @@ pub mod client; /// A downloader that receives and verifies block headers, is generic /// over the Consensus and the HeadersClient being used. /// -/// [`Consensus`]: crate::consensus::Consensus +/// [`Consensus`]: reth_consensus::Consensus /// [`HeadersClient`]: client::HeadersClient pub mod downloader; diff --git a/crates/interfaces/src/p2p/mod.rs b/crates/interfaces/src/p2p/mod.rs index 8e4d7c84f..75f3a8fc4 100644 --- a/crates/interfaces/src/p2p/mod.rs +++ b/crates/interfaces/src/p2p/mod.rs @@ -14,7 +14,7 @@ pub mod full_block; /// of a Linear and a Parallel downloader generic over the [`Consensus`] and /// [`HeadersClient`]. /// -/// [`Consensus`]: crate::consensus::Consensus +/// [`Consensus`]: reth_consensus::Consensus /// [`HeadersClient`]: crate::p2p::headers::client::HeadersClient pub mod headers; diff --git a/crates/interfaces/src/test_utils/headers.rs b/crates/interfaces/src/test_utils/headers.rs index 8262d9ae0..c0da9ff16 100644 --- a/crates/interfaces/src/test_utils/headers.rs +++ b/crates/interfaces/src/test_utils/headers.rs @@ -1,19 +1,17 @@ //! Testing support for headers related interfaces. -use crate::{ - consensus::{self, Consensus, ConsensusError}, - p2p::{ - download::DownloadClient, - error::{DownloadError, DownloadResult, PeerRequestResult, RequestError}, - headers::{ - client::{HeadersClient, HeadersRequest}, - downloader::{HeaderDownloader, SyncTarget}, - error::HeadersDownloaderResult, - }, - priority::Priority, +use crate::p2p::{ + download::DownloadClient, + error::{DownloadError, DownloadResult, PeerRequestResult, RequestError}, + headers::{ + client::{HeadersClient, HeadersRequest}, + downloader::{HeaderDownloader, SyncTarget}, + error::HeadersDownloaderResult, }, + priority::Priority, }; use futures::{Future, FutureExt, Stream, StreamExt}; +use reth_consensus::{Consensus, ConsensusError}; use reth_primitives::{ Header, HeadersDirection, PeerId, SealedBlock, SealedHeader, WithPeerId, U256, }; @@ -274,7 +272,7 @@ impl TestConsensus { impl Consensus for TestConsensus { fn validate_header(&self, _header: &SealedHeader) -> Result<(), ConsensusError> { if self.fail_validation() { - Err(consensus::ConsensusError::BaseFeeMissing) + Err(ConsensusError::BaseFeeMissing) } else { Ok(()) } @@ -286,7 +284,7 @@ impl Consensus for TestConsensus { _parent: &SealedHeader, ) -> Result<(), ConsensusError> { if self.fail_validation() { - Err(consensus::ConsensusError::BaseFeeMissing) + Err(ConsensusError::BaseFeeMissing) } else { Ok(()) } @@ -298,15 +296,15 @@ impl Consensus for TestConsensus { _total_difficulty: U256, ) -> Result<(), ConsensusError> { if self.fail_validation() { - Err(consensus::ConsensusError::BaseFeeMissing) + Err(ConsensusError::BaseFeeMissing) } else { Ok(()) } } - fn validate_block(&self, _block: &SealedBlock) -> Result<(), consensus::ConsensusError> { + fn validate_block(&self, _block: &SealedBlock) -> Result<(), ConsensusError> { if self.fail_validation() { - Err(consensus::ConsensusError::BaseFeeMissing) + Err(ConsensusError::BaseFeeMissing) } else { Ok(()) } diff --git a/crates/net/downloaders/Cargo.toml b/crates/net/downloaders/Cargo.toml index 7ae6db8e6..b5de192f2 100644 --- a/crates/net/downloaders/Cargo.toml +++ b/crates/net/downloaders/Cargo.toml @@ -18,6 +18,7 @@ reth-primitives.workspace = true reth-tasks.workspace = true reth-provider.workspace = true reth-config.workspace = true +reth-consensus.workspace = true # async futures.workspace = true diff --git a/crates/net/downloaders/src/bodies/bodies.rs b/crates/net/downloaders/src/bodies/bodies.rs index d45c9b191..28b43359e 100644 --- a/crates/net/downloaders/src/bodies/bodies.rs +++ b/crates/net/downloaders/src/bodies/bodies.rs @@ -3,16 +3,14 @@ use crate::{bodies::task::TaskDownloader, metrics::BodyDownloaderMetrics}; use futures::Stream; use futures_util::StreamExt; use reth_config::BodiesConfig; -use reth_interfaces::{ - consensus::Consensus, - p2p::{ - bodies::{ - client::BodiesClient, - downloader::{BodyDownloader, BodyDownloaderResult}, - response::BlockResponse, - }, - error::{DownloadError, DownloadResult}, +use reth_consensus::Consensus; +use reth_interfaces::p2p::{ + bodies::{ + client::BodiesClient, + downloader::{BodyDownloader, BodyDownloaderResult}, + response::BlockResponse, }, + error::{DownloadError, DownloadResult}, }; use reth_primitives::{BlockNumber, SealedHeader}; use reth_provider::HeaderProvider; diff --git a/crates/net/downloaders/src/bodies/queue.rs b/crates/net/downloaders/src/bodies/queue.rs index 0fc9635df..072e059a4 100644 --- a/crates/net/downloaders/src/bodies/queue.rs +++ b/crates/net/downloaders/src/bodies/queue.rs @@ -2,12 +2,10 @@ use super::request::BodiesRequestFuture; use crate::metrics::BodyDownloaderMetrics; use futures::{stream::FuturesUnordered, Stream}; use futures_util::StreamExt; -use reth_interfaces::{ - consensus::Consensus, - p2p::{ - bodies::{client::BodiesClient, response::BlockResponse}, - error::DownloadResult, - }, +use reth_consensus::Consensus; +use reth_interfaces::p2p::{ + bodies::{client::BodiesClient, response::BlockResponse}, + error::DownloadResult, }; use reth_primitives::{BlockNumber, SealedHeader}; use std::{ diff --git a/crates/net/downloaders/src/bodies/request.rs b/crates/net/downloaders/src/bodies/request.rs index 302256ef4..1a87928d5 100644 --- a/crates/net/downloaders/src/bodies/request.rs +++ b/crates/net/downloaders/src/bodies/request.rs @@ -1,12 +1,10 @@ use crate::metrics::{BodyDownloaderMetrics, ResponseMetrics}; use futures::{Future, FutureExt}; -use reth_interfaces::{ - consensus::{Consensus as ConsensusTrait, Consensus}, - p2p::{ - bodies::{client::BodiesClient, response::BlockResponse}, - error::{DownloadError, DownloadResult}, - priority::Priority, - }, +use reth_consensus::Consensus; +use reth_interfaces::p2p::{ + bodies::{client::BodiesClient, response::BlockResponse}, + error::{DownloadError, DownloadResult}, + priority::Priority, }; use reth_primitives::{ BlockBody, GotExpected, PeerId, SealedBlock, SealedHeader, WithPeerId, B256, diff --git a/crates/net/downloaders/src/bodies/task.rs b/crates/net/downloaders/src/bodies/task.rs index a57e5e486..2d9bb3f96 100644 --- a/crates/net/downloaders/src/bodies/task.rs +++ b/crates/net/downloaders/src/bodies/task.rs @@ -42,8 +42,9 @@ impl TaskDownloader { /// # Example /// /// ``` + /// use reth_consensus::Consensus; /// use reth_downloaders::bodies::{bodies::BodiesDownloaderBuilder, task::TaskDownloader}; - /// use reth_interfaces::{consensus::Consensus, p2p::bodies::client::BodiesClient}; + /// use reth_interfaces::p2p::bodies::client::BodiesClient; /// use reth_provider::HeaderProvider; /// use std::sync::Arc; /// diff --git a/crates/net/downloaders/src/headers/reverse_headers.rs b/crates/net/downloaders/src/headers/reverse_headers.rs index 3af45c172..8d2318507 100644 --- a/crates/net/downloaders/src/headers/reverse_headers.rs +++ b/crates/net/downloaders/src/headers/reverse_headers.rs @@ -6,17 +6,15 @@ use futures::{stream::Stream, FutureExt}; use futures_util::{stream::FuturesUnordered, StreamExt}; use rayon::prelude::*; use reth_config::config::HeadersConfig; -use reth_interfaces::{ - consensus::Consensus, - p2p::{ - error::{DownloadError, DownloadResult, PeerRequestResult}, - headers::{ - client::{HeadersClient, HeadersRequest}, - downloader::{validate_header_download, HeaderDownloader, SyncTarget}, - error::{HeadersDownloaderError, HeadersDownloaderResult}, - }, - priority::Priority, +use reth_consensus::Consensus; +use reth_interfaces::p2p::{ + error::{DownloadError, DownloadResult, PeerRequestResult}, + headers::{ + client::{HeadersClient, HeadersRequest}, + downloader::{validate_header_download, HeaderDownloader, SyncTarget}, + error::{HeadersDownloaderError, HeadersDownloaderResult}, }, + priority::Priority, }; use reth_primitives::{ BlockHashOrNumber, BlockNumber, GotExpected, Header, HeadersDirection, PeerId, SealedHeader, diff --git a/crates/net/downloaders/src/headers/task.rs b/crates/net/downloaders/src/headers/task.rs index 83f00d4f1..16597342b 100644 --- a/crates/net/downloaders/src/headers/task.rs +++ b/crates/net/downloaders/src/headers/task.rs @@ -44,7 +44,7 @@ impl TaskDownloader { /// # use std::sync::Arc; /// # use reth_downloaders::headers::reverse_headers::ReverseHeadersDownloader; /// # use reth_downloaders::headers::task::TaskDownloader; - /// # use reth_interfaces::consensus::Consensus; + /// # use reth_consensus::Consensus; /// # use reth_interfaces::p2p::headers::client::HeadersClient; /// # fn t(consensus:Arc, client: Arc) { /// let downloader = ReverseHeadersDownloader::::builder().build( diff --git a/crates/net/network/Cargo.toml b/crates/net/network/Cargo.toml index 8e4c110bb..dbf7f5fa2 100644 --- a/crates/net/network/Cargo.toml +++ b/crates/net/network/Cargo.toml @@ -27,6 +27,7 @@ reth-transaction-pool.workspace = true reth-provider.workspace = true reth-rpc-types.workspace = true reth-tokio-util.workspace = true +reth-consensus.workspace = true # ethereum enr = { workspace = true, features = ["serde", "rust-secp256k1"] } diff --git a/crates/net/network/src/import.rs b/crates/net/network/src/import.rs index d127dab8f..738851f0a 100644 --- a/crates/net/network/src/import.rs +++ b/crates/net/network/src/import.rs @@ -50,7 +50,7 @@ pub enum BlockValidation { pub enum BlockImportError { /// Consensus error #[error(transparent)] - Consensus(#[from] reth_interfaces::consensus::ConsensusError), + Consensus(#[from] reth_consensus::ConsensusError), } /// An implementation of `BlockImport` used in Proof-of-Stake consensus that does nothing. diff --git a/crates/node-builder/Cargo.toml b/crates/node-builder/Cargo.toml index c245203ca..aae73f5a6 100644 --- a/crates/node-builder/Cargo.toml +++ b/crates/node-builder/Cargo.toml @@ -37,6 +37,7 @@ reth-stages.workspace = true reth-config.workspace = true reth-downloaders.workspace = true reth-node-events.workspace = true +reth-consensus.workspace = true ## async futures.workspace = true diff --git a/crates/node-builder/src/builder.rs b/crates/node-builder/src/builder.rs index c47478047..3d7d3a044 100644 --- a/crates/node-builder/src/builder.rs +++ b/crates/node-builder/src/builder.rs @@ -22,6 +22,7 @@ use reth_blockchain_tree::{ BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals, }; use reth_config::config::EtlConfig; +use reth_consensus::Consensus; use reth_db::{ database::Database, database_metrics::{DatabaseMetadata, DatabaseMetrics}, @@ -29,7 +30,7 @@ use reth_db::{ DatabaseEnv, }; use reth_exex::{ExExContext, ExExHandle, ExExManager, ExExManagerHandle}; -use reth_interfaces::{consensus::Consensus, p2p::either::EitherDownloader}; +use reth_interfaces::p2p::either::EitherDownloader; use reth_network::{NetworkBuilder, NetworkConfig, NetworkEvents, NetworkHandle}; use reth_node_api::{ FullNodeComponents, FullNodeComponentsAdapter, FullNodeTypes, FullNodeTypesAdapter, NodeTypes, diff --git a/crates/node-builder/src/setup.rs b/crates/node-builder/src/setup.rs index bb67cad66..03bf45893 100644 --- a/crates/node-builder/src/setup.rs +++ b/crates/node-builder/src/setup.rs @@ -2,18 +2,16 @@ use crate::ConfigureEvm; use reth_config::{config::StageConfig, PruneConfig}; +use reth_consensus::Consensus; use reth_db::database::Database; use reth_downloaders::{ bodies::bodies::BodiesDownloaderBuilder, headers::reverse_headers::ReverseHeadersDownloaderBuilder, }; use reth_exex::ExExManagerHandle; -use reth_interfaces::{ - consensus::Consensus, - p2p::{ - bodies::{client::BodiesClient, downloader::BodyDownloader}, - headers::{client::HeadersClient, downloader::HeaderDownloader}, - }, +use reth_interfaces::p2p::{ + bodies::{client::BodiesClient, downloader::BodyDownloader}, + headers::{client::HeadersClient, downloader::HeaderDownloader}, }; use reth_node_core::{ node_config::NodeConfig, diff --git a/crates/node/events/Cargo.toml b/crates/node/events/Cargo.toml index 9c66f1469..83f2bd13a 100644 --- a/crates/node/events/Cargo.toml +++ b/crates/node/events/Cargo.toml @@ -18,9 +18,9 @@ reth-network-api.workspace = true reth-stages.workspace = true reth-prune.workspace = true reth-static-file.workspace = true -reth-interfaces.workspace = true reth-db.workspace = true reth-primitives.workspace = true +reth-rpc-types.workspace = true # async tokio.workspace = true diff --git a/crates/node/events/src/node.rs b/crates/node/events/src/node.rs index b18cc5f0b..32bf66e1b 100644 --- a/crates/node/events/src/node.rs +++ b/crates/node/events/src/node.rs @@ -6,7 +6,6 @@ use reth_beacon_consensus::{ BeaconConsensusEngineEvent, ConsensusEngineLiveSyncProgress, ForkchoiceStatus, }; use reth_db::{database::Database, database_metrics::DatabaseMetadata}; -use reth_interfaces::consensus::ForkchoiceState; use reth_network::{NetworkEvent, NetworkHandle}; use reth_network_api::PeersInfo; use reth_primitives::{ @@ -15,6 +14,7 @@ use reth_primitives::{ BlockNumber, B256, }; use reth_prune::PrunerEvent; +use reth_rpc_types::engine::ForkchoiceState; use reth_stages::{ExecOutput, PipelineEvent}; use reth_static_file::StaticFileProducerEvent; use std::{ diff --git a/crates/rpc/rpc-engine-api/Cargo.toml b/crates/rpc/rpc-engine-api/Cargo.toml index 271363963..b7e6eeccb 100644 --- a/crates/rpc/rpc-engine-api/Cargo.toml +++ b/crates/rpc/rpc-engine-api/Cargo.toml @@ -14,7 +14,6 @@ workspace = true [dependencies] # reth reth-primitives.workspace = true -reth-interfaces.workspace = true reth-provider.workspace = true reth-rpc-types.workspace = true reth-rpc-api.workspace = true diff --git a/crates/rpc/rpc-engine-api/src/engine_api.rs b/crates/rpc/rpc-engine-api/src/engine_api.rs index 7fc52b21c..01db0bb11 100644 --- a/crates/rpc/rpc-engine-api/src/engine_api.rs +++ b/crates/rpc/rpc-engine-api/src/engine_api.rs @@ -6,15 +6,14 @@ use reth_engine_primitives::{ validate_payload_timestamp, EngineApiMessageVersion, EngineTypes, PayloadAttributes, PayloadBuilderAttributes, PayloadOrAttributes, }; -use reth_interfaces::consensus::ForkchoiceState; use reth_payload_builder::PayloadStore; use reth_primitives::{BlockHash, BlockHashOrNumber, BlockNumber, ChainSpec, Hardfork, B256, U64}; use reth_provider::{BlockReader, EvmEnvProvider, HeaderProvider, StateProviderFactory}; use reth_rpc_api::EngineApiServer; use reth_rpc_types::engine::{ CancunPayloadFields, ExecutionPayload, ExecutionPayloadBodiesV1, ExecutionPayloadInputV2, - ExecutionPayloadV1, ExecutionPayloadV3, ForkchoiceUpdated, PayloadId, PayloadStatus, - TransitionConfiguration, CAPABILITIES, + ExecutionPayloadV1, ExecutionPayloadV3, ForkchoiceState, ForkchoiceUpdated, PayloadId, + PayloadStatus, TransitionConfiguration, CAPABILITIES, }; use reth_rpc_types_compat::engine::payload::{ convert_payload_input_v2_to_payload, convert_to_payload_body_v1, diff --git a/crates/stages-api/Cargo.toml b/crates/stages-api/Cargo.toml index d991a47af..d1e31ba78 100644 --- a/crates/stages-api/Cargo.toml +++ b/crates/stages-api/Cargo.toml @@ -18,6 +18,7 @@ reth-db.workspace = true reth-interfaces.workspace = true reth-static-file.workspace = true reth-tokio-util.workspace = true +reth-consensus.workspace = true # metrics reth-metrics.workspace = true diff --git a/crates/stages-api/src/error.rs b/crates/stages-api/src/error.rs index 3b744e7cb..3d7ae1d72 100644 --- a/crates/stages-api/src/error.rs +++ b/crates/stages-api/src/error.rs @@ -1,5 +1,6 @@ +use reth_consensus::ConsensusError; use reth_interfaces::{ - consensus, db::DatabaseError as DbError, executor, p2p::error::DownloadError, RethError, + db::DatabaseError as DbError, executor, p2p::error::DownloadError, RethError, }; use reth_primitives::{BlockNumber, SealedHeader, StaticFileSegment, TxNumber}; use reth_provider::ProviderError; @@ -13,7 +14,7 @@ use tokio::sync::mpsc::error::SendError; pub enum BlockErrorKind { /// The block encountered a validation error. #[error("validation error: {0}")] - Validation(#[from] consensus::ConsensusError), + Validation(#[from] ConsensusError), /// The block encountered an execution error. #[error("execution error: {0}")] Execution(#[from] executor::BlockExecutionError), @@ -49,7 +50,7 @@ pub enum StageError { header: Box, /// The error that occurred when attempting to attach the header. #[source] - error: Box, + error: Box, }, /// The headers stage is missing sync gap. #[error("missing sync gap")] diff --git a/crates/stages-api/src/pipeline/mod.rs b/crates/stages-api/src/pipeline/mod.rs index bb1512958..1b455a939 100644 --- a/crates/stages-api/src/pipeline/mod.rs +++ b/crates/stages-api/src/pipeline/mod.rs @@ -552,8 +552,8 @@ mod tests { use super::*; use crate::{test_utils::TestStage, UnwindOutput}; use assert_matches::assert_matches; + use reth_consensus::ConsensusError; use reth_interfaces::{ - consensus, provider::ProviderError, test_utils::{generators, generators::random_header}, }; @@ -922,9 +922,7 @@ mod tests { 5, Default::default(), )), - error: BlockErrorKind::Validation( - consensus::ConsensusError::BaseFeeMissing, - ), + error: BlockErrorKind::Validation(ConsensusError::BaseFeeMissing), })) .add_unwind(Ok(UnwindOutput { checkpoint: StageCheckpoint::new(0) })) .add_exec(Ok(ExecOutput { checkpoint: StageCheckpoint::new(10), done: true })), diff --git a/crates/stages/Cargo.toml b/crates/stages/Cargo.toml index df98d1dd7..3c4a3d5a1 100644 --- a/crates/stages/Cargo.toml +++ b/crates/stages/Cargo.toml @@ -23,6 +23,7 @@ reth-trie = { workspace = true, features = ["metrics"] } reth-etl.workspace = true reth-config.workspace = true reth-stages-api = { workspace = true, features = ["test-utils"] } +reth-consensus.workspace = true # async tokio = { workspace = true, features = ["sync"] } diff --git a/crates/stages/src/lib.rs b/crates/stages/src/lib.rs index f8e427763..cf2b8acbe 100644 --- a/crates/stages/src/lib.rs +++ b/crates/stages/src/lib.rs @@ -15,7 +15,6 @@ //! # use std::sync::Arc; //! # use reth_downloaders::bodies::bodies::BodiesDownloaderBuilder; //! # use reth_downloaders::headers::reverse_headers::ReverseHeadersDownloaderBuilder; -//! # use reth_interfaces::consensus::Consensus; //! # use reth_interfaces::test_utils::{TestBodiesClient, TestConsensus, TestHeadersClient}; //! # use reth_revm::EvmProcessorFactory; //! # use reth_primitives::{PeerId, MAINNET, B256, PruneModes}; @@ -28,6 +27,7 @@ //! # use reth_provider::test_utils::create_test_provider_factory; //! # use reth_static_file::StaticFileProducer; //! # use reth_config::config::EtlConfig; +//! # use reth_consensus::Consensus; //! # //! # let chain_spec = MAINNET.clone(); //! # let consensus: Arc = Arc::new(TestConsensus::default()); diff --git a/crates/stages/src/sets.rs b/crates/stages/src/sets.rs index 833f2af8e..4f04e9b10 100644 --- a/crates/stages/src/sets.rs +++ b/crates/stages/src/sets.rs @@ -58,10 +58,10 @@ use crate::{ StageSet, StageSetBuilder, }; use reth_config::config::EtlConfig; +use reth_consensus::Consensus; use reth_db::database::Database; -use reth_interfaces::{ - consensus::Consensus, - p2p::{bodies::downloader::BodyDownloader, headers::downloader::HeaderDownloader}, +use reth_interfaces::p2p::{ + bodies::downloader::BodyDownloader, headers::downloader::HeaderDownloader, }; use reth_provider::{ExecutorFactory, HeaderSyncGapProvider, HeaderSyncMode}; use std::sync::Arc; diff --git a/crates/stages/src/stages/headers.rs b/crates/stages/src/stages/headers.rs index a862d4afc..f90149e1a 100644 --- a/crates/stages/src/stages/headers.rs +++ b/crates/stages/src/stages/headers.rs @@ -1,6 +1,7 @@ use futures_util::StreamExt; use reth_codecs::Compact; use reth_config::config::EtlConfig; +use reth_consensus::Consensus; use reth_db::{ cursor::{DbCursorRO, DbCursorRW}, database::Database, @@ -10,7 +11,6 @@ use reth_db::{ }; use reth_etl::Collector; use reth_interfaces::{ - consensus::Consensus, p2p::headers::{downloader::HeaderDownloader, error::HeadersDownloaderError}, provider::ProviderError, }; diff --git a/crates/stages/src/stages/merkle.rs b/crates/stages/src/stages/merkle.rs index 9b4eec87f..bfdb9782b 100644 --- a/crates/stages/src/stages/merkle.rs +++ b/crates/stages/src/stages/merkle.rs @@ -1,10 +1,10 @@ use reth_codecs::Compact; +use reth_consensus::ConsensusError; use reth_db::{ database::Database, tables, transaction::{DbTx, DbTxMut}, }; -use reth_interfaces::consensus; use reth_primitives::{ stage::{EntitiesCheckpoint, MerkleCheckpoint, StageCheckpoint, StageId}, trie::StoredSubNode, @@ -327,7 +327,7 @@ fn validate_state_root( } else { warn!(target: "sync::stages::merkle", ?target_block, ?got, ?expected, "Failed to verify block state root"); Err(StageError::Block { - error: BlockErrorKind::Validation(consensus::ConsensusError::BodyStateRootDiff( + error: BlockErrorKind::Validation(ConsensusError::BodyStateRootDiff( GotExpected { got, expected: expected.state_root }.into(), )), block: Box::new(expected), diff --git a/crates/stages/src/stages/sender_recovery.rs b/crates/stages/src/stages/sender_recovery.rs index 04a30cb2e..5ddb2dfc0 100644 --- a/crates/stages/src/stages/sender_recovery.rs +++ b/crates/stages/src/stages/sender_recovery.rs @@ -1,3 +1,4 @@ +use reth_consensus::ConsensusError; use reth_db::{ cursor::DbCursorRW, database::Database, @@ -6,7 +7,6 @@ use reth_db::{ transaction::{DbTx, DbTxMut}, RawValue, }; -use reth_interfaces::consensus; use reth_primitives::{ stage::{EntitiesCheckpoint, StageCheckpoint, StageId}, Address, PruneSegment, StaticFileSegment, TransactionSignedNoHash, TxNumber, @@ -209,7 +209,7 @@ fn recover_range( Err(StageError::Block { block: Box::new(sealed_header), error: BlockErrorKind::Validation( - consensus::ConsensusError::TransactionSignerRecoveryError, + ConsensusError::TransactionSignerRecoveryError, ), }) } diff --git a/crates/storage/provider/Cargo.toml b/crates/storage/provider/Cargo.toml index 6f9305e88..526cbdaa5 100644 --- a/crates/storage/provider/Cargo.toml +++ b/crates/storage/provider/Cargo.toml @@ -15,6 +15,7 @@ workspace = true # reth reth-primitives.workspace = true reth-interfaces.workspace = true +reth-rpc-types.workspace = true reth-db.workspace = true reth-trie = { workspace = true, features = ["metrics"] } reth-nippy-jar.workspace = true diff --git a/crates/storage/provider/src/providers/mod.rs b/crates/storage/provider/src/providers/mod.rs index f696c86d7..b3011a9b0 100644 --- a/crates/storage/provider/src/providers/mod.rs +++ b/crates/storage/provider/src/providers/mod.rs @@ -17,7 +17,6 @@ use reth_interfaces::{ BlockValidationKind, BlockchainTreeEngine, BlockchainTreeViewer, CanonicalOutcome, InsertPayloadOk, }, - consensus::ForkchoiceState, provider::ProviderResult, RethResult, }; @@ -61,6 +60,7 @@ use chain_info::ChainInfoTracker; mod consistent_view; pub use consistent_view::{ConsistentDbView, ConsistentViewError}; +use reth_rpc_types::engine::ForkchoiceState; /// The main type for interacting with the blockchain. /// diff --git a/crates/storage/provider/src/traits/chain_info.rs b/crates/storage/provider/src/traits/chain_info.rs index 82d879df4..5e6379f01 100644 --- a/crates/storage/provider/src/traits/chain_info.rs +++ b/crates/storage/provider/src/traits/chain_info.rs @@ -1,5 +1,5 @@ -use reth_interfaces::consensus::ForkchoiceState; use reth_primitives::SealedHeader; +use reth_rpc_types::engine::ForkchoiceState; use std::time::Instant; /// A type that can track updates related to fork choice updates.