Skip to content

Commit

Permalink
ETH: Fix inaccurate default difficulty
Browse files Browse the repository at this point in the history
  • Loading branch information
SwimmingTiger committed Jan 5, 2022
1 parent c679c2d commit d97db31
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DownSessionETH.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (down *DownSessionETH) submitResponse(e EventSubmitResponse) {

func (down *DownSessionETH) setDifficulty(e EventSetDifficulty) {
if down.protocol == ProtocolEthereumStratum && down.jobDiff != e.Difficulty {
diff := float64(e.Difficulty) / float64(0xffffffff)
diff := float64(e.Difficulty) / 4294967296.0

var request JSONRPCRequest
request.Method = "mining.set_difficulty"
Expand Down
6 changes: 4 additions & 2 deletions UpSessionETH.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"math"
"net"
"strconv"
"time"
Expand Down Expand Up @@ -349,7 +348,10 @@ func (up *UpSessionETH) handleSetDifficulty(rpcData *JSONRPCLineETH, jsonBytes [
return
}
// nicehash_diff = btcpool_diff / pow(2, 32)
up.defaultDiff = uint64(math.Round(diff * 0xffffffff))
up.defaultDiff = uint64(diff * 4294967296.0)
if glog.V(5) {
glog.Info(up.id, "mining.set_difficulty: ", diff, " -> ", up.defaultDiff)
}

e := EventSetDifficulty{up.defaultDiff}
for _, down := range up.downSessions {
Expand Down

0 comments on commit d97db31

Please sign in to comment.