Switch reindexing to AcceptBlock in-loop and ActivateBestChain afterwards

This commit is contained in:
Pieter Wuille
2016-04-20 15:45:41 +02:00
committed by lateminer
parent 722169b74d
commit 26d8544314
2 changed files with 19 additions and 16 deletions

View File

@@ -4094,7 +4094,8 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha
{
AssertLockHeld(cs_main);
CBlockIndex *&pindex = *ppindex;
CBlockIndex *pindexDummy = NULL;
CBlockIndex *&pindex = ppindex ? *ppindex : pindexDummy;
if (!AcceptBlockHeader(block, state, hash, chainparams, &pindex))
return false;
@@ -4775,13 +4776,14 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
// process in case the block isn't known yet
if (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0) {
LOCK(cs_main);
CValidationState state;
if (ProcessNewBlock(state, chainparams, NULL, &block, true, dbp, hash))
if (AcceptBlock(block, state, chainparams, NULL, true, dbp, hash))
nLoaded++;
if (state.IsError())
break;
} else if (hash != chainparams.GetConsensus().hashGenesisBlock && mapBlockIndex[hash]->nHeight % 1000 == 0) {
LogPrintf("Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight);
LogPrint("reindex", "Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight);
}
// Recursively process earlier encountered successors of this block
@@ -4795,11 +4797,12 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
std::multimap<uint256, CDiskBlockPos>::iterator it = range.first;
if (ReadBlockFromDisk(block, it->second, chainparams.GetConsensus()))
{
uint256 hash = block.GetHash();
LogPrintf("%s: Processing out of order child %s of %s\n", __func__, hash.ToString(),
uint256 hash = block.GetHash();
LogPrint("reindex", "%s: Processing out of order child %s of %s\n", __func__, hash.ToString(),
head.ToString());
LOCK(cs_main);
CValidationState dummy;
if (ProcessNewBlock(dummy, chainparams, NULL, &block, true, &it->second, hash))
if (AcceptBlock(block, dummy, chainparams, NULL, true, &it->second, hash))
{
nLoaded++;
queue.push_back(block.GetHash());