validation: Use MAX_TIMEWARP constant as testnet4 timewarp defense delta
The value is equal to MAX_FUTURE_BLOCK_TIME.
This commit is contained in:
1 file changed
+16
-1
+16
-1
@@ -107,6 +107,21 @@ const std::vector<std::string> CHECKLEVEL_DOC {
|
|||||||
* */
|
* */
|
||||||
static constexpr int PRUNE_LOCK_BUFFER{10};
|
static constexpr int PRUNE_LOCK_BUFFER{10};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum number of seconds that the timestamp of the first
|
||||||
|
* block of a difficulty adjustment period is allowed to
|
||||||
|
* be earlier than the last block of the previous period (BIP94).
|
||||||
|
*/
|
||||||
|
static constexpr int64_t MAX_TIMEWARP{MAX_FUTURE_BLOCK_TIME};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the timestamp of the last block in a difficulty period is set
|
||||||
|
* MAX_FUTURE_BLOCK_TIME seconds in the future, an honest miner should
|
||||||
|
* be able to mine the first block using the current time. This is not
|
||||||
|
* a consensus rule, but changing MAX_TIMEWARP should be done with caution.
|
||||||
|
*/
|
||||||
|
static_assert(MAX_FUTURE_BLOCK_TIME <= MAX_TIMEWARP);
|
||||||
|
|
||||||
GlobalMutex g_best_block_mutex;
|
GlobalMutex g_best_block_mutex;
|
||||||
std::condition_variable g_best_block_cv;
|
std::condition_variable g_best_block_cv;
|
||||||
uint256 g_best_block;
|
uint256 g_best_block;
|
||||||
@@ -4188,7 +4203,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
|
|||||||
// Check timestamp for the first block of each difficulty adjustment
|
// Check timestamp for the first block of each difficulty adjustment
|
||||||
// interval, except the genesis block.
|
// interval, except the genesis block.
|
||||||
if (nHeight % consensusParams.DifficultyAdjustmentInterval() == 0) {
|
if (nHeight % consensusParams.DifficultyAdjustmentInterval() == 0) {
|
||||||
if (block.GetBlockTime() < pindexPrev->GetBlockTime() - 60 * 60 * 2) {
|
if (block.GetBlockTime() < pindexPrev->GetBlockTime() - MAX_TIMEWARP) {
|
||||||
return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "time-timewarp-attack", "block's timestamp is too early on diff adjustment block");
|
return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "time-timewarp-attack", "block's timestamp is too early on diff adjustment block");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user