stratus/eth/storage/permanent/
mod.rs1pub use self::rocks::RocksCfCacheConfig;
2pub use self::rocks::RocksPermanentStorage;
3pub use self::rocks::RocksStorageState;
4
5pub mod rocks;
6
7use std::time::Duration;
8
9use clap::Parser;
10use display_json::DebugAsJson;
11
12#[cfg(feature = "dev")]
14use crate::config::GenesisFileConfig;
15use crate::ext::parse_duration;
16
17#[derive(DebugAsJson, Clone, Parser, serde::Serialize)]
23pub struct PermanentStorageConfig {
24 #[arg(long = "rocks-path-prefix", env = "ROCKS_PATH_PREFIX")]
26 pub rocks_path_prefix: Option<String>,
27
28 #[arg(long = "rocks-shutdown-timeout", env = "ROCKS_SHUTDOWN_TIMEOUT", value_parser=parse_duration, default_value = "4m")]
30 pub rocks_shutdown_timeout: Duration,
31
32 #[clap(flatten)]
34 pub rocks_cf_cache: RocksCfCacheConfig,
35
36 #[arg(long = "rocks-disable-sync-write", env = "ROCKS_DISABLE_SYNC_WRITE")]
38 pub rocks_disable_sync_write: bool,
39
40 #[arg(long = "rocks-cf-size-metrics-interval", env = "ROCKS_CF_SIZE_METRICS_INTERVAL", value_parser=parse_duration)]
42 pub rocks_cf_size_metrics_interval: Option<Duration>,
43
44 #[arg(long = "rocks-file-descriptors-limit", env = "ROCKS_FILE_DESCRIPTORS_LIMIT", default_value = Self::DEFAULT_FILE_DESCRIPTORS_LIMIT)]
46 pub rocks_file_descriptors_limit: u64,
47
48 #[clap(flatten)]
50 #[cfg(feature = "dev")]
51 pub genesis_file: GenesisFileConfig,
52}
53
54impl PermanentStorageConfig {
55 const DEFAULT_FILE_DESCRIPTORS_LIMIT: &'static str = if cfg!(feature = "dev") { "65536" } else { "1048576" };
56 pub fn init(&self) -> anyhow::Result<RocksPermanentStorage> {
58 tracing::info!(config = ?self, "creating permanent storage");
59
60 RocksPermanentStorage::new(
61 self.rocks_path_prefix.clone(),
62 self.rocks_shutdown_timeout,
63 self.rocks_cf_cache.clone(),
64 !self.rocks_disable_sync_write,
65 self.rocks_cf_size_metrics_interval,
66 self.rocks_file_descriptors_limit,
67 )
68 }
69}