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);
+11 -9
View File
@@ -35,20 +35,20 @@
const wname = c.workername || `${c.address}.unnamed`;
seen.add(wname);
const w = byWorker.get(wname);
// "Session best" is the larger of the live stratum client's
// best_diff and the worker_instance's best_diff. ckpool's
// reset_bestshares() clears both when the pool finds a block,
// but reconnect / timing can leave them briefly divergent —
// max() keeps this column aligned with the leaderboard.
const sessionBest = Math.max(c.bestdiff, w?.bestdiff ?? 0);
// "Session best" = best diff for *this stratum TCP session*.
// ckpool zeroes stratum_instance.best_diff when the connection
// ends and on pool restart (in-memory only), so this is the
// value that should reset on miner disconnect / pool restart.
// Don't fall back to worker.best_diff — that's the persistent
// round counter and would defeat the reset semantics.
out.push({
workerName: wname,
user: c.address,
hardware: detectHardware(c.useragent),
hashrate1m: c.dsps1 * 2 ** 32,
hashrate1h: c.dsps60 * 2 ** 32,
bestDiff: sessionBest,
bestEver: w?.bestever ?? sessionBest,
bestDiff: c.bestdiff,
bestEver: w?.bestever ?? c.bestdiff,
lastShare: c.lastshare,
difficulty: c.diff,
address: c.address,
@@ -59,13 +59,15 @@
for (const w of workers) {
if (seen.has(w.worker)) continue;
// Offline worker — no current session, so session-best is 0.
// The lifetime best_ever still applies.
out.push({
workerName: w.worker,
user: w.user,
hardware: "offline",
hashrate1m: w.dsps1 * 2 ** 32,
hashrate1h: w.dsps60 * 2 ** 32,
bestDiff: w.bestdiff,
bestDiff: 0,
bestEver: w.bestever,
lastShare: w.lastshare,
difficulty: w.mindiff,
+4 -6
View File
@@ -49,12 +49,10 @@
hashrate1m: (c?.dsps1 ?? w.dsps1) * 2 ** 32,
hashrate1h: (c?.dsps60 ?? w.dsps60) * 2 ** 32,
diff: c?.diff ?? w.mindiff,
// Session best = larger of client.bestdiff (this stratum
// connection) and worker.bestdiff (this worker in the
// current round). Matches the MinersTable / BestShares
// leaderboard semantics so values are consistent across
// screens.
bestRound: Math.max(c?.bestdiff ?? 0, w.bestdiff),
// Session best = ckpool's stratum_instance.best_diff for the
// currently-connected client only. Resets on miner disconnect
// and pool restart. 0 for offline workers (no current session).
bestRound: c?.bestdiff ?? 0,
bestEver: w.bestever,
lastShare: c?.lastshare ?? w.lastshare,
online: !!c,