diff --git a/ui/src/lib/BestShares.svelte b/ui/src/lib/BestShares.svelte index a694ef2..549d4bd 100644 --- a/ui/src/lib/BestShares.svelte +++ b/ui/src/lib/BestShares.svelte @@ -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); diff --git a/ui/src/lib/MinersTable.svelte b/ui/src/lib/MinersTable.svelte index d7cc886..a887904 100644 --- a/ui/src/lib/MinersTable.svelte +++ b/ui/src/lib/MinersTable.svelte @@ -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, diff --git a/ui/src/lib/UserDetailPage.svelte b/ui/src/lib/UserDetailPage.svelte index 7b94b41..b7ed193 100644 --- a/ui/src/lib/UserDetailPage.svelte +++ b/ui/src/lib/UserDetailPage.svelte @@ -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,