diff --git a/Cargo.lock b/Cargo.lock index 0d7d75f8fac8..275156fabb63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6857,7 +6857,6 @@ dependencies = [ "rand 0.8.5", "reth-auto-seal-consensus", "reth-beacon-consensus", - "reth-blockchain-tree", "reth-config", "reth-consensus-common", "reth-db", diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 16f20a47e2bc..a05667209bad 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -80,7 +80,26 @@ where DB: Database + Clone, EVM: ExecutorFactory, { - /// Create a new blockchain tree. + /// Builds the blockchain tree for the node. + /// + /// This method configures the blockchain tree, which is a critical component of the node, + /// responsible for managing the blockchain state, including blocks, transactions, and receipts. + /// It integrates with the consensus mechanism and the EVM for executing transactions. + /// + /// # Parameters + /// - `externals`: External components required by the blockchain tree: + /// - `provider_factory`: A factory for creating various blockchain-related providers, such + /// as for accessing the database or static files. + /// - `consensus`: The consensus configuration, which defines how the node reaches agreement + /// on the blockchain state with other nodes. + /// - `evm_config`: The EVM (Ethereum Virtual Machine) configuration, which affects how + /// smart contracts and transactions are executed. Proper validation of this configuration + /// is crucial for the correct execution of transactions. + /// - `tree_config`: Configuration for the blockchain tree, including any parameters that affect + /// its structure or performance. + /// - `prune_modes`: Configuration for pruning old blockchain data. This helps in managing the + /// storage space efficiently. It's important to validate this configuration to ensure it does + /// not lead to unintended data loss. pub fn new( externals: TreeExternals, config: BlockchainTreeConfig, @@ -124,6 +143,9 @@ where } /// Set the sync metric events sender. + /// + /// A transmitter for sending synchronization metrics. This is used for monitoring the node's + /// synchronization process with the blockchain network. pub fn with_sync_metrics_tx(mut self, metrics_tx: MetricEventsSender) -> Self { self.sync_metrics_tx = Some(metrics_tx); self diff --git a/crates/node-builder/src/builder.rs b/crates/node-builder/src/builder.rs index 00e62bc30544..44d13becadb5 100644 --- a/crates/node-builder/src/builder.rs +++ b/crates/node-builder/src/builder.rs @@ -20,7 +20,9 @@ use reth_beacon_consensus::{ hooks::{EngineHooks, PruneHook, StaticFileHook}, BeaconConsensusEngine, }; -use reth_blockchain_tree::{BlockchainTreeConfig, ShareableBlockchainTree}; +use reth_blockchain_tree::{ + BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals, +}; use reth_config::config::EtlConfig; use reth_db::{ database::Database, @@ -530,16 +532,20 @@ where let prune_config = config.prune_config()?.or_else(|| reth_config.prune.clone()); + // Configure the blockchain tree for the node let evm_config = types.evm_config(); let tree_config = BlockchainTreeConfig::default(); - let tree = config.build_blockchain_tree( + let tree_externals = TreeExternals::new( provider_factory.clone(), consensus.clone(), - prune_config.clone(), - sync_metrics_tx.clone(), + EvmProcessorFactory::new(config.chain.clone(), evm_config.clone()), + ); + let tree = BlockchainTree::new( + tree_externals, tree_config, - evm_config.clone(), - )?; + prune_config.as_ref().map(|config| config.segments.clone()), + )? + .with_sync_metrics_tx(sync_metrics_tx.clone()); let canon_state_notification_sender = tree.canon_state_notification_sender(); let blockchain_tree = ShareableBlockchainTree::new(tree); diff --git a/crates/node-core/Cargo.toml b/crates/node-core/Cargo.toml index 7722938e318c..4bf2591a1fba 100644 --- a/crates/node-core/Cargo.toml +++ b/crates/node-core/Cargo.toml @@ -38,7 +38,6 @@ reth-downloaders.workspace = true reth-revm.workspace = true reth-stages.workspace = true reth-prune.workspace = true -reth-blockchain-tree.workspace = true reth-static-file.workspace = true # ethereum @@ -106,7 +105,6 @@ optimism = [ "reth-rpc-types-compat/optimism", "reth-auto-seal-consensus/optimism", "reth-consensus-common/optimism", - "reth-blockchain-tree/optimism", "reth-beacon-consensus/optimism", ] diff --git a/crates/node-core/src/node_config.rs b/crates/node-core/src/node_config.rs index aff0ee4c32b3..71b9f0ed42ea 100644 --- a/crates/node-core/src/node_config.rs +++ b/crates/node-core/src/node_config.rs @@ -15,9 +15,6 @@ use metrics_exporter_prometheus::PrometheusHandle; use once_cell::sync::Lazy; use reth_auto_seal_consensus::{AutoSealConsensus, MiningMode}; use reth_beacon_consensus::BeaconConsensus; -use reth_blockchain_tree::{ - config::BlockchainTreeConfig, externals::TreeExternals, BlockchainTree, -}; use reth_config::{ config::{PruneConfig, StageConfig}, Config, @@ -51,10 +48,7 @@ use reth_provider::{ CanonStateSubscriptions, HeaderProvider, HeaderSyncMode, ProviderFactory, StageCheckpointReader, }; -use reth_revm::{ - stack::{Hook, InspectorStackConfig}, - EvmProcessorFactory, -}; +use reth_revm::stack::{Hook, InspectorStackConfig}; use reth_stages::{ prelude::*, stages::{ @@ -62,7 +56,6 @@ use reth_stages::{ IndexStorageHistoryStage, MerkleStage, SenderRecoveryStage, StorageHashingStage, TransactionLookupStage, }, - MetricEvent, }; use reth_static_file::StaticFileProducer; use reth_tasks::TaskExecutor; @@ -72,10 +65,7 @@ use reth_transaction_pool::{ }; use secp256k1::SecretKey; use std::{net::SocketAddr, path::PathBuf, sync::Arc}; -use tokio::sync::{ - mpsc::{Receiver, UnboundedSender}, - watch, -}; +use tokio::sync::{mpsc::Receiver, watch}; use tracing::*; /// The default prometheus recorder handle. We use a global static to ensure that it is only @@ -383,77 +373,6 @@ impl NodeConfig { Ok(builder) } - /// Builds the blockchain tree for the node. - /// - /// This method configures the blockchain tree, which is a critical component of the node, - /// responsible for managing the blockchain state, including blocks, transactions, and receipts. - /// It integrates with the consensus mechanism and the EVM for executing transactions. - /// - /// # Parameters - /// - `provider_factory`: A factory for creating various blockchain-related providers, such as - /// for accessing the database or static files. - /// - `consensus`: The consensus configuration, which defines how the node reaches agreement on - /// the blockchain state with other nodes. - /// - `prune_config`: Configuration for pruning old blockchain data. This helps in managing the - /// storage space efficiently. It's important to validate this configuration to ensure it does - /// not lead to unintended data loss. - /// - `sync_metrics_tx`: A transmitter for sending synchronization metrics. This is used for - /// monitoring the node's synchronization process with the blockchain network. - /// - `tree_config`: Configuration for the blockchain tree, including any parameters that affect - /// its structure or performance. - /// - `evm_config`: The EVM (Ethereum Virtual Machine) configuration, which affects how smart - /// contracts and transactions are executed. Proper validation of this configuration is - /// crucial for the correct execution of transactions. - /// - /// # Returns - /// A `ShareableBlockchainTree` instance, which provides access to the blockchain state and - /// supports operations like block insertion, state reversion, and transaction execution. - /// - /// # Example - /// ```rust,ignore - /// let tree = config.build_blockchain_tree( - /// provider_factory, - /// consensus, - /// prune_config, - /// sync_metrics_tx, - /// BlockchainTreeConfig::default(), - /// evm_config, - /// )?; - /// ``` - /// - /// # Note - /// Ensure that all configurations passed to this method are validated beforehand to prevent - /// runtime errors. Specifically, `prune_config` and `evm_config` should be checked to ensure - /// they meet the node's operational requirements. - pub fn build_blockchain_tree( - &self, - provider_factory: ProviderFactory, - consensus: Arc, - prune_config: Option, - sync_metrics_tx: UnboundedSender, - tree_config: BlockchainTreeConfig, - evm_config: EvmConfig, - ) -> eyre::Result>> - where - DB: Database + Unpin + Clone + 'static, - EvmConfig: ConfigureEvm + Clone + 'static, - { - // configure blockchain tree - let tree_externals = TreeExternals::new( - provider_factory, - consensus.clone(), - EvmProcessorFactory::new(self.chain.clone(), evm_config), - ); - let tree = BlockchainTree::new( - tree_externals, - tree_config, - prune_config.map(|config| config.segments), - )? - .with_sync_metrics_tx(sync_metrics_tx); - - Ok(tree) - } - /// Build a transaction pool and spawn the transaction pool maintenance task pub fn build_and_spawn_txpool( &self,