Browse Source

Fix several alignment issues for x86-32 and ARM

pool
Sammy Libre 7 years ago
parent
commit
bf0ffb035f
  1. 14
      rpc/rpc.go
  2. 16
      stratum/api.go
  3. 4
      stratum/handlers.go
  4. 24
      stratum/miner.go

14
rpc/rpc.go

@ -16,18 +16,18 @@ import ( @@ -16,18 +16,18 @@ import (
type RPCClient struct {
sync.RWMutex
sickRate int64
successRate int64
Accepts int64
Rejects int64
LastSubmissionAt int64
FailsCount int64
Url *url.URL
login string
password string
Name string
sick bool
sickRate int
successRate int
Accepts uint64
Rejects uint64
LastSubmissionAt int64
client *http.Client
FailsCount uint64
}
type GetBlockTemplateReply struct {
@ -125,7 +125,7 @@ func (r *RPCClient) Sick() bool { @@ -125,7 +125,7 @@ func (r *RPCClient) Sick() bool {
func (r *RPCClient) markSick() {
r.Lock()
if !r.sick {
atomic.AddUint64(&r.FailsCount, 1)
atomic.AddInt64(&r.FailsCount, 1)
}
r.sickRate++
r.successRate = 0

16
stratum/api.go

@ -54,10 +54,10 @@ func convertUpstream(u *rpc.RPCClient) map[string]interface{} { @@ -54,10 +54,10 @@ func convertUpstream(u *rpc.RPCClient) map[string]interface{} {
"name": u.Name,
"url": u.Url.String(),
"sick": u.Sick(),
"accepts": atomic.LoadUint64(&u.Accepts),
"rejects": atomic.LoadUint64(&u.Rejects),
"accepts": atomic.LoadInt64(&u.Accepts),
"rejects": atomic.LoadInt64(&u.Rejects),
"lastSubmissionAt": atomic.LoadInt64(&u.LastSubmissionAt),
"failsCount": atomic.LoadUint64(&u.FailsCount),
"failsCount": atomic.LoadInt64(&u.FailsCount),
}
return upstream
}
@ -81,11 +81,11 @@ func (s *StratumServer) collectMinersStats() (float64, float64, int, []interface @@ -81,11 +81,11 @@ func (s *StratumServer) collectMinersStats() (float64, float64, int, []interface
stats["hashrate"] = hashrate
stats["hashrate24h"] = hashrate24h
stats["lastBeat"] = lastBeat
stats["validShares"] = atomic.LoadUint64(&m.Val.validShares)
stats["staleShares"] = atomic.LoadUint64(&m.Val.staleShares)
stats["invalidShares"] = atomic.LoadUint64(&m.Val.invalidShares)
stats["accepts"] = atomic.LoadUint64(&m.Val.accepts)
stats["rejects"] = atomic.LoadUint64(&m.Val.rejects)
stats["validShares"] = atomic.LoadInt64(&m.Val.validShares)
stats["staleShares"] = atomic.LoadInt64(&m.Val.staleShares)
stats["invalidShares"] = atomic.LoadInt64(&m.Val.invalidShares)
stats["accepts"] = atomic.LoadInt64(&m.Val.accepts)
stats["rejects"] = atomic.LoadInt64(&m.Val.rejects)
if !s.config.Frontend.HideIP {
stats["ip"] = m.Val.ip
}

4
stratum/handlers.go

@ -74,14 +74,14 @@ func (s *StratumServer) handleSubmitRPC(cs *Session, params *SubmitParams) (*Sub @@ -74,14 +74,14 @@ func (s *StratumServer) handleSubmitRPC(cs *Session, params *SubmitParams) (*Sub
nonce := strings.ToLower(params.Nonce)
exist := job.submit(nonce)
if exist {
atomic.AddUint64(&miner.invalidShares, 1)
atomic.AddInt64(&miner.invalidShares, 1)
return nil, &ErrorReply{Code: -1, Message: "Duplicate share"}
}
t := s.currentBlockTemplate()
if job.height != t.height {
log.Printf("Stale share for height %d from %s@%s", job.height, miner.id, cs.ip)
atomic.AddUint64(&miner.staleShares, 1)
atomic.AddInt64(&miner.staleShares, 1)
return nil, &ErrorReply{Code: -1, Message: "Block expired"}
}

24
stratum/miner.go

@ -29,11 +29,11 @@ type Miner struct { @@ -29,11 +29,11 @@ type Miner struct {
ip string
lastBeat int64
startedAt int64
validShares uint64
invalidShares uint64
staleShares uint64
accepts uint64
rejects uint64
validShares int64
invalidShares int64
staleShares int64
accepts int64
rejects int64
shares map[int64]int64
}
@ -157,7 +157,7 @@ func (m *Miner) processShare(s *StratumServer, cs *Session, job *Job, t *BlockTe @@ -157,7 +157,7 @@ func (m *Miner) processShare(s *StratumServer, cs *Session, job *Job, t *BlockTe
if !s.config.BypassShareValidation && hex.EncodeToString(hashBytes) != result {
log.Printf("Bad hash from miner %v@%v", m.id, cs.ip)
atomic.AddUint64(&m.invalidShares, 1)
atomic.AddInt64(&m.invalidShares, 1)
return false
}
@ -167,8 +167,8 @@ func (m *Miner) processShare(s *StratumServer, cs *Session, job *Job, t *BlockTe @@ -167,8 +167,8 @@ func (m *Miner) processShare(s *StratumServer, cs *Session, job *Job, t *BlockTe
if block {
_, err := r.SubmitBlock(hex.EncodeToString(shareBuff))
if err != nil {
atomic.AddUint64(&m.rejects, 1)
atomic.AddUint64(&r.Rejects, 1)
atomic.AddInt64(&m.rejects, 1)
atomic.AddInt64(&r.Rejects, 1)
log.Printf("Block rejected at height %d: %v", t.height, err)
} else {
if len(convertedBlob) == 0 {
@ -181,8 +181,8 @@ func (m *Miner) processShare(s *StratumServer, cs *Session, job *Job, t *BlockTe @@ -181,8 +181,8 @@ func (m *Miner) processShare(s *StratumServer, cs *Session, job *Job, t *BlockTe
s.blocksMu.Lock()
s.blockStats[now] = blockEntry{height: t.height, hash: blockFastHash, variance: ratio}
s.blocksMu.Unlock()
atomic.AddUint64(&m.accepts, 1)
atomic.AddUint64(&r.Accepts, 1)
atomic.AddInt64(&m.accepts, 1)
atomic.AddInt64(&r.Accepts, 1)
atomic.StoreInt64(&r.LastSubmissionAt, now)
log.Printf("Block %s found at height %d by miner %v@%v with ratio %.4f", blockFastHash[0:6], t.height, m.id, cs.ip, ratio)
@ -191,12 +191,12 @@ func (m *Miner) processShare(s *StratumServer, cs *Session, job *Job, t *BlockTe @@ -191,12 +191,12 @@ func (m *Miner) processShare(s *StratumServer, cs *Session, job *Job, t *BlockTe
}
} else if hashDiff < cs.endpoint.config.Difficulty {
log.Printf("Rejected low difficulty share of %v from %v@%v", hashDiff, m.id, cs.ip)
atomic.AddUint64(&m.invalidShares, 1)
atomic.AddInt64(&m.invalidShares, 1)
return false
}
atomic.AddInt64(&s.roundShares, cs.endpoint.config.Difficulty)
atomic.AddUint64(&m.validShares, 1)
atomic.AddInt64(&m.validShares, 1)
m.storeShare(cs.endpoint.config.Difficulty)
log.Printf("Valid share at difficulty %v/%v", cs.endpoint.config.Difficulty, hashDiff)
return true

Loading…
Cancel
Save