application.cpp: Cleanup re-indexing logic #587 DOES NOT COMPILE

This commit is contained in:
theoreticalbts 2016-02-16 14:11:05 -05:00
parent 567a40170e
commit 62a414ac85

View file

@ -308,13 +308,25 @@ namespace detail {
} }
_chain_db->add_checkpoints( loaded_checkpoints ); _chain_db->add_checkpoints( loaded_checkpoints );
if( _options->count("replay-blockchain") ) bool need_reindex = false;
{ std::string reindex_reason = "(not needed)";
ilog("Replaying blockchain on user request.");
_chain_db->reindex(_data_dir/"blockchain", initial_state());
} else if( clean ) {
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 // directory doesn't exist
if( !fc::exists( _data_dir ) ) if( !fc::exists( _data_dir ) )
@ -323,7 +335,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;
@ -332,8 +344,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 )
{ {
@ -368,20 +393,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") )
{ {