aboutsummaryrefslogtreecommitdiff
path: root/db.cpp
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-08-16 17:05:50 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-08-16 17:05:50 +0000
commit15399da9fe29336f119121340146d78973b601a5 (patch)
tree35a119aa0cd0adea14657b8dbe184b4eef3bdafb /db.cpp
parent6da916d4acf0c26be81b4547da0e4160d53aacc8 (diff)
blocks-1,
verify block chain on load, so wouldn't have needed to delete blk*.dat, it would have done a reorg automatically git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@137 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'db.cpp')
-rw-r--r--db.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/db.cpp b/db.cpp
index 7116b0aa30..8134a9059c 100644
--- a/db.cpp
+++ b/db.cpp
@@ -459,6 +459,29 @@ bool CTxDB::LoadBlockIndex()
// Load bnBestInvalidWork, OK if it doesn't exist
ReadBestInvalidWork(bnBestInvalidWork);
+ // Verify blocks in the best chain
+ CBlockIndex* pindexFork = NULL;
+ for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
+ {
+ 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;
+ }
+ }
+ if (pindexFork)
+ {
+ printf("LoadBlockIndex() : *** moving best chain pointer back to block %d\n", pindexFork->nHeight);
+ CBlock block;
+ if (!block.ReadFromDisk(pindexFork))
+ return error("LoadBlockIndex() : block.ReadFromDisk failed");
+ CTxDB txdb;
+ block.SetBestChain(txdb, pindexFork);
+ }
+
return true;
}