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 28
28
#include < utility>
29
29
30
30
namespace 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 ()))};
35
31
32
+ int64_t GetMinimumTime (const CBlockIndex* pindexPrev, const int64_t difficulty_adjustment_interval)
33
+ {
34
+ int64_t min_time{pindexPrev->GetMedianTimePast () + 1 };
36
35
// Height of block to be mined.
37
36
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);
40
41
}
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 ()))};
41
50
42
51
if (nOldTime < nNewTime) {
43
52
pblock->nTime = nNewTime;
Original file line number Diff line number Diff line change @@ -211,6 +211,13 @@ class BlockAssembler
211
211
void SortForBlock (const CTxMemPool::setEntries& package, std::vector<CTxMemPool::txiter>& sortedEntries);
212
212
};
213
213
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
+
214
221
int64_t UpdateTime (CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
215
222
216
223
/* * Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed */
You can’t perform that action at this time.
0 commit comments