File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 2828#include < utility>
2929
3030namespace node {
31- int64_t UpdateTime (CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
32- {
33- int64_t nOldTime = pblock->nTime ;
34- int64_t nNewTime{std::max<int64_t >(pindexPrev->GetMedianTimePast () + 1 , TicksSinceEpoch<std::chrono::seconds>(NodeClock::now ()))};
3531
32+ int64_t GetMinimumTime (const CBlockIndex* pindexPrev, const int64_t difficulty_adjustment_interval)
33+ {
34+ int64_t min_time{pindexPrev->GetMedianTimePast () + 1 };
3635 // Height of block to be mined.
3736 const int height{pindexPrev->nHeight + 1 };
38- if (height % consensusParams.DifficultyAdjustmentInterval () == 0 ) {
39- nNewTime = std::max<int64_t >(nNewTime, pindexPrev->GetBlockTime () - MAX_TIMEWARP);
37+ // Account for BIP94 timewarp rule on all networks. This makes future
38+ // activation safer.
39+ if (height % difficulty_adjustment_interval == 0 ) {
40+ min_time = std::max<int64_t >(min_time, pindexPrev->GetBlockTime () - MAX_TIMEWARP);
4041 }
42+ return min_time;
43+ }
44+
45+ int64_t UpdateTime (CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
46+ {
47+ int64_t nOldTime = pblock->nTime ;
48+ int64_t nNewTime{std::max<int64_t >(GetMinimumTime (pindexPrev, consensusParams.DifficultyAdjustmentInterval ()),
49+ TicksSinceEpoch<std::chrono::seconds>(NodeClock::now ()))};
4150
4251 if (nOldTime < nNewTime) {
4352 pblock->nTime = nNewTime;
Original file line number Diff line number Diff line change @@ -211,6 +211,13 @@ class BlockAssembler
211211 void SortForBlock (const CTxMemPool::setEntries& package, std::vector<CTxMemPool::txiter>& sortedEntries);
212212};
213213
214+ /* *
215+ * Get the minimum time a miner should use in the next block. This always
216+ * accounts for the BIP94 timewarp rule, so does not necessarily reflect the
217+ * consensus limit.
218+ */
219+ int64_t GetMinimumTime (const CBlockIndex* pindexPrev, const int64_t difficulty_adjustment_interval);
220+
214221int64_t UpdateTime (CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
215222
216223/* * Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */
You can’t perform that action at this time.
0 commit comments