Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve RPC selection logic #5

Open
1 of 2 tasks
wottpal opened this issue Jan 13, 2023 · 5 comments
Open
1 of 2 tasks

Improve RPC selection logic #5

wottpal opened this issue Jan 13, 2023 · 5 comments

Comments

@wottpal
Copy link
Member

wottpal commented Jan 13, 2023

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).

  • It must be determined whether it's a wss/https rpc url (e.g. via regex) and create the according provider object
  • If an RPC connection fails multiple times it should try the next rpc (until the first one works). Otherwise, providing a full list of RPCs somehow makes no sense.
@niklasp
Copy link
Contributor

niklasp commented Feb 14, 2024

+1

@peetzweg
Copy link
Collaborator

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.

Screen.Recording.2024-02-15.at.10.43.51.mov

@niklasp
Copy link
Contributor

niklasp commented Feb 18, 2024

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
Copy link
Member Author

wottpal commented May 3, 2024

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
Copy link
Collaborator

peetzweg commented May 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants