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

refactor(x/auth): audit x/auth changes #21146

Merged
merged 11 commits into from
Aug 14, 2024
Merged

refactor(x/auth): audit x/auth changes #21146

merged 11 commits into from
Aug 14, 2024

Conversation

sontrinh16
Copy link
Member

@sontrinh16 sontrinh16 commented Aug 1, 2024

Description

Closes: #XXXX


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

  • Bug Fixes

    • Removed outdated deprecation notice for NextAccountNumber in the CHANGELOG.md, ensuring accurate documentation.
  • Documentation

    • Revised CHANGELOG.md to reflect current practices by removing the entry regarding the deprecation of NextAccountNumber.

Copy link
Contributor

coderabbitai bot commented Aug 1, 2024

Walkthrough

Walkthrough

The recent changes across the Cosmos SDK's authentication and vesting modules enhance error handling, refine transaction management, and clarify code practices. Significant modifications include the removal of deprecated methods, updates to transaction expiration logic, and the elimination of CLI command documentation for the vesting module. These updates streamline functionality and guide users towards current practices, ultimately fostering a more efficient and user-friendly experience.

Changes

Files Change Summary
CHANGELOG.md, x/auth/CHANGELOG.md Removed deprecation notice for NextAccountNumber, indicating a shift in account management practices. Improved error handling in multiple functions and streamlined the interface by removing unnecessary methods.
x/auth/ante/unorderedtx/.../manager.go, x/auth/ante/unorderedtx/.../manager_test.go Updated transaction management logic and clarified method comments regarding block time. Adjusted test conditions for transaction expiration based on TTL changes.
x/auth/ante/unorderedtx/snapshotter.go Simplified handling of expired transactions, explicitly stating intent to purge them, enhancing clarity and efficiency in transaction restoration logic.
x/auth/keeper/.../keeper_test.go, x/auth/keeper/.../msg_server.go, x/auth/keeper/.../msg_server_test.go Introduced a new test for migrating account numbers and improved test coverage for non-atomic executions and parameter updates. Renamed context parameter for better readability.
x/auth/vesting/README.md Removed extensive documentation on CLI commands for the vesting module, reducing clarity on user interactions.
x/auth/vesting/types/.../codec.go Removed registration of several message types related to vesting accounts, suggesting a potential refactoring in how these messages are handled within the SDK.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AuthKeeper
    participant MsgServer
    participant TransactionManager

    User->>AuthKeeper: Create Transaction
    AuthKeeper->>MsgServer: Validate Transaction
    MsgServer->>TransactionManager: Process Transaction
    TransactionManager-->>AuthKeeper: Transaction Result
    AuthKeeper-->>User: Confirmation
Loading
sequenceDiagram
    participant User
    participant Keeper
    participant Account

    User->>Keeper: Request Account Migration
    Keeper->>Account: Retrieve Legacy Account Number
    Account-->>Keeper: Return Legacy Number
    Keeper-->>User: Confirm Migration Success
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.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Aug 1, 2024
@sontrinh16 sontrinh16 marked this pull request as ready for review August 8, 2024 02:36
@sontrinh16 sontrinh16 requested a review from a team as a code owner August 8, 2024 02:36
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 (1)
x/auth/CHANGELOG.md (1)

44-44: Consider adding the article "the".

The sentence "Remove vesting CLI" might be clearer as "Remove the vesting CLI."

