-
Notifications
You must be signed in to change notification settings - Fork 373
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
Add gno std
package function GasUsed
#1998
Comments
If it's possible to pull various data from the gno/gnovm/pkg/gnolang/alloc.go Lines 9 to 12 in de2fc45
|
I like this idea a lot, we can take inspiration from what Solidity has: |
I am interested in this issue. I gonna try to implement this one 🙏 |
-> Should we defined the amount of gas in |
I was discussing with @moul on whether we want something like this. We should always consider the implication of all the information we're giving to the developer. Like for the discussions we've had about whether to have Let's take a look at the two use cases in the OP:
I'm unsure about the second one; but the first one sounds like it's more of a candidate for testing. It's something we partly have with the
Exposing gas on-chain, I think, also poses the risk of restricting us more if we want to change the way we count gas in the future. So I'm thinking we should have this function either just as a testing standard library, or not at all. |
I suggest we start by replacing execution time in unit tests with consumed gas, or keeping both side by side. This should be sufficient for most optimization needs, in my opinion. Next, I believe the best targets are:
I would avoid adding |
In my view, displaying Beside it, the |
A display with the execution time+consumed gas isn't something that is going to tire anyone's eyes. |
This would be a great feature for Shiken @moul , since it would be useful to run the code onchain instead of off chain and avoid certain tasks for the API. |
Description
Let's add a function called
GasUsed
, or some name with the same sentiment, that returns the gas used until the current point in execution. It can obtain gas used from the gas meter recently added to the machine -- https://github.com/gnolang/gno/blob/master/gnovm/pkg/gnolang/machine.go#L61. To prevent abusing this function, we should define a reasonable amount of gas to be consumed when it is invoked. The documentation should also be updated as a part of the PR that adds this.There are two potential use cases for this:
The text was updated successfully, but these errors were encountered: