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

How often is eth_chainId called? #1253

Closed
mrwillis opened this issue Jan 26, 2021 · 6 comments
Closed

How often is eth_chainId called? #1253

mrwillis opened this issue Jan 26, 2021 · 6 comments

Comments

@mrwillis
Copy link

Hi Richard,

We have a bunch of event listeners (v5) and we see this request fairly often. Wondering why it's called so frequently.

{method: "eth_chainId", params: [], id: 5267, jsonrpc: "2.0"}
id: 5267
jsonrpc: "2.0"
method: "eth_chainId"
params: []

Thanks!

@mrwillis
Copy link
Author

Realized this is a dupe. Sorry!

@tayvano
Copy link

tayvano commented Jan 26, 2021

We should be friends!

This is what the staticjsonrpcprovider call is for. othewise it checks to make sure the user hasnt changed the network in metamask or whatever

let us know if you figure out a solution for the changes to fallbackproviders that have increased your call load by 4-8x. it seems like our project set ups are similar.

@ricmoo
Copy link
Member

ricmoo commented Jan 27, 2021

@mrwillis Can you link to the dupe?

The base provider will check the chain is on every operation via getNetwork, but most sub-classes override this to short circuit it if they can derive it. What is your setup look like? If you use the InfuraProvider (instead of the JsonRpcProvider with an INFURA URL) for example, zero calls to chainId are made because it is known and cannot change.

It should only double the traffic and not for any of the third-party providers; not sure why it would be 4x to 8x higher. Unless you mean across all backends (not just to one)? In v5 multiple backends are queries simultaneously to make sure the others are not lying. You could increase the stall timeout (how long a backend takes to reply before trying the next) or reduce the quorum to 1. It still should only be a bit higher though... 4x-8x is way took much...

@mrwillis
Copy link
Author

@ricmoo I read this #901

Basically seemed like the recommendation was to use InfuraProvider for Infura. We are actually on matic (sidechain) and use a service called matic-vigil which is basically a matic version of Infura. If we wanted to copy what you did with InfuraProvider to save on # of requests, is StaticJsonRpcProvider the answer here?

@mrwillis mrwillis reopened this Jan 27, 2021
@ricmoo
Copy link
Member

ricmoo commented Jan 27, 2021

That’s correct. The StaticJsonRpcProvider will make the assumption the underlying network cannot change. Which is the case when the network is baked into the URLs. :)

@mrwillis
Copy link
Author

@ricmoo appreciate the continued support. Cannot thank you enough. Will close this for now as the linked issue is effectively this question.

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