mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: move tree setup to builder (#7577)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -6857,7 +6857,6 @@ dependencies = [
|
|||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"reth-auto-seal-consensus",
|
"reth-auto-seal-consensus",
|
||||||
"reth-beacon-consensus",
|
"reth-beacon-consensus",
|
||||||
"reth-blockchain-tree",
|
|
||||||
"reth-config",
|
"reth-config",
|
||||||
"reth-consensus-common",
|
"reth-consensus-common",
|
||||||
"reth-db",
|
"reth-db",
|
||||||
|
|||||||
@ -80,7 +80,26 @@ where
|
|||||||
DB: Database + Clone,
|
DB: Database + Clone,
|
||||||
EVM: ExecutorFactory,
|
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(
|
pub fn new(
|
||||||
externals: TreeExternals<DB, EVM>,
|
externals: TreeExternals<DB, EVM>,
|
||||||
config: BlockchainTreeConfig,
|
config: BlockchainTreeConfig,
|
||||||
@ -124,6 +143,9 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Set the sync metric events sender.
|
/// 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 {
|
pub fn with_sync_metrics_tx(mut self, metrics_tx: MetricEventsSender) -> Self {
|
||||||
self.sync_metrics_tx = Some(metrics_tx);
|
self.sync_metrics_tx = Some(metrics_tx);
|
||||||
self
|
self
|
||||||
|
|||||||
@ -20,7 +20,9 @@ use reth_beacon_consensus::{
|
|||||||
hooks::{EngineHooks, PruneHook, StaticFileHook},
|
hooks::{EngineHooks, PruneHook, StaticFileHook},
|
||||||
BeaconConsensusEngine,
|
BeaconConsensusEngine,
|
||||||
};
|
};
|
||||||
use reth_blockchain_tree::{BlockchainTreeConfig, ShareableBlockchainTree};
|
use reth_blockchain_tree::{
|
||||||
|
BlockchainTree, BlockchainTreeConfig, ShareableBlockchainTree, TreeExternals,
|
||||||
|
};
|
||||||
use reth_config::config::EtlConfig;
|
use reth_config::config::EtlConfig;
|
||||||
use reth_db::{
|
use reth_db::{
|
||||||
database::Database,
|
database::Database,
|
||||||
@ -530,16 +532,20 @@ where
|
|||||||
|
|
||||||
let prune_config = config.prune_config()?.or_else(|| reth_config.prune.clone());
|
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 evm_config = types.evm_config();
|
||||||
let tree_config = BlockchainTreeConfig::default();
|
let tree_config = BlockchainTreeConfig::default();
|
||||||
let tree = config.build_blockchain_tree(
|
let tree_externals = TreeExternals::new(
|
||||||
provider_factory.clone(),
|
provider_factory.clone(),
|
||||||
consensus.clone(),
|
consensus.clone(),
|
||||||
prune_config.clone(),
|
EvmProcessorFactory::new(config.chain.clone(), evm_config.clone()),
|
||||||
sync_metrics_tx.clone(),
|
);
|
||||||
|
let tree = BlockchainTree::new(
|
||||||
|
tree_externals,
|
||||||
tree_config,
|
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 canon_state_notification_sender = tree.canon_state_notification_sender();
|
||||||
let blockchain_tree = ShareableBlockchainTree::new(tree);
|
let blockchain_tree = ShareableBlockchainTree::new(tree);
|
||||||
|
|||||||
@ -38,7 +38,6 @@ reth-downloaders.workspace = true
|
|||||||
reth-revm.workspace = true
|
reth-revm.workspace = true
|
||||||
reth-stages.workspace = true
|
reth-stages.workspace = true
|
||||||
reth-prune.workspace = true
|
reth-prune.workspace = true
|
||||||
reth-blockchain-tree.workspace = true
|
|
||||||
reth-static-file.workspace = true
|
reth-static-file.workspace = true
|
||||||
|
|
||||||
# ethereum
|
# ethereum
|
||||||
@ -106,7 +105,6 @@ optimism = [
|
|||||||
"reth-rpc-types-compat/optimism",
|
"reth-rpc-types-compat/optimism",
|
||||||
"reth-auto-seal-consensus/optimism",
|
"reth-auto-seal-consensus/optimism",
|
||||||
"reth-consensus-common/optimism",
|
"reth-consensus-common/optimism",
|
||||||
"reth-blockchain-tree/optimism",
|
|
||||||
"reth-beacon-consensus/optimism",
|
"reth-beacon-consensus/optimism",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -15,9 +15,6 @@ use metrics_exporter_prometheus::PrometheusHandle;
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use reth_auto_seal_consensus::{AutoSealConsensus, MiningMode};
|
use reth_auto_seal_consensus::{AutoSealConsensus, MiningMode};
|
||||||
use reth_beacon_consensus::BeaconConsensus;
|
use reth_beacon_consensus::BeaconConsensus;
|
||||||
use reth_blockchain_tree::{
|
|
||||||
config::BlockchainTreeConfig, externals::TreeExternals, BlockchainTree,
|
|
||||||
};
|
|
||||||
use reth_config::{
|
use reth_config::{
|
||||||
config::{PruneConfig, StageConfig},
|
config::{PruneConfig, StageConfig},
|
||||||
Config,
|
Config,
|
||||||
@ -51,10 +48,7 @@ use reth_provider::{
|
|||||||
CanonStateSubscriptions, HeaderProvider, HeaderSyncMode, ProviderFactory,
|
CanonStateSubscriptions, HeaderProvider, HeaderSyncMode, ProviderFactory,
|
||||||
StageCheckpointReader,
|
StageCheckpointReader,
|
||||||
};
|
};
|
||||||
use reth_revm::{
|
use reth_revm::stack::{Hook, InspectorStackConfig};
|
||||||
stack::{Hook, InspectorStackConfig},
|
|
||||||
EvmProcessorFactory,
|
|
||||||
};
|
|
||||||
use reth_stages::{
|
use reth_stages::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
stages::{
|
stages::{
|
||||||
@ -62,7 +56,6 @@ use reth_stages::{
|
|||||||
IndexStorageHistoryStage, MerkleStage, SenderRecoveryStage, StorageHashingStage,
|
IndexStorageHistoryStage, MerkleStage, SenderRecoveryStage, StorageHashingStage,
|
||||||
TransactionLookupStage,
|
TransactionLookupStage,
|
||||||
},
|
},
|
||||||
MetricEvent,
|
|
||||||
};
|
};
|
||||||
use reth_static_file::StaticFileProducer;
|
use reth_static_file::StaticFileProducer;
|
||||||
use reth_tasks::TaskExecutor;
|
use reth_tasks::TaskExecutor;
|
||||||
@ -72,10 +65,7 @@ use reth_transaction_pool::{
|
|||||||
};
|
};
|
||||||
use secp256k1::SecretKey;
|
use secp256k1::SecretKey;
|
||||||
use std::{net::SocketAddr, path::PathBuf, sync::Arc};
|
use std::{net::SocketAddr, path::PathBuf, sync::Arc};
|
||||||
use tokio::sync::{
|
use tokio::sync::{mpsc::Receiver, watch};
|
||||||
mpsc::{Receiver, UnboundedSender},
|
|
||||||
watch,
|
|
||||||
};
|
|
||||||
use tracing::*;
|
use tracing::*;
|
||||||
|
|
||||||
/// The default prometheus recorder handle. We use a global static to ensure that it is only
|
/// The default prometheus recorder handle. We use a global static to ensure that it is only
|
||||||
@ -383,77 +373,6 @@ impl NodeConfig {
|
|||||||
Ok(builder)
|
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<DB, EvmConfig>(
|
|
||||||
&self,
|
|
||||||
provider_factory: ProviderFactory<DB>,
|
|
||||||
consensus: Arc<dyn Consensus>,
|
|
||||||
prune_config: Option<PruneConfig>,
|
|
||||||
sync_metrics_tx: UnboundedSender<MetricEvent>,
|
|
||||||
tree_config: BlockchainTreeConfig,
|
|
||||||
evm_config: EvmConfig,
|
|
||||||
) -> eyre::Result<BlockchainTree<DB, EvmProcessorFactory<EvmConfig>>>
|
|
||||||
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
|
/// Build a transaction pool and spawn the transaction pool maintenance task
|
||||||
pub fn build_and_spawn_txpool<DB, Tree>(
|
pub fn build_and_spawn_txpool<DB, Tree>(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
Reference in New Issue
Block a user