gno icon indicating copy to clipboard operation
gno copied to clipboard

feat(Gnovm/std): `GasUsed` function for `std`

Open thinhnx-var opened this issue 1 year ago • 1 comments

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: xxx message 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:

  1. This can be helpful for benchmarking gno code -- users trying to figure out which parts of their code is consuming large amounts of gas
  2. 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 ?

thinhnx-var avatar May 20 '24 08:05 thinhnx-var

@thehowl can you take a look on this. I really need your opinion.

thinhnx-var avatar May 23 '24 07:05 thinhnx-var

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.

codecov[bot] avatar May 29 '24 07:05 codecov[bot]

Apologies for the late review

thehowl avatar Jun 18 '24 09:06 thehowl

Fixes #2467

Kouteki avatar Jul 05 '24 10:07 Kouteki

Closed due to #2571

thinhnx-var avatar Jul 11 '24 03:07 thinhnx-var