- * (vesting) [#19539](https://github.com/cosmos/cosmos-sdk/pull/19539) Remove vesting CLI.
+ * (vesting) [#19539](https://github.com/cosmos/cosmos-sdk/pull/19539) Remove the vesting CLI.
Tools
LanguageTool

[uncategorized] ~44-~44: You might be missing the article “the” here.
Context: ...om//pull/19539) Remove vesting CLI. ### API Breaking Changes * [#194...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 49179eb and 7faddfe.

Files ignored due to path filters (1)
  • x/auth/vesting/types/tx.pb.go is excluded by !**/*.pb.go
Files selected for processing (10)
  • CHANGELOG.md (1 hunks)
  • x/auth/CHANGELOG.md (3 hunks)
  • x/auth/ante/unorderedtx/manager.go (3 hunks)
  • x/auth/ante/unorderedtx/manager_test.go (2 hunks)
  • x/auth/ante/unorderedtx/snapshotter.go (1 hunks)
  • x/auth/keeper/keeper_test.go (2 hunks)
  • x/auth/keeper/msg_server.go (2 hunks)
  • x/auth/keeper/msg_server_test.go (3 hunks)
  • x/auth/vesting/README.md (1 hunks)
  • x/auth/vesting/types/codec.go (3 hunks)
Files skipped from review due to trivial changes (4)
  • CHANGELOG.md
  • x/auth/ante/unorderedtx/manager.go
  • x/auth/keeper/msg_server.go
  • x/auth/vesting/README.md
Additional context used
Path-based instructions (6)
x/auth/vesting/types/codec.go (1)

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

x/auth/ante/unorderedtx/snapshotter.go (1)

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

x/auth/ante/unorderedtx/manager_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/auth/CHANGELOG.md (1)

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

x/auth/keeper/msg_server_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/auth/keeper/keeper_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"

LanguageTool
x/auth/CHANGELOG.md

[uncategorized] ~44-~44: You might be missing the article “the” here.
Context: ...om//pull/19539) Remove vesting CLI. ### API Breaking Changes * [#194...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)

Additional comments not posted (6)
x/auth/vesting/types/codec.go (2)

Line range hint 18-34:
Confirm architectural decision for removal of message registrations.

The removal of message registrations suggests a shift in handling vesting account messages. Confirm that this aligns with broader architectural decisions within the SDK.


Line range hint 9-15:
Verify the necessity of remaining concrete type registrations.

The removal of certain message registrations streamlines the codec. Ensure that the remaining concrete type registrations are necessary and correctly implemented.

Verification successful

Concrete type registrations are necessary and correct.

The registered concrete types BaseVestingAccount, ContinuousVestingAccount, DelayedVestingAccount, PeriodicVestingAccount, and PermanentLockedAccount are actively used across the codebase. Their presence in account creation and testing confirms their necessity for the vesting module's functionality. The current registrations in the codec are appropriate and required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of registered concrete types in the codebase.

# Test: Search for the usage of `BaseVestingAccount` and other registered types.
rg --type go 'BaseVestingAccount|ContinuousVestingAccount|DelayedVestingAccount|PeriodicVestingAccount|PermanentLockedAccount'

Length of output: 112122

x/auth/ante/unorderedtx/snapshotter.go (1)

83-84: Verify correctness of timestamp handling and transaction addition.

The proactive handling of expired transactions improves efficiency. Verify that the logic for timestamp comparison and transaction addition is correct.

Verification successful

Timestamp handling logic is implemented correctly.

The code includes a check to ensure timestamps are non-zero and greater than a specified height, indicating that timestamp handling is appropriately managed.

  • x/auth/ante/unorderedtx/snapshotter.go: Line with if timestamp != 0 && timestamp > height confirms correct logic.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of timestamp handling in transaction addition.

# Test: Check for logic handling timestamps in related functions or documentation.
rg --type go 'timestamp > height'

Length of output: 118

x/auth/ante/unorderedtx/manager_test.go (1)

Line range hint 106-138:
Verify adequacy of test coverage for new purging criteria.

The test changes align with the new purging criteria. Ensure that the test adequately covers edge cases and the new logic.

x/auth/keeper/msg_server_test.go (1)

137-205: Good addition of TestNonAtomicExec.

The new test cases in TestNonAtomicExec effectively cover various scenarios, including error conditions and valid transactions. This enhances the robustness of the Keeper logic.

x/auth/keeper/keeper_test.go (1)

255-282: Well-structured test for TestMigrateAccountNumberUnsafe.

The test effectively validates the migration of account numbers, ensuring that legacy account numbers are correctly handled. The use of mock expectations and assertions is appropriate and clear.

@@ -21,9 +18,6 @@ func RegisterLegacyAminoCodec(cdc corelegacy.Amino) {
cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount")
cdc.RegisterConcrete(&PeriodicVestingAccount{}, "cosmos-sdk/PeriodicVestingAccount")
cdc.RegisterConcrete(&PermanentLockedAccount{}, "cosmos-sdk/PermanentLockedAccount")
legacy.RegisterAminoMsg(cdc, &MsgCreateVestingAccount{}, "cosmos-sdk/MsgCreateVestingAccount")
Copy link
Member

Choose a reason for hiding this comment

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

nice find!

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 7faddfe and 44f6a42.

Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

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 44f6a42 and 9cf6af2.

Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

@sontrinh16 sontrinh16 mentioned this pull request Aug 12, 2024
28 tasks
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.

ACK

@julienrbrt julienrbrt added this pull request to the merge queue Aug 14, 2024
Merged via the queue into main with commit 0fe3115 Aug 14, 2024
75 checks passed
@julienrbrt julienrbrt deleted the son/audit_auth branch August 14, 2024 15:16
mergify bot pushed a commit that referenced this pull request Aug 14, 2024
sontrinh16 added a commit that referenced this pull request Aug 14, 2024
Co-authored-by: son trinh <trinhleson2000@gmail.com>
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/auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants