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