From 259f7e80c81f11aa1334e668f92d84d5fdff775b Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 13:24:17 +0000 Subject: [PATCH] fix(proxy): reset custom diff and preserve share difficulty Co-Authored-By: Virgil --- miner_runtime.go | 3 +++ runtime_support.go | 5 +++++ splitter/nicehash/mapper.go | 6 +++++- splitter/simple/mapper.go | 8 ++++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/miner_runtime.go b/miner_runtime.go index 6090cf5..e90e0cd 100644 --- a/miner_runtime.go +++ b/miner_runtime.go @@ -201,6 +201,9 @@ func (m *Miner) handleLogin(request minerRequest) { return } + m.SetCustomDiff(0) + m.currentJob = nil + m.diff = 0 m.SetPassword(params.Pass) m.SetAgent(params.Agent) m.SetRigID(params.RigID) diff --git a/runtime_support.go b/runtime_support.go index 5b84ccf..9aab3f3 100644 --- a/runtime_support.go +++ b/runtime_support.go @@ -162,10 +162,12 @@ func (customDiff *CustomDiff) OnLogin(event Event) { event.Miner.SetCustomDiff(value) return } + event.Miner.SetCustomDiff(0) return } if customDiff == nil { + event.Miner.SetCustomDiff(0) return } @@ -174,5 +176,8 @@ func (customDiff *CustomDiff) OnLogin(event Event) { customDiff.mu.RUnlock() if globalDiff > 0 { event.Miner.SetCustomDiff(globalDiff) + return } + + event.Miner.SetCustomDiff(0) } diff --git a/splitter/nicehash/mapper.go b/splitter/nicehash/mapper.go index 9b19f83..8ebb8da 100644 --- a/splitter/nicehash/mapper.go +++ b/splitter/nicehash/mapper.go @@ -140,6 +140,10 @@ func (m *NonceMapper) OnResultAccepted(sequence int64, accepted bool, errorMessa if miner == nil { return } + shareDifficulty := context.Job.DifficultyFromTarget() + if shareDifficulty == 0 { + shareDifficulty = miner.Diff() + } eventType := proxy.EventReject if accepted { @@ -162,7 +166,7 @@ func (m *NonceMapper) OnResultAccepted(sequence int64, accepted bool, errorMessa Type: eventType, Miner: miner, Job: jobPointer(context.Job), - Diff: miner.Diff(), + Diff: shareDifficulty, Error: errorMessage, Latency: latency, Expired: context.Expired, diff --git a/splitter/simple/mapper.go b/splitter/simple/mapper.go index a073d8e..e6067ab 100644 --- a/splitter/simple/mapper.go +++ b/splitter/simple/mapper.go @@ -95,11 +95,15 @@ func (m *SimpleMapper) OnResultAccepted(sequence int64, accepted bool, errorMess if miner == nil { return } + shareDifficulty := context.Job.DifficultyFromTarget() + if shareDifficulty == 0 { + shareDifficulty = miner.Diff() + } if accepted { latency := shareLatency(context.SubmittedAt) if m.events != nil { - m.events.Dispatch(proxy.Event{Type: proxy.EventAccept, Miner: miner, Job: jobPointer(context.Job), Diff: miner.Diff(), Latency: latency, Expired: context.Expired}) + m.events.Dispatch(proxy.Event{Type: proxy.EventAccept, Miner: miner, Job: jobPointer(context.Job), Diff: shareDifficulty, Latency: latency, Expired: context.Expired}) } miner.Success(context.RequestID, "OK") return @@ -107,7 +111,7 @@ func (m *SimpleMapper) OnResultAccepted(sequence int64, accepted bool, errorMess latency := shareLatency(context.SubmittedAt) if m.events != nil { - m.events.Dispatch(proxy.Event{Type: proxy.EventReject, Miner: miner, Job: jobPointer(context.Job), Diff: miner.Diff(), Error: errorMessage, Latency: latency, Expired: context.Expired}) + m.events.Dispatch(proxy.Event{Type: proxy.EventReject, Miner: miner, Job: jobPointer(context.Job), Diff: shareDifficulty, Error: errorMessage, Latency: latency, Expired: context.Expired}) } miner.ReplyWithError(context.RequestID, errorMessage) }