feat(Gnovm/std): `GasUsed` function for `std`
Contributors' checklist...
- [x] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
- [ ] Updated the official documentation or not needed
- [x] No breaking changes were made, or a
BREAKING CHANGE: xxxmessage was included in the description - [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to generated graphs, if any. More info here.
As discussion in #1998, We should have this gasUsed() std function with two potential use cases:
- This can be helpful for benchmarking gno code -- users trying to figure out which parts of their code is consuming large amounts of gas
- This can be used to measure performance of running a bit of code if someone would like to deploy a leetcode style realm that accepts interfaces with methods for solving a posed coding problem.
This PR defines a GasUsed() func and a defaultInvokeCost in gas (?) within std package, and whenever the GasUsed() is invoked, the GasMeter will consume this amount, returns the GasConsumedToLimit.
(?) What is a reasonable number for this amount? I just set it to 1000 (store.DefaultGasConfig().ReadCostFlat).
TODO: Should we move the default cost config into store.DefaultGasConfig ?
@thehowl can you take a look on this. I really need your opinion.
Codecov Report
Attention: Patch coverage is 23.07692% with 10 lines in your changes are missing coverage. Please review.
Project coverage is 49.93%. Comparing base (
088eeca) to head (2af4c25).
| Files | Patch % | Lines |
|---|---|---|
| gnovm/stdlibs/native.go | 0.00% | 10 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #2149 +/- ##
==========================================
- Coverage 49.93% 49.93% -0.01%
==========================================
Files 576 577 +1
Lines 77828 77841 +13
==========================================
+ Hits 38862 38868 +6
- Misses 35840 35849 +9
+ Partials 3126 3124 -2
| Flag | Coverage Δ | |
|---|---|---|
| gnovm | 44.96% <23.07%> (+<0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Apologies for the late review
Fixes #2467
Closed due to #2571