aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-08-16 17:51:10 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-08-16 17:51:10 +0000
commita01d5876fa6a9a9fe28cff3ad3ed0e91d5612125 (patch)
tree78c3ba15e465658de39db2fc3d85220fa4f31d2c
parent15399da9fe29336f119121340146d78973b601a5 (diff)
erase the bad chain after disconnecting it
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@138 1a98c847-1fd6-4fd8-948a-caf3550aa51b
-rw-r--r--db.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/db.cpp b/db.cpp
index 8134a9059c..c6127a318d 100644
--- a/db.cpp
+++ b/db.cpp
@@ -460,9 +460,12 @@ 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");
@@ -470,6 +473,7 @@ bool CTxDB::LoadBlockIndex()
{
printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
pindexFork = pindex->pprev;
+ vBad = vChain;
}
}
if (pindexFork)
@@ -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;