Engine: claim rows on the site before sending (processing state), stuck-row alert, failed rows return to queued; gitignore
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -75,9 +75,11 @@ async function tick() {
|
||||
for (const e of Object.values(L.entries).filter(x => x.status === 'sent' && x.tx)) {
|
||||
try { const rc = await provider.getTransactionReceipt(e.tx); if (rc) await settle(e, rc); } catch (err) { if (TRANSIENT.test(String(err.message))) rotate(err.message); }
|
||||
}
|
||||
// 2) what the site has queued
|
||||
// 2) what the site has queued; rows stuck in `processing` with no hash in our ledger need a human, never a re-send
|
||||
const r = await bridge('pending', 'GET');
|
||||
const rows = r.pending || []; t.pending = rows.length;
|
||||
const stuck = (r.stuck || []).filter(s => { const e = L.entries[String(s.id)]; return !e || !e.tx; });
|
||||
if (stuck.length) await alertOnce('stuck:' + stuck.map(s => s.id).join(','), stuck.length + ' payout row(s) stuck in processing with no transaction on record: ' + stuck.map(s => '#' + s.id + ' ' + s.username + ' $' + s.usd).join(', ') + '. Check the wallet history before releasing them.');
|
||||
if (!rows.length) { t.note = 'nothing queued'; return; }
|
||||
const usdPerPol = await polusd.usdPerPol(); if (!(usdPerPol > 0)) { t.note = 'no POL price'; await alertOnce('price', 'no POL price available; payouts held'); return; }
|
||||
let bal = null; try { bal = await balance(); } catch (err) { if (TRANSIENT.test(String(err.message))) rotate(err.message); }
|
||||
@@ -92,15 +94,20 @@ async function tick() {
|
||||
if (paidTodayUsd() + usd > CAP_USD) { t.note = 'daily cap reached'; await alertOnce('cap', 'daily cap $' + CAP_USD + ' reached; ' + rows.length + ' still queued'); break; }
|
||||
if (DRY) { L.entries[id] = { id, status: 'dryrun', usd, pol, to: row.address, user: row.username, at: Date.now() }; save(); log('DRY RUN would pay', pol, 'POL ($' + usd + ') to', row.address, 'for', row.username, 'row', id); t.paid++; continue; }
|
||||
if (bal != null && bal < pol + 0.01) { t.note = 'wallet too low'; break; }
|
||||
// 3) send, record the hash BEFORE anything else, then wait for the receipt
|
||||
// 3) claim the row on the site first (status 4 = processing): a crash between send and callback can then never
|
||||
// make a fresh process pay the same row again; the site lists such rows as `stuck` for a human instead
|
||||
try { const c = await bridge('claim', 'POST', { id: row.id }); if (!c.updated) { log('row', id, 'was not claimable (already processing?)'); continue; } }
|
||||
catch (err) { log('claim failed', id, err.message); t.note = 'claim failed'; break; }
|
||||
// 4) send, record the hash BEFORE anything else, then wait for the receipt
|
||||
let tx;
|
||||
try {
|
||||
tx = await wallet.sendTransaction({ to: row.address, value: ethers.parseEther(String(pol)) });
|
||||
} catch (err) {
|
||||
const msg = String(err.message || err).slice(0, 200);
|
||||
if (TRANSIENT.test(msg)) { rotate(msg); t.note = 'rpc trouble'; break; }
|
||||
L.entries[id] = { id, status: 'failed', usd, pol, to: row.address, user: row.username, at: Date.now(), error: msg }; save();
|
||||
await bridge('failed', 'POST', { id: row.id, reason: msg.slice(0, 200) }).catch(() => {}); continue;
|
||||
await bridge('failed', 'POST', { id: row.id, reason: msg.slice(0, 200) }).catch(() => {}); // row goes back to queued on the site
|
||||
if (TRANSIENT.test(msg)) { rotate(msg); delete L.entries[id]; save(); t.note = 'rpc trouble'; break; } // no hash was produced: safe to retry later
|
||||
continue;
|
||||
}
|
||||
L.entries[id] = { id, status: 'sent', usd, pol, to: row.address, user: row.username, at: Date.now(), tx: tx.hash }; save();
|
||||
log('sent', pol, 'POL ($' + usd + ') to', row.address, 'row', id, 'tx', tx.hash);
|
||||
|
||||
Reference in New Issue
Block a user