Bitcoin Cash Difficulty Error

in #bitcoin3 years ago (edited)


The Difficulty Adjustment Method
Starting in the params file, you can see they use the standard difficulty adjustment interval used in Bitcoin.

 int64_t DifficultyAdjustmentInterval() const {
        return nPowTargetTimespan / nPowTargetSpacing;

The issue with this is that the adjustment interval is using the same values as Bitcoin which in a normal state, adjusts the difficulty every two weeks and expects blocks every 10 minutes.

consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;

Looking at the source code, it seems Bitcoin Cash did expect the hash rate to drop in the future and allow a faster readjustment but they didn't factor in the fork being such a drop.

The current code inside Bitcoin-ABC/Bitcoin Cash takes the timing of 6 blocks taking more or less than 12 hours before reducing the difficulty by 20%. This would be sufficient if the chain started with hash power which left the network but this did not take into account the lack of power from the start as people mined the main Bitcoin chain.

With 1-2% of the hash power of the bitcoin network, they are going to be waiting a long time to find a block. In my opinion, they need to push a code fix that changes the diff adjustment to recalculate after the 12 hours or they are going to deal with a stuck chain until they can convince pools to mine their chain for 6 blocks which will still lower the difficulty only 20% and not bring it back to the 10 minute block target for a few iterations.

// If producing the last 6 block took less than 12h, we keep the same
    // difficulty.
    const CBlockIndex *pindex6 = pindexPrev->GetAncestor(nHeight - 7);
    int64_t mtp6blocks =
        pindexPrev->GetMedianTimePast() - pindex6->GetMedianTimePast();
    if (mtp6blocks < 12 * 3600) {
        return nBits;

    // If producing the last 6 block took more than 12h, increase the difficulty
    // target by 1/4 (which reduces the difficulty by 20%). This ensure the
    // chain do not get stuck in case we lose hashrate abruptly.
    arith_uint256 nPow;
    nPow += (nPow >> 2);