Skip to content

Commit

Permalink
Use the greater of last meta block and last CoinsView block for corru…
Browse files Browse the repository at this point in the history
…ption fix process
  • Loading branch information
presstab committed Apr 26, 2017
1 parent a0fdc94 commit f63c1a3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3941,6 +3941,16 @@ bool static LoadBlockIndexDB()

//get the last block that was properly recorded to the block info file
CBlockIndex* pindexLastMeta = vSortedByHeight[vinfoBlockFile[nLastBlockFile].nHeightLast + 1].second;

//fix Assertion `hashPrevBlock == view.GetBestBlock()' failed. By adjusting height to the last recorded by coinsview
CBlockIndex* pindexCoinsView = mapBlockIndex[pcoinsTip->GetBestBlock()];
for(unsigned int i = vinfoBlockFile[nLastBlockFile].nHeightLast + 1; i < vSortedByHeight.size(); i++)
{
pindexLastMeta = vSortedByHeight[i].second;
if(pindexLastMeta->nHeight > pindexCoinsView->nHeight)
break;
}

LogPrintf("%s: Last block properly recorded: #%d %s\n", __func__, pindexLastMeta->nHeight, pindexLastMeta->GetBlockHash().ToString().c_str());

CBlock lastMetaBlock;
Expand Down

0 comments on commit f63c1a3

Please sign in to comment.