Browse Source

do an extra CheckBlock in ConnectBlock

0.8
Satoshi Nakamoto 14 years ago committed by Gavin Andresen
parent
commit
43deefa435
  1. 13
      db.cpp
  2. 4
      main.cpp
  3. 2
      serialize.h

13
db.cpp

@ -460,12 +460,9 @@ 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");
@ -473,25 +470,17 @@ 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)
{ {
// Reorg back to the fork
printf("LoadBlockIndex() : *** moving best chain pointer back to block %d\n", pindexFork->nHeight); printf("LoadBlockIndex() : *** moving best chain pointer back to block %d\n", pindexFork->nHeight);
CBlock block; CBlock block;
if (!block.ReadFromDisk(pindexFork)) if (!block.ReadFromDisk(pindexFork))
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;

4
main.cpp

@ -1107,6 +1107,10 @@ bool CBlock::DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex)
bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex) bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
{ {
// Check it again in case a previous version let a bad block in
if (!CheckBlock())
return false;
//// issue here: it doesn't know the version //// issue here: it doesn't know the version
unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size()); unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size());

2
serialize.h

@ -20,7 +20,7 @@ class CDataStream;
class CAutoFile; class CAutoFile;
static const int VERSION = 310; static const int VERSION = 310;
static const char* pszSubVer = ".2"; static const char* pszSubVer = ".3";

Loading…
Cancel
Save