chore: move import command to reth-cli-commands (#9394)

This commit is contained in:
joshieDo
2024-07-09 18:02:30 +02:00
committed by GitHub
parent 2fa37b1ad1
commit d39069027c
6 changed files with 25 additions and 10 deletions

2
Cargo.lock generated
View File

@ -6618,6 +6618,7 @@ dependencies = [
"crossterm",
"eyre",
"fdlimit",
"futures",
"human_bytes",
"itertools 0.13.0",
"metrics-process",
@ -6642,6 +6643,7 @@ dependencies = [
"reth-network-p2p",
"reth-node-builder",
"reth-node-core",
"reth-node-events",
"reth-primitives",
"reth-provider",
"reth-prune",

View File

@ -5,14 +5,14 @@ use crate::{
utils::{chain_help, chain_value_parser, SUPPORTED_CHAINS},
LogArgs,
},
commands::{debug_cmd, import},
commands::debug_cmd,
macros::block_executor,
version::{LONG_VERSION, SHORT_VERSION},
};
use clap::{value_parser, Parser, Subcommand};
use reth_chainspec::ChainSpec;
use reth_cli_commands::{
config_cmd, db, dump_genesis, init_cmd, init_state,
config_cmd, db, dump_genesis, import, init_cmd, init_state,
node::{self, NoArgs},
p2p, prune, recover, stage,
};
@ -151,7 +151,9 @@ impl<Ext: clap::Args + fmt::Debug> Cli<Ext> {
}
Commands::Init(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::InitState(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Import(command) => runner.run_blocking_until_ctrl_c(command.execute()),
Commands::Import(command) => runner.run_blocking_until_ctrl_c(
command.execute(|chain_spec| block_executor!(chain_spec)),
),
#[cfg(feature = "optimism")]
Commands::ImportOp(command) => runner.run_blocking_until_ctrl_c(command.execute()),
#[cfg(feature = "optimism")]

View File

@ -1,4 +1,3 @@
//! This contains all of the `reth` commands
pub mod debug_cmd;
pub mod import;

View File

@ -27,6 +27,7 @@ reth-network = { workspace = true, features = ["serde"] }
reth-network-p2p.workspace = true
reth-node-builder.workspace = true
reth-node-core.workspace = true
reth-node-events.workspace = true
reth-primitives.workspace = true
reth-provider.workspace = true
reth-prune.workspace = true
@ -35,8 +36,9 @@ reth-static-file-types.workspace = true
reth-static-file.workspace = true
reth-trie = { workspace = true, features = ["metrics"] }
tokio.workspace = true
itertools.workspace = true
futures.workspace = true
tokio.workspace = true
# misc
ahash = "0.8"

View File

@ -1,9 +1,9 @@
//! Command that initializes the node by importing a chain from a file.
use crate::{macros::block_executor, version::SHORT_VERSION};
use crate::common::{AccessRights, Environment, EnvironmentArgs};
use clap::Parser;
use futures::{Stream, StreamExt};
use reth_beacon_consensus::EthBeaconConsensus;
use reth_cli_commands::common::{AccessRights, Environment, EnvironmentArgs};
use reth_chainspec::ChainSpec;
use reth_config::Config;
use reth_consensus::Consensus;
use reth_db::tables;
@ -13,10 +13,12 @@ use reth_downloaders::{
file_client::{ChunkedFileReader, FileClient, DEFAULT_BYTE_LEN_CHUNK_CHAIN_FILE},
headers::reverse_headers::ReverseHeadersDownloaderBuilder,
};
use reth_evm::execute::BlockExecutorProvider;
use reth_network_p2p::{
bodies::downloader::BodyDownloader,
headers::downloader::{HeaderDownloader, SyncTarget},
};
use reth_node_core::version::SHORT_VERSION;
use reth_node_events::node::NodeEvent;
use reth_primitives::B256;
use reth_provider::{
@ -54,7 +56,11 @@ pub struct ImportCommand {
impl ImportCommand {
/// Execute `import` command
pub async fn execute(self) -> eyre::Result<()> {
pub async fn execute<E, F>(self, executor: F) -> eyre::Result<()>
where
E: BlockExecutorProvider,
F: FnOnce(Arc<ChainSpec>) -> E,
{
info!(target: "reth::cli", "reth {} starting", SHORT_VERSION);
if self.no_state {
@ -68,6 +74,7 @@ impl ImportCommand {
let Environment { provider_factory, config, .. } = self.env.init(AccessRights::RW)?;
let executor = executor(provider_factory.chain_spec());
let consensus = Arc::new(EthBeaconConsensus::new(self.env.chain.clone()));
info!(target: "reth::cli", "Consensus engine initialized");
@ -96,6 +103,7 @@ impl ImportCommand {
Arc::new(file_client),
StaticFileProducer::new(provider_factory.clone(), PruneModes::default()),
self.no_state,
executor.clone(),
)?;
// override the tip
@ -152,17 +160,19 @@ impl ImportCommand {
///
/// If configured to execute, all stages will run. Otherwise, only stages that don't require state
/// will run.
pub fn build_import_pipeline<DB, C>(
pub fn build_import_pipeline<DB, C, E>(
config: &Config,
provider_factory: ProviderFactory<DB>,
consensus: &Arc<C>,
file_client: Arc<FileClient>,
static_file_producer: StaticFileProducer<DB>,
disable_exec: bool,
executor: E,
) -> eyre::Result<(Pipeline<DB>, impl Stream<Item = NodeEvent>)>
where
DB: Database + Clone + Unpin + 'static,
C: Consensus + 'static,
E: BlockExecutorProvider,
{
if !file_client.has_canonical_blocks() {
eyre::bail!("unable to import non canonical blocks");
@ -192,7 +202,6 @@ where
.expect("failed to set download range");
let (tip_tx, tip_rx) = watch::channel(B256::ZERO);
let executor = block_executor!(provider_factory.chain_spec());
let max_block = file_client.max_block().unwrap_or(0);

View File

@ -12,6 +12,7 @@ pub mod common;
pub mod config_cmd;
pub mod db;
pub mod dump_genesis;
pub mod import;
pub mod init_cmd;
pub mod init_state;
pub mod node;