Open fvictorio opened 2 years ago
I discussed with @alcuadrado this checklist item in the Issue description: "Investigate if we can improve the performance of our gas estimation. There might be some low-hanging fruit there."
We looked through the code together, and we decided that it wasn't worth doing anything about. Consequently, I've removed that checklist item from the description.
This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days.
The value of the
gas
config of the Hardhat network is equal to the block gas limit by default. For the rest of the networks, the default value is"auto"
, which means thateth_estimateGas
is used when an explicit gas limit is not specified. The reason this value is different for the Hardhat network is performance: if you don't estimate the gas, transactions are executed significantly faster.This was fine before the London hardfork, but now this default behavior causes an issue in a fairly common situation:
1) You are forking mainnet. This means that (by default) the base fee will match the one in the mainnet. 2) You impersonate an account that doesn't have a lot of ETH (unlike the default ones, that have 1000 ETH each)
These two factors mean that the base price of the tx (
gasLimit * gasPrice
) will likely be higher than the balance of the impersonated account. This leads to an error that is frequently being reported:The solution here is easy: to use
"auto"
as the defaultgas
value for the Hardhat network too. This will have an impact on our performance, so to partially compensate for that, we also need to add a "Performance optimization" guide. This should include the tip of using a fixed gas limit for faster execution, and also some explanation about pinning a block number when forking (this is already documented).