Skip to content

Commit d15c48b

Browse files
authored
Add fallback RPC array feature (#327)
* Improves RPC connection resilience Updates RPC endpoint configuration to support endpoints for fallback. * update tests * format fixes * clear timeout on reject
1 parent e5b492f commit d15c48b

File tree

20 files changed

+326
-183
lines changed

20 files changed

+326
-183
lines changed

components/sections/migrate/__tests__/app-scanning-grid.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ vi.mock('@/config/apps', () => ({
5454
id: 'polkadot',
5555
name: 'Polkadot',
5656
token: { symbol: 'DOT', decimals: 10 },
57-
rpcEndpoint: 'wss://rpc.polkadot.io',
57+
rpcEndpoints: ['wss://rpc.polkadot.io'],
5858
},
5959
],
6060
[
@@ -63,7 +63,7 @@ vi.mock('@/config/apps', () => ({
6363
id: 'kusama',
6464
name: 'Kusama',
6565
token: { symbol: 'KSM', decimals: 12 },
66-
rpcEndpoint: 'wss://kusama-rpc.polkadot.io',
66+
rpcEndpoints: ['wss://kusama-rpc.polkadot.io'],
6767
},
6868
],
6969
[
@@ -72,15 +72,15 @@ vi.mock('@/config/apps', () => ({
7272
id: 'westend',
7373
name: 'Westend',
7474
token: { symbol: 'WND', decimals: 12 },
75-
// No rpcEndpoint - should be filtered out
75+
// No rpcEndpoints - should be filtered out
7676
},
7777
],
7878
]),
7979
polkadotAppConfig: {
8080
id: 'polkadot',
8181
name: 'Polkadot',
8282
token: { symbol: 'DOT', decimals: 10 },
83-
rpcEndpoint: 'wss://rpc.polkadot.io',
83+
rpcEndpoints: ['wss://rpc.polkadot.io'],
8484
},
8585
getChainName: vi.fn((id: string) => {
8686
const names: Record<string, string> = {

components/sections/migrate/app-scanning-grid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const AppScanningGrid = observer(() => {
9595

9696
// Show all available apps (from config), including those still loading
9797
const allApps: AppConfig[] = Array.from(appsConfigs.values())
98-
const appsToSync = allApps.filter(appConfig => appConfig?.rpcEndpoint) as AppConfig[]
98+
const appsToSync = allApps.filter(appConfig => appConfig?.rpcEndpoints && appConfig.rpcEndpoints.length > 0) as AppConfig[]
9999

100100
// Create display apps with enhanced information
101101
const displayApps: App[] = appsToSync.map(config => {

config/apps.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ interface AppConfigJSON {
4949
name: string
5050
bip44Path: string
5151
ss58Prefix: number
52-
rpcEndpoint?: string
52+
rpcEndpoints?: string[]
5353
token: Token
5454
explorer?: AppExplorerConfig
5555
eraTimeInHours?: number
@@ -81,9 +81,9 @@ export interface AppConfig {
8181
*/
8282
ss58Prefix: number
8383
/**
84-
* RPC endpoint for the chain
84+
* RPC endpoints for the chain (with fallback support)
8585
*/
86-
rpcEndpoint?: string
86+
rpcEndpoints?: string[]
8787
/**
8888
* Token configuration
8989
*/
@@ -106,7 +106,7 @@ export const polkadotAppConfig: AppConfig = {
106106
id: 'polkadot',
107107
bip44Path: "m/44'/354'/0'/0'/0'", // 354 = 0x80000162
108108
ss58Prefix: 0,
109-
rpcEndpoint: 'wss://rpc.polkadot.io',
109+
rpcEndpoints: ['wss://rpc.polkadot.io', 'wss://polkadot-rpc.dwellir.com'],
110110
token: {
111111
symbol: 'DOT',
112112
decimals: 10,
@@ -166,13 +166,13 @@ export function getChainName(id: AppId): string {
166166
}
167167

168168
/**
169-
* Get the RPC endpoint for a chain
169+
* Get the RPC endpoints for a chain
170170
* @param id Chain ID
171-
* @returns RPC endpoint or undefined if not available
171+
* @returns RPC endpoints array or undefined if not available
172172
*/
173-
export function getRpcEndpoint(id: AppId): string | undefined {
173+
export function getRpcEndpoints(id: AppId): string[] | undefined {
174174
const app = getAppConfig(id)
175-
return app?.rpcEndpoint
175+
return app?.rpcEndpoints
176176
}
177177

178178
/**

config/appsConfig.json

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Acala",
55
"bip44Path": "m/44'/787'/0'/0'/0'",
66
"ss58Prefix": 10,
7-
"rpcEndpoint": "wss://acala-rpc.aca-api.network",
7+
"rpcEndpoints": ["wss://acala-rpc.aca-api.network", "wss://acala-rpc.dwellir.com"],
88
"token": {
99
"symbol": "ACA",
1010
"decimals": 12
@@ -20,7 +20,7 @@
2020
"name": "Ajuna",
2121
"bip44Path": "m/44'/354'/0'/0'/0'",
2222
"ss58Prefix": 1328,
23-
"rpcEndpoint": "wss://ajuna.ibp.network",
23+
"rpcEndpoints": ["wss://ajuna.ibp.network", "wss://rpc-para.ajuna.network"],
2424
"token": {
2525
"symbol": "AJUN",
2626
"decimals": 12
@@ -36,7 +36,7 @@
3636
"name": "Astar",
3737
"bip44Path": "m/44'/810'/0'/0'/0'",
3838
"ss58Prefix": 5,
39-
"rpcEndpoint": "wss://rpc.astar.network",
39+
"rpcEndpoints": ["wss://rpc.astar.network", "wss://astar-rpc.dwellir.com"],
4040
"token": {
4141
"symbol": "ASTR",
4242
"decimals": 18
@@ -52,7 +52,7 @@
5252
"name": "Bifrost",
5353
"bip44Path": "m/44'/788'/0'/0'/0'",
5454
"ss58Prefix": 6,
55-
"rpcEndpoint": "wss://public-01.mainnet.bifrostnetwork.com/wss",
55+
"rpcEndpoints": ["wss://public-01.mainnet.bifrostnetwork.com/wss", "wss://bifrost-polkadot.ibp.network"],
5656
"token": {
5757
"symbol": "BNC",
5858
"decimals": 12
@@ -68,7 +68,7 @@
6868
"name": "Centrifuge",
6969
"bip44Path": "m/44'/747'/0'/0'/0'",
7070
"ss58Prefix": 36,
71-
"rpcEndpoint": "wss://centrifuge-parachain.api.onfinality.io/public-ws",
71+
"rpcEndpoints": ["wss://centrifuge-parachain.api.onfinality.io/public-ws", "wss://fullnode.centrifuge.io"],
7272
"token": {
7373
"symbol": "CFG",
7474
"decimals": 18
@@ -84,7 +84,7 @@
8484
"name": "Darwinia",
8585
"bip44Path": "m/44'/354'/0'/0'/0'",
8686
"ss58Prefix": 18,
87-
"rpcEndpoint": "wss://darwinia-rpc.dwellir.com",
87+
"rpcEndpoints": ["wss://darwinia-rpc.dwellir.com", "wss://rpc.darwinia.network"],
8888
"token": {
8989
"symbol": "RING",
9090
"decimals": 9
@@ -100,7 +100,7 @@
100100
"name": "Edgeware",
101101
"bip44Path": "m/44'/523'/0'/0'/0'",
102102
"ss58Prefix": 7,
103-
"rpcEndpoint": "wss://edgeware-rpc1.jelliedowl.net",
103+
"rpcEndpoints": ["wss://edgeware-rpc3.jelliedowl.net", "wss://edgeware-rpc2.jelliedowl.net"],
104104
"token": {
105105
"symbol": "EDG",
106106
"decimals": 18
@@ -116,7 +116,7 @@
116116
"name": "HydraDX",
117117
"bip44Path": "m/44'/354'/0'/0'/0'",
118118
"ss58Prefix": 63,
119-
"rpcEndpoint": "wss://hydradx-rpc.dwellir.com",
119+
"rpcEndpoints": ["wss://hydradx-rpc.dwellir.com", "wss://hydration.dotters.network"],
120120
"token": {
121121
"symbol": "HDX",
122122
"decimals": 12
@@ -132,7 +132,7 @@
132132
"name": "Karura",
133133
"bip44Path": "m/44'/686'/0'/0'/0'",
134134
"ss58Prefix": 8,
135-
"rpcEndpoint": "wss://karura-rpc-0.aca-api.network",
135+
"rpcEndpoints": ["wss://karura-rpc-0.aca-api.network", "wss://karura-rpc-1.aca-api.network"],
136136
"token": {
137137
"symbol": "KAR",
138138
"decimals": 12
@@ -163,7 +163,7 @@
163163
"name": "Kusama",
164164
"bip44Path": "m/44'/434'/0'/0'/0'",
165165
"ss58Prefix": 2,
166-
"rpcEndpoint": "wss://kusama-rpc.polkadot.io",
166+
"rpcEndpoints": ["wss://kusama-rpc.polkadot.io", "wss://kusama-rpc.dwellir.com"],
167167
"token": {
168168
"symbol": "KSM",
169169
"decimals": 12
@@ -179,7 +179,7 @@
179179
"name": "People Kusama",
180180
"bip44Path": "m/44'/434'/0'/0'/0'",
181181
"ss58Prefix": 2,
182-
"rpcEndpoint": "wss://people-kusama.api.onfinality.io/public-ws",
182+
"rpcEndpoints": ["wss://people-kusama.api.onfinality.io/public-ws", "wss://people-kusama-rpc.dwellir.com"],
183183
"token": {
184184
"symbol": "KSM",
185185
"decimals": 12,
@@ -196,7 +196,7 @@
196196
"name": "Nodle",
197197
"bip44Path": "m/44'/1003'/0'/0'/0'",
198198
"ss58Prefix": 37,
199-
"rpcEndpoint": "wss://nodle-rpc.dwellir.com",
199+
"rpcEndpoints": ["wss://nodle-rpc.dwellir.com", "wss://nodle-parachain.api.onfinality.io/public-ws"],
200200
"token": {
201201
"symbol": "NODL",
202202
"decimals": 11
@@ -223,7 +223,7 @@
223223
"name": "Pendulum",
224224
"bip44Path": "m/44'/354'/0'/0'/0'",
225225
"ss58Prefix": 56,
226-
"rpcEndpoint": "wss://rpc-pendulum.prd.pendulumchain.tech",
226+
"rpcEndpoints": ["wss://rpc-pendulum.prd.pendulumchain.tech"],
227227
"token": {
228228
"symbol": "PEN",
229229
"decimals": 12
@@ -239,7 +239,7 @@
239239
"name": "Phala",
240240
"bip44Path": "m/44'/354'/0'/0'/0'",
241241
"ss58Prefix": 30,
242-
"rpcEndpoint": "wss://phala-rpc.dwellir.com",
242+
"rpcEndpoints": ["wss://phala-rpc.dwellir.com", "wss://phala.api.onfinality.io/public-ws"],
243243
"token": {
244244
"symbol": "PHA",
245245
"decimals": 12
@@ -255,7 +255,10 @@
255255
"name": "Polkadex",
256256
"bip44Path": "m/44'/799'/0'/0'/0'",
257257
"ss58Prefix": 88,
258-
"rpcEndpoint": "wss://polkadex.api.onfinality.io/public-ws",
258+
"rpcEndpoints": [
259+
"wss://polkadex.api.onfinality.io/public-ws",
260+
"wss://api-polkadex-mainnet.dwellir.com/63708dfe-972e-4f49-b0cb-2b8676052a14"
261+
],
259262
"token": {
260263
"symbol": "PDEX",
261264
"decimals": 12
@@ -271,7 +274,7 @@
271274
"name": "Kusama Asset Hub",
272275
"bip44Path": "m/44'/434'/0'/0'/0'",
273276
"ss58Prefix": 2,
274-
"rpcEndpoint": "wss://asset-hub-kusama-rpc.dwellir.com",
277+
"rpcEndpoints": ["wss://asset-hub-kusama-rpc.dwellir.com", "wss://sys.ibp.network/asset-hub-polkadot"],
275278
"token": {
276279
"symbol": "KSM",
277280
"decimals": 12,
@@ -303,7 +306,7 @@
303306
"name": "XXNetwork",
304307
"bip44Path": "m/44'/1955'/0'/0'/0'",
305308
"ss58Prefix": 55,
306-
"rpcEndpoint": "wss://xxnetwork-rpc.dwellir.com",
309+
"rpcEndpoints": ["wss://xxnetwork-rpc.dwellir.com"],
307310
"token": {
308311
"symbol": "XX",
309312
"decimals": 9

lib/__tests__/account.int.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ describe('Account Integration', () => {
2424
beforeAll(async () => {
2525
// Connect to all endpoints in parallel for faster setup
2626
const [result, assetHubResult, peopleResult] = await Promise.all([
27-
getApiAndProvider(KUSAMA_RPC),
28-
getApiAndProvider(KUSAMA_ASSET_HUB_RPC),
29-
getApiAndProvider(KUSAMA_PEOPLE_RPC),
27+
getApiAndProvider([KUSAMA_RPC]),
28+
getApiAndProvider([KUSAMA_ASSET_HUB_RPC]),
29+
getApiAndProvider([KUSAMA_PEOPLE_RPC]),
3030
])
3131

3232
api = result.api

0 commit comments

Comments
 (0)