Merge pull request #96 from ethcore/shutdown_gracefully
shutdown gracefully on incompatible db open
This commit is contained in:
commit
725120c126
|
@ -6,7 +6,7 @@ use util::{open_db, init_db};
|
||||||
pub fn import(cfg: Config, matches: &ArgMatches) -> Result<(), String> {
|
pub fn import(cfg: Config, matches: &ArgMatches) -> Result<(), String> {
|
||||||
let db = open_db(&cfg);
|
let db = open_db(&cfg);
|
||||||
// TODO: this might be unnecessary here!
|
// TODO: this might be unnecessary here!
|
||||||
init_db(&cfg, &db);
|
try!(init_db(&cfg, &db));
|
||||||
|
|
||||||
let mut writer = create_sync_blocks_writer(db);
|
let mut writer = create_sync_blocks_writer(db);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub fn start(cfg: config::Config) -> Result<(), String> {
|
||||||
let mut el = p2p::event_loop();
|
let mut el = p2p::event_loop();
|
||||||
|
|
||||||
let db = open_db(&cfg);
|
let db = open_db(&cfg);
|
||||||
init_db(&cfg, &db);
|
try!(init_db(&cfg, &db));
|
||||||
|
|
||||||
let p2p_cfg = p2p::Config {
|
let p2p_cfg = p2p::Config {
|
||||||
threads: 4,
|
threads: 4,
|
||||||
|
|
12
pbtc/util.rs
12
pbtc/util.rs
|
@ -23,13 +23,15 @@ pub fn node_table_path() -> PathBuf {
|
||||||
node_table
|
node_table
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_db(cfg: &Config, db: &Arc<db::Store>) {
|
pub fn init_db(cfg: &Config, db: &Arc<db::Store>) -> Result<(), String> {
|
||||||
// insert genesis block if db is empty
|
// insert genesis block if db is empty
|
||||||
let genesis_block = cfg.magic.genesis_block();
|
let genesis_block = cfg.magic.genesis_block();
|
||||||
match db.block_hash(0) {
|
match db.block_hash(0) {
|
||||||
Some(ref db_genesis_block_hash) if db_genesis_block_hash != &genesis_block.hash() => panic!("Trying to open database with incompatible genesis block"),
|
Some(ref db_genesis_block_hash) if db_genesis_block_hash != &genesis_block.hash() => Err("Trying to open database with incompatible genesis block".into()),
|
||||||
Some(_) => (),
|
Some(_) => Ok(()),
|
||||||
None => db.insert_block(&genesis_block)
|
None => {
|
||||||
.expect("Failed to insert genesis block to the database"),
|
db.insert_block(&genesis_block).expect("Failed to insert genesis block to the database");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue