Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions bin/reth/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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")]
Expand Down
1 change: 0 additions & 1 deletion bin/reth/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//! This contains all of the `reth` commands

pub mod debug_cmd;
pub mod import;
4 changes: 3 additions & 1 deletion crates/cli/commands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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::{
Expand Down Expand Up @@ -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 {
Expand All @@ -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");

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions crates/cli/commands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading