Fix and optimize eth_estimateGas API #409
Closed
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.
Prerequisite:
This PR add a
rpc.BlockNumber
input parameters foreth_estimateGas
API because most 3rd-party tools (such as MetaMask, Remix IDE, etc.) require the same parameters for this API.EstimateGas
repeatedly executes a transaction, performing a binary search with multiple gas prices to determine proper pricing. Each call retrieves a new copy of the state https://github.com/BuildOnViction/tomochain/blob/76420ee3ba79120351018b86c1a84c4001ad9064/internal/ethapi/api.go#L1136Because the pending/latest state can be changed during the execution of
EstimateGas
, this can potentially cause strange behaviors.EstimateGas
currently conducts a binary search to determine a suitable gas limit for a tx, and continues searching with a higher gas limit whenever the transaction's execution results in revert. While this makes sense if the reason for revert is out of gas, increasing the gas limit is highly unlikely to allow a non-OOG reverting transaction to succeed (unless it is making unusual use of the GAS opcode).This PR modifies EstimateGas to retrieve the state once and use a copy of it for every call invocation it does. This has two benefits:
Resolve issue:
Supersede:
Reference: