Count Polygon RPC calls by method (DATA_DIR/rpc-count.json every 5 min) for a 24 h measurement
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user