From 492fc20fd1f41ecd9175621cc7b8875b784e8d95 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Thu, 22 Jan 2026 12:09:36 +0000 Subject: [PATCH] fix(cli): clear rocksdb tables in drop-stage command (#21299) Co-authored-by: Amp --- crates/cli/commands/src/stage/drop.rs | 28 ++++++++++++++++--- .../provider/src/providers/rocksdb_stub.rs | 7 +++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/crates/cli/commands/src/stage/drop.rs b/crates/cli/commands/src/stage/drop.rs index 46bad48fd9..cb091ef912 100644 --- a/crates/cli/commands/src/stage/drop.rs +++ b/crates/cli/commands/src/stage/drop.rs @@ -15,7 +15,8 @@ use reth_db_common::{ use reth_node_api::{HeaderTy, ReceiptTy, TxTy}; use reth_node_core::args::StageEnum; use reth_provider::{ - DBProvider, DatabaseProviderFactory, StaticFileProviderFactory, StaticFileWriter, + DBProvider, DatabaseProviderFactory, RocksDBProviderFactory, StaticFileProviderFactory, + StaticFileWriter, StorageSettingsCache, }; use reth_prune::PruneSegment; use reth_stages::StageId; @@ -168,8 +169,20 @@ impl Command { )?; } StageEnum::AccountHistory | StageEnum::StorageHistory => { - tx.clear::()?; - tx.clear::()?; + let settings = provider_rw.cached_storage_settings(); + let rocksdb = tool.provider_factory.rocksdb_provider(); + + if settings.account_history_in_rocksdb { + rocksdb.clear::()?; + } else { + tx.clear::()?; + } + + if settings.storages_history_in_rocksdb { + rocksdb.clear::()?; + } else { + tx.clear::()?; + } reset_stage_checkpoint(tx, StageId::IndexAccountHistory)?; reset_stage_checkpoint(tx, StageId::IndexStorageHistory)?; @@ -177,7 +190,14 @@ impl Command { insert_genesis_history(&provider_rw, self.env.chain.genesis().alloc.iter())?; } StageEnum::TxLookup => { - tx.clear::()?; + if provider_rw.cached_storage_settings().transaction_hash_numbers_in_rocksdb { + tool.provider_factory + .rocksdb_provider() + .clear::()?; + } else { + tx.clear::()?; + } + reset_prune_checkpoint(tx, PruneSegment::TransactionLookup)?; reset_stage_checkpoint(tx, StageId::TransactionLookup)?; diff --git a/crates/storage/provider/src/providers/rocksdb_stub.rs b/crates/storage/provider/src/providers/rocksdb_stub.rs index 5125c7e571..965877db2e 100644 --- a/crates/storage/provider/src/providers/rocksdb_stub.rs +++ b/crates/storage/provider/src/providers/rocksdb_stub.rs @@ -81,6 +81,13 @@ impl RocksDBProvider { pub const fn table_stats(&self) -> Vec { Vec::new() } + + /// Clears all entries from the specified table (stub implementation). + /// + /// This is a no-op since there is no `RocksDB` when the feature is disabled. + pub const fn clear(&self) -> ProviderResult<()> { + Ok(()) + } } impl DatabaseMetrics for RocksDBProvider {