diff --git a/crates/storage/provider/src/either_writer.rs b/crates/storage/provider/src/either_writer.rs index 16eced90dd6..280392d6483 100644 --- a/crates/storage/provider/src/either_writer.rs +++ b/crates/storage/provider/src/either_writer.rs @@ -217,12 +217,16 @@ impl<'a> EitherWriter<'a, (), ()> { P: DBProvider + NodePrimitivesProvider + StorageSettingsCache, P::Tx: DbTxMut, { - #[cfg(all(unix, feature = "rocksdb"))] - if provider.cached_storage_settings().storages_history_in_rocksdb { - return Ok(EitherWriter::RocksDB(_rocksdb_batch)); + match EitherWriterDestination::storages_history(provider) { + EitherWriterDestination::Database => Ok(EitherWriter::Database( + provider.tx_ref().cursor_write::()?, + )), + #[cfg(all(unix, feature = "rocksdb"))] + EitherWriterDestination::RocksDB => Ok(EitherWriter::RocksDB(_rocksdb_batch)), + #[cfg(not(all(unix, feature = "rocksdb")))] + EitherWriterDestination::RocksDB => Err(ProviderError::UnsupportedProvider), + EitherWriterDestination::StaticFile => Err(ProviderError::UnsupportedProvider), } - - Ok(EitherWriter::Database(provider.tx_ref().cursor_write::()?)) } /// Creates a new [`EitherWriter`] for transaction hash numbers based on storage settings. @@ -234,14 +238,16 @@ impl<'a> EitherWriter<'a, (), ()> { P: DBProvider + NodePrimitivesProvider + StorageSettingsCache, P::Tx: DbTxMut, { - #[cfg(all(unix, feature = "rocksdb"))] - if provider.cached_storage_settings().transaction_hash_numbers_in_rocksdb { - return Ok(EitherWriter::RocksDB(_rocksdb_batch)); + match EitherWriterDestination::transaction_hash_numbers(provider) { + EitherWriterDestination::Database => Ok(EitherWriter::Database( + provider.tx_ref().cursor_write::()?, + )), + #[cfg(all(unix, feature = "rocksdb"))] + EitherWriterDestination::RocksDB => Ok(EitherWriter::RocksDB(_rocksdb_batch)), + #[cfg(not(all(unix, feature = "rocksdb")))] + EitherWriterDestination::RocksDB => Err(ProviderError::UnsupportedProvider), + EitherWriterDestination::StaticFile => Err(ProviderError::UnsupportedProvider), } - - Ok(EitherWriter::Database( - provider.tx_ref().cursor_write::()?, - )) } /// Creates a new [`EitherWriter`] for account history based on storage settings. @@ -253,12 +259,16 @@ impl<'a> EitherWriter<'a, (), ()> { P: DBProvider + NodePrimitivesProvider + StorageSettingsCache, P::Tx: DbTxMut, { - #[cfg(all(unix, feature = "rocksdb"))] - if provider.cached_storage_settings().account_history_in_rocksdb { - return Ok(EitherWriter::RocksDB(_rocksdb_batch)); + match EitherWriterDestination::accounts_history(provider) { + EitherWriterDestination::Database => Ok(EitherWriter::Database( + provider.tx_ref().cursor_write::()?, + )), + #[cfg(all(unix, feature = "rocksdb"))] + EitherWriterDestination::RocksDB => Ok(EitherWriter::RocksDB(_rocksdb_batch)), + #[cfg(not(all(unix, feature = "rocksdb")))] + EitherWriterDestination::RocksDB => Err(ProviderError::UnsupportedProvider), + EitherWriterDestination::StaticFile => Err(ProviderError::UnsupportedProvider), } - - Ok(EitherWriter::Database(provider.tx_ref().cursor_write::()?)) } } @@ -944,6 +954,48 @@ impl EitherWriterDestination { Self::Database } } + + /// Returns the destination for writing transaction hash numbers based on storage settings. + #[allow(clippy::missing_const_for_fn)] + pub fn transaction_hash_numbers

(_provider: &P) -> Self + where + P: StorageSettingsCache, + { + #[cfg(all(unix, feature = "rocksdb"))] + if _provider.cached_storage_settings().transaction_hash_numbers_in_rocksdb { + return Self::RocksDB; + } + + Self::Database + } + + /// Returns the destination for writing storage history based on storage settings. + #[allow(clippy::missing_const_for_fn)] + pub fn storages_history

(_provider: &P) -> Self + where + P: StorageSettingsCache, + { + #[cfg(all(unix, feature = "rocksdb"))] + if _provider.cached_storage_settings().storages_history_in_rocksdb { + return Self::RocksDB; + } + + Self::Database + } + + /// Returns the destination for writing account history based on storage settings. + #[allow(clippy::missing_const_for_fn)] + pub fn accounts_history

(_provider: &P) -> Self + where + P: StorageSettingsCache, + { + #[cfg(all(unix, feature = "rocksdb"))] + if _provider.cached_storage_settings().account_history_in_rocksdb { + return Self::RocksDB; + } + + Self::Database + } } #[cfg(test)]