If you change difficulty, change nPowTargetSpacing or nPowTargetTimespan.
class CMainParams : public CChainParams {
public:
CMainParams() {
consensus.nPowTargetSpacing = 32;
consensus.nPowTargetTimespan = 24 * 60 * 60; // one day
source
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
{
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
// Genesis block
if (pindexLast == NULL)
return nProofOfWorkLimit;
// Only change once per difficulty adjustment interval
if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
:
// Go back by what we want to be 14 days worth of blocks
int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);
assert(nHeightFirst >= 0);
const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst);
assert(pindexFirst);
return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params);
}
If you change difficulty, change nPowTargetSpacing or nPowTargetTimespan.
source
above result is
DifficultyAdjustmentInterval = 2700
By the way. bitcoin 0.15.1 is 2016
consensus.nPowTargetTimespan = 14 24 60 60; // two weeks consensus.nPowTargetSpacing = 10 60;
DifficultyAdjustmentInterval = 2016