diff --git a/consensus/update.go b/consensus/update.go index 6b5a9c3a..86fc0c1f 100644 --- a/consensus/update.go +++ b/consensus/update.go @@ -228,10 +228,10 @@ func adjustTarget(s State, blockTimestamp time.Time, targetTimestamp time.Time) shift *= 10 shift /= 10000 * 10000 targetBlockTime := blockInterval + shift - if min := blockInterval / 3; targetBlockTime < min { - targetBlockTime = min - } else if max := blockInterval * 3; targetBlockTime > max { - targetBlockTime = max + if minTime := blockInterval / 3; targetBlockTime < minTime { + targetBlockTime = minTime + } else if maxTime := blockInterval * 3; targetBlockTime > maxTime { + targetBlockTime = maxTime } if oakTotalTime <= 0 { oakTotalTime = 1 @@ -249,12 +249,12 @@ func adjustTarget(s State, blockTimestamp time.Time, targetTimestamp time.Time) if s.childHeight() == s.Network.HardforkASIC.Height { return newTarget } - min := mulTargetFrac(s.ChildTarget, 1004, 1000) - max := mulTargetFrac(s.ChildTarget, 1000, 1004) - if newTarget.CmpWork(min) < 0 { - newTarget = min - } else if newTarget.CmpWork(max) > 0 { - newTarget = max + minTarget := mulTargetFrac(s.ChildTarget, 1004, 1000) + maxTarget := mulTargetFrac(s.ChildTarget, 1000, 1004) + if newTarget.CmpWork(minTarget) < 0 { + newTarget = minTarget + } else if newTarget.CmpWork(maxTarget) > 0 { + newTarget = maxTarget } return newTarget } @@ -280,10 +280,10 @@ func adjustDifficulty(s State, blockTimestamp time.Time, targetTimestamp time.Ti // calculate the new target block time, clamped to a factor of 3 targetBlockTime := s.BlockInterval() + shift - if min := s.BlockInterval() / 3; targetBlockTime < min { - targetBlockTime = min - } else if max := s.BlockInterval() * 3; targetBlockTime > max { - targetBlockTime = max + if minTime := s.BlockInterval() / 3; targetBlockTime < minTime { + targetBlockTime = minTime + } else if maxTime := s.BlockInterval() * 3; targetBlockTime > maxTime { + targetBlockTime = maxTime } // estimate current hashrate @@ -301,10 +301,10 @@ func adjustDifficulty(s State, blockTimestamp time.Time, targetTimestamp time.Ti // clamp the adjustment to 0.4% maxAdjust := s.Difficulty.div64(250) - if min := s.Difficulty.sub(maxAdjust); newDifficulty.Cmp(min) < 0 { - newDifficulty = min - } else if max := s.Difficulty.add(maxAdjust); newDifficulty.Cmp(max) > 0 { - newDifficulty = max + if minDifficulty := s.Difficulty.sub(maxAdjust); newDifficulty.Cmp(minDifficulty) < 0 { + newDifficulty = minDifficulty + } else if maxDifficulty := s.Difficulty.add(maxAdjust); newDifficulty.Cmp(maxDifficulty) > 0 { + newDifficulty = maxDifficulty } return newDifficulty, invTarget(newDifficulty.n) } diff --git a/go.mod b/go.mod index f9cb3428..c5cb82af 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.20 require ( go.sia.tech/mux v1.2.0 - golang.org/x/crypto v0.22.0 - golang.org/x/sys v0.19.0 + golang.org/x/crypto v0.23.0 + golang.org/x/sys v0.20.0 lukechampine.com/frand v1.4.2 ) diff --git a/go.sum b/go.sum index c59e6d20..ecfaf43a 100644 --- a/go.sum +++ b/go.sum @@ -2,10 +2,10 @@ github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmH github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA= go.sia.tech/mux v1.2.0 h1:ofa1Us9mdymBbGMY2XH/lSpY8itFsKIo/Aq8zwe+GHU= go.sia.tech/mux v1.2.0/go.mod h1:Yyo6wZelOYTyvrHmJZ6aQfRoer3o4xyKQ4NmQLJrBSo= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= lukechampine.com/frand v1.4.2 h1:RzFIpOvkMXuPMBb9maa4ND4wjBn71E1Jpf8BzJHMaVw= lukechampine.com/frand v1.4.2/go.mod h1:4S/TM2ZgrKejMcKMbeLjISpJMO+/eZ1zu3vYX9dtj3s= diff --git a/rhp/v2/merkle.go b/rhp/v2/merkle.go index bfdbc46c..b7707f0b 100644 --- a/rhp/v2/merkle.go +++ b/rhp/v2/merkle.go @@ -244,9 +244,9 @@ func RangeProofSize(n, start, end uint64) uint64 { // not overlap end. func nextSubtreeSize(start, end uint64) uint64 { ideal := bits.TrailingZeros64(start) - max := bits.Len64(end-start) - 1 - if ideal > max { - return 1 << max + maxSize := bits.Len64(end-start) - 1 + if ideal > maxSize { + return 1 << maxSize } return 1 << ideal }