Changeset View
Changeset View
Standalone View
Standalone View
src/pow.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | uint32_t GetNextCashWorkRequired(const CBlockIndex *pindexPrev, | ||||
// Long-term block production time stabiliser that should rarely | // Long-term block production time stabiliser that should rarely | ||||
// trigger. Should miners produce blocks considerably faster than | // trigger. Should miners produce blocks considerably faster than | ||||
// target spacing but collude to fudge timestamps to stay above the 30 | // target spacing but collude to fudge timestamps to stay above the 30 | ||||
// minute window, ensure difficulty will rise to compensate anyway. | // minute window, ensure difficulty will rise to compensate anyway. | ||||
if (nHeight > 2016) { | if (nHeight > 2016) { | ||||
const CBlockIndex *p2016 = pindexPrev->GetAncestor(nHeight - 2017); | const CBlockIndex *p2016 = pindexPrev->GetAncestor(nHeight - 2017); | ||||
int64_t t = pindexPrev->GetBlockTime() - p2016->GetBlockTime(); | int64_t t = pindexPrev->GetBlockTime() - p2016->GetBlockTime(); | ||||
// If too fast, increase the target by 1/256. Std deviation over | // If too fast, decrease the target by 1/256. Std deviation over | ||||
// 2016 blocks is 2.2%. | // 2016 blocks is 2.2%. | ||||
if (t < params.nPowTargetSpacing * 2016 * 95 / 100) { | if (t < params.nPowTargetSpacing * 2016 * 95 / 100) { | ||||
nTarget -= (nTarget >> 8); | nTarget -= (nTarget >> 8); | ||||
} | } | ||||
} | } | ||||
// Determine the MTP difference - the difference between the MTP | // Determine the MTP difference - the difference between the MTP | ||||
// of the previous block, and the block 6 blocks earlier | // of the previous block, and the block 6 blocks earlier | ||||
const CBlockIndex *pindex6 = pindexPrev->GetAncestor(nHeight - 7); | const CBlockIndex *pindex6 = pindexPrev->GetAncestor(nHeight - 7); | ||||
assert(pindex6); | assert(pindex6); | ||||
int64_t mtp6blocks = | int64_t mtp6blocks = | ||||
pindexPrev->GetMedianTimePast() - pindex6->GetMedianTimePast(); | pindexPrev->GetMedianTimePast() - pindex6->GetMedianTimePast(); | ||||
// If too fast (< 30 mins), increase the target by 1/256. | // If too fast (< 30 mins), decrease the target by 1/256. | ||||
if (mtp6blocks < params.nPowTargetSpacing * 30 / 10) { | if (mtp6blocks < params.nPowTargetSpacing * 30 / 10) { | ||||
nTarget -= (nTarget >> 8); | nTarget -= (nTarget >> 8); | ||||
} | } | ||||
// If too slow (> 128 mins), decrease the target by 1/64. | // If too slow (> 128 mins), increase the target by 1/64. | ||||
else if (mtp6blocks > params.nPowTargetSpacing * 128 / 10) { | else if (mtp6blocks > params.nPowTargetSpacing * 128 / 10) { | ||||
nTarget += (nTarget >> 6); | nTarget += (nTarget >> 6); | ||||
} | } | ||||
nBits = nTarget.GetCompact(); | nBits = nTarget.GetCompact(); | ||||
// We can't go below the minimum target | // We can't go below the minimum target | ||||
return std::min(nBits, nProofOfWorkLimit); | return std::min(nBits, nProofOfWorkLimit); | ||||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |