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

fix(x/authz): bring back msg response in DispatchActions #21044

Merged
merged 6 commits into from
Aug 16, 2024
Merged

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Jul 23, 2024

Description

k.DispatchActions was always returning an empty byte array after the migration to the msg service router
In v0.50.8 we were writing (deprecated) msgResponse.Data in that [][]byte and no marshalled anys so I'll add a test and a changelog to prevent regressions.

https://github.com/cosmos/cosmos-sdk/blob/v0.50.8/x/authz/keeper/keeper.go#L166-L186

cc @danieljdd

Should be backported to v0.52 after #21041 is merged


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Enhanced response handling and error reporting in the DispatchActions method, improving message processing reliability.
    • Updated the Accept method to require context, improving its alignment with current usage.
    • Simplified message construction by allowing string arguments in NewMsgExec, NewMsgGrant, and NewMsgRevoke.
  • Bug Fixes

    • Improved error handling to ensure clear communication of issues during message processing.

@julienrbrt julienrbrt requested a review from a team as a code owner July 23, 2024 21:53
Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Walkthrough

Walkthrough

The recent modifications to the DispatchActions method in the Keeper structure enhance response handling and error reporting during message processing. The changes allow for capturing responses from the MsgRouterService, encapsulating them in a flexible format, and improving error messages when issues arise. Additionally, significant API changes have been implemented to streamline authorization methods, requiring adjustments in dependent code. This overall improvement facilitates better debugging and maintains the integrity of message communication in the application.

Changes

File Change Summary
x/authz/keeper/keeper.go Enhanced DispatchActions method to capture and handle responses from MsgRouterService. Improved error handling for response encapsulation and marshaling.
x/authz/CHANGELOG.md Introduced breaking API changes: updated k.DispatchActions return type; modified Accept method to require context; removed deprecated Accounts String() method; constructors for messages now accept strings instead of sdk.AccAddress.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant MsgRouterService
    participant Keeper

    Client->>Keeper: Dispatch Actions
    Keeper->>MsgRouterService: Invoke Untyped(msg)
    MsgRouterService-->>Keeper: Response (resp)
    Keeper->>Keeper: Create Any instance with resp
    alt Create Any fails
        Keeper-->>Client: Error message
    else Create Any succeeds
        Keeper->>Keeper: Marshal response
        alt Marshal fails
            Keeper-->>Client: Error message
        else Marshal succeeds
            Keeper-->>Client: Success message
        end
    end
Loading

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.

This comment has been minimized.

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.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7d892e5 and 8186e66.

Files selected for processing (1)
  • x/authz/keeper/keeper.go (2 hunks)
Additional context used
Path-based instructions (1)
x/authz/keeper/keeper.go (1)

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

Additional comments not posted (3)
x/authz/keeper/keeper.go (3)

149-152: Capture and handle the response from InvokeUntyped.

The response from InvokeUntyped is now captured in resp and handled further. This change improves the functionality by allowing the response to be processed.


154-157: Create a new Any type instance and handle errors.

The creation of a new Any type instance using gogoprotoany.NewAnyWithCacheWithValue(resp) allows for flexible encapsulation of the response. The error handling ensures that any issues during this process are communicated clearly.


159-162: Marshal the response and handle errors.

The response is marshaled using gogoproto.Marshal(msgRespAny), and errors during this operation are handled appropriately. This ensures that any issues during the marshaling process are communicated clearly.

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, codebase verification and nitpick comments (8)
x/authz/CHANGELOG.md (8)

36-36: Clarify the description of the k.DispatchActions change.

The description is clear but can be made more concise by removing redundant words.

- `k.DispatchActions` returns a slice of byte slices of proto marshaled anys instead of a slice of byte slices of `sdk.Result.Data`.
+ `k.DispatchActions` now returns proto marshaled `any` types instead of `sdk.Result.Data`.

37-37: Ensure clarity in the Accept method change description.

The description is clear but can be improved for readability.

- `Accept` on the `Authorization` interface now expects the authz environment in the `context.Context`. This is already done when `Accept` is called by `k.DispatchActions`, but should be done manually if `Accept` is called directly.
+ The `Accept` method on the `Authorization` interface now requires the authz environment to be passed in the `context.Context`. This is handled automatically when `Accept` is called by `k.DispatchActions`, but must be done manually if `Accept` is called directly.

38-39: Improve readability of the NewMsgExec, NewMsgGrant, and NewMsgRevoke changes.

The description is clear but can be made more concise.

- Removes the use of Accounts String() method
- `NewMsgExec`, `NewMsgGrant` and `NewMsgRevoke` now takes strings as arguments instead of `sdk.AccAddress`.
- `ExportGenesis` also returns an error.
- `IterateGrants` returns an error, its handler function also returns an error.
+ Removed the use of the `Accounts String()` method.
+ `NewMsgExec`, `NewMsgGrant`, and `NewMsgRevoke` now take strings as arguments instead of `sdk.AccAddress`.
+ `ExportGenesis` and `IterateGrants` now return errors, and the handler function for `IterateGrants` also returns an error.

Line range hint 40-40:
Clarify the NewKeeper change description.

The description is clear but can be improved for readability.

- `NewKeeper` doesn't take a message router anymore. Set the message router in the `appmodule.Environment` instead.
+ `NewKeeper` no longer takes a message router. Set the message router in the `appmodule.Environment` instead.

Line range hint 41-41:
Clarify the appmodule.Environment change description.

The description is clear but can be improved for readability.

- `appmodule.Environment` is received on the Keeper to get access to different application services.
+ The `appmodule.Environment` is now received by the Keeper to access different application services.

Line range hint 42-42:
Clarify the DequeueAndDeleteExpiredGrants change description.

The description is clear but can be improved for readability.

- Update the keeper method `DequeueAndDeleteExpiredGrants` to take a limit argument for the number of grants to prune.
+ Updated the keeper method `DequeueAndDeleteExpiredGrants` to take a limit argument for the number of grants to prune.

Line range hint 43-43:
Clarify the AcceptResponse change description.

The description is clear but can be improved for readability.

- `AcceptResponse` has been moved to sdk/types/authz and the `Updated` field is now of the type `sdk.Msg` instead of `authz.Authorization`.
+ Moved `AcceptResponse` to `sdk/types/authz` and changed the `Updated` field type to `sdk.Msg` instead of `authz.Authorization`.

Line range hint 44-44:
Clarify the InitGenesis and ExportGenesis change description.

The description is clear but can be improved for readability.

- `InitGenesis` and `ExportGenesis` module code and keeper code do not panic but return errors.
+ The `InitGenesis` and `ExportGenesis` module code and keeper code now return errors instead of panicking.
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8186e66 and 9d5bf76.

Files selected for processing (1)
  • x/authz/CHANGELOG.md (1 hunks)
Additional context used
Path-based instructions (1)
x/authz/CHANGELOG.md (1)

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

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Jul 24, 2024
Copy link
Contributor

@testinginprod testinginprod left a comment

Choose a reason for hiding this comment

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

LGTM, I'd add a test though 🙏

@julienrbrt julienrbrt added this pull request to the merge queue Aug 16, 2024
Merged via the queue into main with commit 54df758 Aug 16, 2024
75 checks passed
@julienrbrt julienrbrt deleted the julien/authz branch August 16, 2024 13:33
mergify bot pushed a commit that referenced this pull request Aug 16, 2024
julienrbrt added a commit that referenced this pull request Aug 16, 2024
alpe added a commit that referenced this pull request Aug 19, 2024
* main: (76 commits)
  docs: more app v2 renaming (#21336)
  chore: update link in disclaimer (#21339)
  refactor(x/distribution): audit QA (#21316)
  docs: rename app v2 to app di when talking about runtime v0 (#21329)
  feat(schema): specify JSON mapping (#21243)
  fix(x/authz): bring back msg response in `DispatchActions` (#21044)
  chore: fix all lint issue since golangci-lint bump (#21326)
  refactor(x/mint): v0.52 audit x/mint (#21301)
  chore: fix spelling errors (#21327)
  feat: export genesis in simapp v2 (#21199)
  fix(baseapp)!: Halt at height now does not produce the halt height block (#21256)
  refactor(scripts): remove unused variable (#21320)
  chore(schema/testing): upgrade to go 1.23 iterators (#21282)
  chore: readmes + upgrading docs (#21271)
  feat(client): add auto cli for node service (#21074)
  ci: fix github workflow vulnerable to script injection (#21304)
  build(deps): Bump github.com/prometheus/client_golang from 1.19.1 to 1.20.0 (#21307)
  build(deps): use Go 1.23 instead of Go 1.22 (#21280)
  refactor(x/auth): audit x/auth changes (#21146)
  chore: remove todo: "abstract out staking message back to staking" (#21266)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:x/authz
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants