Browse Source

Tidy up code style

pool
Sammy Libre 8 years ago
parent
commit
7ac236a393
  1. 4
      go-pool/stratum/handlers.go
  2. 26
      go-pool/stratum/miner.go

4
go-pool/stratum/handlers.go

@ -87,8 +87,8 @@ func (s *StratumServer) handleSubmitRPC(cs *Session, e *Endpoint, params *Submit @@ -87,8 +87,8 @@ func (s *StratumServer) handleSubmitRPC(cs *Session, e *Endpoint, params *Submit
}
t := s.currentBlockTemplate()
if job.Height != t.Height {
log.Printf("Block expired for height %v %s@%s", job.Height, miner.Id, miner.IP)
if job.height != t.Height {
log.Printf("Block expired for height %v %s@%s", job.height, miner.Id, miner.IP)
errorReply = &ErrorReply{Code: -1, Message: "Block expired", Close: false}
atomic.AddUint64(&miner.staleShares, 1)
return

26
go-pool/stratum/miner.go

@ -16,11 +16,11 @@ import ( @@ -16,11 +16,11 @@ import (
type Job struct {
sync.RWMutex
Id string
ExtraNonce uint32
Height int64
Difficulty int64
Submissions map[string]bool
id string
extraNonce uint32
height int64
difficulty int64
submissions map[string]struct{}
}
type Miner struct {
@ -42,11 +42,11 @@ type Miner struct { @@ -42,11 +42,11 @@ type Miner struct {
func (job *Job) submit(nonce string) bool {
job.Lock()
defer job.Unlock()
_, exist := job.Submissions[nonce]
_, exist := job.submissions[nonce]
if exist {
return true
}
job.Submissions[nonce] = true
job.submissions[nonce] = struct{}{}
return false
}
@ -64,10 +64,10 @@ func (cs *Session) getJob(t *BlockTemplate) *JobReplyData { @@ -64,10 +64,10 @@ func (cs *Session) getJob(t *BlockTemplate) *JobReplyData {
extraNonce := atomic.AddUint32(&cs.endpoint.extraNonce, 1)
blob := t.nextBlob(extraNonce, cs.endpoint.instanceId)
job := &Job{Id: util.Random(), ExtraNonce: extraNonce, Height: t.Height, Difficulty: cs.difficulty}
job.Submissions = make(map[string]bool)
job := &Job{id: util.Random(), extraNonce: extraNonce, height: t.Height, difficulty: cs.difficulty}
job.submissions = make(map[string]struct{})
cs.pushJob(job)
reply := &JobReplyData{JobId: job.Id, Blob: blob, Target: cs.targetHex}
reply := &JobReplyData{JobId: job.id, Blob: blob, Target: cs.targetHex}
return reply
}
@ -85,7 +85,7 @@ func (cs *Session) findJob(id string) *Job { @@ -85,7 +85,7 @@ func (cs *Session) findJob(id string) *Job {
cs.Lock()
defer cs.Unlock()
for _, job := range cs.validJobs {
if job.Id == id {
if job.id == id {
return job
}
}
@ -138,7 +138,7 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTe @@ -138,7 +138,7 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTe
copy(shareBuff[t.ReservedOffset+4:t.ReservedOffset+7], e.instanceId)
extraBuff := new(bytes.Buffer)
binary.Write(extraBuff, binary.BigEndian, job.ExtraNonce)
binary.Write(extraBuff, binary.BigEndian, job.extraNonce)
copy(shareBuff[t.ReservedOffset:], extraBuff.Bytes())
nonceBuff, _ := hex.DecodeString(nonce)
@ -184,7 +184,7 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTe @@ -184,7 +184,7 @@ func (m *Miner) processShare(s *StratumServer, e *Endpoint, job *Job, t *BlockTe
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)
}
} 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)
atomic.AddUint64(&m.invalidShares, 1)
return false

Loading…
Cancel
Save