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

FallbackProvider repeatedly requests block numbers #1371

Closed
FrederikBolding opened this issue Mar 16, 2021 · 5 comments
Closed

FallbackProvider repeatedly requests block numbers #1371

FrederikBolding opened this issue Mar 16, 2021 · 5 comments
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@FrederikBolding
Copy link

The FallbackProvider requests the block number here (https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/fallback-provider.ts#L500), for it's internal book-keeping of block numbers.

If a user does multiple requests at once to the FallbackProvider this will cause multiple requests to eth_blockNumber, which should be unnecessary since each request will have the same response. This happens because getBlockNumber() calls _getInternalBlockNumber() with maxAge=0 which doesn't allow it to wait for the existing request. I would say that this is unexpected behaviour.

As a second suggestion, perhaps the FallbackProvider can also wait with fetching the block numbers at all until a request is made that needs them?

@ricmoo ricmoo added the enhancement New feature or improvement. label Mar 25, 2021
@ricmoo
Copy link
Member

ricmoo commented Mar 25, 2021

This seems quite likely and something I should fix. Any two calls to block number during the same event loop should share the same Promise.

I have a few other things I need to get to first, but this is a fairly important change I'll get to as soon as possible.

@ricmoo ricmoo added the on-deck This Enhancement or Bug is currently being worked on. label Apr 2, 2021
@ricmoo
Copy link
Member

ricmoo commented Apr 18, 2021

This should be address in 5.1.1, if you'd like to give it a try. :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Apr 18, 2021
@FrederikBolding
Copy link
Author

FrederikBolding commented Apr 20, 2021

@ricmoo Looks good! We will be experimenting with it further!

Would it be possible to not request the block numbers at all up front? In our use case we don't usually query data for anything other than latest, so from reading the code the requested block number shouldn't even be used. I guess it could be turned off via configuration or something like that if you prefer this way of handling block numbers.

pull bot pushed a commit to shapeshift/ethers.js that referenced this issue Jun 4, 2021
@ricmoo
Copy link
Member

ricmoo commented May 14, 2022

This change won't make it in v5, as it is somewhat low-level behaviour that might have other ramifications, but in v6 the AbstractProvider makes no requests until it is actually used, including for block number. :)

@ricmoo ricmoo closed this as completed May 14, 2022
@micwallace
Copy link

@ricmoo I'm still noticing that these requests are still made, even if quorum is 1 and stallTimeout is set to 5 seconds.
I guess it checks the block number of each provider before each request, even if only 1 provider is used?

I may have time to submit a PR this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

3 participants