cuprated/config/
storage.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use std::path::PathBuf;

use serde::{Deserialize, Serialize};

use cuprate_database::config::SyncMode;
use cuprate_database_service::ReaderThreads;
use cuprate_helper::fs::CUPRATE_DATA_DIR;

/// The storage config.
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(deny_unknown_fields, default)]
pub struct StorageConfig {
    /// The amount of reader threads to spawn between the tx-pool and blockchain.
    pub reader_threads: usize,
    /// The tx-pool config.
    pub txpool: TxpoolConfig,
    /// The blockchain config.
    pub blockchain: BlockchainConfig,
}

impl Default for StorageConfig {
    fn default() -> Self {
        Self {
            reader_threads: cuprate_helper::thread::threads_25().get(),
            txpool: Default::default(),
            blockchain: Default::default(),
        }
    }
}

/// The blockchain config.
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(deny_unknown_fields, default)]
pub struct BlockchainConfig {
    #[serde(flatten)]
    pub shared: SharedStorageConfig,
}

impl Default for BlockchainConfig {
    fn default() -> Self {
        Self {
            shared: SharedStorageConfig {
                sync_mode: SyncMode::Async,
            },
        }
    }
}

/// The tx-pool config.
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(deny_unknown_fields, default)]
pub struct TxpoolConfig {
    #[serde(flatten)]
    pub shared: SharedStorageConfig,

    /// The maximum size of the tx-pool.
    pub max_txpool_byte_size: usize,
}

impl Default for TxpoolConfig {
    fn default() -> Self {
        Self {
            shared: SharedStorageConfig {
                sync_mode: SyncMode::Async,
            },
            max_txpool_byte_size: 100_000_000,
        }
    }
}

/// Config values shared between the tx-pool and blockchain.
#[derive(Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
#[serde(deny_unknown_fields, default)]
pub struct SharedStorageConfig {
    /// The [`SyncMode`] of the database.
    pub sync_mode: SyncMode,
}