Created
February 20, 2015 03:50
-
-
Save dexX7/807cb7a0e26383d616d0 to your computer and use it in GitHub Desktop.
bool CheckForOutOfOrderBlockStorage()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool CheckForOutOfOrderBlockStorage() | |
{ | |
AssertLockHeld(cs_main); | |
int64_t nTime = GetTimeMicros(); | |
int blockHeight = 0; | |
int prevBlockFile = 0; | |
unsigned int prevBlockPos = 0; | |
bool unsupportedBlockChain = false; | |
int blockHeightChain = chainActive.Height(); | |
CBlockIndex* pindex = chainActive.Genesis(); | |
while (pindex) { | |
// obtain the block file this is in, and the location in the file | |
int blockFile = pindex->GetBlockPos().nFile; | |
unsigned int blockPos = pindex->GetBlockPos().nPos; | |
blockHeight = pindex->nHeight; | |
printf("block %d blockFile %d blockPos %u time %.2f ms\n", | |
blockHeight, blockFile, blockPos, (0.001 * (GetTimeMicros() - nTime))); | |
// compare against previous block | |
if (blockFile > prevBlockFile) prevBlockPos = 0; // moving onto a new blk?????.dat | |
if (blockPos <= prevBlockPos) { | |
// found a blocks stored out of order | |
unsupportedBlockChain = true; | |
printf("UNSUPPORTED!! blockPos %u <= prevBlockPos %u at height %d\n", | |
blockPos, prevBlockPos, blockHeight); | |
break; // don't bother doing more work than we need to | |
} | |
// move to next block, if there is one | |
prevBlockFile = blockFile; | |
prevBlockPos = blockPos; | |
pindex = chainActive.Next(pindex); | |
} | |
// double check to ensure we saw all blocks, even if passed earlier | |
if (blockHeight < blockHeightChain) { | |
unsupportedBlockChain = true; | |
printf("UNSUPPORTED!! blockHeight %d < blockHeightChain %d\n", | |
blockHeight, blockHeightChain); | |
} | |
printf("blockHeight %d\n", blockHeight); | |
printf("blockHeightChain %d\n", blockHeightChain); | |
printf("time total %.2f ms\n", (0.001 * (GetTimeMicros() - nTime))); | |
return unsupportedBlockChain; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment