Best (session): use only client.best_diff so it actually resets

Math.max(client.best_diff, worker.best_diff) defeated the whole
point of the column. ckpool keeps two separate counters:

  stratum_instance.best_diff  — per TCP session, in memory only,
                                freed on disconnect, gone on
                                ckpool restart.
  worker_instance.best_diff   — per worker name, persisted to the
                                logdir, restored on ckpool restart,
                                survives client disconnects.

Falling back to worker.best_diff when the client value was lower
meant the displayed "session" diff carried over the very events
(miner disconnect, pool restart) that should reset it.

Switch every "Best (session)" computation to read only the live
stratum_instance value. Offline workers — those with a worker
record but no current client — show 0, which is correct: there is
no current session to have a best in.
This commit is contained in:
satoshi
2026-04-26 18:13:18 +03:00
parent 208153bbee
commit ea4c514d78
3 changed files with 24 additions and 24 deletions
+9 -9
View File
@@ -3,12 +3,13 @@
import { formatDifficulty } from "../format";
import type { StratumClient } from "../types";
// Join client data into worker rows so the "session best" column
// matches what the Miners table renders for the same worker.
// ckpool's reset_bestshares() zeroes both worker.best_diff and
// client.best_diff when the pool finds a block, but timing or
// reconnect can leave the two briefly divergent — take the larger
// of the two to stay consistent with the Miners table.
// "Best (session)" = best diff in the current stratum TCP session,
// i.e. only ckpool's stratum_instance.best_diff. Resets on miner
// disconnect (the instance is freed) and on pool restart (in-memory
// state, not persisted). worker.best_diff is a separate persistent
// counter that survives both events, so we deliberately don't fall
// back to it — that fallback was the bug. Offline workers have no
// current session, so their session-best is 0.
const rows = $derived.by(() => {
const ws = snap.data?.workers ?? [];
const cs = snap.data?.clients ?? [];
@@ -19,11 +20,10 @@
}
const enriched = ws.map((w) => {
const c = clientByWorker.get(w.worker);
const sessionBest = Math.max(c?.bestdiff ?? 0, w.bestdiff);
return {
worker: w.worker,
sessionBest,
bestEver: w.bestever || sessionBest,
sessionBest: c?.bestdiff ?? 0,
bestEver: w.bestever || w.bestdiff,
};
});
enriched.sort((a, b) => b.bestEver - a.bestEver);