miner: adjust clock to timewarp rule

This commit is contained in:
Sjors Provoost
2024-08-20 10:45:04 +02:00
parent e929054e12
commit 59ff17e5af
4 changed files with 24 additions and 15 deletions

View File

@@ -33,6 +33,14 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
int64_t nOldTime = pblock->nTime;
int64_t nNewTime{std::max<int64_t>(pindexPrev->GetMedianTimePast() + 1, TicksSinceEpoch<std::chrono::seconds>(NodeClock::now()))};
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);
}
}
if (nOldTime < nNewTime) {
pblock->nTime = nNewTime;
}