|
|
|
@ -54,7 +54,6 @@ type Session struct { |
|
|
|
login string |
|
|
|
login string |
|
|
|
worker string |
|
|
|
worker string |
|
|
|
stratum int |
|
|
|
stratum int |
|
|
|
subscriptionID string |
|
|
|
|
|
|
|
JobDeatils jobDetails |
|
|
|
JobDeatils jobDetails |
|
|
|
Extranonce string |
|
|
|
Extranonce string |
|
|
|
ExtranonceSub bool |
|
|
|
ExtranonceSub bool |
|
|
|
@ -73,7 +72,7 @@ type jobDetails struct { |
|
|
|
|
|
|
|
|
|
|
|
func NewProxy(cfg *Config, backend *storage.RedisClient) *ProxyServer { |
|
|
|
func NewProxy(cfg *Config, backend *storage.RedisClient) *ProxyServer { |
|
|
|
if len(cfg.Name) == 0 { |
|
|
|
if len(cfg.Name) == 0 { |
|
|
|
log.Fatal("You must set instance name") |
|
|
|
log.Fatal("You must set the instance name") |
|
|
|
} |
|
|
|
} |
|
|
|
policy := policy.Start(&cfg.Proxy.Policy, backend) |
|
|
|
policy := policy.Start(&cfg.Proxy.Policy, backend) |
|
|
|
|
|
|
|
|
|
|
|
@ -108,29 +107,19 @@ func NewProxy(cfg *Config, backend *storage.RedisClient) *ProxyServer { |
|
|
|
stateUpdateTimer := time.NewTimer(stateUpdateIntv) |
|
|
|
stateUpdateTimer := time.NewTimer(stateUpdateIntv) |
|
|
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
go func() { |
|
|
|
for { |
|
|
|
for range refreshTimer.C { |
|
|
|
select { |
|
|
|
|
|
|
|
case <-refreshTimer.C: |
|
|
|
|
|
|
|
proxy.fetchBlockTemplate() |
|
|
|
proxy.fetchBlockTemplate() |
|
|
|
refreshTimer.Reset(refreshIntv) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}() |
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
go func() { |
|
|
|
for { |
|
|
|
for range checkTimer.C { |
|
|
|
select { |
|
|
|
|
|
|
|
case <-checkTimer.C: |
|
|
|
|
|
|
|
proxy.checkUpstreams() |
|
|
|
proxy.checkUpstreams() |
|
|
|
checkTimer.Reset(checkIntv) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}() |
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
go func() { |
|
|
|
for { |
|
|
|
for range stateUpdateTimer.C { |
|
|
|
select { |
|
|
|
|
|
|
|
case <-stateUpdateTimer.C: |
|
|
|
|
|
|
|
t := proxy.currentBlockTemplate() |
|
|
|
t := proxy.currentBlockTemplate() |
|
|
|
if t != nil { |
|
|
|
if t != nil { |
|
|
|
rpc := proxy.rpc() |
|
|
|
rpc := proxy.rpc() |
|
|
|
@ -146,13 +135,13 @@ func NewProxy(cfg *Config, backend *storage.RedisClient) *ProxyServer { |
|
|
|
if n > 0 { |
|
|
|
if n > 0 { |
|
|
|
prevblock, err := rpc.GetBlockByHeight(prev) |
|
|
|
prevblock, err := rpc.GetBlockByHeight(prev) |
|
|
|
if err != nil || prevblock == nil { |
|
|
|
if err != nil || prevblock == nil { |
|
|
|
log.Fatalf("Error while retrieving block from node: %v", err) |
|
|
|
log.Fatalf("Error while retrieving block from the node: %v", err) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
prevtime, _ := strconv.ParseInt(strings.Replace(prevblock.Timestamp, "0x", "", -1), 16, 64) |
|
|
|
prevtime, _ := strconv.ParseInt(strings.Replace(prevblock.Timestamp, "0x", "", -1), 16, 64) |
|
|
|
blocktime := float64(timestamp-prevtime) / float64(n) |
|
|
|
blocktime := float64(timestamp-prevtime) / float64(n) |
|
|
|
err = backend.WriteNodeState(cfg.Name, t.Height, t.Difficulty, blocktime) |
|
|
|
err = backend.WriteNodeState(cfg.Name, t.Height, t.Difficulty, blocktime) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Printf("Failed to write node state to backend: %v", err) |
|
|
|
log.Printf("Failed to write node state to the backend: %v", err) |
|
|
|
proxy.markSick() |
|
|
|
proxy.markSick() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
proxy.markOk() |
|
|
|
proxy.markOk() |
|
|
|
@ -162,8 +151,6 @@ func NewProxy(cfg *Config, backend *storage.RedisClient) *ProxyServer { |
|
|
|
proxy.markSick() |
|
|
|
proxy.markSick() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
stateUpdateTimer.Reset(stateUpdateIntv) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}() |
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
|