fix(proxy): reject configs without enabled pools
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
5d8d82b9b5
commit
8a52856719
5 changed files with 27 additions and 0 deletions
|
|
@ -21,6 +21,8 @@ type RouteRegistrar interface {
|
|||
|
||||
// mux := http.NewServeMux()
|
||||
// api.RegisterRoutes(mux, p)
|
||||
// _ = mux
|
||||
//
|
||||
// The mounted routes are GET /1/summary, /1/workers, and /1/miners.
|
||||
func RegisterRoutes(router RouteRegistrar, p *proxy.Proxy) {
|
||||
if router == nil || p == nil {
|
||||
|
|
|
|||
|
|
@ -39,3 +39,19 @@ func TestConfig_Validate_Ugly(t *testing.T) {
|
|||
t.Fatalf("expected invalid workers and empty pool url to fail validation")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfig_Validate_NoEnabledPool_Ugly(t *testing.T) {
|
||||
cfg := &Config{
|
||||
Mode: "simple",
|
||||
Workers: WorkersByRigID,
|
||||
Bind: []BindAddr{{Host: "0.0.0.0", Port: 3333}},
|
||||
Pools: []PoolConfig{
|
||||
{URL: "pool-a.example:3333", Enabled: false},
|
||||
{URL: "pool-b.example:4444", Enabled: false},
|
||||
},
|
||||
}
|
||||
|
||||
if result := cfg.Validate(); result.OK {
|
||||
t.Fatalf("expected config with no enabled pools to fail validation")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,10 +91,17 @@ func (c *Config) Validate() Result {
|
|||
if len(c.Pools) == 0 {
|
||||
return newErrorResult(errors.New("pool list is empty"))
|
||||
}
|
||||
enabledPools := 0
|
||||
for _, pool := range c.Pools {
|
||||
if pool.Enabled && strings.TrimSpace(pool.URL) == "" {
|
||||
return newErrorResult(errors.New("enabled pool url is empty"))
|
||||
}
|
||||
if pool.Enabled {
|
||||
enabledPools++
|
||||
}
|
||||
}
|
||||
if enabledPools == 0 {
|
||||
return newErrorResult(errors.New("pool list has no enabled entries"))
|
||||
}
|
||||
return newSuccessResult()
|
||||
}
|
||||
|
|
|
|||
1
stats.go
1
stats.go
|
|
@ -11,6 +11,7 @@ import (
|
|||
// stats := proxy.NewStats()
|
||||
// bus.Subscribe(proxy.EventAccept, stats.OnAccept)
|
||||
// bus.Subscribe(proxy.EventReject, stats.OnReject)
|
||||
// _ = stats.Summary()
|
||||
type Stats struct {
|
||||
accepted atomic.Uint64
|
||||
rejected atomic.Uint64
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
//
|
||||
// workers := proxy.NewWorkers(proxy.WorkersByRigID, bus)
|
||||
// workers.OnLogin(proxy.Event{Miner: &proxy.Miner{rigID: "rig-alpha", user: "WALLET", ip: "10.0.0.1"}})
|
||||
// _ = workers.List()
|
||||
type Workers struct {
|
||||
mode WorkersMode
|
||||
entries []WorkerRecord // ordered by first-seen (stable)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue