Browse Source

Use job sequence per endpoint

pool
Sammy Libre 8 years ago
parent
commit
1b6473a52b
  1. 4
      go-pool/stratum/miner.go
  2. 7
      go-pool/stratum/stratum.go
  3. 9
      go-pool/util/util.go

4
go-pool/stratum/miner.go

@ -5,6 +5,7 @@ import ( @@ -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 { @@ -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}

7
go-pool/stratum/stratum.go

@ -35,9 +35,10 @@ type StratumServer struct { @@ -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 {

9
go-pool/util/util.go

@ -5,8 +5,6 @@ import ( @@ -5,8 +5,6 @@ import (
"encoding/binary"
"encoding/hex"
"math/big"
"math/rand"
"strconv"
"time"
"unicode/utf8"
@ -20,13 +18,6 @@ func init() { @@ -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)
}

Loading…
Cancel
Save