diff options
author | Matt Corallo <git@bluematt.me> | 2017-07-06 20:00:11 -0400 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2017-07-27 15:03:05 -0400 |
commit | b0f32497b873cd1eaf0be86f8e265355aa86174f (patch) | |
tree | 4f9c82cd3d5f51e5236254cdc874279391e75034 /src/validation.cpp | |
parent | eda888e57352037ab2e60f6ef90098b3ce23a157 (diff) |
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.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index ebbdb7e651..91982ead90 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3538,14 +3538,24 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams) 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 BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); if (it == mapBlockIndex.end()) - return; + return false; chainActive.SetTip(it->second); PruneBlockIndexCandidates(); @@ -3554,6 +3564,7 @@ void LoadChainTip(const CChainParams& chainparams) chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), GuessVerificationProgress(chainparams.TxData(), chainActive.Tip())); + return true; } CVerifyDB::CVerifyDB() |