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 ///
32 /// When the `edge` feature is enabled, returns [`Self::v2()`] so that CI and
33 /// edge builds automatically use v2 storage defaults. Otherwise returns
34 /// [`Self::v1()`]. The `--storage.v2` CLI flag can also opt into v2 at runtime
35 /// regardless of feature flags.
36 pub const fn base() -> Self {
37 #[cfg(feature = "edge")]
38 {
39 Self::v2()
40 }
41 #[cfg(not(feature = "edge"))]
42 {
43 Self::v1()
44 }
45 }
46
47 /// Creates `StorageSettings` for v2 nodes with all storage features enabled:
48 /// - Receipts and transaction senders in static files
49 /// - History indices in `RocksDB` (storages, accounts, transaction hashes)
50 /// - Account and storage changesets in static files
51 /// - Hashed state as canonical state representation
52 ///
53 /// Use this when the `--storage.v2` CLI flag is set.
54 pub const fn v2() -> Self {
55 Self { storage_v2: true }
56 }
57
58 /// Creates `StorageSettings` for v1/legacy nodes.
59 ///
60 /// This keeps all data in MDBX, matching the original storage layout.
61 pub const fn v1() -> Self {
62 Self { storage_v2: false }
63 }
64
65 /// Returns `true` if this node uses v2 storage layout.
66 pub const fn is_v2(&self) -> bool {
67 self.storage_v2
68 }
69
70 /// Whether receipts are stored in static files.
71 pub const fn receipts_in_static_files(&self) -> bool {
72 self.storage_v2
73 }
74
75 /// Whether transaction senders are stored in static files.
76 pub const fn transaction_senders_in_static_files(&self) -> bool {
77 self.storage_v2
78 }
79
80 /// Whether storages history is stored in `RocksDB`.
81 pub const fn storages_history_in_rocksdb(&self) -> bool {
82 self.storage_v2
83 }
84
85 /// Whether transaction hash numbers are stored in `RocksDB`.
86 pub const fn transaction_hash_numbers_in_rocksdb(&self) -> bool {
87 self.storage_v2
88 }
89
90 /// Whether account history is stored in `RocksDB`.
91 pub const fn account_history_in_rocksdb(&self) -> bool {
92 self.storage_v2
93 }
94
95 /// Whether to use hashed state tables (`HashedAccounts`/`HashedStorages`) as the canonical
96 /// state representation instead of plain state tables. Implied by v2 storage layout.
97 pub const fn use_hashed_state(&self) -> bool {
98 self.storage_v2
99 }
100
101 /// Returns `true` if any tables are configured to be stored in `RocksDB`.
102 pub const fn any_in_rocksdb(&self) -> bool {
103 self.storage_v2
104 }
105}