From b0cb2d0df63a56bb8e42076b59235b7147050ab4 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 22 Apr 2024 14:07:21 +0200 Subject: [PATCH] chore: remove consensus setup from node-core (#7793) --- Cargo.lock | 1 - crates/node-builder/src/builder.rs | 24 ++++++++++++++++++---- crates/node-core/Cargo.toml | 2 -- crates/node-core/src/init.rs | 7 ++----- crates/node-core/src/node_config.rs | 31 ++--------------------------- 5 files changed, 24 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6be45296b..473ec4583 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6920,7 +6920,6 @@ dependencies = [ "procfs", "proptest", "rand 0.8.5", - "reth-auto-seal-consensus", "reth-beacon-consensus", "reth-config", "reth-consensus-common", diff --git a/crates/node-builder/src/builder.rs b/crates/node-builder/src/builder.rs index c9178708e..49be32b33 100644 --- a/crates/node-builder/src/builder.rs +++ b/crates/node-builder/src/builder.rs @@ -13,9 +13,10 @@ use crate::{ use eyre::Context; use futures::{future, future::Either, stream, stream_select, Future, StreamExt}; use rayon::ThreadPoolBuilder; +use reth_auto_seal_consensus::{AutoSealConsensus, MiningMode}; use reth_beacon_consensus::{ hooks::{EngineHooks, PruneHook, StaticFileHook}, - BeaconConsensusEngine, + BeaconConsensus, BeaconConsensusEngine, }; use reth_blockchain_tree::{ BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals, @@ -28,7 +29,7 @@ use reth_db::{ DatabaseEnv, }; use reth_exex::{ExExContext, ExExHandle, ExExManager, ExExManagerHandle}; -use reth_interfaces::p2p::either::EitherDownloader; +use reth_interfaces::{consensus::Consensus, p2p::either::EitherDownloader}; use reth_network::{NetworkBuilder, NetworkConfig, NetworkEvents, NetworkHandle}; use reth_node_api::{ FullNodeComponents, FullNodeComponentsAdapter, FullNodeTypes, FullNodeTypesAdapter, NodeTypes, @@ -524,7 +525,12 @@ where info!(target: "reth::cli", "\n{}", config.chain.display_hardforks()); - let consensus = config.consensus(); + // setup the consensus instance + let consensus: Arc = if config.dev.dev { + Arc::new(AutoSealConsensus::new(Arc::clone(&config.chain))) + } else { + Arc::new(BeaconConsensus::new(Arc::clone(&config.chain))) + }; debug!(target: "reth::cli", "Spawning stages metrics listener task"); let (sync_metrics_tx, sync_metrics_rx) = unbounded_channel(); @@ -721,7 +727,17 @@ where info!(target: "reth::cli", "Allocated Genesis Account: {:02}. {} ({} ETH)", idx, address.to_string(), format_ether(alloc.balance)); } - let mining_mode = config.mining_mode(transaction_pool.pending_transactions_listener()); + // install auto-seal + let pending_transactions_listener = transaction_pool.pending_transactions_listener(); + + let mining_mode = if let Some(interval) = config.dev.block_time { + MiningMode::interval(interval) + } else if let Some(max_transactions) = config.dev.block_max_transactions { + MiningMode::instant(max_transactions, pending_transactions_listener) + } else { + info!(target: "reth::cli", "No mining mode specified, defaulting to ReadyTransaction"); + MiningMode::instant(1, pending_transactions_listener) + }; let (_, client, mut task) = reth_auto_seal_consensus::AutoSealBuilder::new( Arc::clone(&config.chain), diff --git a/crates/node-core/Cargo.toml b/crates/node-core/Cargo.toml index 690258a55..d6df37f09 100644 --- a/crates/node-core/Cargo.toml +++ b/crates/node-core/Cargo.toml @@ -33,7 +33,6 @@ reth-evm.workspace = true reth-engine-primitives.workspace = true reth-tasks.workspace = true reth-consensus-common.workspace = true -reth-auto-seal-consensus.workspace = true reth-beacon-consensus.workspace = true # ethereum @@ -98,7 +97,6 @@ optimism = [ "reth-rpc-engine-api/optimism", "reth-provider/optimism", "reth-rpc-types-compat/optimism", - "reth-auto-seal-consensus/optimism", "reth-consensus-common/optimism", "reth-beacon-consensus/optimism", ] diff --git a/crates/node-core/src/init.rs b/crates/node-core/src/init.rs index b0a9c9c92..7f529c2b0 100644 --- a/crates/node-core/src/init.rs +++ b/crates/node-core/src/init.rs @@ -235,10 +235,7 @@ pub fn insert_genesis_header( #[cfg(test)] mod tests { - use std::sync::Arc; - use super::*; - use reth_db::{ cursor::DbCursorRO, models::{storage_sharded_key::StorageShardedKey, ShardedKey}, @@ -246,8 +243,8 @@ mod tests { DatabaseEnv, }; use reth_primitives::{ - Address, Chain, ChainSpec, ForkTimestamps, Genesis, GenesisAccount, IntegerList, GOERLI, - GOERLI_GENESIS_HASH, MAINNET, MAINNET_GENESIS_HASH, SEPOLIA, SEPOLIA_GENESIS_HASH, + Chain, ForkTimestamps, Genesis, IntegerList, GOERLI, GOERLI_GENESIS_HASH, MAINNET, + MAINNET_GENESIS_HASH, SEPOLIA, SEPOLIA_GENESIS_HASH, }; use reth_provider::test_utils::create_test_provider_factory_with_chain_spec; diff --git a/crates/node-core/src/node_config.rs b/crates/node-core/src/node_config.rs index 929f2f552..2b186b19c 100644 --- a/crates/node-core/src/node_config.rs +++ b/crates/node-core/src/node_config.rs @@ -12,15 +12,13 @@ use crate::{ use discv5::ListenConfig; use metrics_exporter_prometheus::PrometheusHandle; use once_cell::sync::Lazy; -use reth_auto_seal_consensus::{AutoSealConsensus, MiningMode}; -use reth_beacon_consensus::BeaconConsensus; use reth_config::{config::PruneConfig, Config}; use reth_db::{database::Database, database_metrics::DatabaseMetrics}; -use reth_interfaces::{consensus::Consensus, p2p::headers::client::HeadersClient, RethResult}; +use reth_interfaces::{p2p::headers::client::HeadersClient, RethResult}; use reth_network::{NetworkBuilder, NetworkConfig, NetworkManager}; use reth_primitives::{ constants::eip4844::MAINNET_KZG_TRUSTED_SETUP, kzg::KzgSettings, stage::StageId, - BlockHashOrNumber, BlockNumber, ChainSpec, Head, SealedHeader, TxHash, B256, MAINNET, + BlockHashOrNumber, BlockNumber, ChainSpec, Head, SealedHeader, B256, MAINNET, }; use reth_provider::{ providers::StaticFileProvider, BlockHashReader, BlockNumReader, HeaderProvider, @@ -29,7 +27,6 @@ use reth_provider::{ use reth_tasks::TaskExecutor; use secp256k1::SecretKey; use std::{net::SocketAddr, path::PathBuf, sync::Arc}; -use tokio::sync::mpsc::Receiver; use tracing::*; /// The default prometheus recorder handle. We use a global static to ensure that it is only @@ -291,18 +288,6 @@ impl NodeConfig { Ok(max_block) } - /// Get the [MiningMode] from the given dev args - pub fn mining_mode(&self, pending_transactions_listener: Receiver) -> MiningMode { - if let Some(interval) = self.dev.block_time { - MiningMode::interval(interval) - } else if let Some(max_transactions) = self.dev.block_max_transactions { - MiningMode::instant(max_transactions, pending_transactions_listener) - } else { - info!(target: "reth::cli", "No mining mode specified, defaulting to ReadyTransaction"); - MiningMode::instant(1, pending_transactions_listener) - } - } - /// Create the [NetworkConfig] for the node pub fn network_config( &self, @@ -337,18 +322,6 @@ impl NodeConfig { Ok(builder) } - /// Returns the [Consensus] instance to use. - /// - /// By default this will be a [BeaconConsensus] instance, but if the `--dev` flag is set, it - /// will be an [AutoSealConsensus] instance. - pub fn consensus(&self) -> Arc { - if self.dev.dev { - Arc::new(AutoSealConsensus::new(Arc::clone(&self.chain))) - } else { - Arc::new(BeaconConsensus::new(Arc::clone(&self.chain))) - } - } - /// Loads 'MAINNET_KZG_TRUSTED_SETUP' pub fn kzg_settings(&self) -> eyre::Result> { Ok(Arc::clone(&MAINNET_KZG_TRUSTED_SETUP))