stratus/eth/storage/permanent/
mod.rs

1pub use self::rocks::RocksPermanentStorage;
2pub use self::rocks::RocksStorageState;
3
4pub mod rocks;
5
6use std::time::Duration;
7
8use clap::Parser;
9use display_json::DebugAsJson;
10
11/// Genesis file configuration
12#[cfg(feature = "dev")]
13use crate::config::GenesisFileConfig;
14use crate::ext::parse_duration;
15
16// -----------------------------------------------------------------------------
17// Config
18// -----------------------------------------------------------------------------
19
20/// Permanent storage configuration.
21#[derive(DebugAsJson, Clone, Parser, serde::Serialize)]
22pub struct PermanentStorageConfig {
23    /// RocksDB storage path prefix to execute multiple local Stratus instances.
24    #[arg(long = "rocks-path-prefix", env = "ROCKS_PATH_PREFIX")]
25    pub rocks_path_prefix: Option<String>,
26
27    /// The maximum time to wait for the RocksDB `wait_for_compaction` shutdown call.
28    #[arg(long = "rocks-shutdown-timeout", env = "ROCKS_SHUTDOWN_TIMEOUT", value_parser=parse_duration, default_value = "4m")]
29    pub rocks_shutdown_timeout: Duration,
30
31    /// Augments or decreases the size of Column Family caches based on a multiplier.
32    #[arg(long = "rocks-cache-size-multiplier", env = "ROCKS_CACHE_SIZE_MULTIPLIER")]
33    pub rocks_cache_size_multiplier: Option<f32>,
34
35    /// Augments or decreases the size of Column Family caches based on a multiplier.
36    #[arg(long = "rocks-disable-sync-write", env = "ROCKS_DISABLE_SYNC_WRITE")]
37    pub rocks_disable_sync_write: bool,
38
39    /// Interval for collecting RocksDB column family size metrics.
40    #[arg(long = "rocks-cf-size-metrics-interval", env = "ROCKS_CF_SIZE_METRICS_INTERVAL", value_parser=parse_duration)]
41    pub rocks_cf_size_metrics_interval: Option<Duration>,
42
43    /// Minimum number of file descriptors required for RocksDB initialization.
44    #[arg(long = "rocks-file-descriptors-limit", env = "ROCKS_FILE_DESCRIPTORS_LIMIT", default_value = Self::DEFAULT_FILE_DESCRIPTORS_LIMIT)]
45    pub rocks_file_descriptors_limit: u64,
46
47    /// Genesis file configuration
48    #[clap(flatten)]
49    #[cfg(feature = "dev")]
50    pub genesis_file: GenesisFileConfig,
51}
52
53impl PermanentStorageConfig {
54    const DEFAULT_FILE_DESCRIPTORS_LIMIT: &'static str = if cfg!(feature = "dev") { "65536" } else { "1048576" };
55    /// Initializes permanent storage implementation.
56    pub fn init(&self) -> anyhow::Result<RocksPermanentStorage> {
57        tracing::info!(config = ?self, "creating permanent storage");
58
59        RocksPermanentStorage::new(
60            self.rocks_path_prefix.clone(),
61            self.rocks_shutdown_timeout,
62            self.rocks_cache_size_multiplier,
63            !self.rocks_disable_sync_write,
64            self.rocks_cf_size_metrics_interval,
65            self.rocks_file_descriptors_limit,
66        )
67    }
68}