Skip to content

Commit 43c8ee9

Browse files
committed
test: Adjust difficulty value if below minimal difficulty (0x20000)
1 parent 1580602 commit 43c8ee9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

test/state/ethash_difficulty.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ int64_t get_bomb_delay(evmc_revision rev) noexcept
3232
int64_t calculate_difficulty_pre_byzantium(int64_t parent_difficulty, int64_t parent_timestamp,
3333
int64_t current_timestamp, int64_t block_number, evmc_revision rev)
3434
{
35+
static constexpr auto MIN_DIFFICULTY = int64_t{0x20000};
36+
3537
// According to https://eips.ethereum.org/EIPS/eip-2
3638
const auto period_count = block_number / 100'000;
3739
const auto offset = parent_difficulty / 2048;
@@ -48,7 +50,8 @@ int64_t calculate_difficulty_pre_byzantium(int64_t parent_difficulty, int64_t pa
4850
else if (period_count == 2)
4951
diff += 1;
5052

51-
return diff;
53+
// Adjust if below min difficulty `0x20000`
54+
return std::max(MIN_DIFFICULTY, diff);
5255
}
5356

5457
} // namespace

0 commit comments

Comments
 (0)