miner: Enforce murch-zawy rule (BIP54)

This commit is contained in:
Fabian Jahr
2026-08-03 01:02:10 +02:00
parent 8a4bab8e97
commit e014e5bb61
2 changed files with 44 additions and 0 deletions

View File

@@ -64,6 +64,13 @@ int64_t GetMinimumTime(const CBlockIndex* pindexPrev, const int64_t difficulty_a
if (height % difficulty_adjustment_interval == 0) {
min_time = std::max<int64_t>(min_time, pindexPrev->GetBlockTime() - MAX_TIMEWARP);
}
// Account for the BIP54 Murch-Zawy rule on all networks: the last block of
// a difficulty adjustment period may not be earlier than its first block.
if (height % difficulty_adjustment_interval == difficulty_adjustment_interval - 1) {
const int first_height{height - static_cast<int>(difficulty_adjustment_interval) + 1};
const CBlockIndex* first_block{Assert(pindexPrev->GetAncestor(first_height))};
min_time = std::max<int64_t>(min_time, first_block->GetBlockTime());
}
return min_time;
}