Skip to main content

cuprate_blockchain/
config.rs

1//! Database configuration.
2use std::path::PathBuf;
3
4#[cfg(feature = "serde")]
5use serde::{Deserialize, Serialize};
6
7use cuprate_helper::fs::CUPRATE_DATA_DIR;
8
9/// The persistence mode to use on the database.
10#[derive(Default, Debug, Clone, Copy, Eq, PartialEq)]
11#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12pub enum Persistence {
13    /// Buffer the changes but don't wait for them to be synced to disk.
14    ///
15    /// This can lead to corruption if there is a crash.
16    Buffer,
17    /// Sync all changes to disk.
18    ///
19    /// This prevents corruption but can be a bit slower.
20    Sync,
21    #[default]
22    /// Buffer changes while syncing but then switch to syncing all changes to disk once synced.
23    ///
24    /// This is a compromise between [`Self::Buffer`] and [`Self::Sync`].
25    BufferThenSync,
26}
27
28/// The tapes cache sizes.
29#[derive(Debug, Clone, Eq, PartialEq)]
30#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
31#[cfg_attr(feature = "serde", serde(deny_unknown_fields, default))]
32pub struct CacheSizes {
33    pub rct_outputs: u64,
34    pub tx_infos: u64,
35    pub block_infos: u64,
36    pub pruned_blobs: u64,
37    pub v1_prunable_blobs: u64,
38    pub prunable_blobs: u64,
39}
40
41impl Default for CacheSizes {
42    fn default() -> Self {
43        Self {
44            rct_outputs: 100 * 1024 * 1024,
45            tx_infos: 1024 * 1024,
46            block_infos: 1024 * 1024,
47            pruned_blobs: 25 * 1024 * 1024,
48            v1_prunable_blobs: 8 * 1024,
49            prunable_blobs: 8 * 1024,
50        }
51    }
52}
53
54//---------------------------------------------------------------------------------------------------- Config
55/// The blockchain database configuration.
56#[derive(Debug, Clone, PartialEq, Eq)]
57#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
58pub struct Config {
59    /// The directory where the blockchain blobs are stored.
60    pub blob_dir: PathBuf,
61    /// The directory where the blockchain indexes are stored.
62    pub index_dir: PathBuf,
63    /// The tapes cache sizes.
64    pub cache_sizes: CacheSizes,
65    /// The [`Persistence`] mode to use.
66    pub persistence: Persistence,
67}
68
69impl Default for Config {
70    fn default() -> Self {
71        Self {
72            blob_dir: CUPRATE_DATA_DIR.to_path_buf(),
73            index_dir: CUPRATE_DATA_DIR.to_path_buf(),
74            cache_sizes: CacheSizes::default(),
75            persistence: Persistence::default(),
76        }
77    }
78}