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

Gas Exactimation v2 #1548

Merged
merged 35 commits into from
Nov 24, 2021
Merged

Gas Exactimation v2 #1548

merged 35 commits into from
Nov 24, 2021

Conversation

fedejinich
Copy link
Contributor

@fedejinich fedejinich commented Jun 1, 2021

Description

This is a new gas estimation algorithm, where ESTIMATED_GAS = GAS_USED + GAS_DEDUCTED_REFUNDS

Motivation and Context

This is a second step of @SergioDemianLerner's old PR:

How Has This Been Tested?

Unit tests
DSL tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)
  • Other information:

@fedejinich fedejinich marked this pull request as ready for review July 12, 2021 15:28
@fedejinich fedejinich force-pushed the gas-exactimation-v2 branch 2 times, most recently from 562a114 to 9b95562 Compare August 17, 2021 14:14
@joaquinlpereyra
Copy link
Contributor

joaquinlpereyra commented Aug 25, 2021

👋🏿 Hello.

So I've been looking at this and it seems that:

  • For calls without value, this is the exact gas estimation that was present previously.
  • For calls with value, this is the gas estimation previously plus the STIPEND_COST constant.

This is because res.getDeductedRefund() will return zero always for local calls, as marked by this comment.

This whole addDeductedRefund logic is unused.

As the PR stands, we still won't actually take into account refunds to calculate the necessary gasLimit someone should send.

So all in all, most of the changes are still unimplemented: to take advantage of these this comment needs to addressed.

Also a comment itself warns of the possibility of an overflow. It is true that the user itself would be the only one affected by the overflow by providing a wrong gasLimit, but there's no reason to perform a simple sanity check and failing early at the beginning of an estimateGas RPC call if that were the case, specially as gasValid in the VM is not called for local calls.

Anyway, all in all, I think to truly take advantage of the PR it needs a bit of work still.

@joaquinlpereyra
Copy link
Contributor

Also seems like a great time to implement something like Geth's gascap .

@fedejinich fedejinich force-pushed the gas-exactimation-v2 branch 2 times, most recently from d2a871c to 5ca9436 Compare September 3, 2021 16:35
@rsksmart rsksmart deleted a comment from sonarcloud bot Sep 3, 2021
@fedejinich fedejinich force-pushed the gas-exactimation-v2 branch 2 times, most recently from d2a871c to ba276a7 Compare September 3, 2021 17:16
@fedejinich
Copy link
Contributor Author

fedejinich commented Sep 7, 2021

I guess there is another inconsistency here, the produced exception it's never added to the ProgramResult

@fedejinich fedejinich force-pushed the gas-exactimation-v2 branch 3 times, most recently from d7615a2 to 038ec16 Compare September 8, 2021 14:06
@rsksmart rsksmart deleted a comment from lgtm-com bot Sep 8, 2021
@fedejinich fedejinich force-pushed the gas-exactimation-v2 branch 2 times, most recently from 9c6c8e2 to 11b1265 Compare September 13, 2021 15:10
@fedejinich
Copy link
Contributor Author

Currently this solution it's overestimating by a small difference. This is "good" because it improves the old algorithm (taking account gas "refunds"), and it won't produce failures if you run a transaction with the estimated value.
On this last steps we're working to match exactly the gasNeeded to perform a transaction.

@fedejinich fedejinich force-pushed the gas-exactimation-v2 branch 3 times, most recently from 7db3b4e to 686b939 Compare September 16, 2021 01:11
@sonarcloud
Copy link

sonarcloud bot commented Nov 23, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

94.5% 94.5% Coverage
0.0% 0.0% Duplication

@Vovchyk Vovchyk merged commit 58ce04c into master Nov 24, 2021
@Vovchyk Vovchyk deleted the gas-exactimation-v2 branch November 24, 2021 07:33
@aeidelman aeidelman added this to the Iris v3.2.0 milestone Dec 8, 2021
@Vovchyk Vovchyk mentioned this pull request May 11, 2022
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.

None yet

5 participants