fix(proxy): align config and login parsing with rfc
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
65f6c733a0
commit
be47d7afde
4 changed files with 34 additions and 12 deletions
|
|
@ -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{
|
cfg := &Config{
|
||||||
Mode: "simple",
|
Mode: "simple",
|
||||||
Workers: WorkersByRigID,
|
Workers: WorkersByRigID,
|
||||||
|
|
@ -51,7 +51,7 @@ func TestConfig_Validate_NoEnabledPool_Ugly(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := cfg.Validate(); result.OK {
|
if result := cfg.Validate(); !result.OK {
|
||||||
t.Fatalf("expected config with no enabled pools to fail validation")
|
t.Fatalf("expected config with no enabled pools to be valid, got error: %v", result.Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,17 +90,10 @@ func (c *Config) Validate() Result {
|
||||||
if len(c.Pools) == 0 {
|
if len(c.Pools) == 0 {
|
||||||
return newErrorResult(NewScopedError("proxy.config", "pool list is empty", nil))
|
return newErrorResult(NewScopedError("proxy.config", "pool list is empty", nil))
|
||||||
}
|
}
|
||||||
enabledPools := 0
|
|
||||||
for _, pool := range c.Pools {
|
for _, pool := range c.Pools {
|
||||||
if pool.Enabled && strings.TrimSpace(pool.URL) == "" {
|
if pool.Enabled && strings.TrimSpace(pool.URL) == "" {
|
||||||
return newErrorResult(NewScopedError("proxy.config", "enabled pool url is empty", nil))
|
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()
|
return newSuccessResult()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
func TestEffectiveShareDifficulty_CustomDiffCapsPoolDifficulty(t *testing.T) {
|
||||||
job := Job{Target: "01000000"}
|
job := Job{Target: "01000000"}
|
||||||
miner := &Miner{customDiff: 25000}
|
miner := &Miner{customDiff: 25000}
|
||||||
|
|
|
||||||
|
|
@ -1036,8 +1036,11 @@ func (m *Miner) handleLogin(request stratumRequest) {
|
||||||
func parseLoginUser(login string, globalDiff uint64) (string, uint64) {
|
func parseLoginUser(login string, globalDiff uint64) (string, uint64) {
|
||||||
plus := strings.LastIndex(login, "+")
|
plus := strings.LastIndex(login, "+")
|
||||||
if plus >= 0 && plus < len(login)-1 {
|
if plus >= 0 && plus < len(login)-1 {
|
||||||
if parsed, err := strconv.ParseUint(login[plus+1:], 10, 64); err == nil {
|
suffix := login[plus+1:]
|
||||||
return login[:plus], parsed
|
if isDigits(suffix) {
|
||||||
|
if parsed, err := strconv.ParseUint(suffix, 10, 64); err == nil {
|
||||||
|
return login[:plus], parsed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return login, 0
|
return login, 0
|
||||||
}
|
}
|
||||||
|
|
@ -1047,6 +1050,18 @@ func parseLoginUser(login string, globalDiff uint64) (string, uint64) {
|
||||||
return login, 0
|
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) {
|
func (m *Miner) handleSubmit(request stratumRequest) {
|
||||||
if m.state != MinerStateReady {
|
if m.state != MinerStateReady {
|
||||||
m.ReplyWithError(requestID(request.ID), "Unauthenticated")
|
m.ReplyWithError(requestID(request.ID), "Unauthenticated")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue