Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

eth_estimateGas does not use blockchain's adjustedTime #3528

Open
MicaiahReid opened this issue Aug 11, 2022 · 5 comments · May be fixed by #4287
Open

eth_estimateGas does not use blockchain's adjustedTime #3528

MicaiahReid opened this issue Aug 11, 2022 · 5 comments · May be fixed by #4287

Comments

@MicaiahReid
Copy link
Contributor

MicaiahReid commented Aug 11, 2022

In the blockchain, when a block is being prepared to be mined, the timestamp is adjusted by the chain's internal offset:

if (timestamp == null) {
    timestamp = this.#adjustedTime(previousHeader.timestamp);
  }

  return new RuntimeBlock(
    Quantity.from(previousNumber + 1n),
    previousBlock.hash(),
    this.coinbase,
    minerOptions.blockGasLimit.toBuffer(),
    BUFFER_ZERO,
    Quantity.from(timestamp),
    minerOptions.difficulty,
    previousHeader.totalDifficulty,
    Block.calcNextBaseFee(previousBlock)
  );

However, eth_estimateGas just uses the parent block's timestamp:

const block = new RuntimeBlock(
  Quantity.from((parentHeader.number.toBigInt() || 0n) + 1n),
  parentHeader.parentHash,
  parentHeader.miner,
  tx.gas.toBuffer(),
  parentHeader.gasUsed.toBuffer(),
  parentHeader.timestamp,
  options.miner.difficulty,
  parentHeader.totalDifficulty,
  0n // no baseFeePerGas for estimates
);

This is particularly annoying if you are using Truffle to test a contract that is time dependent because truffle calls an eth_estimateGas before sending your actual transaction. If you use evm_setTime to the time needed for your contract to do what it needs to do, the actual transaction would pass, but Truffle doesn't let you get that far because the eth_estimateGas fails beforehand.

@davidmurdoch
Copy link
Member

I believe this is related to #3226

@MicaiahReid
Copy link
Contributor Author

Hmm, I don't see the relation but would be interested in understanding how!

@davidmurdoch
Copy link
Member

They both create a RuntimeBlock with incorrect parameters.

@MicaiahReid
Copy link
Contributor Author

Oh duh. Thanks!

@jeffsmale90
Copy link
Contributor

Also related to: #3425 ?

@davidmurdoch davidmurdoch moved this to Inbox in Ganache Aug 18, 2022
@davidmurdoch davidmurdoch moved this from Inbox to Backlog in Ganache Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

3 participants