-
Notifications
You must be signed in to change notification settings - Fork 4
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
used_gas: how can we provide exact measure of gas used/remaining gas back to the contract? #3
Comments
As a brief thought, I believe the only side effects we have or care about are:
So it might not be super onerous to split the metered blocks (in the parlance of our current instrumentation spec) into two at those points. |
Note: I am off for a long weekend now, if I forget to fill this in, please ping me! My main contributions:
|
I can see the following potential use cases:
In this constructed example, if If we want to have an accurate idea of what devs actually care about, perhaps we need input from DevRel. But regardless, if we can make things cleaner without too much hassle, I would prefer that. Who knows, maybe someday, it will save a DeFi contract from breaking mid transaction that their devs were oh-so-sure will always be atomic. |
Problem statement: It is natural to formulate gas metering on the per-instruction basis. But implementation can be much faster if it aggregates all the gas spent in a block. Doing this optimization risks leaking per-block nature of gas accounting. We need to:
|
My takes are
And there's also the case that we can change semantics later via a protocol version. So I'd probably not overthing this, and just do the per-block thing. |
That’s a nice way to formulate it. What counts for a “leak” is, sort of, use-case specific. In our case, for example, we don’t care or need the contract memory to be deterministic at the end of execution, so we can afford to collapse gas accounting for a significantly extended set of instructions compared to use-cases which require memory to reflect exactly the correct termination point. I don’t believe runtime semantics would be affected by such simplifications much if at all, but using the per-instruction-gas model would definitely make it more difficult to write spec tests and an implementation (which might want to handle different modes of operation). |
I worry that if we spontaneously implement something now, it can be quite difficult to actually change the approach taken for various reasons, and protocol bump is probably the least of those, one of which would be interactions with other sorts of instrumentation. Another reason we want to get this right from the get go is to not deal with dozen copies of the instrumentation code in the codebase. |
As per wording, the exact measure of the remaining gas pool is always available. Any attempts to obtain this count should return the exact value. Unfortunately this still doesn’t help with the use case of “attach all remaining gas to the function call action” as there can be an opaque number of webassembly instructions between the call and prior readout of the remaining gas. That said, my feeling is that this ought to be solved outside of this spec/framework. If this is a desirable operation, a host function ought to be adapted or added to implement this behaviour. |
A problem description needs to be written down here.
@matklad @Ekleog @jakmeier @akhi3030
The text was updated successfully, but these errors were encountered: