diff --git a/api.json b/api.json index 23aac9f..2cbb17e 100644 --- a/api.json +++ b/api.json @@ -15,7 +15,7 @@ "behindReverseProxy": false, "blockRefreshInterval": "120ms", "stateUpdateInterval": "3s", - "difficulty": 2000000000, + "difficulty": 8589934592, "hashrateExpiration": "3h", "healthCheck": true, diff --git a/proxy/stratum.go b/proxy/stratum.go index bc7366f..7050cd5 100644 --- a/proxy/stratum.go +++ b/proxy/stratum.go @@ -198,11 +198,6 @@ func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { return err } - if params[1] != "EthereumStratum/1.0.0" { - log.Println("Unsupported stratum version from", cs.ip) - return cs.sendStratumError(req.Id, "unsupported stratum version") - } - cs.ExtranonceSub = true cs.setStratumMode("EthereumStratum/1.0.0") log.Println("Nicehash subscribe", cs.ip) diff --git a/util/util.go b/util/util.go index fd5a11c..1fa154e 100644 --- a/util/util.go +++ b/util/util.go @@ -1,6 +1,7 @@ package util import ( + "encoding/hex" "math/big" "regexp" "strconv" @@ -18,6 +19,14 @@ var pow256 = math.BigPow(2, 256) var addressPattern = regexp.MustCompile("^0x[0-9a-fA-F]{40}$") var zeroHash = regexp.MustCompile("^0?x?0+$") +var Diff1 = StringToBig("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") + +func StringToBig(h string) *big.Int { + n := new(big.Int) + n.SetString(h, 0) + return n +} + func IsValidHexAddress(s string) bool { if IsZeroHash(s) || !addressPattern.MatchString(s) { return false @@ -35,8 +44,13 @@ func MakeTimestamp() int64 { func GetTargetHex(diff int64) string { difficulty := big.NewInt(diff) - diff1 := new(big.Int).Div(pow256, difficulty) - return string(hexutil.Encode(diff1.Bytes())) + diff1 := new(big.Int).Div(Diff1, difficulty) + targetBytes := diff1.Bytes() + if len(targetBytes) < 32 { + padding := make([]byte, 32-len(targetBytes)) + targetBytes = append(padding, targetBytes...) + } + return "0x" + hex.EncodeToString(targetBytes) } func TargetHexToDiff(targetHex string) *big.Int {