diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2012-12-12 09:11:36 -0800 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2012-12-12 09:11:36 -0800 |
commit | dbd5bb803938f0030902b040e7ae191fc75d69b5 (patch) | |
tree | 8e1ff18e14515fe142e747ddec7bda62a9461dde | |
parent | 8b83e2fc2e7440c49902babc7d89b629f8651ad8 (diff) | |
parent | 89b7019be884962729784ab326c46be88ed4784c (diff) |
Merge pull request #2062 from sipa/nocoins
Reconstruct coins/ database when missing
-rw-r--r-- | src/init.cpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 23 |
2 files changed, 11 insertions, 14 deletions
diff --git a/src/init.cpp b/src/init.cpp index b68ca1cf1a..656bda640f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -865,7 +865,7 @@ bool AppInit2() if (walletdb.ReadBestBlock(locator)) pindexRescan = locator.GetBlockIndex(); } - if (pindexBest != pindexRescan) + if (pindexBest && pindexBest != pindexRescan) { uiInterface.InitMessage(_("Rescanning...")); printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight); diff --git a/src/main.cpp b/src/main.cpp index 177dbfe0c8..693cb28d42 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1694,7 +1694,7 @@ bool SetBestChain(CBlockIndex* pindexNew) // Find the fork (typically, there is none) CBlockIndex* pfork = view.GetBestBlock(); CBlockIndex* plonger = pindexNew; - while (pfork != plonger) + while (pfork && pfork != plonger) { while (plonger->nHeight > pfork->nHeight) if (!(plonger = plonger->pprev)) @@ -2330,13 +2330,18 @@ bool static LoadBlockIndexDB() if (pblocktree->ReadBlockFileInfo(nLastBlockFile, infoLastBlockFile)) printf("LoadBlockIndex(): last block file: %s\n", infoLastBlockFile.ToString().c_str()); + // Load bnBestInvalidWork, OK if it doesn't exist + pblocktree->ReadBestInvalidWork(bnBestInvalidWork); + + // Check whether we need to continue reindexing + bool fReindexing = false; + pblocktree->ReadReindexing(fReindexing); + fReindex |= fReindexing; + // Load hashBestChain pointer to end of best chain pindexBest = pcoinsTip->GetBestBlock(); if (pindexBest == NULL) - { - if (pindexGenesisBlock == NULL) - return true; - } + return true; hashBestChain = pindexBest->GetBlockHash(); nBestHeight = pindexBest->nHeight; bnBestChainWork = pindexBest->bnChainWork; @@ -2352,14 +2357,6 @@ bool static LoadBlockIndexDB() BlockHashStr(hashBestChain).c_str(), nBestHeight, DateTimeStrFormat("%x %H:%M:%S", pindexBest->GetBlockTime()).c_str()); - // Load bnBestInvalidWork, OK if it doesn't exist - pblocktree->ReadBestInvalidWork(bnBestInvalidWork); - - // Check whether we need to continue reindexing - bool fReindexing = false; - pblocktree->ReadReindexing(fReindexing); - fReindex |= fReindexing; - // Verify blocks in the best chain int nCheckLevel = GetArg("-checklevel", 1); int nCheckDepth = GetArg( "-checkblocks", 2500); |