Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Block time calculations

View gist:8905544
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
void bridgetest_dumpBlocks()
{
CBlockIndex *blockIndex = pindexGenesisBlock;
uint256 prevHash = 0;
int64_t expectedMintValue;
int32_t blockCount = 0;
int32_t badBlockCount = 0;
time_t lastBlockTime, thisBlockTime;
int32_t totalTime[10][10];
int32_t timeCount[10][10];
 
lastBlockTime = 0;
thisBlockTime = 0;
memset(totalTime, 0, sizeof(int32_t)*10*10);
memset(timeCount, 0, sizeof(int32_t)*10*10);
 
printf("--->>>Begin block value test\n");
 
do {
if (blockIndex->pprev) {
prevHash = blockIndex->pprev->GetBlockHash();
 
expectedMintValue = bridge_getBlockMintedValue(blockIndex->nHeight, prevHash);
thisBlockTime = blockIndex->nTime;
 
if (lastBlockTime) {
time_t timeDiff = thisBlockTime - lastBlockTime;
int32_t truncVal = expectedMintValue / COIN;
int32_t valSection = truncVal / 100000;
int32_t blockSection = blockCount / 10000;
 
if (timeDiff > 0 && timeDiff < 900) {
if (valSection > 10)
valSection = 9;
 
totalTime[blockSection][valSection] += timeDiff;
timeCount[blockSection][valSection]++;
}
else {
printf("time to %d: %ld\n", blockCount, timeDiff);
}
}
 
printf("%d\n", blockCount);
lastBlockTime = thisBlockTime;
}
blockCount++;
blockIndex = blockIndex->pnext;
} while (blockIndex != NULL);
 
for (int32_t blockSection=0; blockSection<10; blockSection++) {
printf("--------------------------\n");
printf("blocks %d - %d\n", blockSection * 10000, (blockSection * 10000) + 9999);
for (int32_t valSection=0; valSection<10; valSection++) {
printf("\tval %06d - %06d: %f secs (%d)\n", valSection * 100000, (valSection * 100000) + 99999, (double)totalTime[blockSection][valSection] / (double)timeCount[blockSection][valSection], timeCount[blockSection][valSection]);
}
}
 
printf("--->>>End block value test\n");
printf("--->>>Tested %d blocks\n", blockCount);
printf("--->>>%d blocks incorrect\n", badBlockCount);
}
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.