Browse Source

update

master
yuriy0803 2 years ago
parent
commit
457d392f80
  1. 31
      proxy/handlers.go
  2. 1
      proxy/proto.go
  3. 8
      proxy/stratum.go

31
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"} 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() 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) 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) ok := s.policy.ApplySharePolicy(cs.ip, !exist && validShare)
// Handle duplicate share
if exist { if exist {
log.Printf("Duplicate share from %s@%s %v", login, cs.ip, params) 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 { if !ok {
cs.disconnect() return false, &ErrorReply{Code: 23, Message: "Invalid share"}
return
} }
return return false, nil
} }
// Handle invalid share
if !validShare { if !validShare {
log.Printf("Invalid share from %s@%s", login, cs.ip) log.Printf("Invalid share from %s@%s", login, cs.ip)
s.backend.WriteWorkerShareStatus(login, id, false, true, false) // Bad shares limit reached, return error and close
// Bad shares limit reached, disconnect the session
if !ok { if !ok {
cs.disconnect() return false, &ErrorReply{Code: 23, Message: "Invalid share"}
return
} }
return return false, nil
} }
// Handle valid share
if s.config.Proxy.Debug { if s.config.Proxy.Debug {
log.Printf("Valid share from %s@%s", login, cs.ip) log.Printf("Valid share from %s@%s", login, cs.ip)
} }
// Apply the policy to determine if the session should be disconnected
if !ok { if !ok {
cs.disconnect() return true, &ErrorReply{Code: -1, Message: "High rate of invalid shares"}
return
} }
}(s, cs, login, id, params)
return true, nil return true, nil
} }

1
proxy/proto.go

@ -12,6 +12,7 @@ type JSONStratumReq struct {
Id interface{} `json:"id"` Id interface{} `json:"id"`
Method string `json:"method"` Method string `json:"method"`
Params interface{} `json:"params"` Params interface{} `json:"params"`
Height string `json:"height"`
} }
type StratumReq struct { type StratumReq struct {

8
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.SeedHash = cs.JobDetails.SeedHash[2:]
cs.JobDetails.HeaderHash = cs.JobDetails.HeaderHash[2:] cs.JobDetails.HeaderHash = cs.JobDetails.HeaderHash[2:]
} }
a := s.currentBlockTemplate()
resp := JSONStratumReq{ resp := JSONStratumReq{
Method: "mining.notify", Method: "mining.notify",
Params: []interface{}{ Params: []interface{}{
@ -437,6 +437,8 @@ func (cs *Session) pushNewJob(s *ProxyServer, result interface{}) error {
// It's undetermined what's more cost-effective // It's undetermined what's more cost-effective
false, false,
}, },
Height: util.ToHex1(int64(a.Height)),
} }
return cs.enc.Encode(&resp) 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:] cs.JobDetails.HeaderHash = cs.JobDetails.HeaderHash[2:]
} }
} }
t := s.currentBlockTemplate()
resp := JSONStratumReq{ resp := JSONStratumReq{
Method: "mining.notify", Method: "mining.notify",
Params: []interface{}{ Params: []interface{}{
@ -532,6 +534,8 @@ func (cs *Session) sendJob(s *ProxyServer, id json.RawMessage, newjob bool) erro
cs.JobDetails.HeaderHash, cs.JobDetails.HeaderHash,
true, true,
}, },
Height: util.ToHex1(int64(t.Height)),
} }
return cs.sendTCPReq(resp) return cs.sendTCPReq(resp)

Loading…
Cancel
Save