From 6191c07fa5012d5edc87ee1f11dd51466e0d0ae3 Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 6 Oct 2026 08:47:11 -0500 Subject: [PATCH] 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 --- chain.js | 6 ++++++ 1 file changed, 6 insertions(+) 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);