aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp79
1 files changed, 61 insertions, 18 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 15a46946fa..99e89d9edc 100644
--- a/src/init.cpp
+++ b/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);
-
- if (fReindex)
- pblocktree->WriteReindexing(true);
-
- if (!LoadBlockIndex())
- return InitError(_("Error loading block database"));
+ uiInterface.InitMessage(_("Loading block index..."));
- // Initialize the block index (no-op if non-empty database was already loaded)
- if (!InitBlockIndex())
- return InitError(_("Error initializing block database"));
-
- uiInterface.InitMessage(_("Verifying block database integrity..."));
+ nStart = GetTimeMillis();
+ do {
+ try {
+ UnloadBlockIndex();
+ delete pcoinsTip;
+ delete pcoinsdbview;
+ delete pblocktree;
+
+ pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex);
+ pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex);
+ pcoinsTip = new CCoinsViewCache(*pcoinsdbview);
+
+ if (fReindex)
+ pblocktree->WriteReindexing(true);
+
+ if (!LoadBlockIndex()) {
+ strLoadError = _("Error loading block database");
+ break;
+ }
+
+ // 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;
+ }
- if (!VerifyDB())
- return InitError(_("Corrupted block database detected. Please restart the client with -reindex."));
+ 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"));