reth_cli_commands/stage/
mod.rs

1//! `reth stage` command
2
3use std::sync::Arc;
4
5use crate::common::CliNodeTypes;
6use clap::{Parser, Subcommand};
7use reth_chainspec::{EthChainSpec, EthereumHardforks};
8use reth_cli::chainspec::ChainSpecParser;
9use reth_cli_runner::CliContext;
10use reth_evm::execute::BlockExecutorProvider;
11
12pub mod drop;
13pub mod dump;
14pub mod run;
15pub mod unwind;
16
17/// `reth stage` command
18#[derive(Debug, Parser)]
19pub struct Command<C: ChainSpecParser> {
20    #[command(subcommand)]
21    command: Subcommands<C>,
22}
23
24/// `reth stage` subcommands
25#[derive(Subcommand, Debug)]
26pub enum Subcommands<C: ChainSpecParser> {
27    /// Run a single stage.
28    ///
29    /// Note that this won't use the Pipeline and as a result runs stages
30    /// assuming that all the data can be held in memory. It is not recommended
31    /// to run a stage for really large block ranges if your computer does not have
32    /// a lot of memory to store all the data.
33    Run(run::Command<C>),
34    /// Drop a stage's tables from the database.
35    Drop(drop::Command<C>),
36    /// Dumps a stage from a range into a new database.
37    Dump(dump::Command<C>),
38    /// Unwinds a certain block range, deleting it from the database.
39    Unwind(unwind::Command<C>),
40}
41
42impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> Command<C> {
43    /// Execute `stage` command
44    pub async fn execute<N, E, F>(self, ctx: CliContext, executor: F) -> eyre::Result<()>
45    where
46        N: CliNodeTypes<ChainSpec = C::ChainSpec>,
47        E: BlockExecutorProvider<Primitives = N::Primitives>,
48        F: FnOnce(Arc<C::ChainSpec>) -> E,
49    {
50        match self.command {
51            Subcommands::Run(command) => command.execute::<N, _, _>(ctx, executor).await,
52            Subcommands::Drop(command) => command.execute::<N>().await,
53            Subcommands::Dump(command) => command.execute::<N, _, _>(executor).await,
54            Subcommands::Unwind(command) => command.execute::<N>().await,
55        }
56    }
57}