Browse Source

formatHashrate miner.go

master
yuriy0803 2 years ago committed by GitHub
parent
commit
bc3cf91578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      proxy/miner.go

16
proxy/miner.go

@ -85,7 +85,8 @@ func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, param
} }
if s.config.Proxy.Debug { if s.config.Proxy.Debug {
log.Printf("Difficulty pool/block/share = %d / %d / %d(%f) from %v@%v", shareDiff, t.Difficulty, shareDiffCalc, shareDiffFloat, login, ip) hashrate := formatHashrate(shareDiffCalc)
log.Printf("Difficulty pool/block/share = %d / %d / %d(%s) from %v@%v", shareDiff, t.Difficulty, shareDiffCalc, hashrate, login, ip)
} }
h, ok := t.headers[hashNoNonce] h, ok := t.headers[hashNoNonce]
@ -134,3 +135,16 @@ func (s *ProxyServer) processShare(login, id, ip string, t *BlockTemplate, param
s.backend.WriteWorkerShareStatus(login, id, true, false, false) s.backend.WriteWorkerShareStatus(login, id, true, false, false)
return false, true return false, true
} }
func formatHashrate(shareDiffCalc int64) string {
units := []string{"H/s", "KH/s", "MH/s", "GH/s", "TH/s", "PH/s"}
var i int
diff := float64(shareDiffCalc)
for i = 0; i < len(units)-1 && diff >= 1000.0; i++ {
diff /= 1000.0
}
formatted := strconv.FormatFloat(diff, 'f', 2, 64)
return formatted + " " + units[i]
}

Loading…
Cancel
Save