Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
user_file is placed next to snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
debris committed Sep 1, 2016
1 parent e349223 commit 79c7dc9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
30 changes: 18 additions & 12 deletions parity/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,31 @@ fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
// load spec file
let spec = try!(cmd.spec.spec());

// load genesis hash
let genesis_hash = spec.genesis_header().hash();

// database paths
let db_dirs = cmd.dirs.database(genesis_hash, spec.fork_name.clone());

// user defaults path
let user_defaults_path = cmd.dirs.user_defaults_path(&spec.fork_name);
let user_defaults_path = db_dirs.user_defaults_path();

// load user defaults
let mut user_defaults = try!(UserDefaults::load(&user_defaults_path));

// check if tracing is on
let tracing = try!(tracing_switch_to_bool(cmd.tracing, &user_defaults));

// load genesis hash
let genesis_hash = spec.genesis_header().hash();

fdlimit::raise_fd_limit();

// select pruning algorithm
let algorithm = cmd.pruning.to_algorithm(&user_defaults);

// prepare client_path
let client_path = cmd.dirs.client_path(genesis_hash, spec.fork_name.as_ref(), algorithm);
let client_path = db_dirs.client_path(algorithm);

// execute upgrades
try!(execute_upgrades(&cmd.dirs, genesis_hash, spec.fork_name.as_ref(), algorithm, cmd.compaction.compaction_profile()));
try!(execute_upgrades(&db_dirs, algorithm, cmd.compaction.compaction_profile()));

