Skip to content

fix: count gas for TypedValue.Sprint and println #3921

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

Closed
wants to merge 4 commits into from

Conversation

petar-dambovaliev
Copy link
Contributor

@petar-dambovaliev petar-dambovaliev commented Mar 11, 2025

Closes 3816

@Gno2D2
Copy link
Collaborator

Gno2D2 commented Mar 11, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

No automated checks match this pull request.

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@petar-dambovaliev petar-dambovaliev marked this pull request as ready for review March 13, 2025 12:04
@Kouteki Kouteki moved this from Triage to In Review in 🧙‍♂️gno.land core team Mar 14, 2025
@ltzmaxwell
Copy link
Contributor

also related: #3819.


func (av *ArrayValue) ProtectedString(m *Machine, seen *seenValues) string {
defer func() {
// 7 characters for the array itself
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow where the value 7 comes from. What's the rationale? It seems like a magic number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return line array[]

Comment on lines 103 to +107
ss := make([]string, len(av.List))
if av.Data == nil {
for i, e := range av.List {
ss[i] = e.ProtectedString(seen)
m.GasMeter.ConsumeGas(OpCPUAssign, CPUCYCLES)
ss[i] = e.ProtectedString(m, seen)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this consumption? The elements should be consumed during their own visit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an assignement at the line below. Shouldn't we charge for it?

}
// NOTE: we may want to unify the representation,
// but for now tests expect this to be different.
// This may be helpful for testing implementation behavior.
m.GasMeter.ConsumeGas(OpCPUAssign, CPUCYCLES)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure we should call .ConsumeGas in so many places.

@thehowl thehowl changed the title fix: straining seahorse fix: count gas for TypedValue.Sprint and println Apr 1, 2025
@kristovatlas
Copy link
Contributor

Can we add a test to verify that gas is counted properly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Straining-Seahorse
6 participants