MCPcopy Create free account
hub / github.com/ethstorage/es-node / expectedDiff

Function expectedDiff

ethstorage/miner/algorithm.go:43–70  ·  view source on GitHub ↗
(interval uint64, difficulty, cutoff, diffAdjDivisor, minDiff *big.Int)

Source from the content-addressed store, hash-verified

41}
42
43func 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}

Callers 2

Test_expectedDiffFunction · 0.85
updateDifficultyMethod · 0.85

Calls 1

SetMethod · 0.80

Tested by 1

Test_expectedDiffFunction · 0.68