-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathadmin-worker.ejs
More file actions
331 lines (323 loc) · 17.1 KB
/
Copy pathadmin-worker.ejs
File metadata and controls
331 lines (323 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<%
/* Precompute a running_accrued column for the recent-shares table.
* The rows come newest-first, so we walk in reverse to accumulate. */
const recentAsc = [...audit.recent].reverse();
let running = 0;
const withRunning = recentAsc.map(r => {
running += r.credit_sats;
return { ...r, running_accrued: running };
}).reverse();
/* The ledger cross-check: sum of what was actually credited per share
* versus the pps_credits running total. These must agree exactly — both
* are written by the proxy from the same per-share amount.
*
* Deliberately NOT compared against sum_difficulty x current_rate: the
* rate is derived per template and moves with network difficulty, so that
* comparison reports a false mismatch after every retarget. */
const meta = audit.meta || null;
const drift = audit.totals.accrued_computed - audit.ledger.accrued;
/* Shown only for context — what today's rate would imply for this much
* work. Divergence here is difficulty movement, not an error. */
const atCurrentRate = meta && meta.rate_sats_per_diff
? Math.floor(audit.totals.sum_difficulty * meta.rate_sats_per_diff) : null;
%>
<!doctype html>
<html lang="en">
<head>
<%- include('partial/head', { title: `audit · ${audit.worker.name} · simplepool`, refresh: 30 }) %>
</head>
<body>
<%- include('partial/nav-admin', { active: 'worker' }) %>
<main class="wrap">
<section class="card info">
<h2>Why is this balance what it is?</h2>
<p class="muted small">
Answers a miner's "where does <em>my</em> number come from"
question at the byte level. Every accepted share is credited
<code>FLOOR(difficulty × rate)</code> sats, and that amount is
stored on the share row as <code>credited_sats</code>. The
totals below <strong>sum those stored values</strong> — they
are not recomputed from today's rate, because the rate moves
with network difficulty and re-deriving history would misreport
every share mined under a different one.
</p>
</section>
<section class="card">
<h2>Rate & fee</h2>
<% if (!meta) { %>
<p class="muted small">
No <code>pool_meta</code> row yet — this database predates
rate publishing, or the proxy has not seen a template since
upgrading. Stored per-share credits are still authoritative.
</p>
<% } else { %>
<div class="grid">
<div><label>Source</label><span>
<%= meta.rate_source %>
<% if (meta.rate_source === 'derived') { %>
<span class="muted small">— from the live block template</span>
<% } else { %>
<span class="muted small">— pinned via <code>pps_sats_per_diff</code></span>
<% } %>
</span></div>
<div><label>Effective rate</label><span class="mono"><%= meta.rate_sats_per_diff.toFixed(4) %> sats/diff</span></div>
<div><label>Fair value (gross)</label><span class="mono"><%= meta.gross_sats_per_diff.toFixed(4) %> sats/diff</span></div>
<div><label>Configured fee</label><span class="mono"><%= (meta.fee_bps / 100).toFixed(2) %>%</span></div>
<div><label>Effective fee</label><span class="mono"><%= (meta.effective_fee_bps / 100).toFixed(4) %>%</span></div>
<div><label>Network difficulty</label><span class="mono"><%= meta.network_difficulty.toLocaleString() %></span></div>
<div><label>Block value</label><span class="mono"><%= meta.block_value_sats.toLocaleString() %> sats</span></div>
<div><label>Rate updated</label><span title="<%= fmtTs(meta.updated_at) %>"><%= ago(meta.updated_at) %></span></div>
</div>
<% if (Math.abs(meta.fee_drift_bps) > 25) { %>
<p class="warn small">
⚠ The effective fee (<%= (meta.effective_fee_bps / 100).toFixed(2) %>%)
disagrees with the configured <code>fee_bps</code>
(<%= (meta.fee_bps / 100).toFixed(2) %>%). The pinned
<code>pps_sats_per_diff</code> has drifted from fair value as
difficulty moved. Remove it to derive the rate automatically.
</p>
<% } %>
<% if (meta.effective_fee_bps < 0) { %>
<p class="warn small">
⚠ The rate <strong>exceeds</strong> fair value — the pool is
paying out more per share than each share earns.
</p>
<% } %>
<% } %>
</section>
<section class="card">
<h2><%= audit.worker.name %></h2>
<div class="grid">
<div><label>Thunder address</label><span class="mono small"><%= audit.worker.thunder_address || '—' %></span></div>
<div><label>First seen</label><span title="<%= fmtTs(audit.worker.first_seen) %>"><%= ago(audit.worker.first_seen) %></span></div>
<div><label>Last seen</label><span title="<%= fmtTs(audit.worker.last_seen) %>"><%= ago(audit.worker.last_seen) %></span></div>
</div>
</section>
<section class="card">
<h2>Ledger</h2>
<div class="grid">
<div><label>Owed (needs payout)</label><strong><%= fmtSats(audit.ledger.owed) %></strong></div>
<div><label>Accrued (all-time, from pps_credits)</label><strong><%= fmtSats(audit.ledger.accrued) %></strong></div>
<div><label>Paid (all-time)</label><strong><%= fmtSats(audit.ledger.paid) %></strong></div>
<div><label>Last updated</label><span title="<%= fmtTs(audit.ledger.last_updated) %>"><%= ago(audit.ledger.last_updated) %></span></div>
</div>
</section>
<section class="card">
<h2>Cross-check</h2>
<p class="muted small" style="margin-top:0">
Every accepted share stores the sats it was credited. Summing
that column must equal the running total in
<code>pps_credits</code> — both are written by the proxy from
the same number. A mismatch means the ledger was edited outside
the proxy, or rows were written before
<code>credited_sats</code> existed.
</p>
<div class="grid">
<div><label>Accepted shares</label><strong><%= fmtN(audit.totals.share_count) %></strong></div>
<div><label>Blocks found</label><strong><%= fmtN(audit.totals.blocks_found) %></strong></div>
<div><label>Σ difficulty</label><strong><%= fmtF(audit.totals.sum_difficulty, 6) %></strong></div>
<div><label>Σ credited_sats — authoritative</label><strong><%= fmtSats(audit.totals.accrued_computed) %></strong></div>
<div><label>pps_credits.accrued (stored)</label><strong><%= fmtSats(audit.ledger.accrued) %></strong></div>
</div>
<% if (drift === 0) { %>
<p class="muted small ok" style="margin-top:0.75em">
✓ Per-share credits sum exactly to the stored ledger.
</p>
<% } else { %>
<p class="muted small bad" style="margin-top:0.75em">
⚠ Differs by <%= fmtSats(drift) %>. Shares accepted before
this build stored <code>credited_sats = 0</code> and cannot
be reconstructed — check
<code>pool_meta.credited_from</code> for where the column
became trustworthy. Otherwise <code>pps_credits</code> was
modified outside the proxy.
</p>
<% } %>
<% if (atCurrentRate !== null) { %>
<p class="muted small" style="margin-top:0.5em">
For reference, this much work at the <em>current</em> rate
(<%= meta.rate_sats_per_diff.toFixed(4) %> sats/diff) would be
<%= fmtSats(atCurrentRate) %>. A difference is normal — it just
means difficulty moved during the window, and each share was
correctly credited at the rate in force at the time.
</p>
<% } %>
</section>
<% const v = audit.verification; %>
<section class="card">
<h2>Verification</h2>
<p class="muted small" style="margin-top:0">
The cross-check above compares two numbers the proxy wrote.
This one recomputes them. Each share stores both the rate it
was credited at and the resulting sats, so
<code>floor(difficulty × rate_used)</code> must reproduce
<code>credited_sats</code> exactly — without consulting any
current rate. <code>rate_history</code> then shows each rate
followed from the block value and difficulty of the template
it came from.
</p>
<% if (!v) { %>
<p class="muted small bad">
⚠ This database predates <code>shares.rate_used</code>, so
the ledger cannot be independently verified. The stored
credits remain authoritative; there is simply nothing to
check them against.
</p>
<% } else { %>
<div class="grid">
<div><label>Credited shares</label><strong><%= fmtN(v.credited) %></strong></div>
<div><label>Verifiable</label><strong><%= fmtN(v.verifiable) %> (<%= v.coverage_pct.toFixed(1) %>%)</strong></div>
<div><label>Arithmetic mismatches</label><strong><%= fmtN(v.mismatched) %></strong></div>
<div><label>Rates not in the log</label><strong><%= fmtN(v.orphaned) %></strong></div>
<div><label>Rate log entries</label><strong><%= fmtN(v.rate_rows) %></strong></div>
<div><label>Rates inconsistent with their inputs</label><strong><%= fmtN(v.rates_inconsistent) %></strong></div>
</div>
<% if (v.ok && v.coverage_pct >= 100) { %>
<p class="muted small ok" style="margin-top:0.75em">
✓ Every credited share re-derives exactly, and every
rate used follows from the template it came from.
</p>
<% } else if (v.ok) { %>
<p class="muted small ok" style="margin-top:0.75em">
✓ No failures among the <%= fmtN(v.verifiable) %> share(s)
that carry a stored rate. The remainder is not checked
— see below.
</p>
<% } else { %>
<p class="muted small bad" style="margin-top:0.75em">
⚠ Verification failed.
<% if (v.mismatched > 0) { %>
<%= fmtN(v.mismatched) %> share(s) do not match
their own stored rate — the credit was not produced
by the rate recorded beside it.
<% } %>
<% if (v.rates_inconsistent > 0) { %>
<%= fmtN(v.rates_inconsistent) %> logged rate(s) do
not follow from their recorded block value,
difficulty and fee.
<% } %>
<% if (v.orphaned > 0) { %>
<%= fmtN(v.orphaned) %> share(s) were credited at a
rate that never appears in <code>rate_history</code>.
<% } %>
This is the check that should never fail; treat it as a
ledger integrity problem, not a display issue.
</p>
<% } %>
<% if (v.unverifiable > 0) { %>
<p class="muted small" style="margin-top:0.5em">
<%= fmtN(v.unverifiable) %> credited share(s) predate
<code>rate_used</code> and are excluded from the checks
above — their credits stand, but cannot be recomputed.
</p>
<% } %>
<% } %>
</section>
<section class="card">
<h2>Daily breakdown</h2>
<% if (audit.days.length === 0) { %>
<p class="muted">No activity yet.</p>
<% } else { %>
<div class="tablewrap"><table>
<thead>
<tr>
<th>Day (UTC)</th>
<th>Shares</th>
<th>Σ difficulty</th>
<th>Accrued this day</th>
<th>Blocks</th>
</tr>
</thead>
<tbody>
<% audit.days.forEach(d => { %>
<tr>
<td class="mono small"><%= d.day %></td>
<td><%= fmtN(d.shares) %></td>
<td><%= fmtF(d.sum_diff, 6) %></td>
<td><strong><%= fmtSats(d.accrued_delta) %></strong></td>
<td><%= d.blocks > 0 ? d.blocks : '' %></td>
</tr>
<% }) %>
</tbody>
</table></div>
<% } %>
</section>
<section class="card">
<h2>Payouts to this worker</h2>
<% if (!audit.payouts || audit.payouts.length === 0) { %>
<p class="muted">No payouts yet. Once the payout worker fires a Thunder tx to this address, each one gets a row here with its txid.</p>
<% } else { %>
<div class="tablewrap"><table>
<thead>
<tr>
<th>When</th>
<th>Amount</th>
<th>Fee</th>
<th>Thunder txid</th>
<th>Note</th>
</tr>
</thead>
<tbody>
<% audit.payouts.forEach(p => { %>
<tr>
<td class="muted small" title="<%= fmtTs(p.paid_at) %>"><%= ago(p.paid_at) %></td>
<td><strong><%= fmtSats(p.sats) %></strong></td>
<td class="muted small"><%= fmtSats(p.fee_sats) %></td>
<td class="mono small"><%= p.txid %></td>
<td class="muted small"><%= p.note || '' %></td>
</tr>
<% }) %>
</tbody>
</table></div>
<% } %>
</section>
<section class="card">
<h2>Recent shares (last <%= withRunning.length %>, newest first)</h2>
<% if (withRunning.length === 0) { %>
<p class="muted">No shares recorded.</p>
<% } else { %>
<p class="muted small" style="margin-top:0">
The <em>credit</em> column is what this share added to your
balance. <em>Running accrued</em> is the sum from the oldest
visible share up to and including this one.
</p>
<div class="tablewrap"><table>
<thead>
<tr>
<th>#</th>
<th>When</th>
<th>Difficulty</th>
<th>Credit</th>
<th>Block?</th>
<th>Running accrued</th>
</tr>
</thead>
<tbody>
<% withRunning.forEach(r => { %>
<tr<%= r.is_block ? ' style="font-weight:600"' : '' %>>
<td class="mono small"><%= r.id %></td>
<td class="mono small" title="<%= fmtTs(r.ts) %>"><%= ago(r.ts) %></td>
<td><%= fmtF(r.difficulty, 6) %></td>
<td><%= fmtSats(r.credit_sats) %></td>
<%# is_block means the hash met the network target — what the
miner actually did. Whether it became a block is a
separate question, so show the verdict beside it rather
than letting a bare tick imply one. %>
<td><% if (r.is_block) { %>✓ <%= r.block_hash ? r.block_hash.slice(0, 10) + '…' : '' %>
<%- blockStatus({ status: r.block_status }) %>
<% } %></td>
<td><%= fmtSats(r.running_accrued) %></td>
</tr>
<% }) %>
</tbody>
</table></div>
<% } %>
</section>
</main>
<footer class="foot">
<span>read-only · auto-refresh 30s</span>
<span class="sep">·</span>
<span>worker audit</span>
</footer>
</body>
</html>