@@ -107,6 +107,21 @@ const std::vector<std::string> CHECKLEVEL_DOC {
107107 * */
108108static constexpr int PRUNE_LOCK_BUFFER{10 };
109109
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+
110125GlobalMutex g_best_block_mutex;
111126std::condition_variable g_best_block_cv;
112127uint256 g_best_block;
@@ -4188,7 +4203,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
41884203 // Check timestamp for the first block of each difficulty adjustment
41894204 // interval, except the genesis block.
41904205 if (nHeight % consensusParams.DifficultyAdjustmentInterval () == 0 ) {
4191- if (block.GetBlockTime () < pindexPrev->GetBlockTime () - 60 * 60 * 2 ) {
4206+ if (block.GetBlockTime () < pindexPrev->GetBlockTime () - MAX_TIMEWARP ) {
41924207 return state.Invalid (BlockValidationResult::BLOCK_INVALID_HEADER, " time-timewarp-attack" , " block's timestamp is too early on diff adjustment block" );
41934208 }
41944209 }
0 commit comments