| 41 | } |
| 42 | |
| 43 | func expectedDiff(interval uint64, difficulty, cutoff, diffAdjDivisor, minDiff *big.Int) *big.Int { |
| 44 | diff := new(big.Int).Set(difficulty) |
| 45 | x := interval / cutoff.Uint64() |
| 46 | if x == 0 { |
| 47 | // diff = diff + ((1 - interval / _cutoff) * diff) / _diffAdjDivisor; |
| 48 | adjust := new(big.Int).Div(diff, diffAdjDivisor) |
| 49 | diff = new(big.Int).Add(diff, adjust) |
| 50 | if diff.Cmp(minDiff) < 0 { |
| 51 | diff = minDiff |
| 52 | } |
| 53 | } else { |
| 54 | // diff = diff - ((interval / _cutoff - 1) * diff) / _diffAdjDivisor; |
| 55 | adjust := new(big.Int).Div( |
| 56 | new(big.Int).Mul( |
| 57 | new(big.Int).SetUint64(x-1), |
| 58 | diff, |
| 59 | ), |
| 60 | diffAdjDivisor, |
| 61 | ) |
| 62 | if new(big.Int).Add(adjust, minDiff).Cmp(diff) > 0 { |
| 63 | diff = minDiff |
| 64 | } else { |
| 65 | diff = new(big.Int).Sub(diff, adjust) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return diff |
| 70 | } |