Issue 279 - unique path for each chains db, network, keystore to prevent collisions (#322)

* make spec.name() part of database_path preventing collisions

resolves #279

* add `id` field to `ChainSpec`

* add blank line for readability

* dot/cli: use spec_id in db_path

* dot/cli: make spec_id part of keystore_path

* dot/cli: make spec_id part of network_path

* add id field to poc-1.json chain spec

* dot/cli: spec_id -> chain_id
This commit is contained in:
snd
2018-07-15 19:31:59 +02:00
committed by Gav Wood
parent 8cafabc4bd
commit 1888adb98e
3 changed files with 19 additions and 11 deletions
+15 -8
View File
@@ -200,13 +200,14 @@ pub fn run<I, T, W>(args: I, worker: W) -> error::Result<()> where
}
let base_path = base_path(&matches);
config.keystore_path = matches.value_of("keystore")
.map(|x| Path::new(x).to_owned())
.unwrap_or_else(|| keystore_path(&base_path))
.unwrap_or_else(|| keystore_path(&base_path, config.chain_spec.id()))
.to_string_lossy()
.into();
config.database_path = db_path(&base_path).to_string_lossy().into();
config.database_path = db_path(&base_path, config.chain_spec.id()).to_string_lossy().into();
config.pruning = match matches.value_of("pruning") {
Some("archive") => PruningMode::ArchiveAll,
@@ -250,7 +251,7 @@ pub fn run<I, T, W>(args: I, worker: W) -> error::Result<()> where
config.network.boot_nodes.extend(matches
.values_of("bootnodes")
.map_or(Default::default(), |v| v.map(|n| n.to_owned()).collect::<Vec<_>>()));
config.network.config_path = Some(network_path(&base_path).to_string_lossy().into());
config.network.config_path = Some(network_path(&base_path, config.chain_spec.id()).to_string_lossy().into());
config.network.net_config_path = config.network.config_path.clone();
let port = match matches.value_of("port") {
@@ -326,7 +327,7 @@ fn export_blocks<E>(matches: &clap::ArgMatches, exit: E) -> error::Result<()>
let base_path = base_path(matches);
let (spec, _) = load_spec(&matches)?;
let mut config = service::Configuration::default_with_spec(spec);
config.database_path = db_path(&base_path).to_string_lossy().into();
config.database_path = db_path(&base_path, config.chain_spec.id()).to_string_lossy().into();
info!("DB path: {}", config.database_path);
let client = service::new_client(config)?;
let (exit_send, exit_recv) = std::sync::mpsc::channel();
@@ -391,7 +392,7 @@ fn import_blocks<E>(matches: &clap::ArgMatches, exit: E) -> error::Result<()>
let (spec, _) = load_spec(&matches)?;
let base_path = base_path(matches);
let mut config = service::Configuration::default_with_spec(spec);
config.database_path = db_path(&base_path).to_string_lossy().into();
config.database_path = db_path(&base_path, config.chain_spec.id()).to_string_lossy().into();
let client = service::new_client(config)?;
let (exit_send, exit_recv) = std::sync::mpsc::channel();
@@ -499,20 +500,26 @@ fn parse_address(default: &str, port_param: &str, matches: &clap::ArgMatches) ->
Ok(address)
}
fn keystore_path(base_path: &Path) -> PathBuf {
fn keystore_path(base_path: &Path, chain_id: &str) -> PathBuf {
let mut path = base_path.to_owned();
path.push("chains");
path.push(chain_id);
path.push("keystore");
path
}
fn db_path(base_path: &Path) -> PathBuf {
fn db_path(base_path: &Path, chain_id: &str) -> PathBuf {
let mut path = base_path.to_owned();
path.push("chains");
path.push(chain_id);
path.push("db");
path
}
fn network_path(base_path: &Path) -> PathBuf {
fn network_path(base_path: &Path, chain_id: &str) -> PathBuf {
let mut path = base_path.to_owned();
path.push("chains");
path.push(chain_id);
path.push("network");
path
}
+1
View File
@@ -1,5 +1,6 @@
{
"name": "PoC-1 Testnet",
"id": "poc-1-testnet",
"genesis": {"raw": {
"0x9768f3cbdd14c1a63474dfbdbe052f42": "0x80f4030000000000",
"0x3b700687fecdff5ec1c4a5b714521eb6": "0x0000000000000000",
+3 -3
View File
@@ -94,7 +94,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
/// Staging testnet config.
pub fn staging_testnet_config() -> ChainSpec<GenesisConfig> {
let boot_nodes = vec![];
ChainSpec::from_genesis("Staging Testnet", staging_testnet_config_genesis, boot_nodes)
ChainSpec::from_genesis("Staging Testnet", "staging_testnet", staging_testnet_config_genesis, boot_nodes)
}
fn testnet_genesis(initial_authorities: Vec<AuthorityId>) -> GenesisConfig {
@@ -169,7 +169,7 @@ fn development_config_genesis() -> GenesisConfig {
/// Development config (single validator Alice)
pub fn development_config() -> ChainSpec<GenesisConfig> {
ChainSpec::from_genesis("Development", development_config_genesis, vec![])
ChainSpec::from_genesis("Development", "development", development_config_genesis, vec![])
}
fn local_testnet_genesis() -> GenesisConfig {
@@ -181,5 +181,5 @@ fn local_testnet_genesis() -> GenesisConfig {
/// Local testnet config (multivalidator Alice + Bob)
pub fn local_testnet_config() -> ChainSpec<GenesisConfig> {
ChainSpec::from_genesis("Local Testnet", local_testnet_genesis, vec![])
ChainSpec::from_genesis("Local Testnet", "local_testnet", local_testnet_genesis, vec![])
}