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 our own axone/prolog fork in logic module #703

Merged
merged 9 commits into from
Jul 25, 2024

Conversation

bdeneux
Copy link
Contributor

@bdeneux bdeneux commented Jul 22, 2024

📝 Description

This PR replace ichiban/prolog module with our own fork axone-protocol/prolog. By doing this, since it's contains breaking changes, we need to align current implementation with this new module.

👨🏻‍🔧 Fixes

This fork contains fixes for those issues :

👩‍💻 Related development

  • This PR also include, in continuity of 🧠 Logic: current_predicate random display #695, the implementation of an ordered map to register in a deterministic order the list of predicates in interpreter.
  • Introduce a new MaxVariables parameter in logic module limits params. By default, MaxVariables limits has been set to 100 000. The related commit message include the breaking changes marker (ab8f734).

Summary by CodeRabbit

  • New Features

    • Introduced the ability to set a maximum number of variables for the interpreter, enhancing resource management.
    • Added default maximum variable limits to improve configurability.
  • Bug Fixes

    • Enhanced error handling in the query interpreter for better specificity in error reporting.
  • Tests

    • Updated test cases to incorporate maximum variable limits and refined expected error messages.
  • Chores

    • Updated dependency management to include new libraries for improved functionality and performance.

Copy link
Contributor

coderabbitai bot commented Jul 22, 2024

Walkthrough

The recent changes enhance the functionality and configurability of a Go project, particularly within the Prolog interpreter and its associated components. Key updates include the introduction of a maximum variable limit, improvements in error handling, and the adoption of ordered maps for better predicate management. These enhancements streamline resource management and improve testing capabilities, thereby refining overall performance and robustness.

Changes

Files Change Summary
go.mod Added new dependencies and replaced a Prolog interpreter library.
proto/.../params.proto Introduced max_variables field in Limits message to set a limit on variable creation.
x/logic/interpreter/interpreter.go Added WithMaxVariables function and modified interpreter initialization for better configurability.
x/logic/interpreter/registry.go Switched from a standard map to an ordered map for preserving predicate order.
x/logic/keeper/features/*.feature Updated gas_used values in multiple feature tests to reflect adjusted performance metrics.
x/logic/keeper/grpc_query_ask_test.go Added maxVariables to tests and updated expected error messages for resource limits.
x/logic/keeper/grpc_query_params_test.go Invoked WithMaxVariables in test case for parameter validation.
x/logic/keeper/interpreter.go Updated newInterpreter to accept max variable limit for improved resource management.
x/logic/prolog/tuple.go Changed tuple representation from engine.Atom(0) to engine.Atom("").
x/logic/types/params.go Introduced DefaultMaxVariables and a new function WithMaxVariables for limit management.
x/logic/types/params_test.go Added WithMaxVariables in TestValidateParams to enforce stricter validation.
x/logic/util/prolog.go Enhanced error handling in QueryInterpreter for more precise error reporting.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Interpreter
    participant ErrorHandler

    User->>Interpreter: Execute query with variables
    Interpreter->>ErrorHandler: Check for variable limits
    ErrorHandler-->>Interpreter: Return error if limit exceeded
    Interpreter-->>User: Return results or error
Loading

🐰 "In the garden where ideas bloom,
New variables dance, dispelling gloom.
With ordered maps and limits set,
Our Prolog tales are not done yet!
Let’s hop along, with joy we cheer,
For every change brings us near!" ✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@bdeneux
Copy link
Contributor Author

bdeneux commented Jul 24, 2024

@amimart This PR is now ready until we release axone-protocol/prolog 😇

@bdeneux bdeneux force-pushed the chore/axone-prolog-interpreter branch from dce2242 to 8b9b329 Compare July 24, 2024 20:33
@bdeneux bdeneux linked an issue Jul 25, 2024 that may be closed by this pull request
Copy link

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #703      +/-   ##
==========================================
+ Coverage   54.37%   54.42%   +0.05%     
==========================================
  Files          73       73              
  Lines        2893     2901       +8     
==========================================
+ Hits         1573     1579       +6     
- Misses       1226     1228       +2     
  Partials       94       94              
Files Coverage Δ
x/logic/keeper/interpreter.go 94.80% <100.00%> (+0.06%) ⬆️
x/logic/types/params.go 94.73% <100.00%> (+0.37%) ⬆️
x/logic/prolog/tuple.go 0.00% <0.00%> (ø)
x/logic/util/prolog.go 0.00% <0.00%> (ø)

@bdeneux bdeneux force-pushed the chore/axone-prolog-interpreter branch from 2f558ae to 7e1d7ae Compare July 25, 2024 06:56
@bdeneux bdeneux marked this pull request as ready for review July 25, 2024 06:59
@bdeneux bdeneux force-pushed the chore/axone-prolog-interpreter branch from 7e1d7ae to 87271fb Compare July 25, 2024 07:04
@bdeneux bdeneux requested review from amimart and ccamel July 25, 2024 07:11
@bdeneux bdeneux self-assigned this Jul 25, 2024
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: 1

Outside diff range, codebase verification and nitpick comments (1)
proto/logic/v1beta2/params.proto (1)

63-64: Fix typo in comment.

The comment for max_variables contains a minor typo: "create" should be "created".

-  // max_variables specifies the maximum number of variables that can be create by the interpreter.
+  // max_variables specifies the maximum number of variables that can be created by the interpreter.
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8bd193e and 87271fb.

Files ignored due to path filters (10)
  • docs/predicate/bech32_address_2.md is excluded by !docs/predicate/**/*.md
  • docs/predicate/block_height_1.md is excluded by !docs/predicate/**/*.md
  • docs/predicate/block_time_1.md is excluded by !docs/predicate/**/*.md
  • docs/predicate/consult_1.md is excluded by !docs/predicate/**/*.md
  • docs/predicate/current_output_1.md is excluded by !docs/predicate/**/*.md
  • docs/predicate/open_3.md is excluded by !docs/predicate/**/*.md
  • docs/predicate/open_4.md is excluded by !docs/predicate/**/*.md
  • docs/proto/logic.md is excluded by !docs/proto/**/*.md
  • go.sum is excluded by !**/*.sum
  • x/logic/types/params.pb.go is excluded by !**/*.pb.go
Files selected for processing (18)
  • go.mod (4 hunks)
  • proto/logic/v1beta2/params.proto (1 hunks)
  • x/logic/interpreter/interpreter.go (2 hunks)
  • x/logic/interpreter/registry.go (2 hunks)
  • x/logic/keeper/features/bech32_address_2.feature (17 hunks)
  • x/logic/keeper/features/block_height_1.feature (2 hunks)
  • x/logic/keeper/features/block_time_1.feature (2 hunks)
  • x/logic/keeper/features/consult_1.feature (3 hunks)
  • x/logic/keeper/features/current_output_1.feature (5 hunks)
  • x/logic/keeper/features/open_3.feature (1 hunks)
  • x/logic/keeper/features/open_4.feature (11 hunks)
  • x/logic/keeper/grpc_query_ask_test.go (3 hunks)
  • x/logic/keeper/grpc_query_params_test.go (1 hunks)
  • x/logic/keeper/interpreter.go (1 hunks)
  • x/logic/prolog/tuple.go (1 hunks)
  • x/logic/types/params.go (3 hunks)
  • x/logic/types/params_test.go (1 hunks)
  • x/logic/util/prolog.go (1 hunks)
Additional context used
Learnings (1)
x/logic/util/prolog.go (1)
Learnt from: bdeneux
PR: axone-protocol/axoned#694
File: x/logic/util/prolog.go:31-31
Timestamp: 2024-07-22T09:40:50.049Z
Learning: The error handling for parsing terms in the `QueryInterpreter` function is covered by tests in `grpc_query_ask_test.go` around line 230.
GitHub Check: codecov/patch
x/logic/prolog/tuple.go

[warning] 7-7: x/logic/prolog/tuple.go#L7
Added line #L7 was not covered by tests

x/logic/util/prolog.go

[warning] 57-57: x/logic/util/prolog.go#L57
Added line #L57 was not covered by tests


[warning] 61-62: x/logic/util/prolog.go#L61-L62
Added lines #L61 - L62 were not covered by tests


[warning] 68-68: x/logic/util/prolog.go#L68
Added line #L68 was not covered by tests

Additional comments not posted (43)
x/logic/prolog/tuple.go (1)

7-7: Verify the impact of changing engine.Atom(0) to engine.Atom("").

The change alters the internal representation of the tuple. Ensure that this modification does not introduce any unintended side effects in tuple handling or unification within the Prolog engine.

Tools
GitHub Check: codecov/patch

[warning] 7-7: x/logic/prolog/tuple.go#L7
Added line #L7 was not covered by tests

x/logic/keeper/features/open_3.feature (1)

34-34: Verify the accuracy of the updated gas_used value.

The gas_used value has been updated from 3877 to 4141. Ensure that this new value accurately reflects the expected gas usage for the operation.

x/logic/keeper/features/block_height_1.feature (2)

19-19: Verify the accuracy of the updated gas_used value.

The gas_used value has been updated from 3876 to 4140. Ensure that this new value accurately reflects the expected gas usage for the operation.


46-46: Verify the accuracy of the updated gas_used value.

The gas_used value has been updated from 3877 to 4141. Ensure that this new value accurately reflects the expected gas usage for the operation.

x/logic/keeper/features/block_time_1.feature (2)

19-19: Verify the updated gas_used value.

The gas_used value has been updated from 3876 to 4140. Ensure that this change is consistent with the underlying calculations and logic.


47-47: Verify the updated gas_used value.

The gas_used value has been updated from 3877 to 4141. Ensure that this change is consistent with the underlying calculations and logic.

x/logic/types/params_test.go (1)

42-42: Verify the new parameter types.WithMaxVariables(math.NewUint(5)).

The new parameter types.WithMaxVariables(math.NewUint(5)) has been added to the test case. Ensure that this change is consistent with the intended functionality and does not introduce any unintended side effects.

x/logic/interpreter/interpreter.go (3)

11-12: Verify the necessity of the new import.

The import statement for cosmossdk.io/math has been added. Ensure that this import is necessary and correctly used in the file.


73-82: Verify the new function WithMaxVariables.

The function WithMaxVariables has been added to set a maximum number of variables for the interpreter. Ensure that this function is correctly implemented and does not introduce any unintended side effects.


88-96: Verify the changes to the New function.

The New function has been modified to use prolog.NewEmpty() for creating an instance of the interpreter. Ensure that this change is consistent with the intended functionality and does not introduce any unintended side effects.

x/logic/keeper/grpc_query_params_test.go (1)

46-46: LGTM! Ensure adequate test coverage.

The addition of types.WithMaxVariables(math.NewUint(5)) enhances the test cases by specifying a maximum number of variables. Ensure that all edge cases related to variable limits are covered in the tests.

x/logic/util/prolog.go (3)

57-57: LGTM! Ensure test coverage for new error handling.

The introduction of panicErr and the additional error handling logic for engine.ErrMaxVariables improve the robustness of the QueryInterpreter function. Ensure that the new error handling paths are covered by tests.

Tools
GitHub Check: codecov/patch

[warning] 57-57: x/logic/util/prolog.go#L57
Added line #L57 was not covered by tests


61-62: LGTM! Ensure test coverage for new error handling.

The new case in the switch statement for panicErr enhances the specificity of error reporting by handling engine.ErrMaxVariables. Ensure that the new error handling paths are covered by tests.

Tools
GitHub Check: codecov/patch

[warning] 61-62: x/logic/util/prolog.go#L61-L62
Added lines #L61 - L62 were not covered by tests


68-68: LGTM! Ensure test coverage for error logging.

The modification to the default case in the switch statement ensures that all errors are consistently recorded, improving debugging and error tracking. Ensure that the error logging paths are covered by tests.

Tools
GitHub Check: codecov/patch

[warning] 68-68: x/logic/util/prolog.go#L68
Added line #L68 was not covered by tests

x/logic/types/params.go (3)

20-20: LGTM!

The introduction of DefaultMaxVariables initialized to 100,000 provides a sensible default limit for the maximum number of variables, enhancing the configurability of the interpreter.


150-155: LGTM!

The new function WithMaxVariables enhances the flexibility of the Limits structure by allowing users to specify a custom maximum number of variables.


172-175: LGTM!

The update to the NewLimits function ensures that a sensible default for MaxVariables is applied if it is not explicitly set, enhancing the robustness of the Limits structure.

x/logic/keeper/features/current_output_1.feature (5)

31-31: Update in gas_used value.

The gas_used value has been updated from 3976 to 4240. Ensure that this change aligns with the expected performance metrics.


69-69: Update in gas_used value.

The gas_used value has been updated from 4010 to 4274. Ensure that this change aligns with the expected performance metrics.


107-107: Update in gas_used value.

The gas_used value has been updated from 3976 to 4240. Ensure that this change aligns with the expected performance metrics.


148-148: Update in gas_used value.

The gas_used value has been updated from 3990 to 4254. Ensure that this change aligns with the expected performance metrics.


179-179: Update in gas_used value.

The gas_used value has been updated from 4261 to 4525. Ensure that this change aligns with the expected performance metrics.

x/logic/keeper/interpreter.go (1)

136-136: Introduction of WithMaxVariables parameter.

The WithMaxVariables(limits.MaxVariables) parameter has been added to the newInterpreter function to enhance the functionality of the interpreter by allowing it to accept a maximum variable limit. Ensure that this change aligns with the expected performance improvements and resource constraints.

x/logic/keeper/features/consult_1.feature (3)

37-37: Update in gas_used value.

The gas_used value has been updated from 3878 to 4142. Ensure that this change aligns with the expected performance metrics.


93-93: Update in gas_used value.

The gas_used value has been updated from 3877 to 4141. Ensure that this change aligns with the expected performance metrics.


147-147: Update in gas_used value.

The gas_used value has been updated from 3877 to 4141. Ensure that this change aligns with the expected performance metrics.

x/logic/interpreter/registry.go (2)

16-123: LGTM!

The transition to an ordered map and the initialization of the registry variable with predicate key-value pairs are appropriate.


128-131: LGTM!

The changes to the RegistryNames function ensure that the list of predicate names maintains the same order as they were added to the registry.

x/logic/keeper/features/open_4.feature (1)

46-46: LGTM!

The updates to the gas_used parameter reflect necessary adjustments to the expected results.

Also applies to: 89-89, 130-130, 152-152, 173-173, 194-194, 215-215, 235-235, 254-254, 273-273, 292-292

x/logic/keeper/features/bech32_address_2.feature (6)

19-19: Verify the updated gas_used value.

The gas_used value has been updated from 3876 to 4140. Ensure this change reflects the updated computational cost accurately.


42-42: Verify the updated gas_used value.

The gas_used value has been updated from 3876 to 4140. Ensure this change reflects the updated computational cost accurately.


66-66: Verify the updated gas_used value.

The gas_used value has been updated from 3876 to 4140. Ensure this change reflects the updated computational cost accurately.


87-87: Verify the updated gas_used value.

The gas_used value has been updated from 3876 to 4140. Ensure this change reflects the updated computational cost accurately.


112-112: Verify the updated gas_used value.

The gas_used value has been updated from 3876 to 4140. Ensure this change reflects the updated computational cost accurately.


133-133: Verify the updated gas_used value.

The gas_used value has been updated from 3876 to 4140. Ensure this change reflects the updated computational cost accurately.

x/logic/keeper/grpc_query_ask_test.go (3)

43-43: LGTM! The addition of maxVariables enhances the test cases.

The new variable maxVariables is added to the test cases struct, allowing for better control over resource limits.


147-147: Verify the updated expected error message for maxGas.

The expected error message has been updated to reflect new gas limit values. Ensure this change accurately reflects the updated resource consumption calculations.


157-160: LGTM! The new test case for maxVariables enhances test coverage.

The new test case checks for the condition where the maximum number of variables is exceeded, improving the robustness of the test suite.

go.mod (5)

57-57: LGTM! The new dependencies enhance the project's capabilities.

The following dependencies have been added:

  • github.com/wk8/go-ordered-map/v2 v2.1.8
  • github.com/bahlo/generic-list-go v0.2.0
  • github.com/buger/jsonparser v1.1.1
  • github.com/cockroachdb/apd/v3 v3.2.1
  • github.com/mailru/easyjson v0.7.7

79-79: LGTM! The custom fork replacement addresses specific needs.

The ichiban/prolog module is replaced with the axone-protocol/prolog fork, enhancing functionality and addressing specific issues.


104-104: LGTM! The new indirect dependency is appropriate.

The following indirect dependency has been added:

  • github.com/bahlo/generic-list-go v0.2.0

112-112: LGTM! The new indirect dependency is appropriate.

The following indirect dependency has been added:

  • github.com/buger/jsonparser v1.1.1

120-120: LGTM! The new indirect dependency is appropriate.

The following indirect dependency has been added:

  • github.com/cockroachdb/apd/v3 v3.2.1

x/logic/prolog/tuple.go Show resolved Hide resolved
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.

Thx 🙏

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.

LGTM thanks! 🙏

@bdeneux bdeneux merged commit 6f266e9 into main Jul 25, 2024
20 checks passed
@bdeneux bdeneux deleted the chore/axone-prolog-interpreter branch July 25, 2024 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants