@@ -107,6 +107,21 @@ const std::vector<std::string> CHECKLEVEL_DOC {
107
107
* */
108
108
static constexpr int PRUNE_LOCK_BUFFER{10 };
109
109
110
+ /* *
111
+ * Maximum number of seconds that the timestamp of the first
112
+ * block of a difficulty adjustment period is allowed to
113
+ * be earlier than the last block of the previous period (BIP94).
114
+ */
115
+ static constexpr int64_t MAX_TIMEWARP{MAX_FUTURE_BLOCK_TIME};
116
+
117
+ /* *
118
+ * If the timestamp of the last block in a difficulty period is set
119
+ * MAX_FUTURE_BLOCK_TIME seconds in the future, an honest miner should
120
+ * be able to mine the first block using the current time. This is not
121
+ * a consensus rule, but changing MAX_TIMEWARP should be done with caution.
122
+ */
123
+ static_assert (MAX_FUTURE_BLOCK_TIME <= MAX_TIMEWARP);
124
+
110
125
GlobalMutex g_best_block_mutex;
111
126
std::condition_variable g_best_block_cv;
112
127
uint256 g_best_block;
@@ -4188,7 +4203,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
4188
4203
// Check timestamp for the first block of each difficulty adjustment
4189
4204
// interval, except the genesis block.
4190
4205
if (nHeight % consensusParams.DifficultyAdjustmentInterval () == 0 ) {
4191
- if (block.GetBlockTime () < pindexPrev->GetBlockTime () - 60 * 60 * 2 ) {
4206
+ if (block.GetBlockTime () < pindexPrev->GetBlockTime () - MAX_TIMEWARP ) {
4192
4207
return state.Invalid (BlockValidationResult::BLOCK_INVALID_HEADER, " time-timewarp-attack" , " block's timestamp is too early on diff adjustment block" );
4193
4208
}
4194
4209
}
0 commit comments