Skip to content

Commit

Permalink
erase the bad chain after disconnecting it
Browse files Browse the repository at this point in the history
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@138 1a98c847-1fd6-4fd8-948a-caf3550aa51b
  • Loading branch information
non-github-bitcoin committed Aug 16, 2010
1 parent 15399da commit a01d587
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions db.cpp
Expand Up @@ -460,16 +460,20 @@ bool CTxDB::LoadBlockIndex()
ReadBestInvalidWork(bnBestInvalidWork);

// Verify blocks in the best chain
vector<CBlockIndex*> vChain;
vector<CBlockIndex*> vBad;
CBlockIndex* pindexFork = NULL;
for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
{
vChain.push_back(pindex);
CBlock block;
if (!block.ReadFromDisk(pindex))
return error("LoadBlockIndex() : block.ReadFromDisk failed");
if (!block.CheckBlock())
{
printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
pindexFork = pindex->pprev;
vBad = vChain;
}
}
if (pindexFork)
Expand All @@ -480,6 +484,14 @@ bool CTxDB::LoadBlockIndex()
return error("LoadBlockIndex() : block.ReadFromDisk failed");
CTxDB txdb;
block.SetBestChain(txdb, pindexFork);

// Delete the bad chain
foreach(CBlockIndex* pindex, vBad)
{
txdb.EraseBlockIndex(pindex->GetBlockHash());
mapBlockIndex.erase(pindex->GetBlockHash());
delete pindex;
}
}

return true;
Expand Down

0 comments on commit a01d587

Please sign in to comment.