// prepare client config
let client_config = to_client_config(&cmd.cache_config, cmd.mode, tracing, cmd.compaction, cmd.wal, cmd.vm_type, "".into(), algorithm);
Expand Down Expand Up @@ -247,8 +250,14 @@ fn execute_export(cmd: ExportBlockchain) -> Result<String, String> {
// load spec file
let spec = try!(cmd.spec.spec());

// load genesis hash
let genesis_hash = spec.genesis_header().hash();

// database paths
let db_dirs = cmd.dirs.database(genesis_hash, spec.fork_name.clone());

// user defaults path
let user_defaults_path = cmd.dirs.user_defaults_path(&spec.fork_name);
let user_defaults_path = db_dirs.user_defaults_path();

// load user defaults
let user_defaults = try!(UserDefaults::load(&user_defaults_path));
Expand All @@ -258,19 +267,16 @@ fn execute_export(cmd: ExportBlockchain) -> Result<String, String> {

let format = cmd.format.unwrap_or_else(Default::default);

// load genesis hash
let genesis_hash = spec.genesis_header().hash();

fdlimit::raise_fd_limit();

// select pruning algorithm
let algorithm = cmd.pruning.to_algorithm(&user_defaults);

// prepare client_path
let client_path = cmd.dirs.client_path(genesis_hash, spec.fork_name.as_ref(), algorithm);
let client_path = db_dirs.client_path(algorithm);

// execute upgrades
try!(execute_upgrades(&cmd.dirs, genesis_hash, spec.fork_name.as_ref(), algorithm, cmd.compaction.compaction_profile()));
try!(execute_upgrades(&db_dirs, algorithm, cmd.compaction.compaction_profile()));

// prepare client config
let client_config = to_client_config(&cmd.cache_config, cmd.mode, tracing, cmd.compaction, cmd.wal, VMType::default(), "".into(), algorithm);
Expand Down
6 changes: 3 additions & 3 deletions parity/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ impl Directories {

#[derive(Debug, PartialEq)]
pub struct DatabaseDirectories {
path: String,
genesis_hash: H256,
fork_name: Option<String>,
pub path: String,
pub genesis_hash: H256,
pub fork_name: Option<String>,
}

impl DatabaseDirectories {
Expand Down
12 changes: 5 additions & 7 deletions parity/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use std::io::{Write, Read, BufReader, BufRead};
use std::time::Duration;
use std::path::Path;
use std::fs::File;
use util::{clean_0x, U256, Uint, Address, path, H256, CompactionProfile};
use util::{clean_0x, U256, Uint, Address, path, CompactionProfile};
use util::journaldb::Algorithm;
use ethcore::client::{Mode, BlockID, VMType, DatabaseCompactionProfile, ClientConfig};
use ethcore::miner::PendingSet;
use cache::CacheConfig;
use dir::Directories;
use dir::DatabaseDirectories;
use upgrade::upgrade;
use migration::migrate;
use ethsync::is_valid_node_url;
Expand Down Expand Up @@ -226,14 +226,12 @@ pub fn to_client_config(
}

pub fn execute_upgrades(
dirs: &Directories,
genesis_hash: H256,
fork_name: Option<&String>,
dirs: &DatabaseDirectories,
pruning: Algorithm,
compaction_profile: CompactionProfile
) -> Result<(), String> {

match upgrade(Some(&dirs.db)) {
match upgrade(Some(&dirs.path)) {
Ok(upgrades_applied) if upgrades_applied > 0 => {
debug!("Executed {} upgrade scripts - ok", upgrades_applied);
},
Expand All @@ -243,7 +241,7 @@ pub fn execute_upgrades(
_ => {},
}

let client_path = dirs.db_version_path(genesis_hash, fork_name, pruning);
let client_path = dirs.version_path(pruning);
migrate(&client_path, pruning, compaction_profile).map_err(|e| format!("{}", e))
}

Expand Down
17 changes: 9 additions & 8 deletions parity/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,29 @@ pub fn execute(cmd: RunCmd) -> Result<(), String> {
// load spec
let spec = try!(cmd.spec.spec());

// load genesis hash
let genesis_hash = spec.genesis_header().hash();

// database paths
let db_dirs = cmd.dirs.database(genesis_hash, spec.fork_name.clone());

// user defaults path
let user_defaults_path = cmd.dirs.user_defaults_path(&spec.fork_name);
let user_defaults_path = db_dirs.user_defaults_path();

// load user defaults
let mut user_defaults = try!(UserDefaults::load(&user_defaults_path));

// check if tracing is on
let tracing = try!(tracing_switch_to_bool(cmd.tracing, &user_defaults));

let fork_name = spec.fork_name.clone();

// load genesis hash
let genesis_hash = spec.genesis_header().hash();

// select pruning algorithm
let algorithm = cmd.pruning.to_algorithm(&user_defaults);

// prepare client_path
let client_path = cmd.dirs.client_path(genesis_hash, fork_name.as_ref(), algorithm);
let client_path = db_dirs.client_path(algorithm);

// execute upgrades
try!(execute_upgrades(&cmd.dirs, genesis_hash, fork_name.as_ref(), algorithm, cmd.compaction.compaction_profile()));
try!(execute_upgrades(&db_dirs, algorithm, cmd.compaction.compaction_profile()));

// run in daemon mode
if let Some(pid_file) = cmd.daemon {
Expand Down
15 changes: 9 additions & 6 deletions parity/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,21 @@ impl SnapshotCommand {
// load spec file
let spec = try!(self.spec.spec());

// load genesis hash
let genesis_hash = spec.genesis_header().hash();

// database paths
let db_dirs = self.dirs.database(genesis_hash, spec.fork_name.clone());

// user defaults path
let user_defaults_path = self.dirs.user_defaults_path(&spec.fork_name);
let user_defaults_path = db_dirs.user_defaults_path();

// load user defaults
let user_defaults = try!(UserDefaults::load(&user_defaults_path));

// check if tracing is on
let tracing = try!(tracing_switch_to_bool(self.tracing, &user_defaults));

// load genesis hash
let genesis_hash = spec.genesis_header().hash();

// Setup logging
let _logger = setup_log(&self.logger_config);

Expand All @@ -93,10 +96,10 @@ impl SnapshotCommand {
let algorithm = self.pruning.to_algorithm(&user_defaults);

// prepare client_path
let client_path = self.dirs.client_path(genesis_hash, spec.fork_name.as_ref(), algorithm);
let client_path = db_dirs.client_path(algorithm);

// execute upgrades
try!(execute_upgrades(&self.dirs, genesis_hash, spec.fork_name.as_ref(), algorithm, self.compaction.compaction_profile()));
try!(execute_upgrades(&db_dirs, algorithm, self.compaction.compaction_profile()));

// prepare client config
let client_config = to_client_config(&self.cache_config, self.mode, tracing, self.compaction, self.wal, VMType::default(), "".into(), algorithm);
Expand Down

0 comments on commit 79c7dc9

Please sign in to comment.