ethapi: estimate gas multiple consecutive calls on the same state #21106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are multiple occasions where you have to estimate the gas limit in a sequential order, meaning estimate should take state changes made by previous calls into consideration. Current
eth_estimateGascreates a copy of the pending state on each call. Because of this, it is not possible to send out multiple txs that depends on each other at the same time.Good example will be DEXs which requires tokens to be
approve(spender, amount)before executing the trade. Currently some DEXs maintains a gas limit map since the gas limit cannot be estimated usingeth_estimateGaswithout having the tokens approved.At MEW we have to guess the gas limit for batch transactions where we will guess extreme amounts just to be on the safe side and this adds txs that are set with unnecessarily higher gas limits to the pending pool.
This PR will let users estimate gas on the same state. Also it is backwards compatible with current ethereum rpc standard.
{"jsonrpc":"2.0","method":"eth_estimateGasList","params":[[{call0-0}, {call0-1}, {call0-2}]],"id":1}in this case
call0s depends on previous call to be executed on the state.backwards compatible
{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{call1-0}],"id":1}