diff --git a/config_test.go b/config_test.go index 58b4e1a..9d7febb 100644 --- a/config_test.go +++ b/config_test.go @@ -40,7 +40,7 @@ func TestConfig_Validate_Ugly(t *testing.T) { } } -func TestConfig_Validate_NoEnabledPool_Ugly(t *testing.T) { +func TestConfig_Validate_NoEnabledPool_Good(t *testing.T) { cfg := &Config{ Mode: "simple", Workers: WorkersByRigID, @@ -51,7 +51,7 @@ func TestConfig_Validate_NoEnabledPool_Ugly(t *testing.T) { }, } - if result := cfg.Validate(); result.OK { - t.Fatalf("expected config with no enabled pools to fail validation") + if result := cfg.Validate(); !result.OK { + t.Fatalf("expected config with no enabled pools to be valid, got error: %v", result.Error) } } diff --git a/core_impl.go b/core_impl.go index f621a34..05f9d81 100644 --- a/core_impl.go +++ b/core_impl.go @@ -90,17 +90,10 @@ func (c *Config) Validate() Result { if len(c.Pools) == 0 { return newErrorResult(NewScopedError("proxy.config", "pool list is empty", nil)) } - enabledPools := 0 for _, pool := range c.Pools { if pool.Enabled && strings.TrimSpace(pool.URL) == "" { return newErrorResult(NewScopedError("proxy.config", "enabled pool url is empty", nil)) } - if pool.Enabled { - enabledPools++ - } - } - if enabledPools == 0 { - return newErrorResult(NewScopedError("proxy.config", "pool list has no enabled entries", nil)) } return newSuccessResult() } diff --git a/customdiff_test.go b/customdiff_test.go index 19823e8..38ec3d4 100644 --- a/customdiff_test.go +++ b/customdiff_test.go @@ -29,6 +29,20 @@ func TestCustomDiff_OnLogin(t *testing.T) { } } +func TestCustomDiff_OnLogin_Ugly(t *testing.T) { + cd := NewCustomDiff(10000) + miner := &Miner{user: "WALLET+50000extra"} + + cd.OnLogin(Event{Miner: miner}) + + if miner.User() != "WALLET+50000extra" { + t.Fatalf("expected non-suffix plus segment to remain unchanged, got %q", miner.User()) + } + if miner.customDiff != 0 { + t.Fatalf("expected invalid suffix to disable custom diff, got %d", miner.customDiff) + } +} + func TestEffectiveShareDifficulty_CustomDiffCapsPoolDifficulty(t *testing.T) { job := Job{Target: "01000000"} miner := &Miner{customDiff: 25000} diff --git a/state_impl.go b/state_impl.go index a110745..31b8d83 100644 --- a/state_impl.go +++ b/state_impl.go @@ -1036,8 +1036,11 @@ func (m *Miner) handleLogin(request stratumRequest) { func parseLoginUser(login string, globalDiff uint64) (string, uint64) { plus := strings.LastIndex(login, "+") if plus >= 0 && plus < len(login)-1 { - if parsed, err := strconv.ParseUint(login[plus+1:], 10, 64); err == nil { - return login[:plus], parsed + suffix := login[plus+1:] + if isDigits(suffix) { + if parsed, err := strconv.ParseUint(suffix, 10, 64); err == nil { + return login[:plus], parsed + } } return login, 0 } @@ -1047,6 +1050,18 @@ func parseLoginUser(login string, globalDiff uint64) (string, uint64) { return login, 0 } +func isDigits(value string) bool { + if value == "" { + return false + } + for _, r := range value { + if r < '0' || r > '9' { + return false + } + } + return true +} + func (m *Miner) handleSubmit(request stratumRequest) { if m.state != MinerStateReady { m.ReplyWithError(requestID(request.ID), "Unauthenticated")