mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 09:08:05 -05:00
refactor: remove db file on db drop command. (#885)
Co-authored-by: lambdaclass-user <github@lambdaclass.com> Co-authored-by: Bjerg <onbjerg@users.noreply.github.com>
This commit is contained in:
@@ -7,7 +7,7 @@ use reth_db::{
|
||||
database::Database,
|
||||
table::Table,
|
||||
tables,
|
||||
transaction::{DbTx, DbTxMut},
|
||||
transaction::DbTx,
|
||||
};
|
||||
use reth_interfaces::test_utils::generators::random_block_range;
|
||||
use reth_provider::insert_canonical_block;
|
||||
@@ -115,7 +115,7 @@ impl Command {
|
||||
tool.list(args)?;
|
||||
}
|
||||
Subcommands::Drop => {
|
||||
tool.drop()?;
|
||||
tool.drop(&self.db)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,41 +203,9 @@ impl<'a, DB: Database> DbTool<'a, DB> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn drop(&mut self) -> Result<()> {
|
||||
macro_rules! drop_tables {
|
||||
([$($table:ident,)*]) => {
|
||||
let _tx = self.db.tx_mut()?;
|
||||
$(_tx.clear::<tables::$table>()?;)*
|
||||
_tx.commit()?;
|
||||
};
|
||||
}
|
||||
|
||||
drop_tables!([
|
||||
CanonicalHeaders,
|
||||
HeaderTD,
|
||||
HeaderNumbers,
|
||||
Headers,
|
||||
BlockBodies,
|
||||
BlockOmmers,
|
||||
NonCanonicalTransactions,
|
||||
Transactions,
|
||||
TxHashNumber,
|
||||
Receipts,
|
||||
Logs,
|
||||
PlainAccountState,
|
||||
PlainStorageState,
|
||||
Bytecodes,
|
||||
BlockTransitionIndex,
|
||||
TxTransitionIndex,
|
||||
AccountHistory,
|
||||
StorageHistory,
|
||||
AccountChangeSet,
|
||||
StorageChangeSet,
|
||||
TxSenders,
|
||||
Config,
|
||||
SyncStage,
|
||||
]);
|
||||
|
||||
fn drop(&mut self, path: &PlatformPath<DbPath>) -> Result<()> {
|
||||
info!(target: "reth::cli", "Dropping db at {}", path);
|
||||
std::fs::remove_dir_all(path).wrap_err("Dropping the database failed")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user