From d2a562c102456545698aaae32ed025df55b22a03 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 2 Aug 2024 13:07:21 +0200 Subject: [PATCH 1/6] make db provider non optional --- crates/storage/errors/src/writer.rs | 3 --- crates/storage/provider/src/writer/mod.rs | 31 ++++------------------- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/crates/storage/errors/src/writer.rs b/crates/storage/errors/src/writer.rs index e74783f69f8d..66d8dd7f7a66 100644 --- a/crates/storage/errors/src/writer.rs +++ b/crates/storage/errors/src/writer.rs @@ -4,9 +4,6 @@ use reth_primitives::StaticFileSegment; /// `StorageWriter` related errors #[derive(Clone, Debug, thiserror_no_std::Error, PartialEq, Eq)] pub enum StorageWriterError { - /// Database writer is missing - #[error("Database writer is missing")] - MissingDatabaseWriter, /// Static file writer is missing #[error("Static file writer is missing")] MissingStaticFileWriter, diff --git a/crates/storage/provider/src/writer/mod.rs b/crates/storage/provider/src/writer/mod.rs index 00776a86d924..ec2ea80b9f7a 100644 --- a/crates/storage/provider/src/writer/mod.rs +++ b/crates/storage/provider/src/writer/mod.rs @@ -39,7 +39,7 @@ enum StorageType { /// both. #[derive(Debug)] pub struct StorageWriter<'a, TX, SF> { - database: Option<&'a DatabaseProvider>, + database: &'a DatabaseProvider, static_file: Option, } @@ -49,24 +49,19 @@ impl<'a, TX, SF> StorageWriter<'a, TX, SF> { /// # Parameters /// - `database`: An optional reference to a database provider. /// - `static_file`: An optional mutable reference to a static file instance. - pub const fn new(database: Option<&'a DatabaseProvider>, static_file: Option) -> Self { + pub const fn new(database: &'a DatabaseProvider, static_file: Option) -> Self { Self { database, static_file } } /// Creates a new instance of [`StorageWriter`] from a database provider and a static file /// instance. pub const fn from(database: &'a DatabaseProvider, static_file: SF) -> Self { - Self::new(Some(database), Some(static_file)) - } - - /// Creates a new instance of [`StorageWriter`] from a static file instance. - pub const fn from_static_file(static_file: SF) -> Self { - Self::new(None, Some(static_file)) + Self::new(database, Some(static_file)) } /// Creates a new instance of [`StorageWriter`] from a database provider. pub const fn from_database(database: &'a DatabaseProvider) -> Self { - Self::new(Some(database), None) + Self::new(database, None) } /// Returns a reference to the database writer. @@ -74,7 +69,7 @@ impl<'a, TX, SF> StorageWriter<'a, TX, SF> { /// # Panics /// If the database provider is not set. fn database(&self) -> &DatabaseProvider { - self.database.as_ref().expect("should exist") + self.database } /// Returns a reference to the static file instance. @@ -93,18 +88,6 @@ impl<'a, TX, SF> StorageWriter<'a, TX, SF> { self.static_file.as_mut().expect("should exist") } - /// Ensures that the database provider is set. - /// - /// # Returns - /// - `Ok(())` if the database provider is set. - /// - `Err(StorageWriterError::MissingDatabaseWriter)` if the database provider is not set. - const fn ensure_database(&self) -> Result<(), StorageWriterError> { - if self.database.is_none() { - return Err(StorageWriterError::MissingDatabaseWriter) - } - Ok(()) - } - /// Ensures that the static file instance is set. /// /// # Returns @@ -342,7 +325,6 @@ where I: Borrow<(H, B256)>, H: Borrow
, { - self.ensure_database()?; self.ensure_static_file_segment(StaticFileSegment::Headers)?; let mut td = self @@ -374,7 +356,6 @@ where where T: Borrow>, { - self.ensure_database()?; self.ensure_static_file_segment(StaticFileSegment::Transactions)?; let mut bodies_cursor = @@ -433,7 +414,6 @@ where initial_block_number: BlockNumber, blocks: impl Iterator>>, ) -> ProviderResult<()> { - self.ensure_database()?; let mut bodies_cursor = self.database().tx_ref().cursor_read::()?; @@ -504,7 +484,6 @@ where execution_outcome: ExecutionOutcome, is_value_known: OriginalValuesKnown, ) -> ProviderResult<()> { - self.ensure_database()?; let (plain_state, reverts) = execution_outcome.bundle.into_plain_state_and_reverts(is_value_known); From 59ecd20193ee9ba28ae44a05c243abed1e18648d Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 2 Aug 2024 13:35:10 +0200 Subject: [PATCH 2/6] make db non optional --- .../commands/debug_cmd/in_memory_merkle.rs | 2 +- bin/reth/src/commands/debug_cmd/merkle.rs | 2 +- .../cli/src/commands/import_receipts.rs | 2 +- crates/stages/stages/src/stages/execution.rs | 2 +- crates/storage/db-common/src/init.rs | 2 +- .../src/providers/database/provider.rs | 2 +- crates/storage/provider/src/writer/mod.rs | 28 ++++++++----------- 7 files changed, 18 insertions(+), 22 deletions(-) diff --git a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs index 3d5e20c8f47c..e3406087d40e 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -171,7 +171,7 @@ impl Command { .try_seal_with_senders() .map_err(|_| BlockValidationError::SenderRecoveryError)?, )?; - let mut storage_writer = StorageWriter::new(Some(&provider_rw), None); + let mut storage_writer = StorageWriter::from_database(&provider_rw); storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::No)?; let storage_lists = provider_rw.changed_storages_with_range(block.number..=block.number)?; let storages = provider_rw.plain_state_storages(storage_lists)?; diff --git a/bin/reth/src/commands/debug_cmd/merkle.rs b/bin/reth/src/commands/debug_cmd/merkle.rs index 9bfaf641245d..982acc997125 100644 --- a/bin/reth/src/commands/debug_cmd/merkle.rs +++ b/bin/reth/src/commands/debug_cmd/merkle.rs @@ -155,7 +155,7 @@ impl Command { executor.execute_and_verify_one((&sealed_block.clone().unseal(), td).into())?; let execution_outcome = executor.finalize(); - let mut storage_writer = StorageWriter::new(Some(&provider_rw), None); + let mut storage_writer = StorageWriter::from_database(&provider_rw); storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::Yes)?; let checkpoint = Some(StageCheckpoint::new( diff --git a/crates/optimism/cli/src/commands/import_receipts.rs b/crates/optimism/cli/src/commands/import_receipts.rs index 30d2f82c9c61..66b172ebf69a 100644 --- a/crates/optimism/cli/src/commands/import_receipts.rs +++ b/crates/optimism/cli/src/commands/import_receipts.rs @@ -231,7 +231,7 @@ where static_file_provider.get_writer(first_block, StaticFileSegment::Receipts)?; // finally, write the receipts - let mut storage_writer = StorageWriter::new(Some(&provider), Some(static_file_producer)); + let mut storage_writer = StorageWriter::from(&provider, static_file_producer); storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::Yes)?; } diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index e7acbd5afdde..86ca70353e2b 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -361,7 +361,7 @@ where let time = Instant::now(); // write output - let mut writer = StorageWriter::new(Some(provider), static_file_producer); + let mut writer = StorageWriter::new(provider, static_file_producer); writer.write_to_storage(state, OriginalValuesKnown::Yes)?; let db_write_duration = time.elapsed(); diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index 19c48637e55a..48b536720874 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -210,7 +210,7 @@ pub fn insert_state<'a, 'b, DB: Database>( Vec::new(), ); - let mut storage_writer = StorageWriter::new(Some(provider), None); + let mut storage_writer = StorageWriter::from_database(provider); storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::Yes)?; trace!(target: "reth::cli", "Inserted state"); diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 7b8bf9770419..b74aee57588c 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -3600,7 +3600,7 @@ impl BlockWriter for DatabaseProvider { // Must be written after blocks because of the receipt lookup. // TODO: should _these_ be moved to storagewriter? seems like storagewriter should be // _above_ db provider - let mut storage_writer = StorageWriter::new(Some(self), None); + let mut storage_writer = StorageWriter::from_database(self); storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::No)?; durations_recorder.record_relative(metrics::Action::InsertState); diff --git a/crates/storage/provider/src/writer/mod.rs b/crates/storage/provider/src/writer/mod.rs index ec2ea80b9f7a..e87f82581b5e 100644 --- a/crates/storage/provider/src/writer/mod.rs +++ b/crates/storage/provider/src/writer/mod.rs @@ -68,7 +68,7 @@ impl<'a, TX, SF> StorageWriter<'a, TX, SF> { /// /// # Panics /// If the database provider is not set. - fn database(&self) -> &DatabaseProvider { + const fn database(&self) -> &DatabaseProvider { self.database } @@ -149,12 +149,9 @@ where let mut state_writer = if self.database().prune_modes_ref().has_receipts_pruning() { StorageWriter::from_database(self.database()) } else { - StorageWriter::new( - Some(self.database()), - Some( - self.static_file() - .get_writer(first_block.number, StaticFileSegment::Receipts)?, - ), + StorageWriter::from( + self.database(), + self.static_file().get_writer(first_block.number, StaticFileSegment::Receipts)?, ) }; @@ -209,7 +206,7 @@ where { let header_writer = self.static_file().get_writer(block.number, StaticFileSegment::Headers)?; - let mut storage_writer = StorageWriter::new(Some(self.database()), Some(header_writer)); + let mut storage_writer = StorageWriter::from(self.database(), header_writer); let td = storage_writer.append_headers_from_blocks( block.header().number, std::iter::once(&(block.header(), block.hash())), @@ -226,8 +223,7 @@ where { let transactions_writer = self.static_file().get_writer(block.number, StaticFileSegment::Transactions)?; - let mut storage_writer = - StorageWriter::new(Some(self.database()), Some(transactions_writer)); + let mut storage_writer = StorageWriter::from(self.database(), transactions_writer); let no_hash_transactions = block.body.clone().into_iter().map(TransactionSignedNoHash::from).collect(); storage_writer.append_transactions_from_blocks( @@ -770,7 +766,7 @@ mod tests { let outcome = ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new()); - let mut writer = StorageWriter::new(Some(&provider), None); + let mut writer = StorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -871,7 +867,7 @@ mod tests { state.merge_transitions(BundleRetention::Reverts); let outcome = ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 2, Vec::new()); - let mut writer = StorageWriter::new(Some(&provider), None); + let mut writer = StorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -939,7 +935,7 @@ mod tests { let outcome = ExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()); - let mut writer = StorageWriter::new(Some(&provider), None); + let mut writer = StorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -1087,7 +1083,7 @@ mod tests { let bundle = state.take_bundle(); let outcome = ExecutionOutcome::new(bundle, Receipts::default(), 1, Vec::new()); - let mut writer = StorageWriter::new(Some(&provider), None); + let mut writer = StorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -1253,7 +1249,7 @@ mod tests { init_state.merge_transitions(BundleRetention::Reverts); let outcome = ExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()); - let mut writer = StorageWriter::new(Some(&provider), None); + let mut writer = StorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -1301,7 +1297,7 @@ mod tests { state.merge_transitions(BundleRetention::Reverts); let outcome = ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new()); - let mut writer = StorageWriter::new(Some(&provider), None); + let mut writer = StorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); From 9f227accc17151a0bc1a4f79ea0d097505e4d36f Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 2 Aug 2024 13:36:19 +0200 Subject: [PATCH 3/6] rename to UnifiedStorageWriter --- .../commands/debug_cmd/in_memory_merkle.rs | 8 ++--- bin/reth/src/commands/debug_cmd/merkle.rs | 4 +-- crates/engine/tree/src/persistence.rs | 10 +++--- crates/stages/stages/src/stages/execution.rs | 4 +-- crates/storage/db-common/src/init.rs | 4 +-- .../src/providers/database/provider.rs | 4 +-- crates/storage/provider/src/writer/mod.rs | 35 ++++++++++--------- 7 files changed, 35 insertions(+), 34 deletions(-) diff --git a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs index e3406087d40e..b0cae6f90b61 100644 --- a/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs +++ b/bin/reth/src/commands/debug_cmd/in_memory_merkle.rs @@ -16,9 +16,9 @@ use reth_network::{BlockDownloaderProvider, NetworkHandle}; use reth_network_api::NetworkInfo; use reth_primitives::BlockHashOrNumber; use reth_provider::{ - writer::StorageWriter, AccountExtReader, ChainSpecProvider, HashingWriter, HeaderProvider, - LatestStateProviderRef, OriginalValuesKnown, ProviderFactory, StageCheckpointReader, - StateWriter, StaticFileProviderFactory, StorageReader, + writer::UnifiedStorageWriter, AccountExtReader, ChainSpecProvider, HashingWriter, + HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderFactory, + StageCheckpointReader, StateWriter, StaticFileProviderFactory, StorageReader, }; use reth_revm::database::StateProviderDatabase; use reth_stages::StageId; @@ -171,7 +171,7 @@ impl Command { .try_seal_with_senders() .map_err(|_| BlockValidationError::SenderRecoveryError)?, )?; - let mut storage_writer = StorageWriter::from_database(&provider_rw); + let mut storage_writer = UnifiedStorageWriter::from_database(&provider_rw); storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::No)?; let storage_lists = provider_rw.changed_storages_with_range(block.number..=block.number)?; let storages = provider_rw.plain_state_storages(storage_lists)?; diff --git a/bin/reth/src/commands/debug_cmd/merkle.rs b/bin/reth/src/commands/debug_cmd/merkle.rs index 982acc997125..08236e30ec4a 100644 --- a/bin/reth/src/commands/debug_cmd/merkle.rs +++ b/bin/reth/src/commands/debug_cmd/merkle.rs @@ -18,7 +18,7 @@ use reth_network_api::NetworkInfo; use reth_network_p2p::full_block::FullBlockClient; use reth_primitives::BlockHashOrNumber; use reth_provider::{ - writer::StorageWriter, BlockNumReader, BlockWriter, ChainSpecProvider, HeaderProvider, + writer::UnifiedStorageWriter, BlockNumReader, BlockWriter, ChainSpecProvider, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderError, ProviderFactory, StateWriter, }; use reth_revm::database::StateProviderDatabase; @@ -155,7 +155,7 @@ impl Command { executor.execute_and_verify_one((&sealed_block.clone().unseal(), td).into())?; let execution_outcome = executor.finalize(); - let mut storage_writer = StorageWriter::from_database(&provider_rw); + let mut storage_writer = UnifiedStorageWriter::from_database(&provider_rw); storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::Yes)?; let checkpoint = Some(StageCheckpoint::new( diff --git a/crates/engine/tree/src/persistence.rs b/crates/engine/tree/src/persistence.rs index 7d396c3dfee1..0c576d4ee2fd 100644 --- a/crates/engine/tree/src/persistence.rs +++ b/crates/engine/tree/src/persistence.rs @@ -3,7 +3,7 @@ use reth_chain_state::ExecutedBlock; use reth_db::Database; use reth_primitives::{SealedBlock, B256}; -use reth_provider::{writer::StorageWriter, ProviderFactory, StaticFileProviderFactory}; +use reth_provider::{writer::UnifiedStorageWriter, ProviderFactory, StaticFileProviderFactory}; use reth_prune::{Pruner, PrunerOutput}; use std::sync::{ mpsc::{Receiver, SendError, Sender}, @@ -62,10 +62,10 @@ where let provider_rw = self.provider.provider_rw().expect("todo: handle errors"); let sf_provider = self.provider.static_file_provider(); - StorageWriter::from(&provider_rw, &sf_provider) + UnifiedStorageWriter::from(&provider_rw, &sf_provider) .remove_blocks_above(new_tip_num) .expect("todo: handle errors"); - StorageWriter::commit_unwind(provider_rw, sf_provider) + UnifiedStorageWriter::commit_unwind(provider_rw, sf_provider) .expect("todo: handle errors"); // we ignore the error because the caller may or may not care about the result @@ -80,10 +80,10 @@ where let provider_rw = self.provider.provider_rw().expect("todo: handle errors"); let static_file_provider = self.provider.static_file_provider(); - StorageWriter::from(&provider_rw, &static_file_provider) + UnifiedStorageWriter::from(&provider_rw, &static_file_provider) .save_blocks(&blocks) .expect("todo: handle errors"); - StorageWriter::commit(provider_rw, static_file_provider) + UnifiedStorageWriter::commit(provider_rw, static_file_provider) .expect("todo: handle errors"); // we ignore the error because the caller may or may not care about the result diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index 86ca70353e2b..b3d2122661d2 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -10,7 +10,7 @@ use reth_primitives::{BlockNumber, Header, StaticFileSegment}; use reth_primitives_traits::format_gas_throughput; use reth_provider::{ providers::{StaticFileProvider, StaticFileProviderRWRefMut, StaticFileWriter}, - writer::StorageWriter, + writer::UnifiedStorageWriter, BlockReader, DatabaseProviderRW, HeaderProvider, LatestStateProviderRef, OriginalValuesKnown, ProviderError, StateWriter, StatsReader, TransactionVariant, }; @@ -361,7 +361,7 @@ where let time = Instant::now(); // write output - let mut writer = StorageWriter::new(provider, static_file_producer); + let mut writer = UnifiedStorageWriter::new(provider, static_file_producer); writer.write_to_storage(state, OriginalValuesKnown::Yes)?; let db_write_duration = time.elapsed(); diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index 48b536720874..9ce2ecc4f483 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -13,7 +13,7 @@ use reth_primitives::{ use reth_provider::{ errors::provider::ProviderResult, providers::{StaticFileProvider, StaticFileWriter}, - writer::StorageWriter, + writer::UnifiedStorageWriter, BlockHashReader, BlockNumReader, BundleStateInit, ChainSpecProvider, DatabaseProviderRW, ExecutionOutcome, HashingWriter, HistoryWriter, OriginalValuesKnown, ProviderError, ProviderFactory, RevertsInit, StageCheckpointWriter, StateWriter, StaticFileProviderFactory, @@ -210,7 +210,7 @@ pub fn insert_state<'a, 'b, DB: Database>( Vec::new(), ); - let mut storage_writer = StorageWriter::from_database(provider); + let mut storage_writer = UnifiedStorageWriter::from_database(provider); storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::Yes)?; trace!(target: "reth::cli", "Inserted state"); diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index b74aee57588c..0e6bfb8b6c37 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -5,7 +5,7 @@ use crate::{ traits::{ AccountExtReader, BlockSource, ChangeSetReader, ReceiptProvider, StageCheckpointWriter, }, - writer::StorageWriter, + writer::UnifiedStorageWriter, AccountReader, BlockExecutionReader, BlockExecutionWriter, BlockHashReader, BlockNumReader, BlockReader, BlockWriter, BundleStateInit, EvmEnvProvider, FinalizedBlockReader, FinalizedBlockWriter, HashingWriter, HeaderProvider, HeaderSyncGap, HeaderSyncGapProvider, @@ -3600,7 +3600,7 @@ impl BlockWriter for DatabaseProvider { // Must be written after blocks because of the receipt lookup. // TODO: should _these_ be moved to storagewriter? seems like storagewriter should be // _above_ db provider - let mut storage_writer = StorageWriter::from_database(self); + let mut storage_writer = UnifiedStorageWriter::from_database(self); storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::No)?; durations_recorder.record_relative(metrics::Action::InsertState); diff --git a/crates/storage/provider/src/writer/mod.rs b/crates/storage/provider/src/writer/mod.rs index e87f82581b5e..ef3b143cde41 100644 --- a/crates/storage/provider/src/writer/mod.rs +++ b/crates/storage/provider/src/writer/mod.rs @@ -38,12 +38,12 @@ enum StorageType { /// [`StorageWriter`] is responsible for managing the writing to either database, static file or /// both. #[derive(Debug)] -pub struct StorageWriter<'a, TX, SF> { +pub struct UnifiedStorageWriter<'a, TX, SF> { database: &'a DatabaseProvider, static_file: Option, } -impl<'a, TX, SF> StorageWriter<'a, TX, SF> { +impl<'a, TX, SF> UnifiedStorageWriter<'a, TX, SF> { /// Creates a new instance of [`StorageWriter`]. /// /// # Parameters @@ -102,7 +102,7 @@ impl<'a, TX, SF> StorageWriter<'a, TX, SF> { } } -impl StorageWriter<'_, (), ()> { +impl UnifiedStorageWriter<'_, (), ()> { /// Commits both storage types in the right order. /// /// NOTE: If unwinding data from storage, use `commit_unwind` instead! @@ -128,7 +128,7 @@ impl StorageWriter<'_, (), ()> { } } -impl<'a, 'b, TX> StorageWriter<'a, TX, &'b StaticFileProvider> +impl<'a, 'b, TX> UnifiedStorageWriter<'a, TX, &'b StaticFileProvider> where TX: DbTxMut + DbTx, { @@ -147,9 +147,9 @@ where // Only write receipts to static files if there is no receipt pruning configured. let mut state_writer = if self.database().prune_modes_ref().has_receipts_pruning() { - StorageWriter::from_database(self.database()) + UnifiedStorageWriter::from_database(self.database()) } else { - StorageWriter::from( + UnifiedStorageWriter::from( self.database(), self.static_file().get_writer(first_block.number, StaticFileSegment::Receipts)?, ) @@ -206,7 +206,7 @@ where { let header_writer = self.static_file().get_writer(block.number, StaticFileSegment::Headers)?; - let mut storage_writer = StorageWriter::from(self.database(), header_writer); + let mut storage_writer = UnifiedStorageWriter::from(self.database(), header_writer); let td = storage_writer.append_headers_from_blocks( block.header().number, std::iter::once(&(block.header(), block.hash())), @@ -223,7 +223,8 @@ where { let transactions_writer = self.static_file().get_writer(block.number, StaticFileSegment::Transactions)?; - let mut storage_writer = StorageWriter::from(self.database(), transactions_writer); + let mut storage_writer = + UnifiedStorageWriter::from(self.database(), transactions_writer); let no_hash_transactions = block.body.clone().into_iter().map(TransactionSignedNoHash::from).collect(); storage_writer.append_transactions_from_blocks( @@ -278,7 +279,7 @@ where } } -impl<'a, 'b, TX> StorageWriter<'a, TX, StaticFileProviderRWRefMut<'b>> +impl<'a, 'b, TX> UnifiedStorageWriter<'a, TX, StaticFileProviderRWRefMut<'b>> where TX: DbTx, { @@ -389,7 +390,7 @@ where } } -impl<'a, 'b, TX> StorageWriter<'a, TX, StaticFileProviderRWRefMut<'b>> +impl<'a, 'b, TX> UnifiedStorageWriter<'a, TX, StaticFileProviderRWRefMut<'b>> where TX: DbTxMut + DbTx, { @@ -469,7 +470,7 @@ where } } -impl<'a, 'b, TX> StateWriter for StorageWriter<'a, TX, StaticFileProviderRWRefMut<'b>> +impl<'a, 'b, TX> StateWriter for UnifiedStorageWriter<'a, TX, StaticFileProviderRWRefMut<'b>> where TX: DbTxMut + DbTx, { @@ -766,7 +767,7 @@ mod tests { let outcome = ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new()); - let mut writer = StorageWriter::from_database(&provider); + let mut writer = UnifiedStorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -867,7 +868,7 @@ mod tests { state.merge_transitions(BundleRetention::Reverts); let outcome = ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 2, Vec::new()); - let mut writer = StorageWriter::from_database(&provider); + let mut writer = UnifiedStorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -935,7 +936,7 @@ mod tests { let outcome = ExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()); - let mut writer = StorageWriter::from_database(&provider); + let mut writer = UnifiedStorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -1083,7 +1084,7 @@ mod tests { let bundle = state.take_bundle(); let outcome = ExecutionOutcome::new(bundle, Receipts::default(), 1, Vec::new()); - let mut writer = StorageWriter::from_database(&provider); + let mut writer = UnifiedStorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -1249,7 +1250,7 @@ mod tests { init_state.merge_transitions(BundleRetention::Reverts); let outcome = ExecutionOutcome::new(init_state.take_bundle(), Receipts::default(), 0, Vec::new()); - let mut writer = StorageWriter::from_database(&provider); + let mut writer = UnifiedStorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); @@ -1297,7 +1298,7 @@ mod tests { state.merge_transitions(BundleRetention::Reverts); let outcome = ExecutionOutcome::new(state.take_bundle(), Receipts::default(), 1, Vec::new()); - let mut writer = StorageWriter::from_database(&provider); + let mut writer = UnifiedStorageWriter::from_database(&provider); writer .write_to_storage(outcome, OriginalValuesKnown::Yes) .expect("Could not write bundle state to DB"); From 9d4087a82aaf034edee77fc121be52c16d078f87 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 2 Aug 2024 13:53:52 +0200 Subject: [PATCH 4/6] use UnifiedStorageWriter::commit everywhere --- crates/cli/commands/src/stage/drop.rs | 7 +++-- crates/cli/commands/src/stage/run.rs | 17 +++++----- .../cli/src/commands/import_receipts.rs | 3 +- crates/stages/api/src/pipeline/mod.rs | 31 ++++++++----------- crates/storage/db-common/src/init.rs | 5 +-- crates/storage/provider/src/writer/mod.rs | 10 ++++++ 6 files changed, 38 insertions(+), 35 deletions(-) diff --git a/crates/cli/commands/src/stage/drop.rs b/crates/cli/commands/src/stage/drop.rs index ec7a91b6dda0..f69b54723c4b 100644 --- a/crates/cli/commands/src/stage/drop.rs +++ b/crates/cli/commands/src/stage/drop.rs @@ -9,7 +9,9 @@ use reth_db_common::{ DbTool, }; use reth_node_core::args::StageEnum; -use reth_provider::{providers::StaticFileWriter, StaticFileProviderFactory}; +use reth_provider::{ + providers::StaticFileWriter, writer::UnifiedStorageWriter, StaticFileProviderFactory, +}; use reth_stages::StageId; use reth_static_file_types::{find_fixed_range, StaticFileSegment}; @@ -174,8 +176,7 @@ impl Command { tx.put::(StageId::Finish.to_string(), Default::default())?; - static_file_provider.commit()?; - provider_rw.commit()?; + UnifiedStorageWriter::commit_unwind(provider_rw, static_file_provider)?; Ok(()) } diff --git a/crates/cli/commands/src/stage/run.rs b/crates/cli/commands/src/stage/run.rs index ddcbdd13ca76..eae9c55bfda7 100644 --- a/crates/cli/commands/src/stage/run.rs +++ b/crates/cli/commands/src/stage/run.rs @@ -27,8 +27,8 @@ use reth_node_metrics::{ version::VersionInfo, }; use reth_provider::{ - ChainSpecProvider, StageCheckpointReader, StageCheckpointWriter, StaticFileProviderFactory, - StaticFileWriter, + writer::UnifiedStorageWriter, ChainSpecProvider, StageCheckpointReader, StageCheckpointWriter, + StaticFileProviderFactory, StaticFileWriter, }; use reth_stages::{ stages::{ @@ -272,12 +272,10 @@ impl Command { } if self.commit { - // For unwinding it makes more sense to commit the database first, since if - // this function is interrupted before the static files commit, we can just - // truncate the static files according to the - // checkpoints on the next start-up. - provider_rw.commit()?; - provider_factory.static_file_provider().commit()?; + UnifiedStorageWriter::commit_unwind( + provider_rw, + provider_factory.static_file_provider(), + )?; provider_rw = provider_factory.provider_rw()?; } } @@ -300,8 +298,7 @@ impl Command { provider_rw.save_stage_checkpoint(exec_stage.id(), checkpoint)?; } if self.commit { - provider_factory.static_file_provider().commit()?; - provider_rw.commit()?; + UnifiedStorageWriter::commit(provider_rw, provider_factory.static_file_provider())?; provider_rw = provider_factory.provider_rw()?; } diff --git a/crates/optimism/cli/src/commands/import_receipts.rs b/crates/optimism/cli/src/commands/import_receipts.rs index 66b172ebf69a..272185d2d008 100644 --- a/crates/optimism/cli/src/commands/import_receipts.rs +++ b/crates/optimism/cli/src/commands/import_receipts.rs @@ -235,10 +235,9 @@ where storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::Yes)?; } - provider.commit()?; // as static files works in file ranges, internally it will be committing when creating the // next file range already, so we only need to call explicitly at the end. - static_file_provider.commit()?; + UnifiedStorageWriter::commit(provider, static_file_provider)?; Ok(ImportReceiptsResult { total_decoded_receipts, total_filtered_out_dup_txns }) } diff --git a/crates/stages/api/src/pipeline/mod.rs b/crates/stages/api/src/pipeline/mod.rs index ce6b1a2863a6..27f732412165 100644 --- a/crates/stages/api/src/pipeline/mod.rs +++ b/crates/stages/api/src/pipeline/mod.rs @@ -8,8 +8,9 @@ use futures_util::Future; use reth_db_api::database::Database; use reth_primitives_traits::constants::BEACON_CONSENSUS_REORG_UNWIND_DEPTH; use reth_provider::{ - providers::StaticFileWriter, FinalizedBlockReader, FinalizedBlockWriter, ProviderFactory, - StageCheckpointReader, StageCheckpointWriter, StaticFileProviderFactory, + providers::StaticFileWriter, writer::UnifiedStorageWriter, FinalizedBlockReader, + FinalizedBlockWriter, ProviderFactory, StageCheckpointReader, StageCheckpointWriter, + StaticFileProviderFactory, }; use reth_prune::PrunerBuilder; use reth_static_file::StaticFileProducer; @@ -342,12 +343,10 @@ where ))?; } - // For unwinding it makes more sense to commit the database first, since if - // this function is interrupted before the static files commit, we can just - // truncate the static files according to the - // checkpoints on the next start-up. - provider_rw.commit()?; - self.provider_factory.static_file_provider().commit()?; + UnifiedStorageWriter::commit_unwind( + provider_rw, + self.provider_factory.static_file_provider(), + )?; stage.post_unwind_commit()?; @@ -455,14 +454,10 @@ where result: out.clone(), }); - // For execution it makes more sense to commit the static files first, since if - // this function is interrupted before the database commit, we can just truncate - // the static files according to the checkpoints on the next - // start-up. - self.provider_factory.static_file_provider().commit()?; - provider_rw.commit()?; - - stage.post_execute_commit()?; + UnifiedStorageWriter::commit( + provider_rw, + self.provider_factory.static_file_provider(), + )?; if done { let block_number = checkpoint.block_number; @@ -520,8 +515,8 @@ fn on_stage_error( StageId::MerkleExecute, prev_checkpoint.unwrap_or_default(), )?; - factory.static_file_provider().commit()?; - provider_rw.commit()?; + + UnifiedStorageWriter::commit(provider_rw, factory.static_file_provider())?; // We unwind because of a validation error. If the unwind itself // fails, we bail entirely, diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index 9ce2ecc4f483..95324cb6820d 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -131,8 +131,9 @@ pub fn init_genesis(factory: ProviderFactory) -> Result UnifiedStorageWriter<'a, TX, SF> { impl UnifiedStorageWriter<'_, (), ()> { /// Commits both storage types in the right order. /// + /// For non-unwinding operations it makes more sense to commit the static files first, since if + /// it is interrupted before the database commit, we can just truncate + /// the static files according to the checkpoints on the next + /// start-up. + /// /// NOTE: If unwinding data from storage, use `commit_unwind` instead! pub fn commit( database: DatabaseProviderRW, @@ -117,6 +122,11 @@ impl UnifiedStorageWriter<'_, (), ()> { /// Commits both storage types in the right order for an unwind operation. /// + /// For unwinding it makes more sense to commit the database first, since if + /// it is interrupted before the static files commit, we can just + /// truncate the static files according to the + /// checkpoints on the next start-up. + /// /// NOTE: Should only be used after unwinding data from storage! pub fn commit_unwind( database: DatabaseProviderRW, From 0a5ef6b77ea836e30bd15c568bec3387dc9b4554 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 2 Aug 2024 14:21:00 +0200 Subject: [PATCH 5/6] clippy --- crates/cli/commands/src/stage/drop.rs | 4 +-- crates/cli/commands/src/stage/run.rs | 2 +- crates/stages/api/src/pipeline/mod.rs | 5 ++- crates/storage/errors/src/writer.rs | 2 +- .../src/providers/database/provider.rs | 2 +- crates/storage/provider/src/writer/mod.rs | 33 ++++++++++--------- 6 files changed, 23 insertions(+), 25 deletions(-) diff --git a/crates/cli/commands/src/stage/drop.rs b/crates/cli/commands/src/stage/drop.rs index f69b54723c4b..d0fa6efb5158 100644 --- a/crates/cli/commands/src/stage/drop.rs +++ b/crates/cli/commands/src/stage/drop.rs @@ -9,9 +9,7 @@ use reth_db_common::{ DbTool, }; use reth_node_core::args::StageEnum; -use reth_provider::{ - providers::StaticFileWriter, writer::UnifiedStorageWriter, StaticFileProviderFactory, -}; +use reth_provider::{writer::UnifiedStorageWriter, StaticFileProviderFactory}; use reth_stages::StageId; use reth_static_file_types::{find_fixed_range, StaticFileSegment}; diff --git a/crates/cli/commands/src/stage/run.rs b/crates/cli/commands/src/stage/run.rs index eae9c55bfda7..a7349f6e95fb 100644 --- a/crates/cli/commands/src/stage/run.rs +++ b/crates/cli/commands/src/stage/run.rs @@ -28,7 +28,7 @@ use reth_node_metrics::{ }; use reth_provider::{ writer::UnifiedStorageWriter, ChainSpecProvider, StageCheckpointReader, StageCheckpointWriter, - StaticFileProviderFactory, StaticFileWriter, + StaticFileProviderFactory, }; use reth_stages::{ stages::{ diff --git a/crates/stages/api/src/pipeline/mod.rs b/crates/stages/api/src/pipeline/mod.rs index 27f732412165..79578f942d70 100644 --- a/crates/stages/api/src/pipeline/mod.rs +++ b/crates/stages/api/src/pipeline/mod.rs @@ -8,9 +8,8 @@ use futures_util::Future; use reth_db_api::database::Database; use reth_primitives_traits::constants::BEACON_CONSENSUS_REORG_UNWIND_DEPTH; use reth_provider::{ - providers::StaticFileWriter, writer::UnifiedStorageWriter, FinalizedBlockReader, - FinalizedBlockWriter, ProviderFactory, StageCheckpointReader, StageCheckpointWriter, - StaticFileProviderFactory, + writer::UnifiedStorageWriter, FinalizedBlockReader, FinalizedBlockWriter, ProviderFactory, + StageCheckpointReader, StageCheckpointWriter, StaticFileProviderFactory, }; use reth_prune::PrunerBuilder; use reth_static_file::StaticFileProducer; diff --git a/crates/storage/errors/src/writer.rs b/crates/storage/errors/src/writer.rs index 66d8dd7f7a66..736a26b4ac46 100644 --- a/crates/storage/errors/src/writer.rs +++ b/crates/storage/errors/src/writer.rs @@ -1,7 +1,7 @@ use crate::db::DatabaseError; use reth_primitives::StaticFileSegment; -/// `StorageWriter` related errors +/// `UnifiedStorageWriter` related errors #[derive(Clone, Debug, thiserror_no_std::Error, PartialEq, Eq)] pub enum StorageWriterError { /// Static file writer is missing diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 0e6bfb8b6c37..4c105e6f35a3 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -3570,7 +3570,7 @@ impl BlockWriter for DatabaseProvider { Ok(block_indices) } - /// TODO(joshie): this fn should be moved to `StorageWriter` eventually + /// TODO(joshie): this fn should be moved to `UnifiedStorageWriter` eventually fn append_blocks_with_state( &self, blocks: Vec, diff --git a/crates/storage/provider/src/writer/mod.rs b/crates/storage/provider/src/writer/mod.rs index 3474aade1246..f1bf5c516429 100644 --- a/crates/storage/provider/src/writer/mod.rs +++ b/crates/storage/provider/src/writer/mod.rs @@ -35,8 +35,8 @@ enum StorageType { StaticFile(S), } -/// [`StorageWriter`] is responsible for managing the writing to either database, static file or -/// both. +/// [`UnifiedStorageWriter`] is responsible for managing the writing to storage with both database +/// and static file providers. #[derive(Debug)] pub struct UnifiedStorageWriter<'a, TX, SF> { database: &'a DatabaseProvider, @@ -44,7 +44,7 @@ pub struct UnifiedStorageWriter<'a, TX, SF> { } impl<'a, TX, SF> UnifiedStorageWriter<'a, TX, SF> { - /// Creates a new instance of [`StorageWriter`]. + /// Creates a new instance of [`UnifiedStorageWriter`]. /// /// # Parameters /// - `database`: An optional reference to a database provider. @@ -53,13 +53,13 @@ impl<'a, TX, SF> UnifiedStorageWriter<'a, TX, SF> { Self { database, static_file } } - /// Creates a new instance of [`StorageWriter`] from a database provider and a static file - /// instance. + /// Creates a new instance of [`UnifiedStorageWriter`] from a database provider and a static + /// file instance. pub const fn from(database: &'a DatabaseProvider, static_file: SF) -> Self { Self::new(database, Some(static_file)) } - /// Creates a new instance of [`StorageWriter`] from a database provider. + /// Creates a new instance of [`UnifiedStorageWriter`] from a database provider. pub const fn from_database(database: &'a DatabaseProvider) -> Self { Self::new(database, None) } @@ -321,8 +321,8 @@ where /// [`HeaderTerminalDifficulties`](tables::HeaderTerminalDifficulties) table to determine the /// total difficulty of the parent block during header insertion. /// - /// NOTE: The static file writer used to construct this [`StorageWriter`] MUST be a writer for - /// the Headers segment. + /// NOTE: The static file writer used to construct this [`UnifiedStorageWriter`] MUST be a + /// writer for the Headers segment. pub fn append_headers_from_blocks( &mut self, initial_block_number: BlockNumber, @@ -353,8 +353,8 @@ where /// [`BlockBodyIndices`](tables::BlockBodyIndices) table to determine the transaction number /// when appending to static files. /// - /// NOTE: The static file writer used to construct this [`StorageWriter`] MUST be a writer for - /// the Transactions segment. + /// NOTE: The static file writer used to construct this [`UnifiedStorageWriter`] MUST be a + /// writer for the Transactions segment. pub fn append_transactions_from_blocks( &mut self, initial_block_number: BlockNumber, @@ -406,11 +406,12 @@ where { /// Appends receipts block by block. /// - /// ATTENTION: If called from [`StorageWriter`] without a static file producer, it will always - /// write them to database. Otherwise, it will look into the pruning configuration to decide. + /// ATTENTION: If called from [`UnifiedStorageWriter`] without a static file producer, it will + /// always write them to database. Otherwise, it will look into the pruning configuration to + /// decide. /// - /// NOTE: The static file writer used to construct this [`StorageWriter`] MUST be a writer for - /// the Receipts segment. + /// NOTE: The static file writer used to construct this [`UnifiedStorageWriter`] MUST be a + /// writer for the Receipts segment. /// /// # Parameters /// - `initial_block_number`: The starting block number. @@ -425,8 +426,8 @@ where self.database().tx_ref().cursor_read::()?; // We write receipts to database in two situations: - // * If we are in live sync. In this case, `StorageWriter` is built without a static file - // writer. + // * If we are in live sync. In this case, `UnifiedStorageWriter` is built without a static + // file writer. // * If there is any kind of receipt pruning let mut storage_type = if self.static_file.is_none() || self.database().prune_modes_ref().has_receipts_pruning() From 21f8f04e0fae013478de2168fa8cb1f59f14ddaf Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 2 Aug 2024 15:58:39 +0200 Subject: [PATCH 6/6] clippy and error rename --- crates/optimism/cli/src/commands/import_receipts.rs | 6 +++--- crates/storage/errors/src/provider.rs | 2 +- crates/storage/errors/src/writer.rs | 2 +- crates/storage/provider/src/writer/mod.rs | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/optimism/cli/src/commands/import_receipts.rs b/crates/optimism/cli/src/commands/import_receipts.rs index 272185d2d008..cf3f6cf0de27 100644 --- a/crates/optimism/cli/src/commands/import_receipts.rs +++ b/crates/optimism/cli/src/commands/import_receipts.rs @@ -16,7 +16,7 @@ use reth_node_core::version::SHORT_VERSION; use reth_optimism_primitives::bedrock_import::is_dup_tx; use reth_primitives::Receipts; use reth_provider::{ - writer::StorageWriter, DatabaseProviderFactory, OriginalValuesKnown, ProviderFactory, + writer::UnifiedStorageWriter, DatabaseProviderFactory, OriginalValuesKnown, ProviderFactory, StageCheckpointReader, StateWriter, StaticFileProviderFactory, StaticFileWriter, StatsReader, }; use reth_stages::StageId; @@ -222,7 +222,7 @@ where } // We're reusing receipt writing code internal to - // `StorageWriter::append_receipts_from_blocks`, so we just use a default empty + // `UnifiedStorageWriter::append_receipts_from_blocks`, so we just use a default empty // `BundleState`. let execution_outcome = ExecutionOutcome::new(Default::default(), receipts, first_block, Default::default()); @@ -231,7 +231,7 @@ where static_file_provider.get_writer(first_block, StaticFileSegment::Receipts)?; // finally, write the receipts - let mut storage_writer = StorageWriter::from(&provider, static_file_producer); + let mut storage_writer = UnifiedStorageWriter::from(&provider, static_file_producer); storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::Yes)?; } diff --git a/crates/storage/errors/src/provider.rs b/crates/storage/errors/src/provider.rs index aa74e06c88f8..1ef05c34d945 100644 --- a/crates/storage/errors/src/provider.rs +++ b/crates/storage/errors/src/provider.rs @@ -147,7 +147,7 @@ pub enum ProviderError { StorageLockError(#[from] crate::lockfile::StorageLockError), /// Storage writer error. #[error(transparent)] - StorageWriterError(#[from] crate::writer::StorageWriterError), + UnifiedStorageWriterError(#[from] crate::writer::UnifiedStorageWriterError), } impl From for ProviderError { diff --git a/crates/storage/errors/src/writer.rs b/crates/storage/errors/src/writer.rs index 736a26b4ac46..362140da7b61 100644 --- a/crates/storage/errors/src/writer.rs +++ b/crates/storage/errors/src/writer.rs @@ -3,7 +3,7 @@ use reth_primitives::StaticFileSegment; /// `UnifiedStorageWriter` related errors #[derive(Clone, Debug, thiserror_no_std::Error, PartialEq, Eq)] -pub enum StorageWriterError { +pub enum UnifiedStorageWriterError { /// Static file writer is missing #[error("Static file writer is missing")] MissingStaticFileWriter, diff --git a/crates/storage/provider/src/writer/mod.rs b/crates/storage/provider/src/writer/mod.rs index f1bf5c516429..39dc3cf4ebc6 100644 --- a/crates/storage/provider/src/writer/mod.rs +++ b/crates/storage/provider/src/writer/mod.rs @@ -21,7 +21,7 @@ use reth_stages_types::{StageCheckpoint, StageId}; use reth_storage_api::{ BlockNumReader, HeaderProvider, ReceiptWriter, StageCheckpointWriter, TransactionsProviderExt, }; -use reth_storage_errors::writer::StorageWriterError; +use reth_storage_errors::writer::UnifiedStorageWriterError; use revm::db::OriginalValuesKnown; use std::{borrow::Borrow, sync::Arc}; use tracing::{debug, instrument}; @@ -94,9 +94,9 @@ impl<'a, TX, SF> UnifiedStorageWriter<'a, TX, SF> { /// - `Ok(())` if the static file instance is set. /// - `Err(StorageWriterError::MissingStaticFileWriter)` if the static file instance is not set. #[allow(unused)] - const fn ensure_static_file(&self) -> Result<(), StorageWriterError> { + const fn ensure_static_file(&self) -> Result<(), UnifiedStorageWriterError> { if self.static_file.is_none() { - return Err(StorageWriterError::MissingStaticFileWriter) + return Err(UnifiedStorageWriterError::MissingStaticFileWriter) } Ok(()) } @@ -301,11 +301,11 @@ where fn ensure_static_file_segment( &self, segment: StaticFileSegment, - ) -> Result<(), StorageWriterError> { + ) -> Result<(), UnifiedStorageWriterError> { match &self.static_file { Some(writer) => { if writer.user_header().segment() != segment { - Err(StorageWriterError::IncorrectStaticFileWriter( + Err(UnifiedStorageWriterError::IncorrectStaticFileWriter( writer.user_header().segment(), segment, )) @@ -313,7 +313,7 @@ where Ok(()) } } - None => Err(StorageWriterError::MissingStaticFileWriter), + None => Err(UnifiedStorageWriterError::MissingStaticFileWriter), } }