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:
Martin Paulucci
2023-01-16 13:40:49 -03:00
committed by GitHub
parent 27ed772d31
commit 3cd8fb5748

View File

@@ -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(())
}
}