fix(proxy): align config and login parsing with rfc

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-05 02:31:37 +00:00
parent 65f6c733a0
commit be47d7afde
4 changed files with 34 additions and 12 deletions

View file

@ -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)
}
}

View file

@ -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()
}

View file

@ -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}

View file

@ -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")