Skip to main content

cuprated/config/
storage.rs

1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5use cuprate_blockchain::config::CacheSizes;
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        #[inline = true]
84        #[comment_out = true]
85        /// The size of each tape cache.
86        ///
87        /// You probably do not need to edit these values.
88        pub tapes_cache_sizes: CacheSizes,
89    }
90}
91
92impl Default for TxpoolConfig {
93    fn default() -> Self {
94        Self {
95            max_txpool_byte_size: 100_000_000,
96            maximum_age_secs: 60 * 60 * 24,
97        }
98    }
99}