Skip to content

remove 21 duplicate rpc urls and add a test that catches them - #3106

Open
0xshubhs wants to merge 2 commits into
DefiLlama:mainfrom
0xshubhs:dedupe-rpc-urls
Open

0xshubhs wants to merge 2 commits into
DefiLlama:mainfrom
0xshubhs:dedupe-rpc-urls

Conversation

@0xshubhs

@0xshubhs 0xshubhs commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3067

tests/check-duplicate-keys.js catches duplicate chainId keys, but the rpcs are an array and arrays keep every entry, so the same url listed twice inside one chain was invisible to it. there were 21 across 18 chains.

removes all 21 and adds checkDuplicateRpcUrls() in the same source-parsing style as the existing checks. it normalises trailing slashes and case, so the https://erpc.xinfin.network / https://erpc.xinfin.network/ pair on chain 50 is caught too.

where the same url appeared once as a bare string and once as an object, the object is kept; it carries tracking and trackingDetails, so nothing is lost. that covers 8 of them (13371, 16600, 20230825, 3501, 50001, 7869, 11297108099). the rest were identical entries and the first is kept.

one needs your call. chain 534351 had https://rpc.ankr.com/scroll_sepolia_testnet twice with the same privacyStatement.ankr but disagreeing on tracking, one "limited", one "none". i kept the first ("limited") because it is the conservative claim, not because i think it is right: ankr is inconsistent across the whole file (50 entries "none", 16 "limited", 3 "yes"), so there is no convention to follow. happy to flip it if "none" is correct, and the wider ankr inconsistency is probably worth its own pass.

$ node tests/check-duplicate-keys.js
✓ No duplicate chainId keys found in extraRpcs (checked 1024 keys)
✓ No duplicate keys found in chainIds (checked 311 keys)
✓ No duplicate rpc urls found in extraRpcs (checked 2774 urls)
✓ All duplicate key checks passed!

and with a duplicate put back:

ERROR: Duplicate rpc urls found in extraRpcs:
  - 50: https://rpc.xdcrpc.com/
✗ 1 test(s) failed:
  - Duplicate rpc urls found in extraRpcs: 1

@Define101

Copy link
Copy Markdown
Member

function checkDuplicateRpcUrls() {
console.log("Checking extraRpcs for duplicate rpc urls within a chain...");
const filePath = path.join(__dirname, "../constants/extraRpcs.js");
const lines = fs.readFileSync(filePath, "utf-8").split("\n");
const normalize = (url) => url.trim().replace(/\/+$/, "").toLowerCase();
const duplicates = [];
let chainId = null;
let inRpcs = false;
let seen = new Set();
let checked = 0;
for (const line of lines) {
const chainMatch = line.match(/^\s{2}(\d+):\s*\{/);
if (chainMatch) {
chainId = chainMatch[1];
inRpcs = false;
seen = new Set();
continue;
}
if (/^\s{4}rpcs:\s*\[/.test(line)) {
inRpcs = true;
continue;
}
if (inRpcs && /^\s{4}\],/.test(line)) {
inRpcs = false;
continue;
}
if (!inRpcs || chainId === null) continue;
const urlMatch =
line.match(/^\s{6}"((?:https?|wss?):\/\/[^"]+)",?\s*$/) ||
line.match(/^\s{8}url:\s*"([^"]+)"/);
if (!urlMatch) continue;
const key = normalize(urlMatch[1]);
checked++;
if (seen.has(key)) {
duplicates.push(`${chainId}: ${urlMatch[1]}`);
} else {
seen.add(key);
}
}
if (duplicates.length > 0) {
console.error("ERROR: Duplicate rpc urls found in extraRpcs:");
duplicates.forEach((d) => console.error(` - ${d}`));
throw new Error(`Duplicate rpc urls found in extraRpcs: ${duplicates.length}`);
}
console.log(`✓ No duplicate rpc urls found in extraRpcs (checked ${checked} urls)`);
}
) misses one-line RPC arrays: it counts 2,774 URLs while the module exports 2,982 entries.

@0xshubhs

Copy link
Copy Markdown
Contributor Author

you are right, thanks. the line scan only saw urls on their own line at fixed indentation, so every single-line rpcs: [...] array was skipped: 2,774 checked against 2,982 exported, 208 missed.

e7f0890 drops the line parsing for this check. duplicate keys have to be read from source because an import keeps only the last one, but arrays survive an import intact, so it now imports extraRpcs the same way the syntax check does and walks every rpcs array. it reports checked 2982 urls on this branch.

rechecked with the complete count: this branch has no duplicates, and neither does a trial merge with current main (2,972 urls). main on its own still has the 21 this pr removes. i also injected a duplicate into a one-line array (chain 1975, rpcs: ["https://rpc.onuschain.io"]) and into a multi-line one (122); the test fails on both, and the first is the case the old scan would have passed.

@github-actions

Copy link
Copy Markdown
Contributor

Validation failed for chain files. Please check the workflow logs for details.

Error message:

Validation failed for chainid-11941.js: Chain name should be an object
Validation failed for chainid-402.js: Chain chain is mandatory

@0xshubhs

0xshubhs commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

On the red validate check here: it is not this PR. Filed the detail as #3226.

Short version. The workflow computes its changed-file list as
git diff base.sha github.sha, and under pull_request_target github.sha is the base branch head,
so that window is "everything merged to main since this PR opened" rather than this PR's changes.
This PR opened 2026-09-01, so the window now holds 27 additionalChainRegistry/ files added by
other people
, and the run failed on two of them:

chainid-11941.js: Chain name should be an object    features is an array of plain strings
chainid-402.js:   Chain chain is mandatory          the file has no chain field

This PR's diff is constants/extraRpcs.js and tests/check-duplicate-keys.js only. Being the oldest
open PR touching extraRpcs.js is the whole reason it draws the widest window.

Replaying the validator over the registry, 8 of 511 files fail it today, so any PR touching
extraRpcs.js fails if one of those 8 lands in its window. #3226 has the breakdown, the upstream
values for the two JuChain files, and the one case (402's chain) where I will not guess a value.

The duplicate-key test itself is unchanged since e7f0890 and still reports checked 2982 urls with
no duplicates on this branch.

@0xshubhs

0xshubhs commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto current main; validate now passes.

Nothing in the diff changed: still -57 in extraRpcs.js and +53 in tests/check-duplicate-keys.js, and node tests/check-duplicate-keys.js reports 2,972 urls checked with no duplicates. The red check was the stale base.sha window described in #3226, not this branch. Ready for review.

(Fixing a previous version of this comment that lost two code spans to shell quoting.)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

21 duplicate rpc urls across 18 chains, the duplicate-key test does not cover them

2 participants