mirror of
https://github.com/kvazar-network/keva-stratum.git
synced 2025-01-11 15:48:00 +00:00
Use job sequence per endpoint
This commit is contained in:
parent
b95f1b8112
commit
1b6473a52b
@ -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}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user