Improve block database load error reporting
This commit is contained in:
73
src/init.cpp
73
src/init.cpp
@@ -82,6 +82,7 @@ void Shutdown(void* parg)
|
||||
if (fFirstThread)
|
||||
{
|
||||
fShutdown = true;
|
||||
fRequestShutdown = true;
|
||||
nTransactionsUpdated++;
|
||||
bitdb.Flush(false);
|
||||
{
|
||||
@@ -791,27 +792,69 @@ bool AppInit2()
|
||||
nTotalCache -= nCoinDBCache;
|
||||
nCoinCacheSize = nTotalCache / 300; // coins in memory require around 300 bytes
|
||||
|
||||
uiInterface.InitMessage(_("Loading block index..."));
|
||||
bool fLoaded = false;
|
||||
while (!fLoaded) {
|
||||
bool fReset = fReindex;
|
||||
std::string strLoadError;
|
||||
|
||||
nStart = GetTimeMillis();
|
||||
pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex);
|
||||
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex);
|
||||
pcoinsTip = new CCoinsViewCache(*pcoinsdbview);
|
||||
uiInterface.InitMessage(_("Loading block index..."));
|
||||
|
||||
if (fReindex)
|
||||
pblocktree->WriteReindexing(true);
|
||||
nStart = GetTimeMillis();
|
||||
do {
|
||||
try {
|
||||
UnloadBlockIndex();
|
||||
delete pcoinsTip;
|
||||
delete pcoinsdbview;
|
||||
delete pblocktree;
|
||||
|
||||
if (!LoadBlockIndex())
|
||||
return InitError(_("Error loading block database"));
|
||||
pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex);
|
||||
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex);
|
||||
pcoinsTip = new CCoinsViewCache(*pcoinsdbview);
|
||||
|
||||
// Initialize the block index (no-op if non-empty database was already loaded)
|
||||
if (!InitBlockIndex())
|
||||
return InitError(_("Error initializing block database"));
|
||||
if (fReindex)
|
||||
pblocktree->WriteReindexing(true);
|
||||
|
||||
uiInterface.InitMessage(_("Verifying block database integrity..."));
|
||||
if (!LoadBlockIndex()) {
|
||||
strLoadError = _("Error loading block database");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!VerifyDB())
|
||||
return InitError(_("Corrupted block database detected. Please restart the client with -reindex."));
|
||||
// Initialize the block index (no-op if non-empty database was already loaded)
|
||||
if (!InitBlockIndex()) {
|
||||
strLoadError = _("Error initializing block database");
|
||||
break;
|
||||
}
|
||||
|
||||
uiInterface.InitMessage(_("Verifying block database integrity..."));
|
||||
if (!VerifyDB()) {
|
||||
strLoadError = _("Corrupted block database detected");
|
||||
break;
|
||||
}
|
||||
} catch(std::exception &e) {
|
||||
strLoadError = _("Error opening block database");
|
||||
break;
|
||||
}
|
||||
|
||||
fLoaded = true;
|
||||
} while(false);
|
||||
|
||||
if (!fLoaded) {
|
||||
// first suggest a reindex
|
||||
if (!fReset) {
|
||||
bool fRet = uiInterface.ThreadSafeMessageBox(
|
||||
strLoadError + ".\n" + _("Do you want to rebuild the block database now?"),
|
||||
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
|
||||
if (fRet) {
|
||||
fReindex = true;
|
||||
fRequestShutdown = false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return InitError(strLoadError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mapArgs.count("-txindex") && fTxIndex != GetBoolArg("-txindex", false))
|
||||
return InitError(_("You need to rebuild the databases using -reindex to change -txindex"));
|
||||
|
||||
Reference in New Issue
Block a user