scio-labs / use-inkathon

Typesafe React hooks and utility functions that simplify the process of working with Substrate-based networks and ink! smart contracts.
https://inkathon.xyz
GNU General Public License v3.0
50 stars 17 forks source link

Improve RPC selection logic #5

Open wottpal opened 1 year ago

wottpal commented 1 year ago

Currently, the RPC selection is too simple. It picks the first item in the rpcUrls array of a SubstrateChain (see https://github.com/scio-labs/use-inkathon/blob/main/src/provider.tsx#L82) and creates a WsProvider object (which even fails if the provided url is not a websocket).

niklasp commented 9 months ago

+1

peetzweg commented 9 months ago

Not sure how good this applies here but a nice detail pjs apps does, is randomizing rpc endpoints. It's a nice detail to prevent overloading a single rpc and centralization through a single rpc provider.

https://github.com/scio-labs/use-inkathon/assets/839848/e17b4e7e-20bc-4e2a-81a0-13426d9d7cf9

niklasp commented 8 months ago

WsProvider accepts a string array of endpoints in the constructor as well as autoConnectMs: number

https://github.com/polkadot-js/api/blob/329929236846364e9feb316462ee300a1dc42608/packages/rpc-provider/src/ws/index.ts#L111

wottpal commented 6 months ago

The only problem I see with passing an array of strings to the WsProvider is that this would still not accompany for a given mixed set of https:// & wss:// endpoints. But I would be fine with having this implemented (after filtering the strings) as suggested … but have also never tried this approach and don't know how well this is handled by polkadot.js internally. Anyone? cc @peetzweg

peetzweg commented 6 months ago

When I had this issue described in #73 I've searched the parameters and docs of pjs but I wasn't able to find a feature like this. I know that pjs tries to reconnect if the connection drops or attempts to initialize it again, however it does not offer a way to specify more than a single provider.