cuprated/config/
storage.rs

1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5use cuprate_database::config::SyncMode;
6use cuprate_database_service::ReaderThreads;
7use cuprate_helper::fs::CUPRATE_DATA_DIR;
8
9use super::macros::config_struct;
10
11config_struct! {
12    /// The storage config.
13    #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
14    #[serde(deny_unknown_fields, default)]
15    pub struct StorageConfig {
16        #[comment_out = true]
17        /// The amount of reader threads to spawn for the tx-pool and blockchain.
18        ///
19        /// The tx-pool and blockchain both share a single threadpool.
20        ///
21        /// Type         | Number
22        /// Valid values | >= 0
23        /// Examples     | 1, 16, 10
24        pub reader_threads: usize,
25
26        #[child = true]
27        /// The tx-pool config.
28        pub txpool: TxpoolConfig,
29
30        #[child = true]
31        /// The blockchain config.
32        pub blockchain: BlockchainConfig,
33    }
34}
35
36impl Default for StorageConfig {
37    fn default() -> Self {
38        Self {
39            reader_threads: cuprate_helper::thread::threads_25().get(),
40            txpool: Default::default(),
41            blockchain: Default::default(),
42        }
43    }
44}
45
46config_struct! {
47    /// The blockchain config.
48    #[derive(Default, Debug, Deserialize, Serialize, PartialEq, Eq)]
49    #[serde(deny_unknown_fields, default)]
50    pub struct BlockchainConfig {
51        #[flatten = true]
52        /// Shared config.
53        ##[serde(flatten)]
54        pub shared: SharedStorageConfig,
55    }
56}
57
58config_struct! {
59    /// The tx-pool config.
60    #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
61    #[serde(deny_unknown_fields, default)]
62    pub struct TxpoolConfig {
63        #[flatten = true]
64        /// Shared config.
65        ##[serde(flatten)]
66        pub shared: SharedStorageConfig,
67
68        /// The maximum size of the tx-pool.
69        ///
70        /// Type         | Number
71        /// Valid values | >= 0
72        /// Examples     | 100_000_000, 50_000_000
73        pub max_txpool_byte_size: usize,
74    }
75}
76
77impl Default for TxpoolConfig {
78    fn default() -> Self {
79        Self {
80            shared: SharedStorageConfig::default(),
81            max_txpool_byte_size: 100_000_000,
82        }
83    }
84}
85
86config_struct! {
87    /// Config values shared between the tx-pool and blockchain.
88    #[derive(Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
89    #[serde(deny_unknown_fields, default)]
90    pub struct SharedStorageConfig {
91        #[comment_out = true]
92        /// The sync mode of the database.
93        ///
94        /// Using "Safe" makes the DB less likely to corrupt
95        /// if there is an unexpected crash, although it will
96        /// make DB writes much slower.
97        ///
98        /// Valid values | "Fast", "Safe"
99        pub sync_mode: SyncMode,
100    }
101}