From fefae4b3e5a1741a4612646ae7a481959979c812 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sun, 5 Apr 2026 01:26:24 +0000 Subject: [PATCH] fix(proxy): classify low difficulty rejects Co-Authored-By: Virgil --- customdiffstats.go | 11 ++++++++++- customdiffstats_test.go | 5 +++-- stats_test.go | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 stats_test.go diff --git a/customdiffstats.go b/customdiffstats.go index f82cb57..3b8a05c 100644 --- a/customdiffstats.go +++ b/customdiffstats.go @@ -109,5 +109,14 @@ func (b *CustomDiffBuckets) bucketLocked(diff uint64) *CustomDiffBucketStats { func isInvalidShareReason(reason string) bool { reason = strings.ToLower(reason) - return strings.Contains(reason, "difficulty") || strings.Contains(reason, "invalid") || strings.Contains(reason, "nonce") + if reason == "" { + return false + } + return strings.Contains(reason, "low diff") || + strings.Contains(reason, "lowdifficulty") || + strings.Contains(reason, "low difficulty") || + strings.Contains(reason, "malformed") || + strings.Contains(reason, "difficulty") || + strings.Contains(reason, "invalid") || + strings.Contains(reason, "nonce") } diff --git a/customdiffstats_test.go b/customdiffstats_test.go index 4d9bd99..9e8fc6e 100644 --- a/customdiffstats_test.go +++ b/customdiffstats_test.go @@ -42,14 +42,15 @@ func TestProxy_CustomDiffStats_Bad(t *testing.T) { } miner := &Miner{customDiff: 10000} - p.events.Dispatch(Event{Type: EventReject, Miner: miner, Error: "Invalid nonce"}) + p.events.Dispatch(Event{Type: EventReject, Miner: miner, Error: "Low difficulty share"}) + p.events.Dispatch(Event{Type: EventReject, Miner: miner, Error: "Malformed share"}) summary := p.Summary() bucket, ok := summary.CustomDiffStats[10000] if !ok { t.Fatalf("expected custom diff bucket 10000 to be present") } - if bucket.Rejected != 1 || bucket.Invalid != 1 { + if bucket.Rejected != 2 || bucket.Invalid != 2 { t.Fatalf("unexpected bucket totals: %+v", bucket) } } diff --git a/stats_test.go b/stats_test.go new file mode 100644 index 0000000..f83838e --- /dev/null +++ b/stats_test.go @@ -0,0 +1,18 @@ +package proxy + +import "testing" + +func TestProxy_Stats_InvalidRejectReasons_Good(t *testing.T) { + stats := NewStats() + + stats.OnReject(Event{Error: "Low difficulty share"}) + stats.OnReject(Event{Error: "Malformed share"}) + + summary := stats.Summary() + if summary.Rejected != 2 { + t.Fatalf("expected two rejected shares, got %d", summary.Rejected) + } + if summary.Invalid != 2 { + t.Fatalf("expected two invalid shares, got %d", summary.Invalid) + } +}