casper_node/components/storage/
config.rs1use std::path::PathBuf;
2
3use datasize::DataSize;
4use serde::{Deserialize, Serialize};
5#[cfg(test)]
6use tempfile::TempDir;
7
8const GIB: usize = 1024 * 1024 * 1024;
9const DEFAULT_MAX_BLOCK_STORE_SIZE: usize = 450 * GIB;
10const DEFAULT_MAX_DEPLOY_STORE_SIZE: usize = 300 * GIB;
11const DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE: usize = 300 * GIB;
12const DEFAULT_MAX_STATE_STORE_SIZE: usize = 10 * GIB;
13
14#[derive(Clone, DataSize, Debug, Deserialize, Serialize)]
16#[serde(deny_unknown_fields)]
17pub struct Config {
18 pub path: PathBuf,
22 pub max_block_store_size: usize,
26 pub max_deploy_store_size: usize,
30 pub max_deploy_metadata_store_size: usize,
34 pub max_state_store_size: usize,
38 pub enable_mem_deduplication: bool,
40 pub mem_pool_prune_interval: u16,
42}
43
44impl Default for Config {
45 fn default() -> Self {
46 Config {
47 path: "/dev/null".into(),
49 max_block_store_size: DEFAULT_MAX_BLOCK_STORE_SIZE,
50 max_deploy_store_size: DEFAULT_MAX_DEPLOY_STORE_SIZE,
51 max_deploy_metadata_store_size: DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE,
52 max_state_store_size: DEFAULT_MAX_STATE_STORE_SIZE,
53 enable_mem_deduplication: true,
54 mem_pool_prune_interval: 4096,
55 }
56 }
57}
58
59impl Config {
60 #[cfg(test)]
65 pub(crate) fn new_for_tests(size_multiplier: u8) -> (Self, TempDir) {
66 if size_multiplier == 0 {
67 panic!("size_multiplier cannot be zero");
68 }
69 let tempdir = tempfile::tempdir().expect("should get tempdir");
70 let path = tempdir.path().join("lmdb");
71
72 let config = Config {
73 path,
74 max_block_store_size: 1024 * 1024 * size_multiplier as usize,
75 max_deploy_store_size: 1024 * 1024 * size_multiplier as usize,
76 max_deploy_metadata_store_size: 1024 * 1024 * size_multiplier as usize,
77 max_state_store_size: 12 * 1024 * size_multiplier as usize,
78 ..Default::default()
79 };
80 (config, tempdir)
81 }
82}