diff --git a/chain.js b/chain.js index cad45e9..6c83383 100644 --- a/chain.js +++ b/chain.js @@ -77,8 +77,14 @@ function getConfig() { function reloadConfig() { cfg = null; return getConfig(); } // ---- JSON-RPC with fallback rotation ---- +// 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; function rpcOnce(url, method, params) { + rpcCount(method); return new Promise((resolve, reject) => { const body = JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }); const u = new URL(url);