fix: prefer configured RPC override over Infura - #773
Conversation
|
@lukiod is attempting to deploy a commit to the Livepeer Foundation Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR fixes RPC endpoint selection so that when NEXT_PUBLIC_L1_RPC_URL / NEXT_PUBLIC_L2_RPC_URL are configured, they are used as the primary RPC URLs instead of Infura (with Infura retained as fallback). This aligns runtime behavior with expectations for local fork testing and reduces unintended traffic to mainnet Infura while preserving production behavior when overrides are not set.
Changes:
- Reordered
NETWORK_RPC_URLS[mainnet]to preferNEXT_PUBLIC_L1_RPC_URLbefore the Infura URL. - Reordered
NETWORK_RPC_URLS[arbitrum]to preferNEXT_PUBLIC_L2_RPC_URLbefore the Infura URL.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
viem's fallback() and the ethers JsonRpcProvider both take the first entry of NETWORK_RPC_URLS, which listed Infura before NEXT_PUBLIC_L1_RPC_URL/NEXT_PUBLIC_L2_RPC_URL. Setting the override made it a backup rather than the active endpoint, so traffic kept going to mainnet Infura -- blocking local fork testing (anvil --fork-url ... has no effect) since blanking INFURA_KEY isn't an option (chains.ts throws without it). Reorder each array so the override comes first when set; Infura remains the fallback, and stays the sole/first entry when no override is configured, so production behavior is unchanged.
c7bf779 to
802ef89
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The change is small, localized, and correctly implements the intended RPC precedence without altering behavior when no override is configured.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
Closes #747.
`lib/chains.ts`'s `NETWORK_RPC_URLS` listed Infura before `NEXT_PUBLIC_L1_RPC_URL`/`NEXT_PUBLIC_L2_RPC_URL`. viem's `fallback()` and the `ethers.providers.JsonRpcProvider` instances both take the first entry, so setting the override made it a backup to Infura rather than the active endpoint — traffic kept going to mainnet Infura. That blocks local fork testing (`anvil --fork-url ... --chain-id 42161` has no effect), and blanking `INFURA_KEY` isn't an option since `chains.ts` throws without it.
Fix: reorder each array so the configured override comes first when set. Infura remains the fallback. When no override is configured, Infura stays the sole/first entry, so production behavior is unchanged.
Verified: