From 79c0cb313b5265d78b17ee9ce423467537eb753c Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Wed, 17 Sep 2025 15:38:29 +0200 Subject: [PATCH 1/2] chore: Remove `reth recover storage-tries` sub-command The sub-command is redundant with the `reth db repair-tries` sub-command, which repairs both storage and account tries as well as outputting the exact fixes which were made. --- crates/cli/commands/src/lib.rs | 1 - crates/cli/commands/src/recover/mod.rs | 45 ----------- .../cli/commands/src/recover/storage_tries.rs | 76 ------------------- crates/ethereum/cli/src/app.rs | 3 - crates/ethereum/cli/src/interface.rs | 6 +- crates/optimism/cli/src/app.rs | 3 - crates/optimism/cli/src/commands/mod.rs | 6 +- 7 files changed, 2 insertions(+), 138 deletions(-) delete mode 100644 crates/cli/commands/src/recover/mod.rs delete mode 100644 crates/cli/commands/src/recover/storage_tries.rs diff --git a/crates/cli/commands/src/lib.rs b/crates/cli/commands/src/lib.rs index 84586359b36..85bc0f1510a 100644 --- a/crates/cli/commands/src/lib.rs +++ b/crates/cli/commands/src/lib.rs @@ -24,7 +24,6 @@ pub mod node; pub mod p2p; pub mod prune; pub mod re_execute; -pub mod recover; pub mod stage; #[cfg(feature = "arbitrary")] pub mod test_vectors; diff --git a/crates/cli/commands/src/recover/mod.rs b/crates/cli/commands/src/recover/mod.rs deleted file mode 100644 index dde0d6c448f..00000000000 --- a/crates/cli/commands/src/recover/mod.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! `reth recover` command. - -use crate::common::CliNodeTypes; -use clap::{Parser, Subcommand}; -use reth_chainspec::{EthChainSpec, EthereumHardforks}; -use reth_cli::chainspec::ChainSpecParser; -use reth_cli_runner::CliContext; -use std::sync::Arc; - -mod storage_tries; - -/// `reth recover` command -#[derive(Debug, Parser)] -pub struct Command { - #[command(subcommand)] - command: Subcommands, -} - -/// `reth recover` subcommands -#[derive(Subcommand, Debug)] -pub enum Subcommands { - /// Recover the node by deleting dangling storage tries. - StorageTries(storage_tries::Command), -} - -impl> Command { - /// Execute `recover` command - pub async fn execute>( - self, - ctx: CliContext, - ) -> eyre::Result<()> { - match self.command { - Subcommands::StorageTries(command) => command.execute::(ctx).await, - } - } -} - -impl Command { - /// Returns the underlying chain being used to run this command - pub fn chain_spec(&self) -> Option<&Arc> { - match &self.command { - Subcommands::StorageTries(command) => command.chain_spec(), - } - } -} diff --git a/crates/cli/commands/src/recover/storage_tries.rs b/crates/cli/commands/src/recover/storage_tries.rs deleted file mode 100644 index 9974f2fd72c..00000000000 --- a/crates/cli/commands/src/recover/storage_tries.rs +++ /dev/null @@ -1,76 +0,0 @@ -use crate::common::{AccessRights, CliNodeTypes, Environment, EnvironmentArgs}; -use alloy_consensus::BlockHeader; -use clap::Parser; -use reth_chainspec::{EthChainSpec, EthereumHardforks}; -use reth_cli::chainspec::ChainSpecParser; -use reth_cli_runner::CliContext; -use reth_db_api::{ - cursor::{DbCursorRO, DbDupCursorRW}, - tables, - transaction::DbTx, -}; -use reth_provider::{BlockNumReader, HeaderProvider, ProviderError}; -use reth_trie::StateRoot; -use reth_trie_db::DatabaseStateRoot; -use std::sync::Arc; -use tracing::*; - -/// `reth recover storage-tries` command -#[derive(Debug, Parser)] -pub struct Command { - #[command(flatten)] - env: EnvironmentArgs, -} - -impl> Command { - /// Execute `storage-tries` recovery command - pub async fn execute>( - self, - _ctx: CliContext, - ) -> eyre::Result<()> { - let Environment { provider_factory, .. } = self.env.init::(AccessRights::RW)?; - - let mut provider = provider_factory.provider_rw()?; - let best_block = provider.best_block_number()?; - let best_header = provider - .sealed_header(best_block)? - .ok_or_else(|| ProviderError::HeaderNotFound(best_block.into()))?; - - let mut deleted_tries = 0; - let tx_mut = provider.tx_mut(); - let mut hashed_account_cursor = tx_mut.cursor_read::()?; - let mut storage_trie_cursor = tx_mut.cursor_dup_read::()?; - let mut entry = storage_trie_cursor.first()?; - - info!(target: "reth::cli", "Starting pruning of storage tries"); - while let Some((hashed_address, _)) = entry { - if hashed_account_cursor.seek_exact(hashed_address)?.is_none() { - deleted_tries += 1; - storage_trie_cursor.delete_current_duplicates()?; - } - - entry = storage_trie_cursor.next()?; - } - - let state_root = StateRoot::from_tx(tx_mut).root()?; - if state_root != best_header.state_root() { - eyre::bail!( - "Recovery failed. Incorrect state root. Expected: {:?}. Received: {:?}", - best_header.state_root(), - state_root - ); - } - - provider.commit()?; - info!(target: "reth::cli", deleted = deleted_tries, "Finished recovery"); - - Ok(()) - } -} - -impl Command { - /// Returns the underlying chain being used to run this command - pub fn chain_spec(&self) -> Option<&Arc> { - Some(&self.env.chain) - } -} diff --git a/crates/ethereum/cli/src/app.rs b/crates/ethereum/cli/src/app.rs index 2e8add1447c..e99dae2ac77 100644 --- a/crates/ethereum/cli/src/app.rs +++ b/crates/ethereum/cli/src/app.rs @@ -165,9 +165,6 @@ where } Commands::P2P(command) => runner.run_until_ctrl_c(command.execute::()), Commands::Config(command) => runner.run_until_ctrl_c(command.execute()), - Commands::Recover(command) => { - runner.run_command_until_exit(|ctx| command.execute::(ctx)) - } Commands::Prune(command) => runner.run_until_ctrl_c(command.execute::()), #[cfg(feature = "dev")] Commands::TestVectors(command) => runner.run_until_ctrl_c(command.execute()), diff --git a/crates/ethereum/cli/src/interface.rs b/crates/ethereum/cli/src/interface.rs index 5f9fd79c67b..c1d91c12c79 100644 --- a/crates/ethereum/cli/src/interface.rs +++ b/crates/ethereum/cli/src/interface.rs @@ -12,7 +12,7 @@ use reth_cli_commands::{ config_cmd, db, download, dump_genesis, export_era, import, import_era, init_cmd, init_state, launcher::FnLauncher, node::{self, NoArgs}, - p2p, prune, re_execute, recover, stage, + p2p, prune, re_execute, stage, }; use reth_cli_runner::CliRunner; use reth_db::DatabaseEnv; @@ -260,9 +260,6 @@ pub enum Commands { /// Write config to stdout #[command(name = "config")] Config(config_cmd::Command), - /// Scripts for node recovery - #[command(name = "recover")] - Recover(recover::Command), /// Prune according to the configuration without any limits #[command(name = "prune")] Prune(prune::PruneCommand), @@ -289,7 +286,6 @@ impl Commands { #[cfg(feature = "dev")] Self::TestVectors(_) => None, Self::Config(_) => None, - Self::Recover(cmd) => cmd.chain_spec(), Self::Prune(cmd) => cmd.chain_spec(), Self::ReExecute(cmd) => cmd.chain_spec(), } diff --git a/crates/optimism/cli/src/app.rs b/crates/optimism/cli/src/app.rs index 0d3d691968b..1e9f7960ad1 100644 --- a/crates/optimism/cli/src/app.rs +++ b/crates/optimism/cli/src/app.rs @@ -102,9 +102,6 @@ where } Commands::P2P(command) => runner.run_until_ctrl_c(command.execute::()), Commands::Config(command) => runner.run_until_ctrl_c(command.execute()), - Commands::Recover(command) => { - runner.run_command_until_exit(|ctx| command.execute::(ctx)) - } Commands::Prune(command) => runner.run_until_ctrl_c(command.execute::()), #[cfg(feature = "dev")] Commands::TestVectors(command) => runner.run_until_ctrl_c(command.execute()), diff --git a/crates/optimism/cli/src/commands/mod.rs b/crates/optimism/cli/src/commands/mod.rs index 040c4668101..5edd55b0ccb 100644 --- a/crates/optimism/cli/src/commands/mod.rs +++ b/crates/optimism/cli/src/commands/mod.rs @@ -7,7 +7,7 @@ use reth_cli::chainspec::ChainSpecParser; use reth_cli_commands::{ config_cmd, db, dump_genesis, init_cmd, node::{self, NoArgs}, - p2p, prune, re_execute, recover, stage, + p2p, prune, re_execute, stage, }; use std::{fmt, sync::Arc}; @@ -51,9 +51,6 @@ pub enum Commands), /// Prune according to the configuration without any limits #[command(name = "prune")] Prune(prune::PruneCommand), @@ -82,7 +79,6 @@ impl< Self::Stage(cmd) => cmd.chain_spec(), Self::P2P(cmd) => cmd.chain_spec(), Self::Config(_) => None, - Self::Recover(cmd) => cmd.chain_spec(), Self::Prune(cmd) => cmd.chain_spec(), Self::ImportOp(cmd) => cmd.chain_spec(), Self::ImportReceiptsOp(cmd) => cmd.chain_spec(), From a1b7269d8558063d4d5c4deea0c3183b6c292c3c Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Fri, 19 Sep 2025 17:06:43 +0200 Subject: [PATCH 2/2] docs fix --- docs/vocs/docs/pages/cli/SUMMARY.mdx | 2 -- docs/vocs/docs/pages/cli/reth.mdx | 1 - 2 files changed, 3 deletions(-) diff --git a/docs/vocs/docs/pages/cli/SUMMARY.mdx b/docs/vocs/docs/pages/cli/SUMMARY.mdx index 8158a9b94e4..7f7012f4c1e 100644 --- a/docs/vocs/docs/pages/cli/SUMMARY.mdx +++ b/docs/vocs/docs/pages/cli/SUMMARY.mdx @@ -40,7 +40,5 @@ - [`reth p2p rlpx ping`](/cli/reth/p2p/rlpx/ping) - [`reth p2p bootnode`](/cli/reth/p2p/bootnode) - [`reth config`](/cli/reth/config) - - [`reth recover`](/cli/reth/recover) - - [`reth recover storage-tries`](/cli/reth/recover/storage-tries) - [`reth prune`](/cli/reth/prune) - [`reth re-execute`](/cli/reth/re-execute) \ No newline at end of file diff --git a/docs/vocs/docs/pages/cli/reth.mdx b/docs/vocs/docs/pages/cli/reth.mdx index 88218426c7a..9a32d647876 100644 --- a/docs/vocs/docs/pages/cli/reth.mdx +++ b/docs/vocs/docs/pages/cli/reth.mdx @@ -21,7 +21,6 @@ Commands: stage Manipulate individual stages p2p P2P Debugging utilities config Write config to stdout - recover Scripts for node recovery prune Prune according to the configuration without any limits re-execute Re-execute blocks in parallel to verify historical sync correctness help Print this message or the help of the given subcommand(s)