question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement gas estimation

See original GitHub issue

What is wrong?

We need to implement gas estimation for the JSON-RPC interface.

An ideal gas estimation API should take into account the following.

  • total gas used isn’t always right due to gas refunds.
  • transactions can alter execution flow based on the txn gas.

How can it be fixed

This should be implemented using a swappable backend API. Accurate gas estimations are likely to be computationally expensive where-as naive estimations based on gas used are likely to work for most use cases and should be computationally cheap.

The API can be something as simple as a function which takes VM instance and a Transaction instance and returns the gas estimation. It might be appropriate to include this as an API on the Chain and VM as Chain.estimate_transaction_gas() and VM.estimate_transaction_gas()

Strategies

We should first implement a PeekGasUsedStrategy which uses the peek gas usage

  1. run the computation with the gas limit set at the full gas limit for the next pending block.
  2. return the computation.gas_meter.start_gas - computation.gas_metea.gas_remaining for the outer computation.

Then we should implement what I believe is the current strategy used by go-ethereum which starts with running the transaction using the gas limit for the next pending block and then performs a binary search, re-running the transaction at each level of the search until it finds the threshold for which the transaction succeeds/fails.

Note that the binary search can be performed at a higher granularity than 1 gas. From @carver comment, a 1024 granularity should produce approximately a 2x speedup.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
pipermerriamcommented, Jan 18, 2018

I have no idea what I was looking at. Disregard.

1reaction
pipermerriamcommented, Jan 11, 2018

Thanks, I updated the spec to reflect the gas limit and the granularity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Estimating gas for a transaction - Nethereum Documentation
The purpose of this sample is to estimate the gas cost of a simple transaction and modify the assigned values of gas and...
Read more >
Ethereum Gas Exactimation - Truffle Suite
Most of the well-known Ethereum implementations like Geth ¹ and Parity ² use interval halving (binary search) to estimate gas by running transactions...
Read more >
10 + 0 GWEI - ETH Gas Fee Tracker - Blocknative
Join the thousands of traders and devs relying on our ETH gas fee tracker. ... Use the iFrame snipped below to add our...
Read more >
MyCryptoHQ/gas-estimation - GitHub
GitHub - MyCryptoHQ/gas-estimation: EIP-1559 gas estimation library, using the estimation strategy of MyCrypto. ... To install it, you can use npm or yarn...
Read more >
How to Build a Gas Fee Estimator using EIP-1559
Tutorial for how to build a gas fee estimation tool for Ethereum using EIP-1559 methods.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found