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