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    Shared {
48        #[comment_out = true]
49        /// The sync mode of the database.
50        ///
51        /// Using "Safe" makes the DB less likely to corrupt
52        /// if there is an unexpected crash, although it will
53        /// make DB writes much slower.
54        ///
55        /// Valid values | "Fast", "Safe"
56        pub sync_mode: SyncMode,
57    }
58
59    /// The blockchain config.
60    #[derive(Default, Debug, Deserialize, Serialize, PartialEq, Eq)]
61    #[serde(deny_unknown_fields, default)]
62    pub struct BlockchainConfig { }
63
64    /// The tx-pool config.
65    #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
66    #[serde(deny_unknown_fields, default)]
67    pub struct TxpoolConfig {
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            sync_mode: SyncMode::default(),
81            max_txpool_byte_size: 100_000_000,
82        }
83    }
84}