mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-08 23:08:19 -05:00
Add RocksDB destination variant and routing helpers
This commit is contained in:
@@ -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<P>(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<P>(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user