From 4d067ec25edeaab846813b785bc1c41e4aa10b98 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Mon, 3 Jun 2024 19:22:28 +0200 Subject: [PATCH] chore: remove `chain` field from `DbTool` (#8562) --- bin/reth/src/commands/db/mod.rs | 4 ++-- bin/reth/src/commands/stage/drop.rs | 2 +- bin/reth/src/commands/stage/dump/execution.rs | 4 ++-- bin/reth/src/commands/stage/dump/hashing_account.rs | 2 +- bin/reth/src/commands/stage/dump/hashing_storage.rs | 2 +- bin/reth/src/commands/stage/dump/merkle.rs | 4 ++-- bin/reth/src/commands/stage/dump/mod.rs | 2 +- bin/reth/src/utils.rs | 13 ++++++++----- 8 files changed, 18 insertions(+), 15 deletions(-) diff --git a/bin/reth/src/commands/db/mod.rs b/bin/reth/src/commands/db/mod.rs index 11d614cb8..cda94f458 100644 --- a/bin/reth/src/commands/db/mod.rs +++ b/bin/reth/src/commands/db/mod.rs @@ -89,7 +89,7 @@ macro_rules! db_ro_exec { let provider_factory = ProviderFactory::new(db, $chain.clone(), StaticFileProvider::read_only($sfp)?); - let $tool = DbTool::new(provider_factory, $chain.clone())?; + let $tool = DbTool::new(provider_factory)?; $command; }; } @@ -153,7 +153,7 @@ impl Command { StaticFileProvider::read_write(&static_files_path)?, ); - let tool = DbTool::new(provider_factory, self.chain.clone())?; + let tool = DbTool::new(provider_factory)?; tool.drop(db_path, static_files_path)?; } Subcommands::Clear(command) => { diff --git a/bin/reth/src/commands/stage/drop.rs b/bin/reth/src/commands/stage/drop.rs index 9e61755cd..5906e4816 100644 --- a/bin/reth/src/commands/stage/drop.rs +++ b/bin/reth/src/commands/stage/drop.rs @@ -61,7 +61,7 @@ impl Command { ); let static_file_provider = provider_factory.static_file_provider(); - let tool = DbTool::new(provider_factory, self.chain.clone())?; + let tool = DbTool::new(provider_factory)?; let static_file_segment = match self.stage { StageEnum::Headers => Some(StaticFileSegment::Headers), diff --git a/bin/reth/src/commands/stage/dump/execution.rs b/bin/reth/src/commands/stage/dump/execution.rs index 2ace21aa7..5c4a41c36 100644 --- a/bin/reth/src/commands/stage/dump/execution.rs +++ b/bin/reth/src/commands/stage/dump/execution.rs @@ -27,7 +27,7 @@ pub(crate) async fn dump_execution_stage( dry_run( ProviderFactory::new( output_db, - db_tool.chain.clone(), + db_tool.chain(), StaticFileProvider::read_write(output_datadir.static_files())?, ), to, @@ -128,7 +128,7 @@ async fn unwind_and_copy( ) -> eyre::Result<()> { let provider = db_tool.provider_factory.provider_rw()?; - let executor = block_executor!(db_tool.chain.clone()); + let executor = block_executor!(db_tool.chain()); let mut exec_stage = ExecutionStage::new_with_executor(executor); exec_stage.unwind( diff --git a/bin/reth/src/commands/stage/dump/hashing_account.rs b/bin/reth/src/commands/stage/dump/hashing_account.rs index 125af668a..a1961ad2e 100644 --- a/bin/reth/src/commands/stage/dump/hashing_account.rs +++ b/bin/reth/src/commands/stage/dump/hashing_account.rs @@ -32,7 +32,7 @@ pub(crate) async fn dump_hashing_account_stage( dry_run( ProviderFactory::new( output_db, - db_tool.chain.clone(), + db_tool.chain(), StaticFileProvider::read_write(output_datadir.static_files())?, ), to, diff --git a/bin/reth/src/commands/stage/dump/hashing_storage.rs b/bin/reth/src/commands/stage/dump/hashing_storage.rs index 98df3a570..7b05761cf 100644 --- a/bin/reth/src/commands/stage/dump/hashing_storage.rs +++ b/bin/reth/src/commands/stage/dump/hashing_storage.rs @@ -23,7 +23,7 @@ pub(crate) async fn dump_hashing_storage_stage( dry_run( ProviderFactory::new( output_db, - db_tool.chain.clone(), + db_tool.chain(), StaticFileProvider::read_write(output_datadir.static_files())?, ), to, diff --git a/bin/reth/src/commands/stage/dump/merkle.rs b/bin/reth/src/commands/stage/dump/merkle.rs index 605f423aa..d75078df7 100644 --- a/bin/reth/src/commands/stage/dump/merkle.rs +++ b/bin/reth/src/commands/stage/dump/merkle.rs @@ -47,7 +47,7 @@ pub(crate) async fn dump_merkle_stage( dry_run( ProviderFactory::new( output_db, - db_tool.chain.clone(), + db_tool.chain(), StaticFileProvider::read_write(output_datadir.static_files())?, ), to, @@ -84,7 +84,7 @@ async fn unwind_and_copy( MerkleStage::default_unwind().unwind(&provider, unwind)?; - let executor = block_executor!(db_tool.chain.clone()); + let executor = block_executor!(db_tool.chain()); // Bring Plainstate to TO (hashing stage execution requires it) let mut exec_stage = ExecutionStage::new( diff --git a/bin/reth/src/commands/stage/dump/mod.rs b/bin/reth/src/commands/stage/dump/mod.rs index e126d3fa1..ec057583b 100644 --- a/bin/reth/src/commands/stage/dump/mod.rs +++ b/bin/reth/src/commands/stage/dump/mod.rs @@ -103,7 +103,7 @@ impl Command { info!(target: "reth::cli", "Database opened"); - let tool = DbTool::new(provider_factory, self.chain.clone())?; + let tool = DbTool::new(provider_factory)?; match &self.command { Stages::Execution(StageCommand { output_datadir, from, to, dry_run, .. }) => { diff --git a/bin/reth/src/utils.rs b/bin/reth/src/utils.rs index 5f8c57976..6dec2953d 100644 --- a/bin/reth/src/utils.rs +++ b/bin/reth/src/utils.rs @@ -11,7 +11,7 @@ use reth_db::{ }; use reth_fs_util as fs; use reth_primitives::ChainSpec; -use reth_provider::ProviderFactory; +use reth_provider::{ChainSpecProvider, ProviderFactory}; use std::{path::Path, rc::Rc, sync::Arc}; use tracing::info; @@ -29,17 +29,20 @@ pub use reth_node_core::utils::*; pub struct DbTool { /// The provider factory that the db tool will use. pub provider_factory: ProviderFactory, - /// The [`ChainSpec`] that the db tool will use. - pub chain: Arc, } impl DbTool { /// Takes a DB where the tables have already been created. - pub fn new(provider_factory: ProviderFactory, chain: Arc) -> eyre::Result { + pub fn new(provider_factory: ProviderFactory) -> eyre::Result { // Disable timeout because we are entering a TUI which might read for a long time. We // disable on the [`DbTool`] level since it's only used in the CLI. provider_factory.provider()?.disable_long_read_transaction_safety(); - Ok(Self { provider_factory, chain }) + Ok(Self { provider_factory }) + } + + /// Get an [`Arc`] to the [`ChainSpec`]. + pub fn chain(&self) -> Arc { + self.provider_factory.chain_spec() } /// Grabs the contents of the table within a certain index range and places the