cuprated/config/storage.rs
1use serde::{Deserialize, Serialize};
2
3use cuprate_blockchain::config::{CacheSizes, Persistence};
4
5use super::{default::DefaultOrCustom, macros::config_struct};
6
7config_struct! {
8 /// The storage config.
9 #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
10 #[serde(deny_unknown_fields, default)]
11 pub struct StorageConfig {
12 #[comment_out = true]
13 /// The amount of reader threads to spawn for the tx-pool and blockchain.
14 ///
15 /// The tx-pool and blockchain both share a single threadpool.
16 ///
17 /// Type | Number
18 /// Valid values | >= 0
19 /// Examples | 1, 16, 10
20 pub reader_threads: usize,
21
22 #[comment_out = true]
23 /// The size of the fjall read cache.
24 ///
25 /// Fjall recommends using 20 to 25 % of available memory.
26 ///
27 /// Type | Number
28 /// Valid values | >= 0
29 /// Examples | 64_000_000
30 pub fjall_cache_size: DefaultOrCustom<u64>,
31
32 #[child = true]
33 /// The tx-pool config.
34 pub txpool: TxpoolConfig,
35
36 #[child = true]
37 /// The blockchain config.
38 pub blockchain: BlockchainConfig,
39 }
40}
41
42impl Default for StorageConfig {
43 fn default() -> Self {
44 Self {
45 reader_threads: cuprate_helper::thread::threads().get() * 4,
46 fjall_cache_size: DefaultOrCustom::Default,
47 txpool: Default::default(),
48 blockchain: Default::default(),
49 }
50 }
51}
52
53config_struct! {
54 /// The tx-pool config.
55 #[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
56 #[serde(deny_unknown_fields, default)]
57 pub struct TxpoolConfig {
58 /// The maximum size of the tx-pool.
59 ///
60 /// Type | Number
61 /// Valid values | >= 0
62 /// Examples | 100_000_000, 50_000_000
63 pub max_txpool_byte_size: usize,
64
65 /// The maximum age of transactions in the pool in seconds.
66 /// Transactions will be dropped after this time is reached.
67 ///
68 /// Type | Number
69 /// Valid values | >= 0
70 /// Examples | 100_000_000, 50_000_000
71 pub maximum_age_secs: u64,
72 }
73}
74
75config_struct! {
76 /// The blockchain config.
77 #[derive(Default, Debug, Deserialize, Serialize, PartialEq, Eq)]
78 #[serde(deny_unknown_fields, default)]
79 pub struct BlockchainConfig {
80 /// Whether to prune the blockchain. This reduces the size of the blockchain by removing most transaction proof data.
81 /// Note that once a node is pruned it cannot be un-pruned.
82 ///
83 /// Defaults to `false`.
84 pub prune: bool,
85 #[comment_out = true]
86 /// The persistence mode of the database.
87 ///
88 /// ## Buffer
89 /// Buffer the changes but don't wait for them to be synced to disk.
90 /// This can lead to corruption if there is a crash.
91 ///
92 /// ## Sync
93 /// Sync all changes to disk.
94 /// This prevents corruption but can be a bit slower.
95 ///
96 /// ## BufferThenSync
97 /// Buffer changes while syncing but then switch to syncing all changes to disk once synced.
98 /// This is a compromise between Buffer and Sync.
99 ///
100 /// Type | String
101 /// Valid values | "Buffer", "Sync", "BufferThenSync"
102 /// Examples | "BufferThenSync"
103 pub persistence: Persistence,
104
105 #[inline = true]
106 #[comment_out = true]
107 /// The size of each tape cache.
108 ///
109 /// You probably do not need to edit these values.
110 pub tapes_cache_sizes: CacheSizes,
111 }
112}
113
114impl Default for TxpoolConfig {
115 fn default() -> Self {
116 Self {
117 max_txpool_byte_size: 100_000_000,
118 maximum_age_secs: 60 * 60 * 24,
119 }
120 }
121}