Timewarp attack 600 second grace period

I don’t think this is dangerous for the network for the numbers we’re discussing, i.e. a 10% speedup after a sustained 51% attack for 59 difficulty periods. And why would a miner want to reduce their own fee revenue?

But no miner ran into that bug so far, because it takes significant hash rate to push MTP above wall clock time and perform this attack. With the timewarp rule, griefing a miner that uses wall clock time only requires finding the last block in a retarget period and setting its time (a bit more than) 600 seconds in the future. Both attacks are free, but the latter only requires luck, no large percentage of hash power.

The main change adds this to miner.cpp:

if (consensusParams.enforce_BIP94) {
        // Height of block to be mined.
        const int height{pindexPrev->nHeight + 1};
        if (height % consensusParams.DifficultyAdjustmentInterval() == 0) {
            nNewTime = std::max<int64_t>(nNewTime, pindexPrev->GetBlockTime() - MAX_TIMEWARP);
        }
    }

The pull request description is focussed on a different scenario, but this (also) fixes the second griefing attack.

Yes, 150 minutes makes the above griefing attack on broken miner software impossible, because the attacker can’t put their timestamp more than 120 minutes in the future.

Hopefully the above example illustrates this? With a 150 minute threshold there’s no (additional) danger in having a bug in mining software that ignores the nTime value provided in the Bicoin Core template. They might ignore it by accident like SRI Pool and JDC update `nTime` field with current timestamp - they should use the one sent by TP · Issue #1324 · stratum-mining/stratum · GitHub, or they might have custom code that calculates nTime correctly under the current rules (but not accounting for the new timewarp rule).