-
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
feat(Gnovm/std): GasUsed
function for std
#2149
Conversation
@thehowl can you take a look on this. I really need your opinion. |
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure whether this makes sense in the first place. See my comment on #1998 .
@@ -13,6 +13,8 @@ func IsOriginCall() bool // injected | |||
func GetChainID() string // injected | |||
func GetHeight() int64 // injected | |||
|
|||
func GasUsed() int64 // injected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please place this next to the other injected functions (and align // injected
), please!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name this gas.go
var ( | ||
gasUsedInvoked = "GasUsedCalled" | ||
/* | ||
Consider where to save this config | ||
defaultGasConfig = store.DefaultGasConfig() | ||
*/ | ||
// defaultGasConfig = int64(1000) | ||
defaultInvokeCost = store.DefaultGasConfig().ReadCostFlat | ||
) | ||
|
||
// DefaultCost will be consumed whenever GasUsed is called, now set it ReadCostPerByte | ||
func GasUsed(m *gno.Machine) int64 { | ||
m.GasMeter.ConsumeGas(defaultInvokeCost, gasUsedInvoked) | ||
return m.GasMeter.GasConsumedToLimit() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't consume gas here; we'll need to benchmark all native functions and add a cost on another occasion.
Apologies for the late review |
Fixes #2467 |
Closed due to #2571 |
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the descriptionAs discussion in #1998, We should have this gasUsed() std function with two potential use cases:
This PR defines a
GasUsed()
func and adefaultInvokeCost
in gas (?) withinstd
package, and whenever theGasUsed()
is invoked, the GasMeter will consume this amount, returns theGasConsumedToLimit
.(?) 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
?