RPC breaker: bench only for health failures (request errors such as invalid block range move on without benching); drop the discontinued 1rpc.io provider

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-12 11:40:26 -05:00
parent 7dc537ba1f
commit 9c892d4b12
+6 -3
View File
@@ -21,8 +21,8 @@ const CONTRACT = '0x33bdaeefd6d17d80ae53816c916dfb26c4fb2daf';
const RPCS = [ const RPCS = [
'https://polygon-bor-rpc.publicnode.com', 'https://polygon-bor-rpc.publicnode.com',
'https://polygon.gateway.tenderly.co', 'https://polygon.gateway.tenderly.co',
'https://polygon.drpc.org', 'https://polygon.drpc.org'
'https://1rpc.io/matic' // 1rpc.io/matic removed 2026-10-12: answers "This endpoint has been discontinued", HTML pages and rate-limit errors (36 benchings today)
]; ];
// keccak-256 hashes verified against live logs (tx 0x8a74c439…, 0x45e07f27…) // keccak-256 hashes verified against live logs (tx 0x8a74c439…, 0x45e07f27…)
const T_REGISTERED = '0xe4a74887d749eb048f14bfef37b204477f3a5ff67055908b7c8cc62c202aef17'; // MemberRegistered(uint48,address,uint48,uint8) const T_REGISTERED = '0xe4a74887d749eb048f14bfef37b204477f3a5ff67055908b7c8cc62c202aef17'; // MemberRegistered(uint48,address,uint48,uint8)
@@ -137,6 +137,9 @@ let rpcIdx = 0;
// Circuit breaker (2026-10-11): a provider that fails or hangs is benched for RPC_BENCH_MS so the next lookups skip it instead of // Circuit breaker (2026-10-11): a provider that fails or hangs is benched for RPC_BENCH_MS so the next lookups skip it instead of
// each paying the full timeout first (cold member lookups were taking 15 s whenever the round-robin landed on a hanging // each paying the full timeout first (cold member lookups were taking 15 s whenever the round-robin landed on a hanging
// provider). Member lookups also use a short timeout: a healthy provider answers eth_call in well under a second. // provider). Member lookups also use a short timeout: a healthy provider answers eth_call in well under a second.
// bench only for provider-health failures (timeouts, connection errors, rate limits, 5xx). A deterministic JSON-RPC reply such as
// "invalid block range" or "query returned more than N results" is about the request, so the next provider is tried without benching.
const benchable = e => /timeout|timed out|abort|ECONN|EAI_AGAIN|ENOTFOUND|EPIPE|socket|hang up|429|too many|rate.?limit|temporar|internal error|service unavailable|50[234]/i.test(String(e && e.message || e));
const RPC_BENCH_MS = 10 * 60 * 1000; const rpcBenched = new Map(); // url -> benched until (ms) const RPC_BENCH_MS = 10 * 60 * 1000; const rpcBenched = new Map(); // url -> benched until (ms)
const ETH_CALL_TIMEOUT_MS = 4000; const ETH_CALL_TIMEOUT_MS = 4000;
async function rpc(method, params, timeoutMs = 15000, urls = RPCS) { async function rpc(method, params, timeoutMs = 15000, urls = RPCS) {
@@ -160,7 +163,7 @@ async function rpc(method, params, timeoutMs = 15000, urls = RPCS) {
if (urls === RPCS) rpcIdx = (rpcIdx + 1) % urls.length; // round-robin: spread the load, never camp on one provider if (urls === RPCS) rpcIdx = (rpcIdx + 1) % urls.length; // round-robin: spread the load, never camp on one provider
rpcBenched.delete(url); rpcBenched.delete(url);
return j.result; return j.result;
} catch (e) { lastErr = e; rpcBenched.set(url, Date.now() + RPC_BENCH_MS); console.warn('rpc', method, 'failed on', url, '->', String(e.message || e).slice(0, 80), '(benched 10 min)'); } } catch (e) { lastErr = e; const bench = benchable(e); if (bench) rpcBenched.set(url, Date.now() + RPC_BENCH_MS); console.warn('rpc', method, 'failed on', url, '->', String(e.message || e).slice(0, 80), bench ? '(benched 10 min)' : '(request error, next provider)'); }
} }
throw lastErr; throw lastErr;
} }