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

feat(x/authz): Add MsgRevokeAll #20161

Merged
merged 22 commits into from
Apr 26, 2024

Conversation

kien6034
Copy link
Contributor

@kien6034 kien6034 commented Apr 23, 2024

Description

Closes: #20139


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

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

    • Added functionality to revoke all grants at once in the x/authz module.
    • Introduced a new message type MsgRevokeAll to revoke all grants issued by a specified granter without specifying individual grantee addresses.
  • Documentation

    • Updated documentation to reflect the new revocation features and message types.
  • Tests

    • Expanded testing coverage to include scenarios with multiple grantee addresses and testing of the revoke all grants functionality.

@kien6034 kien6034 requested a review from a team as a code owner April 23, 2024 17:52
@kien6034 kien6034 marked this pull request as draft April 23, 2024 17:52
Copy link
Contributor

coderabbitai bot commented Apr 23, 2024

Walkthrough

Walkthrough

The x/authz module has been enriched with a new feature, RevokeAll, enabling users to revoke all grants issued by a granter with a single action. This update encompasses changes to the keeper logic, testing procedures, and API definitions to accommodate this functionality.

Changes

Files Changes
x/authz/CHANGELOG.md
x/authz/README.md
Added documentation for the new RevokeAll method.
x/authz/keeper/keeper.go Implemented DeleteAllGrants function to revoke all authorizations at once.
x/authz/keeper/keeper_test.go
x/authz/proto/cosmos/authz/v1beta1/tx.proto
Enhanced testing to cover the new RevokeAll functionality and updated RPC methods.
api/cosmos/authz/v1beta1/event.pulsar.go
x/authz/proto/cosmos/authz/v1beta1/event.proto
Added EventRevokeAll to handle events for the revocation of all grants.

Assessment against linked issues

Objective Addressed Explanation
Add authz MsgRevokeAll message (Issue #20139)

Recent Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 0244888 and 549b64b.
Files selected for processing (1)
  • x/authz/CHANGELOG.md (1 hunks)
Additional Context Used
LanguageTool (34)
x/authz/CHANGELOG.md (34)

Near line 30: Unpaired symbol: ‘[’ seems to be missing
Context: ...## [Unreleased] ### Features * [#18737](https://github.com/cosmos/cosmos-sdk/pu...


Near line 30: Possible spelling mistake found.
Context: ... Added a limit of 200 grants pruned per BeginBlock and the PruneExpiredGrants message t...


Near line 30: Possible spelling mistake found.
Context: ... grants pruned per BeginBlock and the PruneExpiredGrants message that prunes 75 expired grants ...


Near line 31: Unpaired symbol: ‘[’ seems to be missing
Context: ...5 expired grants on every run. * [#20161](https://github.com/cosmos/cosmos-sdk/pu...


Near line 31: Possible spelling mistake found.
Context: ...com//pull/20161) Added RevokeAll method to revoke all grants at once. ...


Near line 35: Unpaired symbol: ‘[’ seems to be missing
Context: ...ce. ### API Breaking Changes * [#19783](https://github.com/cosmos/cosmos-sdk/pu...


Near line 35: Put a space after the comma, but not before the comma.
Context: ...oves the use of Accounts String() method * NewMsgExec, NewMsgGrant and NewMsgRevoke now ta...


Near line 36: Possible spelling mistake found.
Context: ...nts String() method * NewMsgExec, NewMsgGrant and NewMsgRevoke now takes strings a...


Near line 36: Possible spelling mistake found.
Context: ...d * NewMsgExec, NewMsgGrant and NewMsgRevoke now takes strings as arguments instead...


Near line 36: Add a space between sentences.
Context: ...w takes strings as arguments instead of sdk.AccAddress. * ExportGenesis also returns an...


Near line 37: This sentence does not start with an uppercase letter.
Context: ...sdk.AccAddress. * ExportGenesis also returns an error. * IterateGrants...


Near line 38: This sentence does not start with an uppercase letter.
Context: ...returns an error. * IterateGrants returns an error, its handler function also ret...


Near line 39: Unpaired symbol: ‘[’ seems to be missing
Context: ...unction also returns an error. * [#19637](https://github.com/cosmos/cosmos-sdk/pu...


Near line 39: Possible spelling mistake found.
Context: ...ithub.com//pull/19637) NewKeeper doesn't take a message router anymore....


Near line 39: Add a space between sentences.
Context: ... anymore. Set the message router in the appmodule.Environment instead. * [#19490](https://github.com...


Near line 40: Unpaired symbol: ‘[’ seems to be missing
Context: ...ppmodule.Environment` instead. * [#19490](https://github.com/cosmos/cosmos-sdk/pu...


Near line 40: Add a space between sentences.
Context: ...ithub.com//pull/19490) appmodule.Environment is received on the Keeper to get acces...


Near line 41: Unpaired symbol: ‘[’ seems to be missing
Context: ...ifferent application services. * [#18737](https://github.com/cosmos/cosmos-sdk/pu...


Near line 41: Possible spelling mistake found.
Context: ...dk/pull/18737) Update the keeper method DequeueAndDeleteExpiredGrants to take a limit argument for the numbe...


Near line 42: Unpaired symbol: ‘[’ seems to be missing
Context: ...the number of grants to prune. * [#16509](https://github.com/cosmos/cosmos-sdk/pu...


Near line 42: Possible spelling mistake found.
Context: ...ithub.com//pull/16509) AcceptResponse has been moved to sdk/types/authz and ...


Near line 42: Possible spelling mistake found.
Context: ...509) AcceptResponse has been moved to sdk/types/authz and the Updated field is ...


Near line 42: Possible spelling mistake found.
Context: ...ptResponsehas been moved to sdk/types/authz and theUpdated` field is now of the t...


Near line 42: Add a space between sentences.
Context: ... the Updated field is now of the type sdk.Msg instead of authz.Authorization. * [#...


Near line 42: Add a space between sentences.
Context: ...is now of the type sdk.Msg instead of authz.Authorization. * [#19740](https://github.com/cosmos/...


Near line 43: Unpaired symbol: ‘[’ seems to be missing
Context: ...tead of authz.Authorization. * [#19740](https://github.com/cosmos/cosmos-sdk/pu...


Near line 43: Possible spelling mistake found.
Context: ...ithub.com//pull/19740) InitGenesis and ExportGenesis module code and ke...


Near line 43: Possible spelling mistake found.
Context: ...osmos-sdk/pull/19740) InitGenesis and ExportGenesis module code and keeper code do not pan...


Near line 47: Unpaired symbol: ‘[’ seems to be missing
Context: ...## Consensus Breaking Changes * [#19188](https://github.com/cosmos/cosmos-sdk/pu...


Near line 47: Possible spelling mistake found.
Context: ...smos-sdk/pull/19188) Remove creation of BaseAccount when sending a message to an account t...


Near line 51: Unpaired symbol: ‘[’ seems to be missing
Context: ...oes not exist. ### Bug Fixes * [#19874](https://github.com/cosmos/cosmos-sdk/pu...


Near line 51: Possible spelling mistake found.
Context: ...hen querying transaction events (cosmos.tx.v1beta1.Service/GetTxsEvent) the respon...


Near line 51: Add a space between sentences.
Context: ...g transaction events (cosmos.tx.v1beta1.Service/GetTxsEvent) the response will contain ...


Near line 51: Possible spelling mistake found.
Context: ...ction events (cosmos.tx.v1beta1.Service/GetTxsEvent) the response will contain only UTF-8 c...

Path-based Instructions (1)
x/authz/CHANGELOG.md (1)

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


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

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

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

Out of diff range and nitpick comments (9)
api/cosmos/authz/v1beta1/tx.pulsar.go (9)

2881-2884: Ensure that global variables are necessary and used appropriately.

Global variables can lead to issues with maintainability and thread safety. Consider if these variables can be encapsulated within a function or struct.


2894-2894: Type aliasing used for fastReflection_MsgRevokeAll should be justified with comments.

Explain why this type aliasing is necessary, as it can confuse future maintainers.


2933-2938: Review the necessity of the Type method returning custom type information.

If the Go type information is not used elsewhere, consider simplifying this method to return only the descriptor as recommended.


3312-3312: Type aliasing used for fastReflection_MsgRevokeAllResponse should be justified with comments.

Explain why this type aliasing is necessary, as it can confuse future maintainers.


3351-3356: Review the necessity of the Type method returning custom type information for the response message.

If the Go type information is not used elsewhere, consider simplifying this method to return only the descriptor as recommended.


4715-4720: Review deprecated method Descriptor for MsgRevokeAll.

Consider replacing deprecated methods with their recommended alternatives to maintain compatibility with newer protobuf versions.


4749-4754: Review deprecated method Descriptor for MsgRevokeAllResponse.

Consider replacing deprecated methods with their recommended alternatives to maintain compatibility with newer protobuf versions.


4784-4784: Review deprecated method Descriptor for MsgPruneExpiredGrants.

Consider replacing deprecated methods with their recommended alternatives to maintain compatibility with newer protobuf versions.


4820-4820: Review deprecated method Descriptor for MsgPruneExpiredGrantsResponse.

Consider replacing deprecated methods with their recommended alternatives to maintain compatibility with newer protobuf versions.

@julienrbrt julienrbrt changed the title [feat/authz] Add MsgRevokeAll feat(x/authz): Add MsgRevokeAll Apr 23, 2024
@julienrbrt julienrbrt self-assigned this Apr 23, 2024
api/cosmos/authz/v1beta1/event.pulsar.go Dismissed Show dismissed Hide dismissed
api/cosmos/authz/v1beta1/event.pulsar.go Dismissed Show dismissed Hide dismissed
api/cosmos/authz/v1beta1/tx.pulsar.go Dismissed Show dismissed Hide dismissed
api/cosmos/authz/v1beta1/tx.pulsar.go Dismissed Show dismissed Hide dismissed
api/cosmos/authz/v1beta1/tx.pulsar.go Dismissed Show dismissed Hide dismissed
api/cosmos/authz/v1beta1/tx.pulsar.go Dismissed Show dismissed Hide dismissed
@kien6034 kien6034 marked this pull request as ready for review April 24, 2024 11:53
@kien6034
Copy link
Contributor Author

@TropicalDog17 tks for contributing. @julienrbrt the PR is ready, can you please review this PR?

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

x/authz/CHANGELOG.md Outdated Show resolved Hide resolved
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

Out of diff range and nitpick comments (1)
x/authz/CHANGELOG.md (1)

31-31: Ensure consistency in the changelog entry format.

The changelog entry for the RevokeAll method could be improved by specifying what it revokes (e.g., "all authorization grants") to provide clearer information to the users.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

mostly lgtm!

count := 0
err := k.IterateGranterGrants(ctx, granter, func(grantee sdk.AccAddress, msgType string) (stop bool, err error) {
count++
if err := k.DeleteGrant(ctx, grantee, granter, msgType); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should delete in the iterator (? cc @facundomedica).
shall we insted keep a map of that and delete afterwards?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think for now we can delete in the iterator. For your comment, perhaps we can move to a followup PR ?

Copy link
Member

Choose a reason for hiding this comment

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

No, we can't delete in an iterator, as it's not deemed safe. Let's please gather all of the keys first and then delete them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@facundomedica updated sir

x/authz/proto/cosmos/authz/v1beta1/tx.proto Outdated Show resolved Hide resolved
x/authz/proto/cosmos/authz/v1beta1/tx.proto Show resolved Hide resolved
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: 6

Out of diff range and nitpick comments (2)
api/cosmos/authz/v1beta1/tx.pulsar.go (2)

4784-4784: Deprecated method usage in Descriptor.

The Descriptor method is marked as deprecated. Consider using the recommended alternative ProtoReflect.Descriptor to adhere to current best practices.


4820-4820: Deprecated method usage in Descriptor.

The Descriptor method is marked as deprecated. Consider using the recommended alternative ProtoReflect.Descriptor to adhere to current best practices.

Comment on lines +2881 to +2884
var (
md_MsgRevokeAll protoreflect.MessageDescriptor
fd_MsgRevokeAll_granter protoreflect.FieldDescriptor
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Initialization of global variables should be avoided due to potential initialization order issues and side effects.

Consider moving these initializations into an init() function or directly into the file_cosmos_authz_v1beta1_tx_proto_init() function to ensure they are properly initialized in a controlled manner.

Comment on lines +2977 to +2986
switch fd.FullName() {
case "cosmos.authz.v1beta1.MsgRevokeAll.granter":
return x.Granter != ""
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.authz.v1beta1.MsgRevokeAll"))
}
panic(fmt.Errorf("message cosmos.authz.v1beta1.MsgRevokeAll does not contain field %s", fd.FullName()))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Error handling in Has method uses panics for control flow, which is not recommended.

Replace panics with error returns to improve error handling and avoid potential runtime panics that can terminate the application unexpectedly.

Comment on lines +2994 to +3004
func (x *fastReflection_MsgRevokeAll) Clear(fd protoreflect.FieldDescriptor) {
switch fd.FullName() {
case "cosmos.authz.v1beta1.MsgRevokeAll.granter":
x.Granter = ""
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.authz.v1beta1.MsgRevokeAll"))
}
panic(fmt.Errorf("message cosmos.authz.v1beta1.MsgRevokeAll does not contain field %s", fd.FullName()))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Use of panics for error handling in Clear method.

Consider revising the error handling strategy to return errors instead of using panics, enhancing the robustness and reliability of the code.

Comment on lines +3034 to +3045
// Set is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_MsgRevokeAll) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) {
switch fd.FullName() {
case "cosmos.authz.v1beta1.MsgRevokeAll.granter":
x.Granter = value.Interface().(string)
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.authz.v1beta1.MsgRevokeAll"))
}
panic(fmt.Errorf("message cosmos.authz.v1beta1.MsgRevokeAll does not contain field %s", fd.FullName()))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The Set method uses panics for error handling, which could lead to abrupt termination of the program.

It is safer to handle errors gracefully by returning them to the caller, allowing them to decide on the appropriate action.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

Could you add an autocli config? (In autocli.go)

@kien6034 kien6034 requested a review from julienrbrt April 25, 2024 09:19
@kien6034
Copy link
Contributor Author

@julienrbrt I updated code according to your comments

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

@@ -2898,7 +3674,7 @@ func (x *MsgPruneExpiredGrants) ProtoReflect() protoreflect.Message {
}

func (x *MsgPruneExpiredGrants) slowProtoReflect() protoreflect.Message {
mi := &file_cosmos_authz_v1beta1_tx_proto_msgTypes[6]
mi := &file_cosmos_authz_v1beta1_tx_proto_msgTypes[8]
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that the method slowProtoReflect for MsgPruneExpiredGrants is fully implemented. This snippet shows an incomplete implementation which might be an error or oversight.

Would you like me to complete the implementation of this method or open a GitHub issue to track this task?

@@ -3316,7 +4092,7 @@
}

func (x *MsgPruneExpiredGrantsResponse) slowProtoReflect() protoreflect.Message {
mi := &file_cosmos_authz_v1beta1_tx_proto_msgTypes[7]
mi := &file_cosmos_authz_v1beta1_tx_proto_msgTypes[9]
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that the method slowProtoReflect for MsgPruneExpiredGrantsResponse is fully implemented. This snippet shows an incomplete implementation which might be an error or oversight.

Would you like me to complete the implementation of this method or open a GitHub issue to track this task?

@kien6034 kien6034 requested a review from facundomedica April 25, 2024 15:34
@@ -256,6 +256,31 @@ func (k Keeper) DeleteGrant(ctx context.Context, grantee, granter sdk.AccAddress
})
}

// DeleteAllGrants revokes all authorizations granted to the grantee by the granter.
func (k Keeper) DeleteAllGrants(ctx context.Context, granter sdk.AccAddress) error {
var keysToDelete []string
Copy link
Member

Choose a reason for hiding this comment

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

nit: no need to be a []string, make it a [][]byte please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah. I've just updated

Copy link
Member

@facundomedica facundomedica left a comment

Choose a reason for hiding this comment

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

LGTM, there's a small nit to solve but everything else looks good. Thank you!

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

Out of diff range and nitpick comments (1)
x/authz/CHANGELOG.md (1)

31-31: Ensure consistency in the changelog entry format.

Consider adding a brief description of the MsgRevokeAll message along with the RevokeAll method to provide more context about the change.

@kien6034 kien6034 requested a review from facundomedica April 26, 2024 06:03
@julienrbrt julienrbrt enabled auto-merge April 26, 2024 07:14
@julienrbrt julienrbrt added this pull request to the merge queue Apr 26, 2024
Merged via the queue into cosmos:main with commit 2d0d190 Apr 26, 2024
57 of 60 checks passed
meetrick pushed a commit to meetrick/cosmos-sdk that referenced this pull request Apr 29, 2024
Co-authored-by: Tuan Tran <[email protected]>
Co-authored-by: Khanh Hoa <[email protected]>
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.

[Feature]: add authz MsgRevokeAll message
5 participants