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 (
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
"log" "log"
"strconv"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -61,7 +62,8 @@ func (cs *Session) getJob(t *BlockTemplate) *JobReplyData {
extraNonce := atomic.AddUint32(&cs.endpoint.extraNonce, 1) extraNonce := atomic.AddUint32(&cs.endpoint.extraNonce, 1)
blob := t.nextBlob(extraNonce, cs.endpoint.instanceId) 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{}) job.submissions = make(map[string]struct{})
cs.pushJob(job) cs.pushJob(job)
reply := &JobReplyData{JobId: job.id, Blob: blob, Target: cs.targetHex} reply := &JobReplyData{JobId: job.id, Blob: blob, Target: cs.targetHex}

7
go-pool/stratum/stratum.go

@ -35,9 +35,10 @@ type StratumServer struct {
} }
type Endpoint struct { type Endpoint struct {
config *pool.Port config *pool.Port
instanceId []byte instanceId []byte
extraNonce uint32 extraNonce uint32
jobSequence uint64
} }
type Session struct { type Session struct {

9
go-pool/util/util.go

@ -5,8 +5,6 @@ import (
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
"math/big" "math/big"
"math/rand"
"strconv"
"time" "time"
"unicode/utf8" "unicode/utf8"
@ -20,13 +18,6 @@ func init() {
Diff1.SetString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 16) 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 { func MakeTimestamp() int64 {
return time.Now().UnixNano() / int64(time.Millisecond) return time.Now().UnixNano() / int64(time.Millisecond)
} }

Loading…
Cancel
Save