diff --git a/crates/node/core/src/args/rocksdb.rs b/crates/node/core/src/args/rocksdb.rs index 61bc33bc90d..26b954744a6 100644 --- a/crates/node/core/src/args/rocksdb.rs +++ b/crates/node/core/src/args/rocksdb.rs @@ -2,6 +2,28 @@ use clap::{ArgAction, Args}; +/// Default value for `RocksDB` tx hash flag. +/// +/// When the `edge` feature is enabled, defaults to `true` to store transaction hash numbers in +/// `RocksDB`. Otherwise defaults to `false` for legacy behavior. +const fn default_rocksdb_tx_hash_flag() -> bool { + cfg!(feature = "edge") +} + +/// Default value for `RocksDB` storages history flag. +/// +/// Always defaults to `false` as edge mode does not enable this. +const fn default_rocksdb_storages_history_flag() -> bool { + false +} + +/// Default value for `RocksDB` account history flag. +/// +/// Always defaults to `false` as edge mode does not enable this. +const fn default_rocksdb_account_history_flag() -> bool { + false +} + /// Parameters for `RocksDB` table routing configuration. /// /// These flags control which database tables are stored in `RocksDB` instead of MDBX. @@ -47,6 +69,30 @@ impl RocksDbArgs { } Ok(()) } + + /// Returns the tx hash flag value with the appropriate default based on the `edge` feature. + pub const fn tx_hash_with_default(&self) -> bool { + match self.tx_hash { + Some(value) => value, + None => default_rocksdb_tx_hash_flag(), + } + } + + /// Returns the storages history flag value with the appropriate default. + pub const fn storages_history_with_default(&self) -> bool { + match self.storages_history { + Some(value) => value, + None => default_rocksdb_storages_history_flag(), + } + } + + /// Returns the account history flag value with the appropriate default. + pub const fn account_history_with_default(&self) -> bool { + match self.account_history { + Some(value) => value, + None => default_rocksdb_account_history_flag(), + } + } } /// Error type for `RocksDB` argument validation. @@ -119,4 +165,50 @@ mod tests { let args = RocksDbArgs { all: true, account_history: Some(false), ..Default::default() }; assert_eq!(args.validate(), Err(RocksDbArgsError::ConflictingFlags("account-history"))); } + + #[test] + fn test_default_values_with_edge_feature() { + // When edge feature is enabled, tx_hash should default to true + // When edge feature is disabled, it should default to false + let args = RocksDbArgs::default(); + + #[cfg(feature = "edge")] + { + assert!(args.tx_hash_with_default()); + } + + #[cfg(not(feature = "edge"))] + { + assert!(!args.tx_hash_with_default()); + } + + // storages_history and account_history always default to false + assert!(!args.storages_history_with_default()); + assert!(!args.account_history_with_default()); + } + + #[test] + fn test_explicit_values_override_defaults() { + let args = RocksDbArgs { + all: false, + tx_hash: Some(true), + storages_history: Some(true), + account_history: Some(true), + }; + + assert!(args.tx_hash_with_default()); + assert!(args.storages_history_with_default()); + assert!(args.account_history_with_default()); + + let args = RocksDbArgs { + all: false, + tx_hash: Some(false), + storages_history: Some(false), + account_history: Some(false), + }; + + assert!(!args.tx_hash_with_default()); + assert!(!args.storages_history_with_default()); + assert!(!args.account_history_with_default()); + } } diff --git a/crates/node/core/src/node_config.rs b/crates/node/core/src/node_config.rs index aeff14a8755..699b5751b38 100644 --- a/crates/node/core/src/node_config.rs +++ b/crates/node/core/src/node_config.rs @@ -358,10 +358,10 @@ impl NodeConfig { } /// Returns the effective storage settings derived from static-file and `RocksDB` CLI args. - pub fn storage_settings(&self) -> StorageSettings { - let tx_hash = self.rocksdb.all || self.rocksdb.tx_hash.unwrap_or(false); - let storages_history = self.rocksdb.all || self.rocksdb.storages_history.unwrap_or(false); - let account_history = self.rocksdb.all || self.rocksdb.account_history.unwrap_or(false); + pub const fn storage_settings(&self) -> StorageSettings { + let tx_hash = self.rocksdb.all || self.rocksdb.tx_hash_with_default(); + let storages_history = self.rocksdb.all || self.rocksdb.storages_history_with_default(); + let account_history = self.rocksdb.all || self.rocksdb.account_history_with_default(); StorageSettings { receipts_in_static_files: self.static_files.receipts, @@ -613,3 +613,58 @@ impl Clone for NodeConfig { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_storage_settings_default_with_edge_feature() { + // Test that storage settings respect edge feature defaults + let config = NodeConfig::default(); + let settings = config.storage_settings(); + + // When edge feature is enabled, tx_hash should default to true + // When edge feature is disabled, it should default to false + #[cfg(feature = "edge")] + { + assert!(settings.transaction_hash_numbers_in_rocksdb); + } + + #[cfg(not(feature = "edge"))] + { + assert!(!settings.transaction_hash_numbers_in_rocksdb); + } + + // storages_history and account_history always default to false + assert!(!settings.storages_history_in_rocksdb); + assert!(!settings.account_history_in_rocksdb); + } + + #[test] + fn test_storage_settings_with_explicit_rocksdb_args() { + let mut config = NodeConfig::default(); + config.rocksdb.tx_hash = Some(true); + config.rocksdb.storages_history = Some(true); + config.rocksdb.account_history = Some(true); + + let settings = config.storage_settings(); + + assert!(settings.transaction_hash_numbers_in_rocksdb); + assert!(settings.storages_history_in_rocksdb); + assert!(settings.account_history_in_rocksdb); + } + + #[test] + fn test_storage_settings_with_rocksdb_all() { + let mut config = NodeConfig::default(); + config.rocksdb.all = true; + + let settings = config.storage_settings(); + + // When all is set, all RocksDB flags should be true + assert!(settings.transaction_hash_numbers_in_rocksdb); + assert!(settings.storages_history_in_rocksdb); + assert!(settings.account_history_in_rocksdb); + } +}