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}
23
24impl StorageSettings {
25 /// Creates `StorageSettings` for legacy nodes.
26 ///
27 /// This explicitly sets `receipts_in_static_files` and `transaction_senders_in_static_files` to
28 /// `false`, ensuring older nodes continue writing receipts and transaction senders to the
29 /// database when receipt pruning is enabled.
30 pub const fn legacy() -> Self {
31 Self { receipts_in_static_files: false, transaction_senders_in_static_files: false }
32 }
33
34 /// Sets the `receipts_in_static_files` flag to the provided value.
35 pub const fn with_receipts_in_static_files(mut self, value: bool) -> Self {
36 self.receipts_in_static_files = value;
37 self
38 }
39
40 /// Sets the `transaction_senders_in_static_files` flag to the provided value.
41 pub const fn with_transaction_senders_in_static_files(mut self, value: bool) -> Self {
42 self.transaction_senders_in_static_files = value;
43 self
44 }
45}