diff --git a/codechain/codechain.yml b/codechain/codechain.yml index 293459d031..b7a9fe47a2 100644 --- a/codechain/codechain.yml +++ b/codechain/codechain.yml @@ -50,6 +50,11 @@ args: long: chain help: Set the blockchain type out of solo, simple_poa, tendermint, cuckoo, blake_pow, corgi, mainnet or a path to chain scheme file. takes_value: true + - base-path: + long: base-path + value_name: PATH + help: Specify the base directory path on which the "db" and "keys" directory will be created. + takes_value: true - db-path: long: db-path value_name: PATH diff --git a/codechain/config/mod.rs b/codechain/config/mod.rs index cfe1b520e5..5255e650e8 100644 --- a/codechain/config/mod.rs +++ b/codechain/config/mod.rs @@ -202,6 +202,7 @@ pub struct Ipc { pub struct Operating { pub quiet: Option, pub instance_id: Option, + pub base_path: Option, pub db_path: Option, pub keys_path: Option, pub password_path: Option, @@ -314,6 +315,9 @@ impl Operating { if other.instance_id.is_some() { self.instance_id = other.instance_id; } + if other.base_path.is_some() { + self.base_path = other.base_path.clone(); + } if other.db_path.is_some() { self.db_path = other.db_path.clone(); } @@ -335,6 +339,9 @@ impl Operating { if let Some(instance_id) = matches.value_of("instance-id") { self.instance_id = Some(instance_id.parse().map_err(|e| format!("{}", e))?); } + if let Some(base_path) = matches.value_of("base-path") { + self.base_path = Some(base_path.to_string()); + } if let Some(db_path) = matches.value_of("db-path") { self.db_path = Some(db_path.to_string()); } diff --git a/codechain/config/presets/config.dev.toml b/codechain/config/presets/config.dev.toml index f950bb6e43..c3a685d1b2 100644 --- a/codechain/config/presets/config.dev.toml +++ b/codechain/config/presets/config.dev.toml @@ -1,7 +1,6 @@ [codechain] quiet = false -db_path = "db" -keys_path = "keys" +base_path = "." chain = "solo" [mining] diff --git a/codechain/config/presets/config.prod.toml b/codechain/config/presets/config.prod.toml index 391f7ac001..b192dbe316 100644 --- a/codechain/config/presets/config.prod.toml +++ b/codechain/config/presets/config.prod.toml @@ -1,7 +1,6 @@ [codechain] quiet = false -db_path = "db" -keys_path = "keys" +base_path = "." chain = "mainnet" [mining] diff --git a/codechain/constants.rs b/codechain/constants.rs index 5330f0e809..04b5da5d1b 100644 --- a/codechain/constants.rs +++ b/codechain/constants.rs @@ -15,3 +15,4 @@ // along with this program. If not, see . pub const DEFAULT_KEYS_PATH: &str = "keys"; +pub const DEFAULT_DB_PATH: &str = "db"; diff --git a/codechain/run_node.rs b/codechain/run_node.rs index ddefd40697..44555739a2 100644 --- a/codechain/run_node.rs +++ b/codechain/run_node.rs @@ -41,7 +41,7 @@ use kvdb_rocksdb::{Database, DatabaseConfig}; use parking_lot::{Condvar, Mutex}; use crate::config::{self, load_config}; -use crate::constants::DEFAULT_KEYS_PATH; +use crate::constants::{DEFAULT_DB_PATH, DEFAULT_KEYS_PATH}; use crate::dummy_network_service::DummyNetworkService; use crate::json::PasswordFile; use crate::rpc::{rpc_http_start, rpc_ipc_start, rpc_ws_start}; @@ -202,8 +202,9 @@ fn unlock_accounts(ap: &AccountProvider, pf: &PasswordFile) -> Result<(), String } pub fn open_db(cfg: &config::Operating, client_config: &ClientConfig) -> Result, String> { - let db_path = cfg.db_path.as_ref().map(String::as_str).unwrap(); - let client_path = Path::new(db_path); + let base_path = cfg.base_path.as_ref().unwrap().clone(); + let db_path = cfg.db_path.as_ref().map(String::clone).unwrap_or_else(|| base_path + "/" + DEFAULT_DB_PATH); + let client_path = Path::new(&db_path); let mut db_config = DatabaseConfig::with_columns(NUM_COLUMNS); db_config.memory_budget = client_config.db_cache_size; @@ -251,11 +252,10 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> { clogger::init(&LoggerConfig::new(instance_id)).expect("Logger must be successfully initialized"); let pf = load_password_file(&config.operating.password_path)?; - let keys_path = match config.operating.keys_path { - Some(ref keys_path) => keys_path, - None => DEFAULT_KEYS_PATH, - }; - let ap = prepare_account_provider(keys_path)?; + let base_path = config.operating.base_path.as_ref().unwrap().clone(); + let keys_path = + config.operating.keys_path.as_ref().map(String::clone).unwrap_or_else(|| base_path + "/" + DEFAULT_KEYS_PATH); + let ap = prepare_account_provider(&keys_path)?; unlock_accounts(&*ap, &pf)?; let client_config: ClientConfig = Default::default();