No double posts: badge and find posts reserve an in-flight key the sweeps skip (bikereo2's First Find posted twice, 16 s race); faucet keeps a drip due on transient node errors and rotates through HUNT_RPC (comma list)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-21 10:45:23 -05:00
parent f65db23b58
commit bed75d1b0f
2 changed files with 24 additions and 6 deletions
+11 -2
View File
@@ -19,10 +19,18 @@ let provider = null, wallet = null, ticking = false;
function enabled() { return !!(process.env.HUNT_WALLET_KEY && process.env.HUNT_RPC); }
function init() {
if (!enabled()) return false;
provider = new ethers.JsonRpcProvider(process.env.HUNT_RPC, Number(process.env.HUNT_CHAIN_ID) || undefined);
wallet = new ethers.Wallet(process.env.HUNT_WALLET_KEY.trim(), provider);
rpcs = String(process.env.HUNT_RPC).split(',').map(s => s.trim()).filter(Boolean); rpcAt = 0;
connect();
return true;
}
let rpcs = [], rpcAt = 0;
function connect() {
provider = new ethers.JsonRpcProvider(rpcs[rpcAt % rpcs.length], Number(process.env.HUNT_CHAIN_ID) || undefined);
wallet = new ethers.Wallet(process.env.HUNT_WALLET_KEY.trim(), provider);
}
// a node hiccup is not a failed drip: 5xx, timeouts, connection resets, rate limits, missing responses
const TRANSIENT = /server response 5\d\d|timeout|ETIMEDOUT|ECONNRESET|ECONNREFUSED|EAI_AGAIN|429|rate limit|missing response|could not detect network|bad response|SERVER_ERROR|NETWORK_ERROR/i;
function rotate(reason) { if (rpcs.length > 1) { rpcAt = (rpcAt + 1) % rpcs.length; connect(); console.warn('faucet: RPC rotated to', rpcs[rpcAt % rpcs.length], 'after', reason.slice(0, 80)); } }
function address() { return wallet ? wallet.address : null; }
async function balance() { if (!provider || !wallet) return null; const b = await provider.getBalance(wallet.address); return Number(ethers.formatEther(b)); }
@@ -66,6 +74,7 @@ async function tick(notify) {
// the send itself failed only if no hash was recorded; a hash means the chain has it, leave it 'sent'
const cur = store.read('payouts', []).find(x => x.id === p.id);
if (cur && cur.status === 'sent' && cur.tx) continue;
if (TRANSIENT.test(msg)) { rewards.mark(p.id, { status: 'due', error: 'node: ' + msg.slice(0, 120) }); console.warn('faucet: transient, left due:', p.id, msg.slice(0, 120)); rotate(msg); break; } // next tick, next node
rewards.mark(p.id, { status: 'failed', error: msg.slice(0, 200) });
if (notify) await notify('failed', Object.assign({}, p, { error: String(e.message || e).slice(0, 200) }));
}