Skip to main content

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/// Controls whether this node uses v2 storage layout (static files + `RocksDB` routing)
9/// or v1/legacy layout (everything in MDBX).
10///
11/// These should be set during `init_genesis` or `init_db` depending on whether we want dictate
12/// behaviour of new or old nodes respectively.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Compact, Serialize, Deserialize)]
14#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
15#[add_arbitrary_tests(compact)]
16pub struct StorageSettings {
17    /// Whether this node uses v2 storage layout.
18    ///
19    /// When `true`, enables all v2 storage features:
20    /// - Receipts and transaction senders in static files
21    /// - History indices in `RocksDB` (accounts, storages, transaction hashes)
22    /// - Account and storage changesets in static files
23    /// - Hashed state tables as canonical state representation
24    ///
25    /// When `false`, uses v1/legacy layout (everything in MDBX).
26    pub storage_v2: bool,
27}
28
29impl StorageSettings {
30    /// Returns the default base `StorageSettings`.
31    pub const fn base() -> Self {
32        Self::v2()
33    }
34
35    /// Creates `StorageSettings` for v2 nodes with all storage features enabled:
36    /// - Receipts and transaction senders in static files
37    /// - History indices in `RocksDB` (storages, accounts, transaction hashes)
38    /// - Account and storage changesets in static files
39    /// - Hashed state as canonical state representation
40    ///
41    /// Use this when the `--storage.v2` CLI flag is set.
42    pub const fn v2() -> Self {
43        Self { storage_v2: true }
44    }
45
46    /// Creates `StorageSettings` for v1/legacy nodes.
47    ///
48    /// This keeps all data in MDBX, matching the original storage layout.
49    pub const fn v1() -> Self {
50        Self { storage_v2: false }
51    }
52
53    /// Returns `true` if this node uses v2 storage layout.
54    pub const fn is_v2(&self) -> bool {
55        self.storage_v2
56    }
57
58    /// Whether receipts are stored in static files.
59    pub const fn receipts_in_static_files(&self) -> bool {
60        self.storage_v2
61    }
62
63    /// Whether transaction senders are stored in static files.
64    pub const fn transaction_senders_in_static_files(&self) -> bool {
65        self.storage_v2
66    }
67
68    /// Whether storages history is stored in `RocksDB`.
69    pub const fn storages_history_in_rocksdb(&self) -> bool {
70        self.storage_v2
71    }
72
73    /// Whether transaction hash numbers are stored in `RocksDB`.
74    pub const fn transaction_hash_numbers_in_rocksdb(&self) -> bool {
75        self.storage_v2
76    }
77
78    /// Whether account history is stored in `RocksDB`.
79    pub const fn account_history_in_rocksdb(&self) -> bool {
80        self.storage_v2
81    }
82
83    /// Whether to use hashed state tables (`HashedAccounts`/`HashedStorages`) as the canonical
84    /// state representation instead of plain state tables. Implied by v2 storage layout.
85    pub const fn use_hashed_state(&self) -> bool {
86        self.storage_v2
87    }
88
89    /// Returns `true` if any tables are configured to be stored in `RocksDB`.
90    pub const fn any_in_rocksdb(&self) -> bool {
91        self.storage_v2
92    }
93}