From 8a528567196e10d00df54cbc55f34ffdee29572a Mon Sep 17 00:00:00 2001 From: Virgil Date: Sun, 5 Apr 2026 02:09:46 +0000 Subject: [PATCH] fix(proxy): reject configs without enabled pools Co-Authored-By: Virgil --- api/router.go | 2 ++ config_test.go | 16 ++++++++++++++++ core_impl.go | 7 +++++++ stats.go | 1 + worker.go | 1 + 5 files changed, 27 insertions(+) diff --git a/api/router.go b/api/router.go index 30f380a..3fb9315 100644 --- a/api/router.go +++ b/api/router.go @@ -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 { diff --git a/config_test.go b/config_test.go index e5f31c4..58b4e1a 100644 --- a/config_test.go +++ b/config_test.go @@ -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") + } +} diff --git a/core_impl.go b/core_impl.go index 83c269d..07a0152 100644 --- a/core_impl.go +++ b/core_impl.go @@ -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() } diff --git a/stats.go b/stats.go index ac2aa05..35fd897 100644 --- a/stats.go +++ b/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 diff --git a/worker.go b/worker.go index a7d9c01..f55aaac 100644 --- a/worker.go +++ b/worker.go @@ -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)