Browse Source

update

master
yuriy0803 2 years ago
parent
commit
4cbb8f0d08
  1. 11
      proxy/blocks.go
  2. 71
      proxy/proxy.go

11
proxy/blocks.go

@ -12,7 +12,7 @@ import (
"github.com/yuriy0803/open-etc-pool-friends/util"
)
const maxBacklog = 10
const maxBacklog = 3
type heightDiffPair struct {
diff *big.Int
@ -59,13 +59,8 @@ func (s *ProxyServer) fetchBlockTemplate() {
return
}
// No need to update, we have fresh job
if t != nil {
if t.Header == reply[0] {
return
}
if _, ok := t.headers[reply[0]]; ok {
return
}
if t != nil && t.Header == reply[0] {
return
}
pendingReply.Difficulty = util.ToHex(s.config.Proxy.Difficulty)

71
proxy/proxy.go

@ -175,7 +175,6 @@ func (s *ProxyServer) Start() {
r := mux.NewRouter()
r.Handle("/{login:0x[0-9a-fA-F]{40}}/{id:[0-9a-zA-Z-_]{1,200}}", s)
r.Handle("/{login:0x[0-9a-fA-F]{40}}", s)
r.HandleFunc("/etc", s.MiningNotify)
srv := &http.Server{
Addr: s.config.Proxy.Listen,
Handler: r,
@ -362,73 +361,3 @@ func (s *ProxyServer) isSick() bool {
func (s *ProxyServer) markOk() {
atomic.StoreInt64(&s.failsCount, 0)
}
func (s *ProxyServer) MiningNotify(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "405 method not allowed.", http.StatusMethodNotAllowed)
return
}
body := make([]byte, r.ContentLength)
r.Body.Read(body)
var reply []string
err := json.Unmarshal(body, &reply)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
w.WriteHeader(http.StatusOK)
t := s.currentBlockTemplate()
// No need to update, we have fresh job
if t != nil {
if t.Header == reply[0] {
return
}
if _, ok := t.headers[reply[0]]; ok {
return
}
}
diff := util.TargetHexToDiff(reply[2])
height, err := strconv.ParseUint(strings.Replace(reply[3], "0x", "", -1), 16, 64)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
pendingReply := &rpc.GetBlockReplyPart{
Difficulty: util.ToHex(s.config.Proxy.Difficulty),
Number: reply[3],
}
newTemplate := BlockTemplate{
Header: reply[0],
Seed: reply[1],
Target: reply[2],
Height: height,
Difficulty: diff,
GetPendingBlockCache: pendingReply,
headers: make(map[string]heightDiffPair),
}
// Copy job backlog and add current one
newTemplate.headers[reply[0]] = heightDiffPair{
diff: diff,
height: height,
}
if t != nil {
for k, v := range t.headers {
if v.height > height-maxBacklog {
newTemplate.headers[k] = v
}
}
}
s.blockTemplate.Store(&newTemplate)
log.Printf("New block notified at height %d / %s / %d", height, reply[0][0:10], diff)
// Stratum
if s.config.Proxy.Stratum.Enabled {
go s.broadcastNewJobs()
}
}

Loading…
Cancel
Save