Skip to main content

reth_db_api/models/
metadata.rs

1//! Storage metadata models.
2
3use alloc::{string::String, vec::Vec};
4use reth_codecs::{add_arbitrary_tests, Compact};
5use serde::{Deserialize, Serialize};
6
7/// Storage configuration settings for this node.
8///
9/// Controls whether this node uses v2 storage layout (static files + `RocksDB` routing)
10/// or v1/legacy layout (everything in MDBX).
11///
12/// These should be set during `init_genesis` or `init_db` depending on whether we want dictate
13/// behaviour of new or old nodes respectively.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Compact, Serialize, Deserialize)]
15#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
16#[add_arbitrary_tests(compact)]
17pub struct StorageSettings {
18    /// Whether this node uses v2 storage layout.
19    ///
20    /// When `true`, enables all v2 storage features:
21    /// - Receipts and transaction senders in static files
22    /// - History indices in `RocksDB` (accounts, storages, transaction hashes)
23    /// - Account and storage changesets in static files
24    /// - Hashed state tables as canonical state representation
25    ///
26    /// When `false`, uses v1/legacy layout (everything in MDBX).
27    pub storage_v2: bool,
28}
29
30impl StorageSettings {
31    /// Returns the default base `StorageSettings`.
32    pub const fn base() -> Self {
33        Self::v2()
34    }
35
36    /// Creates `StorageSettings` for v2 nodes with all storage features enabled:
37    /// - Receipts and transaction senders in static files
38    /// - History indices in `RocksDB` (storages, accounts, transaction hashes)
39    /// - Account and storage changesets in static files
40    /// - Hashed state as canonical state representation
41    ///
42    /// Use this when the `--storage.v2` CLI flag is set.
43    pub const fn v2() -> Self {
44        Self { storage_v2: true }
45    }
46
47    /// Creates `StorageSettings` for v1/legacy nodes.
48    ///
49    /// This keeps all data in MDBX, matching the original storage layout.
50    pub const fn v1() -> Self {
51        Self { storage_v2: false }
52    }
53
54    /// Returns `true` if this node uses v2 storage layout.
55    pub const fn is_v2(&self) -> bool {
56        self.storage_v2
57    }
58
59    /// Whether receipts are stored in static files.
60    pub const fn receipts_in_static_files(&self) -> bool {
61        self.storage_v2
62    }
63
64    /// Whether transaction senders are stored in static files.
65    pub const fn transaction_senders_in_static_files(&self) -> bool {
66        self.storage_v2
67    }
68
69    /// Whether storages history is stored in `RocksDB`.
70    pub const fn storages_history_in_rocksdb(&self) -> bool {
71        self.storage_v2
72    }
73
74    /// Whether transaction hash numbers are stored in `RocksDB`.
75    pub const fn transaction_hash_numbers_in_rocksdb(&self) -> bool {
76        self.storage_v2
77    }
78
79    /// Whether account history is stored in `RocksDB`.
80    pub const fn account_history_in_rocksdb(&self) -> bool {
81        self.storage_v2
82    }
83
84    /// Whether to use hashed state tables (`HashedAccounts`/`HashedStorages`) as the canonical
85    /// state representation instead of plain state tables. Implied by v2 storage layout.
86    pub const fn use_hashed_state(&self) -> bool {
87        self.storage_v2
88    }
89
90    /// Returns `true` if any tables are configured to be stored in `RocksDB`.
91    pub const fn any_in_rocksdb(&self) -> bool {
92        self.storage_v2
93    }
94}
95
96/// Marker for an in-progress partial state trie unwind.
97#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
98pub struct PartialStateTrieUnwindMarker {
99    /// The Finish stage block number before the unwind started.
100    pub finish_block_number: u64,
101    /// The partial state trie frontier the pipeline is unwinding to.
102    pub partial_state_trie: u64,
103}
104
105/// A pipeline unwind that must finish before forward execution can resume.
106#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
107pub struct PipelineUnwind {
108    /// Last block to retain.
109    pub target: u64,
110    /// Stages in execution order. Offline unwinds intentionally exclude online stages.
111    pub stages: Vec<String>,
112    /// Invalid block that caused the unwind, if any.
113    pub bad_block: Option<u64>,
114}