diff --git a/substrate/core/cli/src/lib.rs b/substrate/core/cli/src/lib.rs index 0e06c6232d..dc3c96f9cd 100644 --- a/substrate/core/cli/src/lib.rs +++ b/substrate/core/cli/src/lib.rs @@ -228,7 +228,10 @@ where .into(); config.database_path = db_path(&base_path, config.chain_spec.id()).to_string_lossy().into(); - + config.database_cache_size = match matches.value_of("database_cache_size") { + Some(s) => Some(s.parse().map_err(|_| "Invalid Database Cache size specified")?), + _=> None + }; config.pruning = match matches.value_of("pruning") { Some("archive") => PruningMode::ArchiveAll, None => PruningMode::default(), diff --git a/substrate/core/cli/src/params.rs b/substrate/core/cli/src/params.rs index c5293b821b..59d1d68233 100644 --- a/substrate/core/cli/src/params.rs +++ b/substrate/core/cli/src/params.rs @@ -45,6 +45,10 @@ pub struct CoreParams { #[structopt(long = "light")] light: bool, + /// Limit the memory the database cache can use + #[structopt(long = "db-cache", value_name = "MiB")] + database_cache_size: Option, + /// Listen on this multiaddress #[structopt(long = "listen-addr", value_name = "LISTEN_ADDR")] listen_addr: Vec, diff --git a/substrate/core/service/src/components.rs b/substrate/core/service/src/components.rs index fe2e7df385..ab74201f6f 100644 --- a/substrate/core/service/src/components.rs +++ b/substrate/core/service/src/components.rs @@ -415,7 +415,7 @@ impl Components for FullComponents { ), error::Error> { let db_settings = client_db::DatabaseSettings { - cache_size: None, + cache_size: config.database_cache_size.map(|u| u as usize), path: config.database_path.as_str().into(), pruning: config.pruning.clone(), }; diff --git a/substrate/core/service/src/config.rs b/substrate/core/service/src/config.rs index b91c26ed04..636b555617 100644 --- a/substrate/core/service/src/config.rs +++ b/substrate/core/service/src/config.rs @@ -45,6 +45,8 @@ pub struct Configuration { pub keystore_path: String, /// Path to the database. pub database_path: String, + /// Cache Size for internal database in MiB + pub database_cache_size: Option, /// Pruning settings. pub pruning: PruningMode, /// Additional key seeds. @@ -81,6 +83,7 @@ impl Configuration ( network: network_config, keystore_path: root.join("key").to_str().unwrap().into(), database_path: root.join("db").to_str().unwrap().into(), + database_cache_size: None, pruning: Default::default(), keys: keys, chain_spec: (*spec).clone(),