From 1b6473a52b92fd97911f7abb4fa76694dc77cde1 Mon Sep 17 00:00:00 2001 From: Sammy Libre Date: Wed, 7 Dec 2016 13:42:41 +0500 Subject: [PATCH] Use job sequence per endpoint --- go-pool/stratum/miner.go | 4 +++- go-pool/stratum/stratum.go | 7 ++++--- go-pool/util/util.go | 9 --------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/go-pool/stratum/miner.go b/go-pool/stratum/miner.go index da653dc..b160fca 100644 --- a/go-pool/stratum/miner.go +++ b/go-pool/stratum/miner.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "encoding/hex" "log" + "strconv" "sync" "sync/atomic" "time" @@ -61,7 +62,8 @@ 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} + id := atomic.AddUint64(&cs.endpoint.jobSequence, 1) + job := &Job{id: strconv.FormatUint(id, 10), 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} diff --git a/go-pool/stratum/stratum.go b/go-pool/stratum/stratum.go index 5d02794..4f97b7f 100644 --- a/go-pool/stratum/stratum.go +++ b/go-pool/stratum/stratum.go @@ -35,9 +35,10 @@ type StratumServer struct { } type Endpoint struct { - config *pool.Port - instanceId []byte - extraNonce uint32 + config *pool.Port + instanceId []byte + extraNonce uint32 + jobSequence uint64 } type Session struct { diff --git a/go-pool/util/util.go b/go-pool/util/util.go index 2973287..0308fac 100644 --- a/go-pool/util/util.go +++ b/go-pool/util/util.go @@ -5,8 +5,6 @@ import ( "encoding/binary" "encoding/hex" "math/big" - "math/rand" - "strconv" "time" "unicode/utf8" @@ -20,13 +18,6 @@ func init() { Diff1.SetString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16) } -func Random() string { - min := int64(100000000000000) - max := int64(999999999999999) - n := rand.Int63n(max-min+1) + min - return strconv.FormatInt(n, 10) -} - func MakeTimestamp() int64 { return time.Now().UnixNano() / int64(time.Millisecond) }