-
Notifications
You must be signed in to change notification settings - Fork 441
feat(gasmeter): support detailed metering and reporting #4953
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
Open
aeddi
wants to merge
16
commits into
gnolang:master
Choose a base branch
from
aeddi:gas-details
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
🐳 devops
🛠️ gnodev
🐹 golang
Pull requests that update Go code
📦 🌐 tendermint v2
Issues or PRs tm2 related
📦 ⛰️ gno.land
Issues or PRs gno.land package related
📦 🤖 gnovm
Issues or PRs gnovm related
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the gas metering system to make its usage more consistent across the codebase, supporting detailed metering and reporting.
Changes
1. Move gas meter to dedicated package (a9f9eeb)
This commit moves the gas meter out of the
tm2/pkg/storepackage to its own package undertm2/pkg/gas, since it's not only related to store operations anymore. It also renames some functions to be more aligned with Go best practices (e.g.gas.NewGasMeter→gas.NewMeter).2. Centralize gas operations and costs (00cb42e)
This commit makes gas metering usage more consistent. Previously, the metering was scattered across the codebase:
gnovm/pkg/gnolang/machine.go, using a multiplier ingnovm/pkg/gnolang/machine.gognovm/pkg/gnolang/alloc.gognovm/pkg/gnolang/garbage_collector.go, using a multiplier ingnovm/pkg/gnolang/machine.gognovm/pkg/gnolang/go2gno.gognovm/pkg/gnolang/store.go, costs modifiable by param of the storegnovm/pkg/gnolang/uverse.gotm2/pkg/sdk/auth/ante.go, costs can be changed by params intm2/pkg/sdk/auth/params.goAfter this commit:
tm2/pkg/gas/operation.goand the associated costs intm2/pkg/gas/config.go.gasMeter.GasConsume(OpCPUCall, 1).gasMeter.GasConsume(OpNativePrintPerByte, len(output)).float64to allow division through this simple API (multiply by 0.5 to get half, etc.), but the gas counting still usesint64.3. Add float support to overflow package (ebdf7a1)
This commit adds support for float operations to the overflow package, since the gas metering now uses
float64for cost and multiplier.4. Add detailed gas reporting (dd954ff)
This commit adds detailed gas report support. The gas meter now keeps track of how many times an operation was performed and how much gas it consumed in total. Operations are grouped into categories so we can produce reports per category.
Note: Category mapping is done on access to keep gas metering as fast as possible by relying on a simple fixed-size array to store the counters.
5. Deduplicate tx info printing (07b6cf2)
This commit deduplicates the tx info printing that was duplicated in 3 different places. Now this part only calls the
PrintTxInfofunction frominfo.go.6. Add verbose flag to gnokey (92b7b86)
This commit adds a new verbosity flag to
gnokeyto display 4 levels of gas reports.Note: The default keep the current behavior so we don't break any existing tooling relying on gnokey output.
Examples
Level 0 output
Level 1 output
Level 2 output
Level 3 output
Questions
tm2/pkg/sdk/auth/params.go. Except for the default values, these gas costs were set by the genesis file.Does it make sense to set some costs through the genesis while others are defined in a config struct somewhere in the codebase? Should we make all costs configurable via the genesis file, or remove all cost parameters from the genesis (as I did in this PR)?