Fix Share stats disappearing regression
This commit is contained in:
6 files changed
+266
-2
No files matched your search
@@ -570,6 +570,66 @@ func FindBestPowData(path string) (best *PowData, bestAt time.Time, seen, unpars
|
||||
return best, bestAt, seen, unparseable, err
|
||||
}
|
||||
|
||||
// ShareStats is a full accounting of the accepted and rejected shares
|
||||
// recorded in a ckpool log, used to rebuild the all-time counters when
|
||||
// the stored ones are lost or truncated. Diffs holds each accepted
|
||||
// share's difficulty in log order so the caller can bucket them with
|
||||
// its own thresholds rather than duplicating that policy here.
|
||||
type ShareStats struct {
|
||||
Accepted int64
|
||||
DiffSum float64
|
||||
Diffs []float64
|
||||
RejectReasons map[string]int64
|
||||
}
|
||||
|
||||
// ScanShareStats reads an entire ckpool log and tallies every accepted
|
||||
// and rejected share it contains. On a busy pool this walks millions of
|
||||
// lines, so it is meant for explicit recovery, never for the startup
|
||||
// path.
|
||||
func ScanShareStats(path string) (*ShareStats, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
st := &ShareStats{RejectReasons: make(map[string]int64)}
|
||||
err = scanLines(f, func(line string) {
|
||||
if strings.Contains(line, "Accepted client") {
|
||||
m := acceptedShareRE.FindStringSubmatch(line)
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
d, perr := strconv.ParseFloat(m[1], 64)
|
||||
if perr != nil {
|
||||
return
|
||||
}
|
||||
st.Accepted++
|
||||
st.DiffSum += d
|
||||
st.Diffs = append(st.Diffs, d)
|
||||
return
|
||||
}
|
||||
if !strings.Contains(line, "Rejected client") {
|
||||
return
|
||||
}
|
||||
if m := rejectedDiffRE.FindStringSubmatch(line); m != nil {
|
||||
st.RejectReasons[rejectKeyword(m[1])]++
|
||||
return
|
||||
}
|
||||
if m := rejectedInvalRE.FindStringSubmatch(line); m != nil {
|
||||
reason := strings.TrimSpace(m[1])
|
||||
if reason == "" {
|
||||
reason = "Unknown"
|
||||
}
|
||||
st.RejectReasons[reason]++
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return st, nil
|
||||
}
|
||||
|
||||
// sleep returns false if ctx was cancelled during the wait.
|
||||
func sleep(ctx context.Context, d time.Duration) bool {
|
||||
select {
|
||||
|
||||
Reference in new issue
Block a user