erase the bad chain after disconnecting it
This commit is contained in:
parent
bb3fd02930
commit
21ca2d833b
12
db.cpp
12
db.cpp
@ -460,9 +460,12 @@ bool CTxDB::LoadBlockIndex()
|
|||||||
ReadBestInvalidWork(bnBestInvalidWork);
|
ReadBestInvalidWork(bnBestInvalidWork);
|
||||||
|
|
||||||
// Verify blocks in the best chain
|
// Verify blocks in the best chain
|
||||||
|
vector<CBlockIndex*> vChain;
|
||||||
|
vector<CBlockIndex*> vBad;
|
||||||
CBlockIndex* pindexFork = NULL;
|
CBlockIndex* pindexFork = NULL;
|
||||||
for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
|
for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
|
||||||
{
|
{
|
||||||
|
vChain.push_back(pindex);
|
||||||
CBlock block;
|
CBlock block;
|
||||||
if (!block.ReadFromDisk(pindex))
|
if (!block.ReadFromDisk(pindex))
|
||||||
return error("LoadBlockIndex() : block.ReadFromDisk failed");
|
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());
|
printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str());
|
||||||
pindexFork = pindex->pprev;
|
pindexFork = pindex->pprev;
|
||||||
|
vBad = vChain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pindexFork)
|
if (pindexFork)
|
||||||
@ -480,6 +484,14 @@ bool CTxDB::LoadBlockIndex()
|
|||||||
return error("LoadBlockIndex() : block.ReadFromDisk failed");
|
return error("LoadBlockIndex() : block.ReadFromDisk failed");
|
||||||
CTxDB txdb;
|
CTxDB txdb;
|
||||||
block.SetBestChain(txdb, pindexFork);
|
block.SetBestChain(txdb, pindexFork);
|
||||||
|
|
||||||
|
// Delete the bad chain
|
||||||
|
foreach(CBlockIndex* pindex, vBad)
|
||||||
|
{
|
||||||
|
txdb.EraseBlockIndex(pindex->GetBlockHash());
|
||||||
|
mapBlockIndex.erase(pindex->GetBlockHash());
|
||||||
|
delete pindex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user