From 457d392f80c7e60bb9ce655876da612f0dca8a77 Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Tue, 19 Mar 2024 00:12:30 +0100 Subject: [PATCH] update --- proxy/handlers.go | 61 +++++++++++++++++------------------------------ proxy/proto.go | 1 + proxy/stratum.go | 8 +++++-- 3 files changed, 29 insertions(+), 41 deletions(-) diff --git a/proxy/handlers.go b/proxy/handlers.go index 7efc91f..0318419 100644 --- a/proxy/handlers.go +++ b/proxy/handlers.go @@ -110,51 +110,34 @@ func (s *ProxyServer) handleSubmitRPC(cs *Session, login, id string, params []st return false, &ErrorReply{Code: -1, Message: "Malformed PoW result"} } - // Process the share in a separate goroutine - go func(s *ProxyServer, cs *Session, login, id string, params []string) { - // Get the current block template - t := s.currentBlockTemplate() - - // Check if the share already exists and if it's valid - exist, validShare := s.processShare(login, id, cs.ip, t, params, stratumMode != EthProxy) - - // Apply the share policy to determine if the share should be accepted - ok := s.policy.ApplySharePolicy(cs.ip, !exist && validShare) - - // Handle duplicate share - if exist { - log.Printf("Duplicate share from %s@%s %v", login, cs.ip, params) - if !ok { - cs.disconnect() - return - } - return - } - - // Handle invalid share - if !validShare { - log.Printf("Invalid share from %s@%s", login, cs.ip) - s.backend.WriteWorkerShareStatus(login, id, false, true, false) - // Bad shares limit reached, disconnect the session - if !ok { - cs.disconnect() - return - } - return - } + t := s.currentBlockTemplate() + exist, validShare := s.processShare(login, id, cs.ip, t, params, stratumMode != EthProxy) + ok := s.policy.ApplySharePolicy(cs.ip, !exist && validShare) - // Handle valid share - if s.config.Proxy.Debug { - log.Printf("Valid share from %s@%s", login, cs.ip) + if exist { + log.Printf("Duplicate share from %s@%s %v", login, cs.ip, params) + // see https://github.com/sammy007/open-ethereum-pool/compare/master...nicehashdev:patch-1 + if !ok { + return false, &ErrorReply{Code: 23, Message: "Invalid share"} } + return false, nil + } - // Apply the policy to determine if the session should be disconnected + if !validShare { + log.Printf("Invalid share from %s@%s", login, cs.ip) + // Bad shares limit reached, return error and close if !ok { - cs.disconnect() - return + return false, &ErrorReply{Code: 23, Message: "Invalid share"} } - }(s, cs, login, id, params) + return false, nil + } + if s.config.Proxy.Debug { + log.Printf("Valid share from %s@%s", login, cs.ip) + } + if !ok { + return true, &ErrorReply{Code: -1, Message: "High rate of invalid shares"} + } return true, nil } diff --git a/proxy/proto.go b/proxy/proto.go index ec84b7e..25d38a9 100644 --- a/proxy/proto.go +++ b/proxy/proto.go @@ -12,6 +12,7 @@ type JSONStratumReq struct { Id interface{} `json:"id"` Method string `json:"method"` Params interface{} `json:"params"` + Height string `json:"height"` } type StratumReq struct { diff --git a/proxy/stratum.go b/proxy/stratum.go index 963babe..a0f97f8 100644 --- a/proxy/stratum.go +++ b/proxy/stratum.go @@ -420,7 +420,7 @@ func (cs *Session) pushNewJob(s *ProxyServer, result interface{}) error { cs.JobDetails.SeedHash = cs.JobDetails.SeedHash[2:] cs.JobDetails.HeaderHash = cs.JobDetails.HeaderHash[2:] } - + a := s.currentBlockTemplate() resp := JSONStratumReq{ Method: "mining.notify", Params: []interface{}{ @@ -437,6 +437,8 @@ func (cs *Session) pushNewJob(s *ProxyServer, result interface{}) error { // It's undetermined what's more cost-effective false, }, + + Height: util.ToHex1(int64(a.Height)), } return cs.enc.Encode(&resp) } @@ -523,7 +525,7 @@ func (cs *Session) sendJob(s *ProxyServer, id json.RawMessage, newjob bool) erro cs.JobDetails.HeaderHash = cs.JobDetails.HeaderHash[2:] } } - + t := s.currentBlockTemplate() resp := JSONStratumReq{ Method: "mining.notify", Params: []interface{}{ @@ -532,6 +534,8 @@ func (cs *Session) sendJob(s *ProxyServer, id json.RawMessage, newjob bool) erro cs.JobDetails.HeaderHash, true, }, + + Height: util.ToHex1(int64(t.Height)), } return cs.sendTCPReq(resp)