Fix bug where updated DB version causes crash on restart
This commit is contained in:
parent
c63e1da22f
commit
ab0d789d72
2 changed files with 1 additions and 39 deletions
|
|
@ -111,31 +111,6 @@ void database::open(
|
|||
{
|
||||
try
|
||||
{
|
||||
auto is_new = [&]() -> bool
|
||||
{
|
||||
// directory doesn't exist
|
||||
if( !fc::exists( data_dir ) )
|
||||
return true;
|
||||
// if directory exists but is empty, return true; else false.
|
||||
return ( fc::directory_iterator( data_dir ) == fc::directory_iterator() );
|
||||
};
|
||||
|
||||
auto is_outdated = [&]() -> bool
|
||||
{
|
||||
if( !fc::exists( data_dir / "db_version" ) )
|
||||
return true;
|
||||
std::string version_str;
|
||||
fc::read_file_contents( data_dir / "db_version", version_str );
|
||||
return (version_str != GRAPHENE_CURRENT_DB_VERSION);
|
||||
};
|
||||
|
||||
if( (!is_new()) && is_outdated() )
|
||||
{
|
||||
ilog( "Old database version detected, reindex is required" );
|
||||
wipe( data_dir, false );
|
||||
fc::remove_all( data_dir / "db_version" );
|
||||
}
|
||||
|
||||
object_database::open(data_dir);
|
||||
|
||||
_block_id_to_block.open(data_dir / "database" / "block_num_to_block");
|
||||
|
|
@ -153,19 +128,6 @@ void database::open(
|
|||
FC_ASSERT( head_block_num() == 0, "last block ID does not match current chain state" );
|
||||
}
|
||||
}
|
||||
|
||||
// doing this down here helps ensure that DB will be wiped
|
||||
// if any of the above steps were interrupted on a previous run
|
||||
if( !fc::exists( data_dir / "db_version" ) )
|
||||
{
|
||||
std::ofstream db_version(
|
||||
(data_dir / "db_version").generic_string().c_str(),
|
||||
std::ios::out | std::ios::binary | std::ios::trunc );
|
||||
std::string version_string = GRAPHENE_CURRENT_DB_VERSION;
|
||||
db_version.write( version_string.c_str(), version_string.size() );
|
||||
db_version.close();
|
||||
}
|
||||
|
||||
//idump((head_block_id())(head_block_num()));
|
||||
}
|
||||
FC_CAPTURE_LOG_AND_RETHROW( (data_dir) )
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@
|
|||
#define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4
|
||||
#define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3
|
||||
|
||||
#define GRAPHENE_CURRENT_DB_VERSION "BTS2.1"
|
||||
#define GRAPHENE_CURRENT_DB_VERSION "BTS2.2"
|
||||
|
||||
#define GRAPHENE_IRREVERSIBLE_THRESHOLD (70 * GRAPHENE_1_PERCENT)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue