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
9/// The storage config.
10#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
11#[serde(deny_unknown_fields, default)]
12pub struct StorageConfig {
13    /// The amount of reader threads to spawn between the tx-pool and blockchain.
14    pub reader_threads: usize,
15    /// The tx-pool config.
16    pub txpool: TxpoolConfig,
17    /// The blockchain config.
18    pub blockchain: BlockchainConfig,
19}
20
21impl Default for StorageConfig {
22    fn default() -> Self {
23        Self {
24            reader_threads: cuprate_helper::thread::threads_25().get(),
25            txpool: Default::default(),
26            blockchain: Default::default(),
27        }
28    }
29}
30
31/// The blockchain config.
32#[derive(Default, Debug, Deserialize, Serialize, PartialEq, Eq)]
33#[serde(deny_unknown_fields, default)]
34pub struct BlockchainConfig {
35    #[serde(flatten)]
36    pub shared: SharedStorageConfig,
37}
38
39/// The tx-pool config.
40#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
41#[serde(deny_unknown_fields, default)]
42pub struct TxpoolConfig {
43    #[serde(flatten)]
44    pub shared: SharedStorageConfig,
45
46    /// The maximum size of the tx-pool.
47    pub max_txpool_byte_size: usize,
48}
49
50impl Default for TxpoolConfig {
51    fn default() -> Self {
52        Self {
53            shared: SharedStorageConfig::default(),
54            max_txpool_byte_size: 100_000_000,
55        }
56    }
57}
58
59/// Config values shared between the tx-pool and blockchain.
60#[derive(Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
61#[serde(deny_unknown_fields, default)]
62pub struct SharedStorageConfig {
63    /// The [`SyncMode`] of the database.
64    pub sync_mode: SyncMode,
65}