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

avoid unnecessary binary search in gas estimation #876

Merged
merged 9 commits into from
Nov 13, 2023

Conversation

shunjizhan
Copy link
Collaborator

@shunjizhan shunjizhan commented Nov 1, 2023

Change

Currently the eth_estimateGas RPC is slow with a p95 performance of 3.5s. This is because we need to binary search the best passing gasLimit, which calls eth_call repeatedly, usually 5-8 times.

However, in most cases if the contract doesn't have special logics to deal with gas, a gasLimit that is slightly more than gasUsed should make it work. We only need to do binary search if that's not the case.

So we can first check if usedGas * 1.2 works, to avoid binary search in most cases, which should speed up the gas estimation, and respectively reduce node burden, by 5-8X .

Also removed some gas related legacy codes

Screenshot 2023-11-01 at 17 46 54

Test

Added tests to make sure it still works for odd gas contract whose passing gaslimit is much higher than actual used gas

@shunjizhan shunjizhan requested review from xlc and zjb0807 November 1, 2023 10:06
@shunjizhan shunjizhan changed the title add short circuit break for gas estimation avoid unnecessary binary search in gas estimation Nov 1, 2023
* use snapshot for endpoint tests

* to deterministic snapshot

* update snapshot
@shunjizhan shunjizhan merged commit 798e615 into master Nov 13, 2023
@shunjizhan shunjizhan deleted the optimize-estimateGas branch November 13, 2023 05:56
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

Successfully merging this pull request may close these issues.

3 participants