Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions codechain/codechain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions codechain/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ pub struct Ipc {
pub struct Operating {
pub quiet: Option<bool>,
pub instance_id: Option<usize>,
pub base_path: Option<String>,
pub db_path: Option<String>,
pub keys_path: Option<String>,
pub password_path: Option<String>,
Expand Down Expand Up @@ -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();
}
Expand All @@ -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());
}
Expand Down
3 changes: 1 addition & 2 deletions codechain/config/presets/config.dev.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[codechain]
quiet = false
db_path = "db"
keys_path = "keys"
base_path = "."
chain = "solo"

[mining]
Expand Down
3 changes: 1 addition & 2 deletions codechain/config/presets/config.prod.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[codechain]
quiet = false
db_path = "db"
keys_path = "keys"
base_path = "."
chain = "mainnet"

[mining]
Expand Down
1 change: 1 addition & 0 deletions codechain/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

pub const DEFAULT_KEYS_PATH: &str = "keys";
pub const DEFAULT_DB_PATH: &str = "db";
16 changes: 8 additions & 8 deletions codechain/run_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -202,8 +202,9 @@ fn unlock_accounts(ap: &AccountProvider, pf: &PasswordFile) -> Result<(), String
}

pub fn open_db(cfg: &config::Operating, client_config: &ClientConfig) -> Result<Arc<KeyValueDB>, 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;
Expand Down Expand Up @@ -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();
Expand Down