use std::path::PathBuf;
use datasize::DataSize;
use serde::{Deserialize, Serialize};
#[cfg(test)]
use tempfile::TempDir;
const GIB: usize = 1024 * 1024 * 1024;
const DEFAULT_MAX_BLOCK_STORE_SIZE: usize = 450 * GIB;
const DEFAULT_MAX_DEPLOY_STORE_SIZE: usize = 300 * GIB;
const DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE: usize = 300 * GIB;
const DEFAULT_MAX_STATE_STORE_SIZE: usize = 10 * GIB;
#[derive(Clone, DataSize, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
pub path: PathBuf,
pub max_block_store_size: usize,
pub max_deploy_store_size: usize,
pub max_deploy_metadata_store_size: usize,
pub max_state_store_size: usize,
pub enable_mem_deduplication: bool,
pub mem_pool_prune_interval: u16,
}
impl Default for Config {
fn default() -> Self {
Config {
path: "/dev/null".into(),
max_block_store_size: DEFAULT_MAX_BLOCK_STORE_SIZE,
max_deploy_store_size: DEFAULT_MAX_DEPLOY_STORE_SIZE,
max_deploy_metadata_store_size: DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE,
max_state_store_size: DEFAULT_MAX_STATE_STORE_SIZE,
enable_mem_deduplication: true,
mem_pool_prune_interval: 4096,
}
}
}
impl Config {
#[cfg(test)]
pub(crate) fn new_for_tests(size_multiplier: u8) -> (Self, TempDir) {
if size_multiplier == 0 {
panic!("size_multiplier cannot be zero");
}
let tempdir = tempfile::tempdir().expect("should get tempdir");
let path = tempdir.path().join("lmdb");
let config = Config {
path,
max_block_store_size: 1024 * 1024 * size_multiplier as usize,
max_deploy_store_size: 1024 * 1024 * size_multiplier as usize,
max_deploy_metadata_store_size: 1024 * 1024 * size_multiplier as usize,
max_state_store_size: 12 * 1024 * size_multiplier as usize,
..Default::default()
};
(config, tempdir)
}
}