From f63c1a372e8ecdb5a17d9a4b6f2e2362354a400d Mon Sep 17 00:00:00 2001 From: presstab Date: Mon, 24 Apr 2017 18:53:29 -0600 Subject: [PATCH] Use the greater of last meta block and last CoinsView block for corruption fix process --- src/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) 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;