Skip to content
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

⛽️ Use the default gas cost params when lookup predicate cost #759

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

bdeneux
Copy link
Contributor

@bdeneux bdeneux commented Sep 27, 2024

This pull request includes a change to the x/logic/keeper/interpreter.go file to improve the handling of default predicate costs in the gasMeterHookFn function following this issue #757 and since implementation of hooks in interpreter (#756).

Keep the defaultPredicateCost const used to be the final default value in case no default cost set (nil or zero value) on module's params.

Summary by CodeRabbit

  • New Features

    • Enhanced cost calculation for predicates to improve efficiency and accuracy.
  • Bug Fixes

    • Fixed potential issues with default predicate cost handling when values are nil or zero.

Copy link
Contributor

coderabbitai bot commented Sep 27, 2024

Walkthrough

The changes involve a modification to the gasMeterHookFn function in the x/logic/keeper/interpreter.go file. The cost calculation for predicates has been updated to utilize the nonNilNorZeroOrDefaultUint64 function, which checks the gasPolicy.DefaultPredicateCost against a default value. This change refines the logic for determining predicate costs without altering the overall structure of the function.

Changes

File Change Summary
x/logic/keeper/interpreter.go Updated cost calculation in gasMeterHookFn to use nonNilNorZeroOrDefaultUint64 for predicates.

Possibly related issues

Poem

🐰 In the code where costs do play,
A new function leads the way.
With checks for nil and zero found,
The predicate costs are now more sound.
Hooray for logic, clear and bright,
A hop towards efficiency, what a delight! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #759      +/-   ##
==========================================
+ Coverage   54.86%   54.89%   +0.03%     
==========================================
  Files          73       73              
  Lines        2938     2940       +2     
==========================================
+ Hits         1612     1614       +2     
  Misses       1230     1230              
  Partials       96       96              
Files with missing lines Coverage Δ
x/logic/keeper/interpreter.go 92.85% <100.00%> (+0.12%) ⬆️

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
x/logic/keeper/interpreter.go (1)

Line range hint 209-216: Effective reuse of nonNilNorZeroOrDefaultUint64 function

The nonNilNorZeroOrDefaultUint64 function is well-utilized in the new context of determining the default predicate cost. Its implementation correctly handles nil and zero values, which is crucial for the robustness of the gas metering system.

Consider renaming the function to getValueOrDefault or resolveDefaultValue for improved clarity, as it now serves a more general purpose in the codebase. This would make its role more immediately apparent to other developers.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 66270c2 and 350b78a.

📒 Files selected for processing (1)
  • x/logic/keeper/interpreter.go (1 hunks)
🧰 Additional context used
📓 Learnings (2)
📓 Common learnings
Learnt from: ccamel
PR: axone-protocol/axoned#756
File: x/logic/keeper/interpreter.go:197-200
Timestamp: 2024-09-25T07:11:26.077Z
Learning: Unregistered predicates are user-defined and should have a default gas consumption applied, referencing the module's `default_predicate_cost` configuration value instead of a hard-coded constant.
x/logic/keeper/interpreter.go (1)
Learnt from: ccamel
PR: axone-protocol/axoned#756
File: x/logic/keeper/interpreter.go:197-200
Timestamp: 2024-09-25T07:11:26.077Z
Learning: Unregistered predicates are user-defined and should have a default gas consumption applied, referencing the module's `default_predicate_cost` configuration value instead of a hard-coded constant.
🔇 Additional comments (2)
x/logic/keeper/interpreter.go (2)

176-178: Improved robustness in predicate cost calculation

The changes to the cost calculation in the gasMeterHookFn function are well-implemented and align with the PR objectives. By using nonNilNorZeroOrDefaultUint64, the code now handles cases where gasPolicy.DefaultPredicateCost might be nil or zero, falling back to the defaultPredicateCost constant. This improvement ensures that there's always a valid cost value, enhancing the robustness of the gas metering system.

The modification also addresses the previous learning about using the module's configuration value for unregistered predicates, which is a good practice for maintaining consistency and flexibility in the system.


176-178: Summary: Effective implementation of default predicate cost handling

The changes in this PR are focused and effective. They successfully implement the requirement to maintain a default predicate cost when the module's parameters are nil or zero. This enhancement improves the robustness of the gas metering system and aligns well with previous feedback about handling unregistered predicates.

The implementation is clean, uses existing utility functions effectively, and doesn't introduce unnecessary complexity. It's a good example of making a targeted improvement that enhances the overall reliability of the system.

Copy link
Member

@ccamel ccamel left a comment

Choose a reason for hiding this comment

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

Great! 👍

@bdeneux bdeneux self-assigned this Sep 27, 2024
Copy link
Member

@amimart amimart left a comment

Choose a reason for hiding this comment

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

👍

@bdeneux bdeneux merged commit 97f924a into main Sep 30, 2024
20 checks passed
@bdeneux bdeneux deleted the feat/use-default-cost-param branch September 30, 2024 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Use configuration value for default gas consumption in 'lookupCost' function
3 participants