Browse Source

update

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

61
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
}

1
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 {

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.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)

Loading…
Cancel
Save