Browse Source

Tidy up struct exports

pool
Sammy Libre 8 years ago
parent
commit
f3d5c5c718
  1. 2
      go-pool/stratum/api.go
  2. 2
      go-pool/stratum/handlers.go
  3. 21
      go-pool/stratum/miner.go
  4. 2
      go-pool/stratum/stratum.go

2
go-pool/stratum/api.go

@ -85,7 +85,7 @@ func (s *StratumServer) collectMinersStats() (float64, float64, int, []interface
stats["accepts"] = atomic.LoadUint64(&m.Val.accepts) stats["accepts"] = atomic.LoadUint64(&m.Val.accepts)
stats["rejects"] = atomic.LoadUint64(&m.Val.rejects) stats["rejects"] = atomic.LoadUint64(&m.Val.rejects)
if !s.config.Frontend.HideIP { if !s.config.Frontend.HideIP {
stats["ip"] = m.Val.IP stats["ip"] = m.Val.ip
} }
if now-lastBeat > (int64(s.timeout/2) / 1000000) { if now-lastBeat > (int64(s.timeout/2) / 1000000) {

2
go-pool/stratum/handlers.go

@ -79,7 +79,7 @@ func (s *StratumServer) handleSubmitRPC(cs *Session, e *Endpoint, params *Submit
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, miner.IP) log.Printf("Stale share for height %d from %s@%s", job.height, miner.id, miner.ip)
atomic.AddUint64(&miner.staleShares, 1) atomic.AddUint64(&miner.staleShares, 1)
return nil, &ErrorReply{Code: -1, Message: "Block expired"} return nil, &ErrorReply{Code: -1, Message: "Block expired"}
} }

21
go-pool/stratum/miner.go

@ -25,11 +25,10 @@ type Job struct {
type Miner struct { type Miner struct {
sync.RWMutex sync.RWMutex
Id string id string
IP string ip string
LastBeat int64 lastBeat int64
Endpoint *Endpoint endpoint *Endpoint
startedAt int64 startedAt int64
validShares uint64 validShares uint64
invalidShares uint64 invalidShares uint64
@ -52,7 +51,7 @@ func (job *Job) submit(nonce string) bool {
func NewMiner(id string, ip string) *Miner { func NewMiner(id string, ip string) *Miner {
shares := make(map[int64]int64) shares := make(map[int64]int64)
return &Miner{Id: id, IP: ip, shares: shares} return &Miner{id: id, ip: ip, shares: shares}
} }
func (cs *Session) getJob(t *BlockTemplate) *JobReplyData { func (cs *Session) getJob(t *BlockTemplate) *JobReplyData {
@ -94,11 +93,11 @@ func (cs *Session) findJob(id string) *Job {
func (m *Miner) heartbeat() { func (m *Miner) heartbeat() {
now := util.MakeTimestamp() now := util.MakeTimestamp()
atomic.StoreInt64(&m.LastBeat, now) atomic.StoreInt64(&m.lastBeat, now)
} }
func (m *Miner) getLastBeat() int64 { func (m *Miner) getLastBeat() int64 {
return atomic.LoadInt64(&m.LastBeat) return atomic.LoadInt64(&m.lastBeat)
} }
func (m *Miner) storeShare(diff int64) { func (m *Miner) storeShare(diff int64) {
@ -154,7 +153,7 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, 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, m.IP) log.Printf("Bad hash from miner %v@%v", m.id, m.ip)
atomic.AddUint64(&m.invalidShares, 1) atomic.AddUint64(&m.invalidShares, 1)
return false return false
} }
@ -182,10 +181,10 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTe
atomic.AddUint64(&m.accepts, 1) atomic.AddUint64(&m.accepts, 1)
atomic.AddUint64(&r.Accepts, 1) atomic.AddUint64(&r.Accepts, 1)
atomic.StoreInt64(&r.LastSubmissionAt, util.MakeTimestamp()) atomic.StoreInt64(&r.LastSubmissionAt, util.MakeTimestamp())
log.Printf("Block %v found at height %v by miner %v@%v", blockFastHash[0:6], t.Height, m.Id, m.IP) log.Printf("Block %v found at height %v by miner %v@%v", blockFastHash[0:6], t.Height, m.id, m.ip)
} }
} else if hashDiff < job.difficulty { } else if hashDiff < job.difficulty {
log.Printf("Rejected low difficulty share of %v from %v@%v", hashDiff, m.Id, m.IP) log.Printf("Rejected low difficulty share of %v from %v@%v", hashDiff, m.id, m.ip)
atomic.AddUint64(&m.invalidShares, 1) atomic.AddUint64(&m.invalidShares, 1)
return false return false
} }

2
go-pool/stratum/stratum.go

@ -322,7 +322,7 @@ func (s *StratumServer) isActive(cs *Session) bool {
} }
func (s *StratumServer) registerMiner(miner *Miner) { func (s *StratumServer) registerMiner(miner *Miner) {
s.miners.Set(miner.Id, miner) s.miners.Set(miner.id, miner)
} }
func (s *StratumServer) removeMiner(id string) { func (s *StratumServer) removeMiner(id string) {

Loading…
Cancel
Save