|
|
|
|
@ -175,6 +175,7 @@ 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, |
|
|
|
|
@ -361,3 +362,73 @@ 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() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|