trufflesuite / ganache

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
2.61k stars 675 forks source link

fix: use adjusted time on estimate gas when latest block is being used #4287

Open luzzif opened 1 year ago

luzzif commented 1 year ago

When estimating gas, use the adjusted timestamp in case the latest block tag is being used. This helps avoid some errors in time-dependent contracts when using Ganache in fork mode.

Should fix https://github.com/trufflesuite/ganache/issues/3528.

This is my first PR here, would love some guidance.

luzzif commented 1 year ago

A bit of delay on this but... I just implemented the same logic on eth_call on a local fork, but using a slightly different way. I made the readyNextBlock in the blockchain class public and when latest is passed as the block I use that instead of the standard built RuntimeBlock. I wonder if we could simplify the implementation of the eth_estimateGas logic by doing the same here. The only thing we probably need to change is that I noticed that in the eth_estimateGas case the gas limit defaults to the miner's call gas limit instead of the default block gas limit used in the standard readyNextBlock function.