Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/painel.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ const proxyUp = () => !!PROXY_URL() && Date.now() - proxy.okAt < 2 * 60e3;
// Para esquecer um worker, apague-o de workers.json e reinicie o serviço.
let known = loadJson('workers.json', {});

// O mesmo share chega por mais de um caminho (pool com 2 casas, proxy com mais): 1410,95 e 1410,9534 são um recorde só
const sameShare = (a, b) => Math.abs(a - b) <= Math.max(Math.min(0.011, Math.max(a, b) * 0.01), Math.max(a, b) * 1e-4);

let records = loadJson('records.json', null);
let recordsDirty = false;
if (!Array.isArray(records)) { records = []; recordsDirty = true; }
Expand All @@ -308,8 +311,6 @@ for (const w of Object.values(known)) {
recordsDirty = true;
}
}
// O mesmo share chega por mais de um caminho (pool com 2 casas, proxy com mais): 1410,95 e 1410,9534 são um recorde só
const sameShare = (a, b) => Math.abs(a - b) <= Math.max(Math.min(0.011, Math.max(a, b) * 0.01), Math.max(a, b) * 1e-4);
function dedupeRecords(list) {
const out = [];
for (const r of [...list].sort((a, b) => new Date(a.at || 0) - new Date(b.at || 0))) {
Expand Down
12 changes: 12 additions & 0 deletions tests/painel.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,15 @@ test('recordes com dificuldade fracionária (< 1, ex.: NerdMiner / ESP32)', () =
fs.rmSync(dir, { recursive: true, force: true });
}
});

test('inicialização com workers.json preexistente não causa ReferenceError de sameShare', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'painel-init-'));
fs.writeFileSync(path.join(dir, 'workers.json'), JSON.stringify({
miner1: { name: 'miner1', bestDifficulty: 0.5, lastSeen: new Date().toISOString() }
}));
const { execFileSync } = require('child_process');
assert.doesNotThrow(() => {
execFileSync(process.execPath, ['-e', `process.env.DATA_DIR = ${JSON.stringify(dir)}; require('./src/painel');`]);
});
fs.rmSync(dir, { recursive: true, force: true });
});
Loading