From 4cbb8f0d08115a01d2db95cd07481f21923b98e8 Mon Sep 17 00:00:00 2001 From: yuriy0803 <68668177+yuriy0803@users.noreply.github.com> Date: Sun, 29 Oct 2023 13:21:26 +0100 Subject: [PATCH] update --- proxy/blocks.go | 11 +++----- proxy/proxy.go | 71 ------------------------------------------------- 2 files changed, 3 insertions(+), 79 deletions(-) diff --git a/proxy/blocks.go b/proxy/blocks.go index 13b429f..e417110 100644 --- a/proxy/blocks.go +++ b/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) diff --git a/proxy/proxy.go b/proxy/proxy.go index 4849ad3..e1ef082 100644 --- a/proxy/proxy.go +++ b/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() - } -}