Skip to content

Commit 92c1d7d

Browse files
committed
validation: Use MAX_TIMEWARP constant as testnet4 timewarp defense delta
The value is equal to MAX_FUTURE_BLOCK_TIME.
1 parent 4b2fad5 commit 92c1d7d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/validation.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ const std::vector<std::string> CHECKLEVEL_DOC {
107107
* */
108108
static 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+
110125
GlobalMutex g_best_block_mutex;
111126
std::condition_variable g_best_block_cv;
112127
uint256 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

Comments
 (0)