From c09a29e1493195b147ef26b0e1a61ba4b35e8bb6 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Tue, 28 Nov 2023 19:42:33 +0300 Subject: [PATCH 1/3] feat: split env PREFILL_UNSAFE_EL_RPC_URLS to 1, 5, 17000 chains --- .env.example | 4 +++- .github/workflows/ci-ipfs-test-production.yml | 4 +++- .github/workflows/ci-ipfs-testnet.yml | 4 +++- .github/workflows/ci-ipfs.yml | 4 +++- config/rpc.ts | 11 ++++++++++- config/types.ts | 12 ++++++++++-- env-dynamics.mjs | 8 +++++++- utils/parse-env-config.ts | 7 ++++++- 8 files changed, 45 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 59f3f5dde..35bde4ae2 100644 --- a/.env.example +++ b/.env.example @@ -4,7 +4,9 @@ EL_RPC_URLS_5= EL_RPC_URLS_17000= # IPFS prefill RPC URLs - list of URLs delimited by commas -PREFILL_UNSAFE_EL_RPC_URLS= +PREFILL_UNSAFE_EL_RPC_URLS_1= +PREFILL_UNSAFE_EL_RPC_URLS_5= +PREFILL_UNSAFE_EL_RPC_URLS_17000= # supported networks for connecting wallet SUPPORTED_CHAINS=1,17000 diff --git a/.github/workflows/ci-ipfs-test-production.yml b/.github/workflows/ci-ipfs-test-production.yml index f3fb96b69..12714bd6e 100644 --- a/.github/workflows/ci-ipfs-test-production.yml +++ b/.github/workflows/ci-ipfs-test-production.yml @@ -39,7 +39,9 @@ jobs: REWARDS_BACKEND_BASE_PATH: ${{ vars.REWARDS_BACKEND_BASE_PATH }} WQ_API_BASE_PATH: ${{ vars.WQ_API_BASE_PATH }} ETH_API_BASE_PATH: ${{ vars.ETH_API_BASE_PATH }} - PREFILL_UNSAFE_EL_RPC_URLS: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS }} + PREFILL_UNSAFE_EL_RPC_URLS_1: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_1 }} + PREFILL_UNSAFE_EL_RPC_URLS_5: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_5 }} + PREFILL_UNSAFE_EL_RPC_URLS_17000: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_17000 }} WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }} - uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/ci-ipfs-testnet.yml b/.github/workflows/ci-ipfs-testnet.yml index e4df1dbe3..b083cc1ce 100644 --- a/.github/workflows/ci-ipfs-testnet.yml +++ b/.github/workflows/ci-ipfs-testnet.yml @@ -39,7 +39,9 @@ jobs: REWARDS_BACKEND_BASE_PATH: ${{ vars.REWARDS_BACKEND_BASE_PATH }} WQ_API_BASE_PATH: ${{ vars.WQ_API_BASE_PATH }} ETH_API_BASE_PATH: ${{ vars.ETH_API_BASE_PATH }} - PREFILL_UNSAFE_EL_RPC_URLS: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS }} + PREFILL_UNSAFE_EL_RPC_URLS_1: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_1 }} + PREFILL_UNSAFE_EL_RPC_URLS_5: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_5 }} + PREFILL_UNSAFE_EL_RPC_URLS_17000: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_17000 }} WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }} - uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/ci-ipfs.yml b/.github/workflows/ci-ipfs.yml index efeea54be..801fb55ad 100644 --- a/.github/workflows/ci-ipfs.yml +++ b/.github/workflows/ci-ipfs.yml @@ -55,7 +55,9 @@ jobs: REWARDS_BACKEND_BASE_PATH: ${{ vars.REWARDS_BACKEND_BASE_PATH }} WQ_API_BASE_PATH: ${{ vars.WQ_API_BASE_PATH }} ETH_API_BASE_PATH: ${{ vars.ETH_API_BASE_PATH }} - PREFILL_UNSAFE_EL_RPC_URLS: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS }} + PREFILL_UNSAFE_EL_RPC_URLS_1: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_1 }} + PREFILL_UNSAFE_EL_RPC_URLS_5: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_5 }} + PREFILL_UNSAFE_EL_RPC_URLS_17000: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_17000 }} WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }} - uses: actions/upload-artifact@v3 with: diff --git a/config/rpc.ts b/config/rpc.ts index c08398ac7..5304b3deb 100644 --- a/config/rpc.ts +++ b/config/rpc.ts @@ -17,10 +17,19 @@ export const useGetRpcUrlByChainId = () => { return useCallback( (chainId: CHAINS) => { + // Needs this condition 'cause in 'providers/web3.tsx' we add `wagmiChains.polygonMumbai` to supportedChains + // so, here chainId = 80001 is arriving which to raises an invariant + if (!clientConfig.supportedChainIds.includes(chainId)) { + // Has no effect on functionality. Just a fix. + // Return empty string as stub + // (see: 'providers/web3.tsx' --> jsonRpcBatchProvider --> getStaticRpcBatchProvider) + return ''; + } + if (dynamics.ipfsMode) { const rpc = clientConfig.savedClientConfig.rpcUrls[chainId] || - clientConfig.prefillUnsafeElRpcUrls?.[0]; + clientConfig.prefillUnsafeElRpcUrls[chainId]?.[0]; invariant(rpc, '[useGetRpcUrlByChainId] RPC is required!'); return rpc; diff --git a/config/types.ts b/config/types.ts index 85387e082..48c21d7bb 100644 --- a/config/types.ts +++ b/config/types.ts @@ -1,7 +1,11 @@ +import { CHAINS } from 'utils/chains'; + export type EnvConfigRaw = { defaultChain: string | number; supportedChains: number[]; - prefillUnsafeElRpcUrls: string[]; + prefillUnsafeElRpcUrls1: string[]; + prefillUnsafeElRpcUrls5: string[]; + prefillUnsafeElRpcUrls17000: string[]; ipfsMode: boolean; walletconnectProjectId: string; }; @@ -9,7 +13,11 @@ export type EnvConfigRaw = { export type EnvConfigParsed = { defaultChain: number; supportedChainIds: number[]; - prefillUnsafeElRpcUrls: string[]; + prefillUnsafeElRpcUrls: { + [CHAINS.Mainnet]: string[]; + [CHAINS.Goerli]: string[]; + [CHAINS.Holesky]: string[]; + }; ipfsMode: boolean; walletconnectProjectId: string; }; diff --git a/env-dynamics.mjs b/env-dynamics.mjs index 7d8dd481a..60d85d5c3 100644 --- a/env-dynamics.mjs +++ b/env-dynamics.mjs @@ -37,7 +37,13 @@ export const walletconnectProjectId = process.env.WALLETCONNECT_PROJECT_ID; export const ipfsMode = toBoolean(process.env.IPFS_MODE); /** @type string[] */ -export const prefillUnsafeElRpcUrls = process.env.PREFILL_UNSAFE_EL_RPC_URLS?.split(',') ?? []; +export const prefillUnsafeElRpcUrls1 = process.env.PREFILL_UNSAFE_EL_RPC_URLS_1?.split(',') ?? []; + +/** @type string[] */ +export const prefillUnsafeElRpcUrls5 = process.env.PREFILL_UNSAFE_EL_RPC_URLS_5?.split(',') ?? []; + +/** @type string[] */ +export const prefillUnsafeElRpcUrls17000 = process.env.PREFILL_UNSAFE_EL_RPC_URLS_17000?.split(',') ?? []; /** @type string */ export const widgetApiBasePathForIpfs = process.env.WIDGET_API_BASE_PATH_FOR_IPFS; diff --git a/utils/parse-env-config.ts b/utils/parse-env-config.ts index be035ada3..c6fc5e252 100644 --- a/utils/parse-env-config.ts +++ b/utils/parse-env-config.ts @@ -1,10 +1,15 @@ import { EnvConfigRaw, EnvConfigParsed } from 'config/types'; +import { CHAINS } from 'utils/chains'; export const parseEnvConfig = (envConfig: EnvConfigRaw): EnvConfigParsed => { return { defaultChain: Number(envConfig.defaultChain), supportedChainIds: envConfig.supportedChains, - prefillUnsafeElRpcUrls: envConfig.prefillUnsafeElRpcUrls, + prefillUnsafeElRpcUrls: { + [CHAINS.Mainnet]: envConfig.prefillUnsafeElRpcUrls1, + [CHAINS.Goerli]: envConfig.prefillUnsafeElRpcUrls5, + [CHAINS.Holesky]: envConfig.prefillUnsafeElRpcUrls17000, + }, ipfsMode: envConfig.ipfsMode, walletconnectProjectId: envConfig.walletconnectProjectId, }; From 24ac5955cbc1ab82078d592b16dd1824aa7fec72 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 29 Nov 2023 12:34:41 +0300 Subject: [PATCH 2/3] fix: cond for useGetRpcUrlByChainId for Mainnet --- config/rpc.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/rpc.ts b/config/rpc.ts index 5304b3deb..7782ecf16 100644 --- a/config/rpc.ts +++ b/config/rpc.ts @@ -19,7 +19,11 @@ export const useGetRpcUrlByChainId = () => { (chainId: CHAINS) => { // Needs this condition 'cause in 'providers/web3.tsx' we add `wagmiChains.polygonMumbai` to supportedChains // so, here chainId = 80001 is arriving which to raises an invariant - if (!clientConfig.supportedChainIds.includes(chainId)) { + // chainId = 1 we need anytime! + if ( + chainId !== CHAINS.Mainnet && + !clientConfig.supportedChainIds.includes(chainId) + ) { // Has no effect on functionality. Just a fix. // Return empty string as stub // (see: 'providers/web3.tsx' --> jsonRpcBatchProvider --> getStaticRpcBatchProvider) From e46a0e4fda488809bf31d26201c19b0aa6fc7eba Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 29 Nov 2023 13:22:38 +0300 Subject: [PATCH 3/3] refactor: for ipfs prod and stagging only mainnet rpc --- .github/workflows/ci-ipfs-test-production.yml | 2 -- .github/workflows/ci-ipfs.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/.github/workflows/ci-ipfs-test-production.yml b/.github/workflows/ci-ipfs-test-production.yml index 12714bd6e..a49604ffb 100644 --- a/.github/workflows/ci-ipfs-test-production.yml +++ b/.github/workflows/ci-ipfs-test-production.yml @@ -40,8 +40,6 @@ jobs: WQ_API_BASE_PATH: ${{ vars.WQ_API_BASE_PATH }} ETH_API_BASE_PATH: ${{ vars.ETH_API_BASE_PATH }} PREFILL_UNSAFE_EL_RPC_URLS_1: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_1 }} - PREFILL_UNSAFE_EL_RPC_URLS_5: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_5 }} - PREFILL_UNSAFE_EL_RPC_URLS_17000: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_17000 }} WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }} - uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/ci-ipfs.yml b/.github/workflows/ci-ipfs.yml index 801fb55ad..e7b44db41 100644 --- a/.github/workflows/ci-ipfs.yml +++ b/.github/workflows/ci-ipfs.yml @@ -56,8 +56,6 @@ jobs: WQ_API_BASE_PATH: ${{ vars.WQ_API_BASE_PATH }} ETH_API_BASE_PATH: ${{ vars.ETH_API_BASE_PATH }} PREFILL_UNSAFE_EL_RPC_URLS_1: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_1 }} - PREFILL_UNSAFE_EL_RPC_URLS_5: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_5 }} - PREFILL_UNSAFE_EL_RPC_URLS_17000: ${{ secrets.PREFILL_UNSAFE_EL_RPC_URLS_17000 }} WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }} - uses: actions/upload-artifact@v3 with: