From 2da99baeaf08d2751cf1161e6e92d22b8640f450 Mon Sep 17 00:00:00 2001 From: yongkangc Date: Thu, 11 Dec 2025 06:21:54 +0000 Subject: [PATCH] Add RocksDB destination variant and routing helpers --- crates/storage/provider/src/either_writer.rs | 54 ++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/crates/storage/provider/src/either_writer.rs b/crates/storage/provider/src/either_writer.rs index 36747f1b2c..26e82c7228 100644 --- a/crates/storage/provider/src/either_writer.rs +++ b/crates/storage/provider/src/either_writer.rs @@ -277,6 +277,8 @@ pub enum EitherWriterDestination { Database, /// Write to static file StaticFile, + /// Write to `RocksDB` + RocksDB, } impl EitherWriterDestination { @@ -292,6 +294,34 @@ impl EitherWriterDestination { Self::Database } } + + /// Returns the destination for storages history writes based on storage settings. + pub fn storages_history

(provider: &P) -> Self + where + P: StorageSettingsCache, + { + if cfg!(all(unix, feature = "rocksdb")) && + provider.cached_storage_settings().storages_history_in_rocksdb + { + Self::RocksDB + } else { + Self::Database + } + } + + /// Returns the destination for transaction hash numbers writes based on storage settings. + pub fn transaction_hash_numbers

(provider: &P) -> Self + where + P: StorageSettingsCache, + { + if cfg!(all(unix, feature = "rocksdb")) && + provider.cached_storage_settings().transaction_hash_numbers_in_rocksdb + { + Self::RocksDB + } else { + Self::Database + } + } } #[cfg(test)] @@ -348,4 +378,28 @@ mod tests { ); } } + + #[test] + fn rocksdb_destinations_follow_flags_with_cfg_fallback() { + let factory = create_test_provider_factory(); + let settings = StorageSettings::legacy() + .with_storages_history_in_rocksdb(true) + .with_transaction_hash_numbers_in_rocksdb(true); + factory.set_storage_settings_cache(settings); + + let provider = factory.database_provider_ro().unwrap(); + + let expect_rocks = cfg!(all(unix, feature = "rocksdb")); + + let storages_dest = EitherWriterDestination::storages_history(&provider); + let tx_hash_dest = EitherWriterDestination::transaction_hash_numbers(&provider); + + if expect_rocks { + assert!(matches!(storages_dest, EitherWriterDestination::RocksDB)); + assert!(matches!(tx_hash_dest, EitherWriterDestination::RocksDB)); + } else { + assert!(matches!(storages_dest, EitherWriterDestination::Database)); + assert!(matches!(tx_hash_dest, EitherWriterDestination::Database)); + } + } }