feat: fetch chain config from remote URL and remove HTML scraping#2709
feat: fetch chain config from remote URL and remove HTML scraping#2709
Conversation
Removes bundled chain files (chains.json, extra-chains.json, sourcify-chains-default.json) and replaces them with a remote fetch from a URL configured via config.chains.remoteUrl. This decouples the server from chain data, enabling the separate sourcifyeth/sourcify-chains repo to own chain generation and trigger server restarts on updates. Loading priority: 1. src/sourcify-chains.json (self-hosted override, unchanged) 2. fetch from config.chains.remoteUrl at startup (3 retries, 3s delay) Changes: - Remove chains.json, extra-chains.json, sourcify-chains-default.json - Add config.chains.remoteUrl setting pointing to sourcifyeth/sourcify-chains - Refactor sourcify-chains.ts: export async initializeSourcifyChains() and a mutable sourcifyChainsMap populated at startup; pass etherscanApi to SourcifyChain constructor so /chains and Etherscan key lookup work - Wrap CLI startup in async IIFE; await initializeSourcifyChains() so getEtherscanApiKeyForEachChain() sees the populated chain map - ServerFixture: use LOCAL_CHAINS as default so tests don't need remote URL - chain-tests.spec.ts: replace static JSON import with async initializeSourcifyChains() + sourcifyChainsMap; use Mocha --delay - Add --delay to test:chains mocha invocation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
After switching to async chain loading, sourcifyChainsMap is empty until initializeSourcifyChains() is called. Tests that access the map during registration (it() description strings) or during test execution now fail with "Cannot read properties of undefined". Fixes: - ServerFixture.before(): call initializeSourcifyChains() so all integration tests have the full chain map populated at runtime - etherscan.spec.ts: replace sourcifyChainsMap[id].name in it() description strings with testChainId (map is empty at registration time) - contract-creation-util.spec.ts: add before() calling initializeSourcifyChains() (test doesn't use ServerFixture) - verificationWorker.spec.ts: same — add initializeSourcifyChains() before the sourcifyChainsMap-based stub setup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@claude review |
|
Claude finished @kuzdogan's task in 3m 4s —— View job PR Review
Overall this is a well-motivated change — removing 57k lines of bundled JSON and the fragile HTML-scraping infrastructure is a clear win. The implementation is mostly clean but there are a few items worth addressing. Issues1. sourcifyChainsMap[chainId] = new SourcifyChain({ ... }); // chainId is numbervs. line 282: sourcifyChainsMap[chain.chainId.toString()] = chain; // explicit string
2. Unusual TypeScript non-null assertion pattern ( if (!chainsExtensions!) {The let chainsExtensions: SourcifyChainsExtensionsObjectWithHeaderEnvName | undefined;
// ... fetch loop ...
if (!chainsExtensions) {
throw new Error(...);
}3. Lost chain metadata from The old code merged new SourcifyChain({
name: extension.sourcifyName,
chainId,
supported,
rpcs,
etherscanApi,
fetchContractCreationTxUsing,
});Fields like 4. PR description vs. actual The PR description says "ServerFixture uses chains: fixtureOptions_?.chains || sourcifyChainsMap,And 5. No startup resilience / offline fallback Previously the server could start offline (chains were bundled). Now if the remote URL is unreachable after 3 retries, the server exits with a fatal error. This changes the operational profile significantly. Worth documenting as a known trade-off, and potentially worth adding a config option like 6. No integrity check on remote config The fetched JSON is parsed and used directly. If the GitHub raw URL is ever served with unexpected content (CDN misconfiguration, compromised file, etc.), there's no schema validation before Minor notes
What's working well
|
Summary
This PR makes two related changes to how Sourcify manages chain configuration:
1. Remote chain config
Removes the bundled
chains.json,sourcify-chains-default.json, andextra-chains.jsonfrom the server, replacing them with a remote fetch at startup from
sourcifyeth/sourcify-chains.
sourcify-chains-default.jsonfrom the remote URL on startupsourcify-chains.jsonoverride still supported for self-hosted instanceschains.remoteUrlindefault.jspoints to the published chain listnightly CI that pulls from QuickNode, dRPC, Etherscan, and Blockscout APIs
2. Remove blockscoutScrape and etherscanScrape
Removes both HTML-scraping methods for contract creation transaction lookup:
blockscoutApi, deprecated, or moved toadditional-chains.json(Bitkub Chain, Velas, Ozone Chain — low activity, no v2 API)With both removed, the entire scraping infrastructure is also deleted:
getScrapeContractCreationFetcher,getCreatorTxByScraping, regex constants.Test changes
chain-tests.spec.ts: replaced staticsourcify-chains-default.jsonimport with asyncinitializeSourcifyChains()+sourcifyChainsMap; uses Mocha--delayflagServerFixture: usesLOCAL_CHAINSas default chains so integration tests don't need a remote URLcontract-creation-util.spec.ts: removed two scrape tests (Blockscout old/new regex)🤖 Generated with Claude Code