Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support gas estimates with block identifier #189

Merged
merged 1 commit into from
May 29, 2020

Conversation

wolovim
Copy link
Member

@wolovim wolovim commented May 21, 2020

What was wrong?

Re: ethereum/web3.py#1639, py-evm supports gas estimation with block identifiers, but eth-tester didn't yet pass those values through.

How was it fixed?

estimate_gas now accepts and processes a block_number.

Feedback appreciated @carver (and anyone else interested); I processed the minimum surface area of this package required to get this far and get passing tests on the Web3 side.

To-Do:

Cute Animal Picture

CHANGELOG Outdated Show resolved Hide resolved
Copy link
Contributor

@carver carver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that the block number was already supported by _get_normalized_and_unsigned_evm_transaction. Makes this a short and sweet PR.

Only other thing to add is a test. See this for inspiration:

https://github.com/ethereum/eth-tester/blob/master/eth_tester/utils/backend_testing.py#L670-L687

The best kind of test would be one that checks that the gas cost is actually different depending on the block supplied. One way to do it would be to estimate the gas cost of running the transaction before the contract was deployed.

eth_tester/backends/pyevm/main.py Outdated Show resolved Hide resolved
Copy link
Contributor

@carver carver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looking at the test, I'm realizing that the assertion is pretty weak, because the estimates are allowed to vary somewhat randomly.

I guess I should have said the best kind of test would be to write a contract that burns gas in a way that's easily detectable by block number, like burning (100k * block_number) gas. But given how much other low-hanging fruit there is for improvement in other places & projects, I'm okay calling this good enough and moving on. 👍 if you want to add an issue to do that ^. (it's right on the border of a Good First Issue: great that nothing else will block on its progress, not good that it will surely require a lot of back and forth as a new test contract is added)

@pipermerriam
Copy link
Member

Bike-shedding over the the way to test:

Contract with a toggle-able flag which just returns immediately or burns a bunch of gas in a loop. Then you can set it and test on either side of the block number where the flag was toggled. Agreed on this being lower priority for testing. Like @carver said, probably better to document the testing approach in a "good first issue".

@wolovim
Copy link
Member Author

wolovim commented May 29, 2020

👍 new issue coming following the merge.

@wolovim wolovim merged commit 276eaeb into ethereum:master May 29, 2020
@wolovim wolovim deleted the contract-estimate-gas branch May 29, 2020 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants