Merge remote-tracking branch 'cnx/587-bugfix-witness-reindex-logic'

This commit is contained in:
Vikram Rajkumar 2017-05-21 17:10:10 -05:00
commit aaf6c5e8f8

View file

@ -386,13 +386,25 @@ namespace detail {
}
_chain_db->add_checkpoints( loaded_checkpoints );
if( _options->count("replay-blockchain") )
{
ilog("Replaying blockchain on user request.");
_chain_db->reindex(_data_dir/"blockchain", initial_state());
} else if( clean ) {
bool need_reindex = false;
std::string reindex_reason = "(not needed)";
auto is_new = [&]() -> bool
while( true )
{
if( _options->count("replay-blockchain" ) )
{
need_reindex = true;
reindex_reason = "user request";
break;
}
if( !clean )
{
need_reindex = true;
reindex_reason = "unclean shutdown";
break;
}
auto check_is_new = [&]() -> bool
{
// directory doesn't exist
if( !fc::exists( _data_dir ) )
@ -401,7 +413,7 @@ namespace detail {
return ( fc::directory_iterator( _data_dir ) == fc::directory_iterator() );
};
auto is_outdated = [&]() -> bool
auto check_is_outdated = [&]() -> bool
{
if( !fc::exists( _data_dir / "db_version" ) )
return true;
@ -410,8 +422,21 @@ namespace detail {
return (version_str != GRAPHENE_CURRENT_DB_VERSION);
};
bool need_reindex = (!is_new() && is_outdated());
std::string reindex_reason = "version upgrade";
bool is_new = check_is_new();
if( is_new )
{
need_reindex = false;
break;
}
if( is_outdated )
{
need_reindex = true;
reindex_reason = "outdated datadir";
break;
}
}
if( !need_reindex )
{
@ -446,20 +471,6 @@ namespace detail {
db_version.close();
}
}
} else {
wlog("Detected unclean shutdown. Replaying blockchain...");
_chain_db->reindex(_data_dir / "blockchain", initial_state());
}
if (!_options->count("genesis-json") &&
_chain_db->get_chain_id() != graphene::egenesis::get_egenesis_chain_id()) {
elog("Detected old database. Nuking and starting over.");
_chain_db->wipe(_data_dir / "blockchain", true);
_chain_db.reset();
_chain_db = std::make_shared<chain::database>();
_chain_db->add_checkpoints(loaded_checkpoints);
_chain_db->open(_data_dir / "blockchain", initial_state);
}
if( _options->count("force-validate") )
{