fix(proxy): reset custom diff and preserve share difficulty

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 13:24:17 +00:00
parent 22e98635e7
commit 259f7e80c8
4 changed files with 19 additions and 3 deletions

View file

@ -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)

View file

@ -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)
}

View file

@ -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,

View file

@ -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)
}