reth_db_api/models/
metadata.rs

1//! Storage metadata models.
2
3use reth_codecs::{add_arbitrary_tests, Compact};
4use serde::{Deserialize, Serialize};
5
6/// Storage configuration settings for this node.
7///
8/// These should be set during `init_genesis` or `init_db` depending on whether we want dictate
9/// behaviour of new or old nodes respectively.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Compact)]
11#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
12#[add_arbitrary_tests(compact)]
13pub struct StorageSettings {
14    /// Whether this node always writes receipts to static files.
15    ///
16    /// If this is set to FALSE AND receipt pruning IS ENABLED, all receipts should be written to DB. Otherwise, they should be written to static files. This ensures that older nodes do not need to migrate their current DB tables to static files. For more, read: <https://github.com/paradigmxyz/reth/issues/18890#issuecomment-3457760097>
17    #[serde(default)]
18    pub receipts_in_static_files: bool,
19    /// Whether this node always writes transaction senders to static files.
20    #[serde(default)]
21    pub transaction_senders_in_static_files: bool,
22    /// Whether `StoragesHistory` is stored in `RocksDB`.
23    #[serde(default)]
24    pub storages_history_in_rocksdb: bool,
25    /// Whether `TransactionHashNumbers` is stored in `RocksDB`.
26    #[serde(default)]
27    pub transaction_hash_numbers_in_rocksdb: bool,
28    /// Whether `AccountsHistory` is stored in `RocksDB`.
29    #[serde(default)]
30    pub account_history_in_rocksdb: bool,
31}
32
33impl StorageSettings {
34    /// Creates `StorageSettings` for legacy nodes.
35    ///
36    /// This explicitly sets `receipts_in_static_files` and `transaction_senders_in_static_files` to
37    /// `false`, ensuring older nodes continue writing receipts and transaction senders to the
38    /// database when receipt pruning is enabled.
39    pub const fn legacy() -> Self {
40        Self {
41            receipts_in_static_files: false,
42            transaction_senders_in_static_files: false,
43            storages_history_in_rocksdb: false,
44            transaction_hash_numbers_in_rocksdb: false,
45            account_history_in_rocksdb: false,
46        }
47    }
48
49    /// Sets the `receipts_in_static_files` flag to the provided value.
50    pub const fn with_receipts_in_static_files(mut self, value: bool) -> Self {
51        self.receipts_in_static_files = value;
52        self
53    }
54
55    /// Sets the `transaction_senders_in_static_files` flag to the provided value.
56    pub const fn with_transaction_senders_in_static_files(mut self, value: bool) -> Self {
57        self.transaction_senders_in_static_files = value;
58        self
59    }
60
61    /// Sets the `storages_history_in_rocksdb` flag to the provided value.
62    pub const fn with_storages_history_in_rocksdb(mut self, value: bool) -> Self {
63        self.storages_history_in_rocksdb = value;
64        self
65    }
66
67    /// Sets the `transaction_hash_numbers_in_rocksdb` flag to the provided value.
68    pub const fn with_transaction_hash_numbers_in_rocksdb(mut self, value: bool) -> Self {
69        self.transaction_hash_numbers_in_rocksdb = value;
70        self
71    }
72
73    /// Sets the `account_history_in_rocksdb` flag to the provided value.
74    pub const fn with_account_history_in_rocksdb(mut self, value: bool) -> Self {
75        self.account_history_in_rocksdb = value;
76        self
77    }
78}