From 3bf9280b3c0e16eb3e680bb436cb0a14574ffd0a Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Tue, 10 Feb 2026 21:19:33 -0500 Subject: [PATCH] refactor(storage): add `with_*_opt` builder methods to `StorageSettings` (#21998) Co-authored-by: Amp --- crates/node/core/src/node_config.rs | 30 +++------ crates/storage/db-api/src/models/metadata.rs | 68 ++++++++++++++++++++ 2 files changed, 77 insertions(+), 21 deletions(-) diff --git a/crates/node/core/src/node_config.rs b/crates/node/core/src/node_config.rs index 1e6c1407ea..48e87cf05d 100644 --- a/crates/node/core/src/node_config.rs +++ b/crates/node/core/src/node_config.rs @@ -375,18 +375,11 @@ impl NodeConfig { let mut s = if self.storage.v2 { StorageSettings::v2() } else { StorageSettings::base() }; // Apply static files overrides (only when explicitly set) - if let Some(v) = self.static_files.receipts { - s = s.with_receipts_in_static_files(v); - } - if let Some(v) = self.static_files.transaction_senders { - s = s.with_transaction_senders_in_static_files(v); - } - if let Some(v) = self.static_files.account_changesets { - s = s.with_account_changesets_in_static_files(v); - } - if let Some(v) = self.static_files.storage_changesets { - s = s.with_storage_changesets_in_static_files(v); - } + s = s + .with_receipts_in_static_files_opt(self.static_files.receipts) + .with_transaction_senders_in_static_files_opt(self.static_files.transaction_senders) + .with_account_changesets_in_static_files_opt(self.static_files.account_changesets) + .with_storage_changesets_in_static_files_opt(self.static_files.storage_changesets); // Apply rocksdb overrides // --rocksdb.all sets all rocksdb flags to true @@ -398,15 +391,10 @@ impl NodeConfig { } // Individual rocksdb flags override --rocksdb.all when explicitly set - if let Some(v) = self.rocksdb.tx_hash { - s = s.with_transaction_hash_numbers_in_rocksdb(v); - } - if let Some(v) = self.rocksdb.storages_history { - s = s.with_storages_history_in_rocksdb(v); - } - if let Some(v) = self.rocksdb.account_history { - s = s.with_account_history_in_rocksdb(v); - } + s = s + .with_transaction_hash_numbers_in_rocksdb_opt(self.rocksdb.tx_hash) + .with_storages_history_in_rocksdb_opt(self.rocksdb.storages_history) + .with_account_history_in_rocksdb_opt(self.rocksdb.account_history); s = s.with_use_hashed_state(self.storage.use_hashed_state); diff --git a/crates/storage/db-api/src/models/metadata.rs b/crates/storage/db-api/src/models/metadata.rs index 366b1174f2..14b9cb44ae 100644 --- a/crates/storage/db-api/src/models/metadata.rs +++ b/crates/storage/db-api/src/models/metadata.rs @@ -135,6 +135,74 @@ impl StorageSettings { self } + /// Sets `receipts_in_static_files` if `value` is `Some`. + pub const fn with_receipts_in_static_files_opt(mut self, value: Option) -> Self { + if let Some(v) = value { + self.receipts_in_static_files = v; + } + self + } + + /// Sets `transaction_senders_in_static_files` if `value` is `Some`. + pub const fn with_transaction_senders_in_static_files_opt( + mut self, + value: Option, + ) -> Self { + if let Some(v) = value { + self.transaction_senders_in_static_files = v; + } + self + } + + /// Sets `account_changesets_in_static_files` if `value` is `Some`. + pub const fn with_account_changesets_in_static_files_opt( + mut self, + value: Option, + ) -> Self { + if let Some(v) = value { + self.account_changesets_in_static_files = v; + } + self + } + + /// Sets `storage_changesets_in_static_files` if `value` is `Some`. + pub const fn with_storage_changesets_in_static_files_opt( + mut self, + value: Option, + ) -> Self { + if let Some(v) = value { + self.storage_changesets_in_static_files = v; + } + self + } + + /// Sets `transaction_hash_numbers_in_rocksdb` if `value` is `Some`. + pub const fn with_transaction_hash_numbers_in_rocksdb_opt( + mut self, + value: Option, + ) -> Self { + if let Some(v) = value { + self.transaction_hash_numbers_in_rocksdb = v; + } + self + } + + /// Sets `storages_history_in_rocksdb` if `value` is `Some`. + pub const fn with_storages_history_in_rocksdb_opt(mut self, value: Option) -> Self { + if let Some(v) = value { + self.storages_history_in_rocksdb = v; + } + self + } + + /// Sets `account_history_in_rocksdb` if `value` is `Some`. + pub const fn with_account_history_in_rocksdb_opt(mut self, value: Option) -> Self { + if let Some(v) = value { + self.account_history_in_rocksdb = v; + } + self + } + /// Returns `true` if any tables are configured to be stored in `RocksDB`. pub const fn any_in_rocksdb(&self) -> bool { self.transaction_hash_numbers_in_rocksdb ||