diff --git a/src/main.cpp b/src/main.cpp index cae8ef8e30ee1..4f14222d75fd3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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;