diff --git a/splitter/nicehash/storage.go b/splitter/nicehash/storage.go index c4b9482..247ee61 100644 --- a/splitter/nicehash/storage.go +++ b/splitter/nicehash/storage.go @@ -21,6 +21,7 @@ type NonceStorage struct { job proxy.Job // current job from pool prevJob proxy.Job // previous job (for stale submit validation) cursor int // search starts here (round-robin allocation) + expired uint64 // stale job ID hits for the previous job mu sync.Mutex } @@ -132,6 +133,7 @@ func (s *NonceStorage) JobForID(id string) (job proxy.Job, valid bool, expired b return s.job, true, false } if s.prevJob.IsValid() && s.prevJob.ClientID != "" && id == s.prevJob.JobID { + s.expired++ return s.prevJob, true, true } return proxy.Job{}, false, false @@ -166,6 +168,16 @@ func (s *NonceStorage) SlotCount() (free int, dead int, active int) { return free, dead, active } +// ExpiredCount returns the number of times the previous job ID has been accepted as stale. +// +// count := storage.ExpiredCount() +func (s *NonceStorage) ExpiredCount() uint64 { + s.mu.Lock() + defer s.mu.Unlock() + + return s.expired +} + // Miners returns a snapshot of the active miner map. func (s *NonceStorage) Miners() map[int64]*proxy.Miner { s.mu.Lock() diff --git a/splitter/nicehash/storage_test.go b/splitter/nicehash/storage_test.go index 1a4874f..ec35a22 100644 --- a/splitter/nicehash/storage_test.go +++ b/splitter/nicehash/storage_test.go @@ -60,6 +60,9 @@ func TestNonceStorage_IsValidJobID_Ugly(t *testing.T) { if !storage.IsValidJobID("job-1") { t.Fatal("expected previous job ID from same client to remain valid") } + if got := storage.ExpiredCount(); got != 1 { + t.Fatalf("expected stale job lookups to increment the expired counter, got %d", got) + } } func TestNonceStorage_IsValidJobID_BadClientID(t *testing.T) {