Browse Source

More user-friendly error message if UTXO DB runs ahead of block DB

This gives LoadChainTip a return value - allowing it to indicate that
the UTXO DB ran ahead of the block DB. This just provides a nicer
error message instead of the previous mysterious
assert(!setBlockIndexCandidates.empty()) error.

This also calls ActivateBestChain in case we just loaded the genesis
block in LoadChainTip, avoiding relying on the ActivateBestChain
in ThreadImport before continuing init process.
0.15
Matt Corallo 7 years ago
parent
commit
b0f32497b8
  1. 10
      src/init.cpp
  2. 17
      src/validation.cpp
  3. 2
      src/validation.h

10
src/init.cpp

@ -1442,7 +1442,15 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
break; break;
} }
pcoinsTip = new CCoinsViewCache(pcoinscatcher); pcoinsTip = new CCoinsViewCache(pcoinscatcher);
LoadChainTip(chainparams);
if (!fReindex && !fReindexChainState) {
// LoadChainTip sets chainActive based on pcoinsTip's best block
if (!LoadChainTip(chainparams)) {
strLoadError = _("Error initializing block database");
break;
}
assert(chainActive.Tip() != NULL);
}
if (!fReindex && chainActive.Tip() != NULL) { if (!fReindex && chainActive.Tip() != NULL) {
uiInterface.InitMessage(_("Rewinding blocks...")); uiInterface.InitMessage(_("Rewinding blocks..."));

17
src/validation.cpp

@ -3538,14 +3538,24 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
return true; return true;
} }
void LoadChainTip(const CChainParams& chainparams) bool LoadChainTip(const CChainParams& chainparams)
{ {
if (chainActive.Tip() && chainActive.Tip()->GetBlockHash() == pcoinsTip->GetBestBlock()) return; if (chainActive.Tip() && chainActive.Tip()->GetBlockHash() == pcoinsTip->GetBestBlock()) return true;
if (pcoinsTip->GetBestBlock().IsNull() && mapBlockIndex.size() == 1) {
// In case we just added the genesis block, connect it now, so
// that we always have a chainActive.Tip() when we return.
LogPrintf("%s: Connecting genesis block...\n", __func__);
CValidationState state;
if (!ActivateBestChain(state, chainparams)) {
return false;
}
}
// Load pointer to end of best chain // Load pointer to end of best chain
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
if (it == mapBlockIndex.end()) if (it == mapBlockIndex.end())
return; return false;
chainActive.SetTip(it->second); chainActive.SetTip(it->second);
PruneBlockIndexCandidates(); PruneBlockIndexCandidates();
@ -3554,6 +3564,7 @@ void LoadChainTip(const CChainParams& chainparams)
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(),
DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()),
GuessVerificationProgress(chainparams.TxData(), chainActive.Tip())); GuessVerificationProgress(chainparams.TxData(), chainActive.Tip()));
return true;
} }
CVerifyDB::CVerifyDB() CVerifyDB::CVerifyDB()

2
src/validation.h

@ -262,7 +262,7 @@ bool LoadGenesisBlock(const CChainParams& chainparams);
* initializing state if we're running with -reindex. */ * initializing state if we're running with -reindex. */
bool LoadBlockIndex(const CChainParams& chainparams); bool LoadBlockIndex(const CChainParams& chainparams);
/** Update the chain tip based on database information. */ /** Update the chain tip based on database information. */
void LoadChainTip(const CChainParams& chainparams); bool LoadChainTip(const CChainParams& chainparams);
/** Unload database information */ /** Unload database information */
void UnloadBlockIndex(); void UnloadBlockIndex();
/** Run an instance of the script checking thread */ /** Run an instance of the script checking thread */

Loading…
Cancel
Save