verge: [Question] Submitblock

main.h

static const int SAME_ALGO_MAX_COUNT = 5;

main.cpp

bool CBlock::CheckPrevAlgo(CBlockIndex* pIndex)
{
    unsigned checkedBlocks = 0;
    unsigned sameAlgoBlocks = 0;

    while (pIndex && checkedBlocks != 2*SAME_ALGO_MAX_COUNT)
    {
        if (::GetAlgo(pIndex->nVersion) == GetAlgo())
            ++sameAlgoBlocks;
        
        ++checkedBlocks;
        pIndex = pIndex->pprev;
    }

    if (sameAlgoBlocks > SAME_ALGO_MAX_COUNT)
        return false;

    return true;
}
// 2*SAME_ALGO_MAX_COUNT = 10 blocks
checkedBlocks != 2*SAME_ALGO_MAX_COUNT)

Can we get some clarification on the same algorithm rejection rules for submit block? It looks like It can take 5 of the same algorithm for every 10 blocks, shouldn’t it be 5 of the same algorithm for every 6 which forces the algo to change every max+1.

while (pIndex && checkedBlocks != SAME_ALGO_MAX_COUNT+1

Why not this instead?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 29 (16 by maintainers)

Most upvoted comments

@Positivism Well to clarify this. In the while iteration you specified the max searched blocks. That means we iterate backwards through each block, but we don’t want want to search through the entire blockchain until we reach the end, so we specified a max of 2 * MAX_SAME_ALGO_COUNT as the max search field.

That means lastBlock; lastBlock - 1; lastBlock - 2; ...; lastBlock - 10; end and within those ten blocks we should not have more than 6 of the current Algorithm that we are using. And this check basically checking our assumption after we searched through the last 10 blocks:

 if (sameAlgoBlocks > SAME_ALGO_MAX_COUNT)
        return false;

Just to clean that up in the best case you should have the same algo 2 time each ten blocks, but sometimes they can skip or replay algos for various reasons, that’s why it can most likely vary within 2-3 times per ten blocks.