Skip to content

Instantly share code, notes, and snippets.

@dexX7
Created February 20, 2015 03:50
Show Gist options
  • Save dexX7/b8b47abaddf3619c3432 to your computer and use it in GitHub Desktop.
Save dexX7/b8b47abaddf3619c3432 to your computer and use it in GitHub Desktop.
bool CheckBlockStorageOrder()
bool CheckBlockStorageOrder()
{
AssertLockHeld(cs_main);
int nHeight = 0;
int nFilePrev = 0;
unsigned int nPosPrev = 0;
int nHeightChain = chainActive.Height();
CBlockIndex* pindex = chainActive.Genesis();
while (pindex) {
int nFile = pindex->GetBlockPos().nFile;
unsigned int nPos = pindex->GetBlockPos().nPos;
nHeight = pindex->nHeight;
if (nFile > nFilePrev) {
// moving onto a new blk?????.dat
nPosPrev = 0;
}
if (nPos <= nPosPrev) {
// found a blocks stored out of order
return false;
}
nFilePrev = nFile;
nPosPrev = nPos;
pindex = chainActive.Next(pindex);
}
if (nHeight < nHeightChain) {
// blocks appear to be missing and have no successor
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment