mirror of
https://github.com/kvazar-network/keva-stratum.git
synced 2025-03-12 05:51:05 +00:00
Tidy up code style
This commit is contained in:
parent
98f1c60a74
commit
7ac236a393
@ -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
|
||||
|
@ -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 {
|
||||
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 {
|
||||
|
||||
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 {
|
||||
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
|
||||
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
|
||||
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…
x
Reference in New Issue
Block a user