Merge remote-tracking branch 'cnx/587-bugfix-witness-reindex-logic'
This commit is contained in:
commit
aaf6c5e8f8
1 changed files with 59 additions and 48 deletions
|
|
@ -386,13 +386,25 @@ namespace detail {
|
||||||
}
|
}
|
||||||
_chain_db->add_checkpoints( loaded_checkpoints );
|
_chain_db->add_checkpoints( loaded_checkpoints );
|
||||||
|
|
||||||
|
bool need_reindex = false;
|
||||||
|
std::string reindex_reason = "(not needed)";
|
||||||
|
|
||||||
|
while( true )
|
||||||
|
{
|
||||||
if( _options->count("replay-blockchain" ) )
|
if( _options->count("replay-blockchain" ) )
|
||||||
{
|
{
|
||||||
ilog("Replaying blockchain on user request.");
|
need_reindex = true;
|
||||||
_chain_db->reindex(_data_dir/"blockchain", initial_state());
|
reindex_reason = "user request";
|
||||||
} else if( clean ) {
|
break;
|
||||||
|
}
|
||||||
|
if( !clean )
|
||||||
|
{
|
||||||
|
need_reindex = true;
|
||||||
|
reindex_reason = "unclean shutdown";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
auto is_new = [&]() -> bool
|
auto check_is_new = [&]() -> bool
|
||||||
{
|
{
|
||||||
// directory doesn't exist
|
// directory doesn't exist
|
||||||
if( !fc::exists( _data_dir ) )
|
if( !fc::exists( _data_dir ) )
|
||||||
|
|
@ -401,7 +413,7 @@ namespace detail {
|
||||||
return ( fc::directory_iterator( _data_dir ) == fc::directory_iterator() );
|
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" ) )
|
if( !fc::exists( _data_dir / "db_version" ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -410,8 +422,21 @@ namespace detail {
|
||||||
return (version_str != GRAPHENE_CURRENT_DB_VERSION);
|
return (version_str != GRAPHENE_CURRENT_DB_VERSION);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool need_reindex = (!is_new() && is_outdated());
|
bool is_new = check_is_new();
|
||||||
std::string reindex_reason = "version upgrade";
|
|
||||||
|
if( is_new )
|
||||||
|
{
|
||||||
|
need_reindex = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( is_outdated )
|
||||||
|
{
|
||||||
|
need_reindex = true;
|
||||||
|
reindex_reason = "outdated datadir";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( !need_reindex )
|
if( !need_reindex )
|
||||||
{
|
{
|
||||||
|
|
@ -446,20 +471,6 @@ namespace detail {
|
||||||
db_version.close();
|
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") )
|
if( _options->count("force-validate") )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue