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

add expected approval&reject expressions to MsgNewAction #791

Merged
merged 4 commits into from
Sep 5, 2024

Conversation

mn13
Copy link
Contributor

@mn13 mn13 commented Sep 5, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced action handling with the addition of expected approval and rejection expressions.
    • Improved message processing capabilities within the action module for more complex interactions.
  • Bug Fixes

    • Strengthened data integrity by ensuring fee-related data is always present, reducing null-related errors.
  • Documentation

    • Updated changelog to reflect the new functionalities and structural changes in the action handling process.

@mn13 mn13 linked an issue Sep 5, 2024 that may be closed by this pull request
Copy link
Contributor

coderabbitai bot commented Sep 5, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

Walkthrough

The changes introduce new fields to the MsgNewAction message to handle expected approval and rejection expressions, enhancing action creation logic. The AddAction function is modified to accept these expressions, allowing for more complex decision-making. Additionally, the structure for handling votes replaces the Approvers list in actions, introducing a voting mechanism with associated expressions for approval and rejection.

Changes

File Change Summary
CHANGELOG.md Added expected expressions to MsgAddAction, enhancing action handling capabilities.
proto/warden/act/v1beta1/tx.proto Modified MsgNewAction to include expected_approve_expression and expected_reject_expression. Updated imports for new fields.
warden/x/act/keeper/actions.go Updated AddAction function to include expectedApproveExpression and expectedRejectExpression parameters.
warden/x/act/keeper/msg_server_new_action.go Modified NewAction method to pass new parameters to AddAction, enhancing action creation logic.

Possibly related issues


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 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.

This comment has been minimized.

@mn13 mn13 requested a review from Pitasi September 5, 2024 09:22
Copy link

vercel bot commented Sep 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
warden-help-center ⬜️ Ignored (Inspect) Visit Preview Sep 5, 2024 11:47am

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: 2

Outside diff range, codebase verification and nitpick comments (2)
CHANGELOG.md (2)

58-58: Enhance the description for MsgAddAction changes.

The entry for the addition of expected expressions to MsgAddAction could benefit from a more detailed description. It would be helpful to explain what "expected expressions" are and how they contribute to the functionality.


58-58: Clarify the impact of non-nullable KeychainFees fields.

While the entry mentions making KeychainFees fields non-nullable, it would be beneficial to include information on the potential impact this change may have on existing data and any necessary migrations or updates required to accommodate this change.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9d33f5b and b2d91ed.

Files ignored due to path filters (2)
  • api/warden/act/v1beta1/tx.pulsar.go is excluded by !api/**
  • warden/x/act/types/v1beta1/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • proto/warden/act/v1beta1/tx.proto (2 hunks)
  • warden/x/act/keeper/actions.go (3 hunks)
  • warden/x/act/keeper/msg_server_new_action.go (1 hunks)
Additional context used
Path-based instructions (3)
warden/x/act/keeper/msg_server_new_action.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

warden/x/act/keeper/actions.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Additional comments not posted (6)
warden/x/act/keeper/msg_server_new_action.go (1)

18-18: Good error handling and structure.

The function properly wraps errors with additional context, making debugging easier. The use of fmt.Errorf is consistent with best practices in Go:

return nil, fmt.Errorf("can't unpack any: %w", err)

The overall structure of the function is clear and follows the Uber Golang style guide.

proto/warden/act/v1beta1/tx.proto (2)

12-12: Approved import statement.

The import of shield/ast/ast.proto is necessary for the new fields in MsgNewAction that utilize .shield.ast.Expression.


72-75: Approved new fields in MsgNewAction.

The addition of expected_approval_expression and expected_reject_expression enhances the functionality of the MsgNewAction message by allowing it to encapsulate additional logic for action approvals and rejections. Ensure that these new fields are properly integrated and utilized in the system's action handling logic.

Run the following script to verify the integration of the new fields:

Verification successful

Verified integration of new fields in MsgNewAction.

The fields expected_approval_expression and expected_reject_expression are successfully integrated into the system's logic, as evidenced by their presence and usage in multiple parts of the codebase. This confirms their proper incorporation into the action handling logic.

  • Locations where the fields are integrated:
    • warden/x/act/types/v1beta1/tx.pb.go
    • api/warden/act/v1beta1/tx.pulsar.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of new fields in the system's action handling logic.

# Test: Search for the usage of new fields. Expect: Proper integration in the system.
rg --type proto -A 5 $'expected_approval_expression|expected_reject_expression'

Length of output: 110


Script:

#!/bin/bash
# Description: Verify the integration of new fields in the system's action handling logic.

# Test: Search for the usage of new fields across the entire codebase.
rg 'expected_approval_expression|expected_reject_expression' -A 5

Length of output: 10178

warden/x/act/keeper/actions.go (2)

137-137: Review the expanded function signature.

The function AddAction now includes parameters for expectedApprovalExpression and expectedRejectExpression. This change aligns with the PR objectives to enhance action handling with expressions for approvals and rejections.


Line range hint 137-149: Ensure robust handling of new parameters.

The integration of expectedApprovalExpression and expectedRejectExpression into the action creation process is crucial. It's important to ensure that these expressions are correctly processed and applied to the action's rule. Consider adding unit tests to verify the correct application of these expressions.

CHANGELOG.md (1)

Line range hint 1-58: Approve the structure and formatting of the changelog.

The changelog is well-structured and adheres to the recommended format from Keep a Changelog. The entries are appropriately grouped and tagged, facilitating easy navigation and understanding.

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: 2

Outside diff range, codebase verification and nitpick comments (1)
warden/x/act/keeper/actions.go (1)

Line range hint 137-149: Complexity and Maintainability of AddAction.

The AddAction function has significantly increased in complexity with the addition of new logic for handling expressions. This includes interactions with rulesRegistry and preprocessing of rules, which adds several layers of logic that need careful testing.

  • Refactor Suggestion: Consider breaking down this function into smaller, more manageable functions that handle specific parts of the action creation process. This can improve maintainability and make the code easier to understand and test.
  • Performance: Ensure that the preprocessing and rule evaluation do not introduce performance bottlenecks, especially in contexts where actions are created frequently.
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9d33f5b and b2d91ed.

Files ignored due to path filters (2)
  • api/warden/act/v1beta1/tx.pulsar.go is excluded by !api/**
  • warden/x/act/types/v1beta1/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • proto/warden/act/v1beta1/tx.proto (2 hunks)
  • warden/x/act/keeper/actions.go (3 hunks)
  • warden/x/act/keeper/msg_server_new_action.go (1 hunks)
Additional context used
Path-based instructions (3)
warden/x/act/keeper/msg_server_new_action.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

warden/x/act/keeper/actions.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Additional comments not posted (6)
proto/warden/act/v1beta1/tx.proto (2)

12-12: Approved import statement.

The import of shield/ast/ast.proto is necessary for the new fields in MsgNewAction to reference the .shield.ast.Expression type.


72-75: Approved new fields in MsgNewAction.

The addition of expected_approval_expression and expected_reject_expression enhances the message's functionality by allowing it to encapsulate more complex logic for action approvals and rejections. Ensure that the rest of the system integrates these changes correctly.

Run the following script to verify the integration:

warden/x/act/keeper/actions.go (2)

137-137: Review the addition of new parameters in AddAction.

The function signature of AddAction has been expanded to include expectedApprovalExpression and expectedRejectExpression. This change aligns with the PR objectives to enhance action creation logic by allowing for more complex decision-making based on these expressions.

  • Correctness: The parameters are correctly typed as ast.Expression, which is consistent with handling expressions in this context.
  • Best Practice: Including these parameters directly in the function signature enhances the clarity and explicitness of what AddAction expects as inputs, adhering to the principle of explicit interfaces.

Line range hint 137-149: Ensure robust error handling and validation.

The function performs multiple operations that can fail, such as message unpacking, rule retrieval, and action persistence. Each of these steps includes error handling, but it's crucial to ensure that these are handled as expected across different scenarios.

  • Verification Needed: Additional tests should be written to cover scenarios where each of these steps might fail, ensuring that the function behaves correctly under error conditions.
  • Security: Validate that the expressions provided do not allow for injection of malicious code or execution of unintended actions.
CHANGELOG.md (2)

58-58: Review the entry for clarity and accuracy.

The entry for MsgNewAction under "Consensus Breaking Changes" correctly links to the GitHub issue and describes the addition of expected expressions. However, ensure that the description is clear about how these expressions affect the action creation logic, enhancing the understanding for readers who might not be familiar with the context.


Line range hint 1-58: Confirm documentation correctness and completeness.

The documentation in CHANGELOG.md is well-structured and adheres to the guidelines from Keep a Changelog and Semantic Versioning. No grammatical errors or misspellings were detected, and the documentation appears complete, accurately reflecting the changes made in the PR.

@@ -15,7 +15,7 @@ func (k msgServer) NewAction(ctx context.Context, msg *types.MsgNewAction) (*typ
return nil, fmt.Errorf("can't unpack any: %w", err)
}

act, err := k.AddAction(ctx, msg.Creator, message, msg.ActionTimeoutHeight)
act, err := k.AddAction(ctx, msg.Creator, message, msg.ActionTimeoutHeight, *msg.ExpectedApprovalExpression, *msg.ExpectedRejectExpression)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure safe handling of pointer dereferences.

The function AddAction is called with dereferenced pointers *msg.ExpectedApprovalExpression and *msg.ExpectedRejectExpression. It's crucial to ensure that these fields are not nil before dereferencing to avoid runtime panics. Consider adding a check before this line to ensure that both fields are non-nil.

Here's a suggested change to add nil checks:

+	if msg.ExpectedApprovalExpression == nil || msg.ExpectedRejectExpression == nil {
+		return nil, fmt.Errorf("expected expressions must not be nil")
+	}
	act, err := k.AddAction(ctx, msg.Creator, message, msg.ActionTimeoutHeight, *msg.ExpectedApprovalExpression, *msg.ExpectedRejectExpression)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
act, err := k.AddAction(ctx, msg.Creator, message, msg.ActionTimeoutHeight, *msg.ExpectedApprovalExpression, *msg.ExpectedRejectExpression)
if msg.ExpectedApprovalExpression == nil || msg.ExpectedRejectExpression == nil {
return nil, fmt.Errorf("expected expressions must not be nil")
}
act, err := k.AddAction(ctx, msg.Creator, message, msg.ActionTimeoutHeight, *msg.ExpectedApprovalExpression, *msg.ExpectedRejectExpression)

@@ -144,6 +145,8 @@ func (k Keeper) AddAction(ctx context.Context, creator string, msg sdk.Msg, time
return nil, errors.Wrapf(types.ErrNoRuleRegistryHandler, "%v", err)
}

// todo: check that expressions from rulesRegistry (templateRegistry) match with expected
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO comment needs addressing or removal.

There is a todo comment that suggests a future implementation detail about checking expressions from the rules registry. This indicates that the implementation may not be complete.

  • Action Required: It's important to either implement the necessary checks or update the comment to reflect any changes made. Leaving TODOs in production code can lead to technical debt if not tracked properly.

@mn13 mn13 force-pushed the 773-expected-expressions-to-msg-new-action branch from b2d91ed to 3862601 Compare September 5, 2024 10:30
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b2d91ed and 3862601.

Files ignored due to path filters (2)
  • api/warden/act/v1beta1/tx.pulsar.go is excluded by !api/**
  • warden/x/act/types/v1beta1/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • proto/warden/act/v1beta1/tx.proto (2 hunks)
  • warden/x/act/keeper/actions.go (3 hunks)
  • warden/x/act/keeper/msg_server_new_action.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • CHANGELOG.md
  • proto/warden/act/v1beta1/tx.proto
  • warden/x/act/keeper/actions.go
  • warden/x/act/keeper/msg_server_new_action.go

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3862601 and c20863e.

Files ignored due to path filters (3)
  • api/warden/act/v1beta1/tx.pulsar.go is excluded by !api/**
  • warden/x/act/types/v1beta1/tx.pb.go is excluded by !**/*.pb.go
  • warden/x/warden/types/v1beta3/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (2)
  • proto/warden/act/v1beta1/tx.proto (2 hunks)
  • warden/x/act/keeper/msg_server_new_action.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • proto/warden/act/v1beta1/tx.proto
  • warden/x/act/keeper/msg_server_new_action.go

@mn13 mn13 force-pushed the 773-expected-expressions-to-msg-new-action branch from 19abc7e to bebb7a3 Compare September 5, 2024 11:00
@mn13 mn13 force-pushed the 773-expected-expressions-to-msg-new-action branch from bebb7a3 to 7bdc1e0 Compare September 5, 2024 11:47
@mn13 mn13 merged commit 3396066 into main Sep 5, 2024
10 of 12 checks passed
@mn13 mn13 deleted the 773-expected-expressions-to-msg-new-action branch September 5, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 - [x/act V2]: Add ExpectedExpressions to MsgNewAction
2 participants