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(accounts/base): give chains the possibility to pick their chosen pubkey types for the base accounts #21466

Merged
merged 8 commits into from
Sep 3, 2024

Conversation

testinginprod
Copy link
Contributor

@testinginprod testinginprod commented Aug 29, 2024

Description

It is now possible to plug in different pubkeys in base account.

This allows chains to inject custom pubkeys into the base account type, making the transition to x/accounts for accounts of any kind much more simpler!


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 public key handling with flexible representations using google.protobuf.Any.
    • Introduced new message types: QueryPubKey and QueryPubKeyResponse for querying public keys.
    • Updated account creation process to support Secp256K1 public keys.
    • Added functionality to allow integration of custom public key types in the account structure.
  • Bug Fixes

    • Improved error handling and validation for public key management.
  • Documentation

    • Updated documentation to reflect changes in public key handling and new message types.
  • Tests

    • Enhanced test cases for public key validation and serialization.

Copy link
Contributor

coderabbitai bot commented Aug 29, 2024

Warning

Rate limit exceeded

@testinginprod has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 18 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 33cb6b6 and b13ff06.

Walkthrough

Walkthrough

The changes involve significant modifications to the handling of public keys within the Cosmos SDK account management system. Key message types, MsgInit and MsgSwapPubKey, have been updated to utilize the google.protobuf.Any type for public keys, enhancing flexibility. New message types for querying public keys have been introduced. Additionally, various account management functions and test cases have been updated to support these changes, improving public key validation and handling.

Changes

Files Change Summary
api/cosmos/accounts/defaults/base/v1/base.pulsar.go, x/accounts/proto/cosmos/accounts/defaults/base/v1/base.proto Updated MsgInit and MsgSwapPubKey to use google.protobuf.Any for public keys; added QueryPubKey and QueryPubKeyResponse message types.
scripts/protocgen.sh Increased maximum search depth for .proto files from 5 to 8 to include deeper nested files.
simapp/app.go Modified NewSimApp to include baseaccount.WithSecp256K1PubKey() for account initialization.
x/accounts/defaults/base/account.go, x/accounts/defaults/base/account_test.go Removed specific public key type; added PubKeyType field; updated NewAccount to accept options; enhanced public key handling in tests.
x/accounts/defaults/base/pubkey.go Introduced a PubKey interface and utility functions for public key management and validation.
x/accounts/depinject.go Updated ProvideModule to include additional parameter for account creation.

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.

@testinginprod testinginprod marked this pull request as ready for review August 29, 2024 13:50
@testinginprod testinginprod requested a review from a team as a code owner August 29, 2024 13:50

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

Outside diff range, codebase verification and nitpick comments (1)
x/accounts/depinject.go (1)

67-67: Update function call to match new signature

The function call to baseaccount.NewAccount in tests/integration/auth/keeper/msg_server_test.go does not include the baseaccount.WithSecp256K1PubKey() parameter. Please update this instance to ensure consistency with the new function signature.

  • File: tests/integration/auth/keeper/msg_server_test.go
Analysis chain

LGTM! But verify the function usage in the codebase.

The change enhances the account creation process by configuring the account to utilize a specific public key type (Secp256K1). Ensure that all function calls to baseaccount.NewAccount match the new signature.

The code changes are approved.

Run the following script to verify the function usage:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `baseaccount.NewAccount` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'baseaccount.NewAccount'

Length of output: 1609

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 33c463e and 803aafa.

Files ignored due to path filters (2)
  • store/internal/kv/kv.pb.go is excluded by !**/*.pb.go
  • x/accounts/defaults/base/v1/base.pb.go is excluded by !**/*.pb.go
Files selected for processing (8)
  • api/cosmos/accounts/defaults/base/v1/base.pulsar.go (25 hunks)
  • scripts/protocgen.sh (1 hunks)
  • simapp/app.go (1 hunks)
  • x/accounts/defaults/base/account.go (6 hunks)
  • x/accounts/defaults/base/account_test.go (10 hunks)
  • x/accounts/defaults/base/pubkey.go (1 hunks)
  • x/accounts/depinject.go (1 hunks)
  • x/accounts/proto/cosmos/accounts/defaults/base/v1/base.proto (3 hunks)
Additional context used
Path-based instructions (6)
x/accounts/defaults/base/pubkey.go (1)

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

x/accounts/depinject.go (1)

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

x/accounts/defaults/base/account_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/defaults/base/account.go (1)

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

simapp/app.go (1)

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

api/cosmos/accounts/defaults/base/v1/base.pulsar.go (1)

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

Shellcheck
scripts/protocgen.sh

[warning] 32-32: For loops over find output are fragile. Use find -exec or a while read loop.

(SC2044)

Additional comments not posted (48)
x/accounts/proto/cosmos/accounts/defaults/base/v1/base.proto (4)

7-7: LGTM!

The import statement for google/protobuf/any.proto is necessary for the changes made to the pub_key fields.


11-12: LGTM!

Changing the pub_key field type from bytes to google.protobuf.Any allows for a more flexible representation of public keys.


22-22: LGTM!

Changing the new_pub_key field type from bytes to google.protobuf.Any allows for a more flexible representation of public keys.


38-44: LGTM!

The addition of the QueryPubKey and QueryPubKeyResponse messages facilitates querying public keys in a more versatile manner.

x/accounts/defaults/base/pubkey.go (4)

31-36: LGTM!

The WithSecp256K1PubKey function correctly implements the validation for secp256k1 public keys.


38-42: LGTM!

The WithPubKey function correctly implements the option for generic public keys without validation.


44-65: LGTM!

The WithPubKeyWithValidationFunc function correctly implements the option for generic public keys with a custom validation function.


67-72: LGTM!

The nameFromTypeURL function correctly extracts the name from a type URL.

x/accounts/defaults/base/account_test.go (5)

30-33: LGTM!

The change enhances the robustness of public key handling by ensuring that the provided public key is correctly parsed and validated.

The code changes are approved.


45-45: LGTM!

The change ensures that public keys are correctly serialized, which is crucial for maintaining the integrity of account management in the system.

The code changes are approved.

Also applies to: 57-57, 64-64


86-86: LGTM!

The change ensures that public keys are correctly serialized, which is crucial for maintaining the integrity of account management in the system.

The code changes are approved.

Also applies to: 103-103, 114-114, 125-125


158-158: LGTM!

The change ensures that public keys are correctly serialized, which is crucial for maintaining the integrity of account management in the system.

The code changes are approved.


261-269: LGTM!

The function is correctly implemented and enhances the robustness of public key handling in the test cases.

The code changes are approved.

x/accounts/defaults/base/account.go (8)

32-33: LGTM!

The addition of the Option type and its usage in the NewAccount function enhances the flexibility of account creation by allowing additional configurations.

The code changes are approved.

Also applies to: 34-34, 45-47


36-44: LGTM!

The changes enhance the flexibility of public key management and improve the robustness of the account management system.

The code changes are approved.

Also applies to: 57-58, 65-66


71-71: LGTM!

The change ensures that public keys are correctly saved and validated during account initialization.

The code changes are approved.


79-79: LGTM!

The change ensures that public keys are correctly saved and validated during key swapping.

The code changes are approved.


90-90: LGTM!

The change ensures that public keys are correctly handled during authentication.

The code changes are approved.

Also applies to: 95-95, 112-112


131-134: LGTM!

The change reflects the broader public key handling and improves error handling by providing clearer context for failures.

The code changes are approved.

Also applies to: 140-140, 143-145, 148-150, 155-155


208-230: LGTM!

The method is correctly implemented and enhances the robustness of public key handling in the account management system.

The code changes are approved.


232-254: LGTM!

The method is correctly implemented and enhances the robustness of public key handling in the account management system.

The code changes are approved.

simapp/app.go (1)

308-308: Ensure the new public key type is supported.

The addition of baseaccount.WithSecp256K1PubKey() as a parameter to baseaccount.NewAccount is correct. However, ensure that the new public key type is supported throughout the codebase and that any necessary changes are made to accommodate it.

Run the following script to verify the usage of baseaccount.WithSecp256K1PubKey in the codebase:

api/cosmos/accounts/defaults/base/v1/base.pulsar.go (26)

10-10: LGTM!

The import statement for anypb is correct and necessary for the changes made in the file.


92-93: LGTM!

The Range method correctly handles the new *anypb.Any type for PubKey.


114-114: LGTM!

The Has method correctly handles the new *anypb.Any type for PubKey.


151-151: LGTM!

The Get method correctly handles the new *anypb.Any type for PubKey.


173-173: LGTM!

The Set method correctly handles the new *anypb.Any type for PubKey.


195-198: LGTM!

The Mutable method correctly handles the new *anypb.Any type for PubKey.


213-214: LGTM!

The NewField method correctly handles the new *anypb.Any type for PubKey.


284-285: LGTM!

The Size method correctly handles the new *anypb.Any type for PubKey.


317-327: LGTM!

The Marshal method correctly handles the new *anypb.Any type for PubKey.


Line range hint 384-413: LGTM!

The Unmarshal method correctly handles the new *anypb.Any type for PubKey.


883-884: LGTM!

The Range method correctly handles the new *anypb.Any type for NewPubKey.


905-905: LGTM!

The Has method correctly handles the new *anypb.Any type for NewPubKey.


942-942: LGTM!

The Get method correctly handles the new *anypb.Any type for NewPubKey.


964-964: LGTM!

The Set method correctly handles the new *anypb.Any type for NewPubKey.


986-989: LGTM!

The Mutable method correctly handles the new *anypb.Any type for NewPubKey.


1004-1005: LGTM!

The NewField method correctly handles the new *anypb.Any type for NewPubKey.


1075-1076: LGTM!

The Size method correctly handles the new *anypb.Any type for NewPubKey.


1108-1118: LGTM!

The Marshal method correctly handles the new *anypb.Any type for NewPubKey.


Line range hint 1175-1204: LGTM!

The Unmarshal method correctly handles the new *anypb.Any type for NewPubKey.


2790-2795: LGTM!

The Range method correctly handles the new *anypb.Any type for PubKey.


2810-2812: LGTM!

The Has method correctly handles the new *anypb.Any type for PubKey.


2846-2849: LGTM!

The Get method correctly handles the new *anypb.Any type for PubKey.


2869-2871: LGTM!

The Set method correctly handles the new *anypb.Any type for PubKey.


2893-2896: LGTM!

The Mutable method correctly handles the new *anypb.Any type for PubKey.


2909-2912: LGTM!

The NewField method correctly handles the new *anypb.Any type for PubKey.


2982-2983: LGTM!

The Size method correctly handles the new *anypb.Any type for PubKey.

@@ -29,7 +29,7 @@ for dir in $proto_dirs; do

# check if buf.gen.gogo.yaml exists in the proto directory
if [ -f "buf.gen.gogo.yaml" ]; then
for file in $(find . -maxdepth 5 -name '*.proto'); do
for file in $(find . -maxdepth 8 -name '*.proto'); do
Copy link
Contributor

Choose a reason for hiding this comment

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

Use find -exec to address the Shellcheck warning.

For loops over find output are fragile. Use find -exec to address the Shellcheck warning.

Apply this diff to fix the issue:

-      for file in $(find . -maxdepth 8 -name '*.proto'); do
+      find . -maxdepth 8 -name '*.proto' -exec sh -c '
+        for file; do
+          if grep -q "option go_package" "$file" && grep -H -o -c "option go_package.*cosmossdk.io/api" "$file" | grep -q ":0$"; then
+            buf generate --template buf.gen.gogo.yaml "$file"
+          fi
+        done
+      ' sh {} +
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
for file in $(find . -maxdepth 8 -name '*.proto'); do
find . -maxdepth 8 -name '*.proto' -exec sh -c '
for file; do
if grep -q "option go_package" "$file" && grep -H -o -c "option go_package.*cosmossdk.io/api" "$file" | grep -q ":0$"; then
buf generate --template buf.gen.gogo.yaml "$file"
fi
done
' sh {} +
Tools
Shellcheck

[warning] 32-32: For loops over find output are fragile. Use find -exec or a while read loop.

(SC2044)


// PubKey defines a generic pubkey.
type PubKey interface {
gogoproto.Message
Copy link
Member

Choose a reason for hiding this comment

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

should we make this core tx.Msg to be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed, let me fix

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 803aafa and 3320e85.

Files selected for processing (2)
  • simapp/CHANGELOG.md (1 hunks)
  • tests/integration/auth/keeper/msg_server_test.go (1 hunks)
Additional context used
Path-based instructions (2)
simapp/CHANGELOG.md (1)

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

tests/integration/auth/keeper/msg_server_test.go (3)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (2)
simapp/CHANGELOG.md (1)

48-48: LGTM!

The changelog entry is well-written and follows the guidelines.

tests/integration/auth/keeper/msg_server_test.go (1)

81-81: LGTM!

The modification enhances the account creation process by specifying the use of a Secp256K1 public key. This change is likely to impact cryptographic operations and the overall behavior of the account in subsequent tests.

@testinginprod testinginprod added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Aug 29, 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: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3320e85 and 33cb6b6.

Files selected for processing (1)
  • x/accounts/defaults/base/pubkey.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/accounts/defaults/base/pubkey.go

// pub_key defines the secp256k1 pubkey for the account.
bytes pub_key = 1;
// pub_key defines a pubkey for the account arbitrary encapsulated.
google.protobuf.Any pub_key = 1;
Copy link
Member

Choose a reason for hiding this comment

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

why do we need an Any here? What would be the improvement over just bytes?

Copy link
Member

Choose a reason for hiding this comment

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

Probably so that you know from the type url what is the pub key type

@testinginprod testinginprod added this pull request to the merge queue Sep 3, 2024
Merged via the queue into main with commit 8431dbd Sep 3, 2024
78 checks passed
@testinginprod testinginprod deleted the tip/accounts/base/flexible_pubkeys branch September 3, 2024 17:14
mergify bot pushed a commit that referenced this pull request Sep 3, 2024
… pubkey types for the base accounts (#21466)

(cherry picked from commit 8431dbd)

# Conflicts:
#	api/cosmos/accounts/defaults/base/v1/base.pulsar.go
#	store/internal/kv/kv.pb.go
julienrbrt added a commit that referenced this pull request Sep 3, 2024
… pubkey types for the base accounts (backport #21466) (#21524)

Co-authored-by: testinginprod <98415576+testinginprod@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
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:Store C:x/accounts Type: Build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants