Fix underflow

This commit is contained in:
Vurich 2017-07-03 16:49:06 +02:00
parent cc718bb108
commit 2e90e02a2c
1 changed files with 10 additions and 4 deletions

View File

@ -453,11 +453,14 @@ impl Ethash {
let parent_has_uncles = parent.uncles_hash() != &sha3::SHA3_EMPTY_LIST_RLP;
let min_difficulty = self.ethash_params.minimum_difficulty;
let difficulty_hardfork = header.number() >= self.ethash_params.difficulty_hardfork_transition;
let difficulty_bound_divisor = match difficulty_hardfork {
true => self.ethash_params.difficulty_hardfork_bound_divisor,
false => self.ethash_params.difficulty_bound_divisor,
let difficulty_bound_divisor = if difficulty_hardfork {
self.ethash_params.difficulty_hardfork_bound_divisor
} else {
self.ethash_params.difficulty_bound_divisor
};
let duration_limit = self.ethash_params.duration_limit;
let frontier_limit = self.ethash_params.homestead_transition;
@ -483,7 +486,10 @@ impl Ethash {
if diff_inc <= threshold {
*parent.difficulty() + *parent.difficulty() / difficulty_bound_divisor * (threshold - diff_inc).into()
} else {
*parent.difficulty() - *parent.difficulty() / difficulty_bound_divisor * min(diff_inc - threshold, 99).into()
let multiplier = min(diff_inc - threshold, 99).into();
parent.difficulty().saturating_sub(
*parent.difficulty() / difficulty_bound_divisor * multiplier
)
}
};
target = max(min_difficulty, target);