diff --git a/chain.js b/chain.js index 4937dbc..3715275 100644 --- a/chain.js +++ b/chain.js @@ -128,11 +128,17 @@ function saveState() { // ranged getLogs: publicnode and tenderly take a 2000-block span; drpc and 1rpc cap at 50 const LOG_RPCS = ['https://polygon-bor-rpc.publicnode.com', 'https://polygon.gateway.tenderly.co']; +// RPC call counter (2026-10-06, Marty: measure 24 h of Polygon traffic before choosing a paid endpoint): counts every request +// this module sends, by method, and writes DATA_DIR/rpc-count.json every 5 minutes. Read-only bookkeeping; no behaviour change. +const RPC_COUNT = { since: Date.now(), m: {} }; +const rpcCount = method => { RPC_COUNT.m[method] = (RPC_COUNT.m[method] || 0) + 1; }; +setInterval(() => { try { fs.writeFileSync(path.join(DATA_DIR, 'rpc-count.json'), JSON.stringify(Object.assign({ at: Date.now() }, RPC_COUNT))); } catch (e) {} }, 300000).unref(); let rpcIdx = 0; async function rpc(method, params, timeoutMs = 15000, urls = RPCS) { let lastErr = new Error('no rpc'); for (let i = 0; i < urls.length; i++) { const url = urls[(rpcIdx + i) % urls.length]; + rpcCount(method); try { const ctrl = new AbortController(); const t = setTimeout(() => ctrl.abort(), timeoutMs);