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

16
stratum/api.go

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

4
stratum/handlers.go

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

24
stratum/miner.go

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

Loading…
Cancel
Save