Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy0803 committed Mar 18, 2024
1 parent d35ccca commit 457d392
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 41 deletions.
61 changes: 22 additions & 39 deletions proxy/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions proxy/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions proxy/stratum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand All @@ -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)
}
Expand Down Expand Up @@ -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{}{
Expand All @@ -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)
Expand Down

0 comments on commit 457d392

Please sign in to comment.