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/accounts)!: accounts and auth module use the same account number tracking #20405

Merged
merged 32 commits into from
Jun 3, 2024

Conversation

sontrinh16
Copy link
Member

@sontrinh16 sontrinh16 commented May 15, 2024

Description

As for right now, x/accounts use a seperate account number sequence which we should merge it with auth account sequece, this is a first step to make x/auth -> x/accounts compat

continue work from #20234


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 logic to sync account numbers between the accounts and auth modules.
  • Bug Fixes

    • Enhanced account number handling across multiple modules to ensure consistency.
  • Tests

    • Updated tests to include new expectations for account number generation.
    • Added context imports and mock implementations for account number handling.
  • Chores

    • Updated import paths for logging in test utilities.

Copy link
Contributor

coderabbitai bot commented May 15, 2024

Walkthrough

The changes introduce a new logic to synchronize account numbers between the accounts and auth modules in the SimApp. This involves updating the RegisterUpgradeHandlers function and adding new methods in both modules to handle account number generation and initialization. Additionally, numerous tests have been updated to mock and test the new functionality, ensuring seamless integration and migration from version 5 to 6 of the x/auth module.

Changes

Files/Groups Change Summaries
simapp/upgrades.go Updated RegisterUpgradeHandlers to sync account numbers between accounts and auth modules.
tests/integration/... Added context import, new expectations for NextAccountNumber method, and logic to handle account number generation across multiple test files.
x/accounts/keeper.go Introduced NextAccountNumber and InitAccountNumberSeqUnsafe methods in the Keeper struct.
x/auth/keeper/... Updated various files to handle account number synchronization, including removing NextAccountNumber from AccountKeeper and adding migration functions.
x/auth/module.go Updated ConsensusVersion from 5 to 6 and added Migrate5To6 migration function.
x/auth/types/expected_keepers.go Added NextAccountNumber and InitAccountNumberSeqUnsafe methods to the AccountsModKeeper interface.
x/auth/testutil/expected_keepers_mocks.go Updated MockAccountsModKeeper to include NextAccountNumber and InitAccountNumberSeqUnsafe methods.
testutil/mock/logger.go Changed import path for the log package.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant SimApp
    participant AccountsModule
    participant AuthModule

    User->>SimApp: Initiate Upgrade
    SimApp->>AuthModule: Retrieve Current Account Number
    AuthModule-->>SimApp: Return Account Number
    SimApp->>AccountsModule: Set Account Number
    SimApp->>SimApp: Run Migrations
    SimApp-->>User: Upgrade Complete
Loading
sequenceDiagram
    participant Test
    participant MockAccountsModKeeper
    participant Context

    Test->>MockAccountsModKeeper: Expect NextAccountNumber
    MockAccountsModKeeper->>Context: Retrieve Account Number
    Context-->>MockAccountsModKeeper: Return Mock Account Number
    MockAccountsModKeeper-->>Test: Return Account Number
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 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.

@sontrinh16 sontrinh16 changed the title [WIP] refactor(x/accounts): accounts and auth module use the same account number tracking [WIP] refactor(x/accounts)!: accounts and auth module use the same account number tracking May 15, 2024
@sontrinh16 sontrinh16 marked this pull request as ready for review May 23, 2024 14:10
@sontrinh16 sontrinh16 requested a review from a team as a code owner May 23, 2024 14:10
@sontrinh16 sontrinh16 changed the title [WIP] refactor(x/accounts)!: accounts and auth module use the same account number tracking refactor(x/accounts)!: accounts and auth module use the same account number tracking May 23, 2024
@@ -25,6 +25,15 @@ func (app SimApp) RegisterUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// sync accounts module and auth module account number
Copy link
Contributor

Choose a reason for hiding this comment

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

@julienrbrt @tac0turtle where should the migration live?

it needs to set x/accounts Account number to auth's account number.

Copy link
Member

Choose a reason for hiding this comment

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

if accounts does not have a dependency on auth but auth has a dep on accounts then I think it would be good for auth to have the migration and set it in the other module

Copy link
Member Author

Choose a reason for hiding this comment

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

added the migration in

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, pending migration location

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 and nitpick comments (1)
tests/integration/staking/keeper/deterministic_test.go (1)

Line range hint 1-1027: Consider adding specific tests to directly verify the synchronization of account numbers between the x/accounts and x/auth modules, ensuring that the unified tracking is functioning as expected across different scenarios.

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between b3e53cf and 6d85cea.
Files selected for processing (19)
  • simapp/upgrades.go (1 hunks)
  • tests/integration/bank/keeper/deterministic_test.go (2 hunks)
  • tests/integration/distribution/keeper/msg_server_test.go (2 hunks)
  • tests/integration/evidence/keeper/infraction_test.go (1 hunks)
  • tests/integration/example/example_test.go (3 hunks)
  • tests/integration/gov/keeper/keeper_test.go (2 hunks)
  • tests/integration/slashing/keeper/keeper_test.go (2 hunks)
  • tests/integration/staking/keeper/common_test.go (3 hunks)
  • tests/integration/staking/keeper/deterministic_test.go (2 hunks)
  • x/accounts/keeper.go (1 hunks)
  • x/auth/ante/testutil_test.go (2 hunks)
  • x/auth/keeper/deterministic_test.go (2 hunks)
  • x/auth/keeper/keeper.go (2 hunks)
  • x/auth/keeper/keeper_test.go (2 hunks)
  • x/auth/testutil/expected_keepers_mocks.go (1 hunks)
  • x/auth/types/expected_keepers.go (1 hunks)
  • x/auth/vesting/testutil/expected_keepers_mocks.go (1 hunks)
  • x/distribution/migrations/v4/migrate_funds_test.go (2 hunks)
  • x/group/migrations/v2/migrate_test.go (3 hunks)
Files not reviewed due to errors (1)
  • x/auth/testutil/expected_keepers_mocks.go (no review received)
Additional Context Used
Path-based Instructions (19)
x/auth/types/expected_keepers.go (1)

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

simapp/upgrades.go (1)

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

x/distribution/migrations/v4/migrate_funds_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/group/migrations/v2/migrate_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/vesting/testutil/expected_keepers_mocks.go (1)

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

x/auth/testutil/expected_keepers_mocks.go (1)

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

tests/integration/gov/keeper/keeper_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"

tests/integration/staking/keeper/common_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"

tests/integration/example/example_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"

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"

x/auth/ante/testutil_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.go (1)

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

x/auth/keeper/deterministic_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/keeper.go (1)

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

tests/integration/bank/keeper/deterministic_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"

tests/integration/evidence/keeper/infraction_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"

tests/integration/slashing/keeper/keeper_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"

tests/integration/staking/keeper/deterministic_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"

tests/integration/distribution/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 (18)
x/auth/types/expected_keepers.go (1)

22-22: Addition of NextAccountNumber method to AccountsModKeeper aligns with the PR's objectives to synchronize account numbers.

simapp/upgrades.go (1)

28-36: Proper implementation of account number synchronization between auth and accounts modules during upgrades.

x/distribution/migrations/v4/migrate_funds_test.go (1)

57-63: Proper testing of account number generation logic in migration tests.

x/group/migrations/v2/migrate_test.go (1)

Line range hint 108-130: Proper testing of account number generation logic in group migration tests.

tests/integration/gov/keeper/keeper_test.go (1)

81-86: Ensure the mock for NextAccountNumber is correctly simulating the account number increment.

This mock setup correctly simulates the behavior of incrementing account numbers, which is crucial for testing the integration of the gov module with the account number synchronization changes.

tests/integration/staking/keeper/common_test.go (1)

191-196: Ensure the mock for NextAccountNumber is correctly simulating the account number increment.

This mock setup correctly simulates the behavior of incrementing account numbers, which is crucial for testing the integration of the staking module with the account number synchronization changes.

tests/integration/example/example_test.go (1)

53-58: Ensure the mock for NextAccountNumber is correctly simulating the account number increment.

This mock setup correctly simulates the behavior of incrementing account numbers, which is crucial for testing the integration of the example module with the account number synchronization changes.

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

66-71: Ensure the mock for NextAccountNumber is correctly simulating the account number increment.

This mock setup correctly simulates the behavior of incrementing account numbers, which is crucial for testing the integration of the auth module with the account number synchronization changes.

x/auth/ante/testutil_test.go (1)

83-88: Ensure the mock for NextAccountNumber is correctly simulating the account number increment.

This mock setup correctly simulates the behavior of incrementing account numbers, which is crucial for testing the integration of the ante module with the account number synchronization changes.

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

73-78: LGTM! The mock setup for NextAccountNumber correctly simulates sequential account number generation, which is essential for testing the integration of account number synchronization between modules.

x/accounts/keeper.go (2)

110-118: LGTM! The implementation of NextAccountNumber uses collections.Sequence for atomic increments, ensuring thread safety and correctness in concurrent environments.


121-125: LGTM! The SetAccountNumber method provides a controlled way to set the account number directly, which is essential for operations like migrations.

tests/integration/bank/keeper/deterministic_test.go (1)

88-93: LGTM! The mock setup for NextAccountNumber in the bank keeper tests correctly simulates sequential account number generation, aligning with the integration needs of the account number synchronization feature.

tests/integration/evidence/keeper/infraction_test.go (1)

110-115: The mock setup for NextAccountNumber is correctly implemented and suitable for integration testing scenarios.

tests/integration/slashing/keeper/keeper_test.go (1)

85-92: The mock setup for NextAccountNumber is correctly implemented and suitable for integration testing scenarios.

tests/integration/staking/keeper/deterministic_test.go (1)

96-101: The mocking of NextAccountNumber with a sequential increment setup is well-implemented and aligns with the integration test's needs for simulating account number generation.

tests/integration/distribution/keeper/msg_server_test.go (2)

4-4: Added import of "context" package.

This change is necessary for the new context handling in the test functions.


99-104: Added logic for simulating account number generation.

This change aligns with the PR's objective to synchronize account numbers across modules. It effectively mocks the NextAccountNumber method to simulate sequential account number generation, which is crucial for testing the integrated behavior of the distribution module with the new account number handling.

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 and nitpick comments (1)
x/accounts/keeper.go (1)

121-132: LGTM! The InitAccountNumberSeq function includes a safety check to ensure the account number is not set to a lower value than the current, which is crucial for data integrity.

Consider adding detailed documentation for this method, explaining its usage and the importance of the safety check.

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8feaaba and 91cce64.
Files selected for processing (9)
  • x/accounts/keeper.go (1 hunks)
  • x/auth/ante/testutil_test.go (2 hunks)
  • x/auth/keeper/deterministic_test.go (2 hunks)
  • x/auth/keeper/keeper.go (3 hunks)
  • x/auth/keeper/keeper_test.go (2 hunks)
  • x/auth/keeper/migrations.go (3 hunks)
  • x/auth/testutil/expected_keepers_mocks.go (2 hunks)
  • x/auth/types/expected_keepers.go (1 hunks)
  • x/auth/vesting/testutil/expected_keepers_mocks.go (2 hunks)
Files skipped from review as they are similar to previous changes (8)
  • x/auth/ante/testutil_test.go
  • x/auth/keeper/deterministic_test.go
  • x/auth/keeper/keeper.go
  • x/auth/keeper/keeper_test.go
  • x/auth/keeper/migrations.go
  • x/auth/testutil/expected_keepers_mocks.go
  • x/auth/types/expected_keepers.go
  • x/auth/vesting/testutil/expected_keepers_mocks.go
Additional Context Used
Path-based Instructions (1)
x/accounts/keeper.go (1)

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

Additional comments not posted (2)
x/accounts/keeper.go (2)

110-119: LGTM! The NextAccountNumber function correctly fetches and increments the account number, with proper error handling.


Line range hint 1-450: The rest of the file appears well-structured and adheres to best practices. The methods related to account handling are implemented correctly, and there are no apparent performance issues.
[APROVED]

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 and nitpick comments (2)
server/config/priv_validator_key.json (1)

1-11: Ensure secure handling of private keys.

This file contains sensitive information, including private keys. It's crucial to ensure that this file is securely stored and access is restricted to prevent unauthorized access.

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

25-30: Consider alternative error handling strategies to panic.

Using panic for error handling can be appropriate for unrecoverable errors, but it also terminates the program, which might not always be desirable. Consider alternatives like returning errors to the caller, especially in a library or module that might be used in various contexts where more graceful error handling could be necessary.

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 91cce64 and db13681.
Files selected for processing (10)
  • server/config/config.toml (1 hunks)
  • server/config/genesis.json (1 hunks)
  • server/config/node_key.json (1 hunks)
  • server/config/priv_validator_key.json (1 hunks)
  • server/data/priv_validator_state.json (1 hunks)
  • x/auth/keeper/account.go (1 hunks)
  • x/auth/keeper/genesis.go (1 hunks)
  • x/auth/keeper/keeper.go (4 hunks)
  • x/auth/keeper/keeper_test.go (4 hunks)
  • x/group/migrations/v2/migrate_test.go (3 hunks)
Files skipped from review due to trivial changes (4)
  • server/config/config.toml
  • server/config/genesis.json
  • server/config/node_key.json
  • server/data/priv_validator_state.json
Files skipped from review as they are similar to previous changes (3)
  • x/auth/keeper/keeper.go
  • x/auth/keeper/keeper_test.go
  • x/group/migrations/v2/migrate_test.go
Additional Context Used
Path-based Instructions (2)
x/auth/keeper/genesis.go (1)

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

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

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

Comment on lines +32 to +35
n, err := ak.AccountsModKeeper.NextAccountNumber(ctx)
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential logical flaw in setting the last account number.

The logic for updating lastAccNum seems to be inside a loop that checks if lastAccNum is less than accNum. This could lead to incorrect behavior if not all accounts are processed or if the account numbers are not strictly increasing. Consider revising this logic to ensure that lastAccNum correctly reflects the highest account number after all accounts are processed.

server/config/genesis.json Outdated Show resolved Hide resolved
x/auth/keeper/account.go Dismissed Show dismissed Hide dismissed
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 db13681 and effe701.
Files selected for processing (1)
  • x/auth/keeper/keeper.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/auth/keeper/keeper.go

@sontrinh16 sontrinh16 requested a review from alpe May 29, 2024 16:57
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: 3

Outside diff range and nitpick comments (2)
x/auth/keeper/migrations.go (1)

16-17: Consider adding a comment explaining the purpose of accNum.

Adding a comment here would improve code readability and maintainability, especially for new developers or external contributors who might work on this code in the future.

x/accounts/keeper.go (1)

Line range hint 17-17: Remove the use of the internal package to adhere to best practices.

Using internal packages from other modules can lead to maintenance issues and tightly coupled code. Consider refactoring to use public interfaces or duplicating the necessary parts within this module.

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between effe701 and 35c522e.

Files selected for processing (7)
  • testutil/mock/logger.go (1 hunks)
  • x/accounts/keeper.go (1 hunks)
  • x/auth/keeper/keeper.go (3 hunks)
  • x/auth/keeper/migrations.go (3 hunks)
  • x/auth/testutil/expected_keepers_mocks.go (2 hunks)
  • x/auth/types/expected_keepers.go (1 hunks)
  • x/auth/vesting/testutil/expected_keepers_mocks.go (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/auth/testutil/expected_keepers_mocks.go
  • x/auth/types/expected_keepers.go
  • x/auth/vesting/testutil/expected_keepers_mocks.go
Additional context used
Path-based instructions (4)
x/auth/keeper/migrations.go (1)

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

testutil/mock/logger.go (1)

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

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

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

x/accounts/keeper.go (1)

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

golangci-lint
x/auth/keeper/migrations.go

15-15: undefined: AccountKeeper


21-21: undefined: AccountKeeper

x/auth/keeper/keeper.go

107-107: cannot use &AccountKeeper{} (value of type *AccountKeeper) as AccountKeeperI value in variable declaration: *AccountKeeper does not implement AccountKeeperI (missing method GetAccount)


163-163: ak.GetAccount undefined (type AccountKeeper has no field or method GetAccount)


173-173: ak.GetAccount undefined (type AccountKeeper has no field or method GetAccount)


239-239: ak.GetAccount undefined (type AccountKeeper has no field or method GetAccount)


250-250: ak.NewAccount undefined (type AccountKeeper has no field or method NewAccount)


265-265: ak.SetAccount undefined (type AccountKeeper has no field or method SetAccount)

x/accounts/keeper.go

17-17: use of internal package cosmossdk.io/x/accounts/internal/implementation not allowed

Additional comments not posted (3)
x/auth/keeper/migrations.go (2)

22-25: Ensure proper error handling when creating accNumSeq.


51-52: Ensure that the migration logic in Migrate4To5 is thoroughly tested.

Verification successful

The search did not reveal any test functions directly related to Migrate4To5. However, there was a test function named TestMigrate in x/auth/migrations/v5/migrate_test.go, which might be relevant.

To ensure comprehensive verification, we should inspect the contents of x/auth/migrations/v5/migrate_test.go to confirm if it covers the Migrate4To5 function.


The TestMigrate function in x/auth/migrations/v5/migrate_test.go does indeed test the migration logic, specifically the Migrate function, which is called within Migrate4To5. This confirms that the migration logic is being tested.

  • TestMigrate sets up a mock store and schema, sets a legacy sequence value, and verifies that the migration correctly updates the sequence.
  • It also tests the case where the global account number is not set, ensuring the migration handles this scenario correctly.

Thus, the migration logic in Migrate4To5 is thoroughly tested.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the test coverage for the migration logic in `Migrate4To5`.

# Test: Search for tests related to `Migrate4To5`.
rg --type go $'Migrate4To5' --context 5

Length of output: 1830



Script:

#!/bin/bash
# Description: Verify the test coverage for the migration logic in `Migrate4To5`.

# Find all Go test files in the x/auth directory.
test_files=$(fd --type f --extension go --search-path x/auth --exec echo {})

# Search for test functions related to migration in the found test files.
for file in $test_files; do
  echo "Searching in $file"
  rg --type go --context 5 'func Test.*Migrate' $file
done

Length of output: 30192



Script:

#!/bin/bash
# Description: Inspect the contents of the test file that might cover the Migrate4To5 function.

# Display the contents of the test file to verify if it tests Migrate4To5.
cat x/auth/migrations/v5/migrate_test.go

Length of output: 1190

testutil/mock/logger.go (1)

10-10: Update to the new import path for the log package is correct and follows the project's dependency updates.

This change aligns with the recent updates to the logging infrastructure, ensuring compatibility and maintaining the project's standards.

Comment on lines +56 to +62
func (m Migrator) Migrate5To6(ctx context.Context) error {
currentAccNum, err := m.accNum.Peek(ctx)
if err != nil {
return err
}

return m.keeper.AccountsModKeeper.InitAccountNumberSeqUnsafe(ctx, currentAccNum)
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor to handle errors more gracefully instead of just returning them.

-	if err != nil {
-		return err
-	}
+	if err != nil {
+		// Consider logging the error or handling it according to your error policy
+		return fmt.Errorf("failed to peek account number: %w", err)
+	}

This change enhances error reporting and maintains consistency with error handling practices throughout the codebase.

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.

Suggested change
func (m Migrator) Migrate5To6(ctx context.Context) error {
currentAccNum, err := m.accNum.Peek(ctx)
if err != nil {
return err
}
return m.keeper.AccountsModKeeper.InitAccountNumberSeqUnsafe(ctx, currentAccNum)
func (m Migrator) Migrate5To6(ctx context.Context) error {
currentAccNum, err := m.accNum.Peek(ctx)
if err != nil {
// Consider logging the error or handling it according to your error policy
return fmt.Errorf("failed to peek account number: %w", err)
}
return m.keeper.AccountsModKeeper.InitAccountNumberSeqUnsafe(ctx, currentAccNum)

Comment on lines 121 to 132
// InitAccountNumberSeqUnsafe use to set accounts account number tracking.
// Only use for account number migration.
func (k Keeper) InitAccountNumberSeqUnsafe(ctx context.Context, accNum uint64) error {
currentNum, err := k.AccountNumber.Peek(ctx)
if err != nil {
return err
}
if currentNum >= accNum {
return fmt.Errorf("cannot set number lower than current account number got %v while current account number is %v", accNum, currentNum)
}
return k.AccountNumber.Set(ctx, accNum)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comprehensive documentation for InitAccountNumberSeqUnsafe.

+// InitAccountNumberSeqUnsafe sets the initial account number sequence.
+// This method is unsafe and should only be used during migrations.

Adding detailed comments will improve code readability and help other developers understand the context and risks associated with using this method.

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.

Suggested change
// InitAccountNumberSeqUnsafe use to set accounts account number tracking.
// Only use for account number migration.
func (k Keeper) InitAccountNumberSeqUnsafe(ctx context.Context, accNum uint64) error {
currentNum, err := k.AccountNumber.Peek(ctx)
if err != nil {
return err
}
if currentNum >= accNum {
return fmt.Errorf("cannot set number lower than current account number got %v while current account number is %v", accNum, currentNum)
}
return k.AccountNumber.Set(ctx, accNum)
}
// InitAccountNumberSeqUnsafe sets the initial account number sequence.
// This method is unsafe and should only be used during migrations.
func (k Keeper) InitAccountNumberSeqUnsafe(ctx context.Context, accNum uint64) error {
currentNum, err := k.AccountNumber.Peek(ctx)
if err != nil {
return err
}
if currentNum >= accNum {
return fmt.Errorf("cannot set number lower than current account number got %v while current account number is %v", accNum, currentNum)
}
return k.AccountNumber.Set(ctx, accNum)
}

Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

This looks good now. A small nit on an error message but good to go 🏄

x/accounts/keeper.go Show resolved Hide resolved
return err
}

return m.keeper.AccountsModKeeper.InitAccountNumberSeqUnsafe(ctx, currentAccNum)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 35c522e and c2edaa6.

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

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

x/accounts/keeper.go (1)

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

golangci-lint
x/auth/keeper/keeper.go

109-109: cannot use &AccountKeeper{} (value of type *AccountKeeper) as AccountKeeperI value in variable declaration: *AccountKeeper does not implement AccountKeeperI (missing method GetAccount)


165-165: ak.GetAccount undefined (type AccountKeeper has no field or method GetAccount)


175-175: ak.GetAccount undefined (type AccountKeeper has no field or method GetAccount)


241-241: ak.GetAccount undefined (type AccountKeeper has no field or method GetAccount)


252-252: ak.NewAccount undefined (type AccountKeeper has no field or method NewAccount)


267-267: ak.SetAccount undefined (type AccountKeeper has no field or method SetAccount)

x/accounts/keeper.go

17-17: use of internal package cosmossdk.io/x/accounts/internal/implementation not allowed

Additional comments not posted (1)
x/accounts/keeper.go (1)

110-119: The implementation of NextAccountNumber looks correct and well-handled.

func (ak AccountKeeper) NextAccountNumber(ctx context.Context) uint64 {
n, err := ak.AccountNumber.Next(ctx)
n, err := ak.AccountsModKeeper.NextAccountNumber(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Address the error handling issue in NextAccountNumber to prevent potential service disruptions.

-	panic(err)
+	if err != nil {
+		return 0, err
+	}

This change allows the caller to handle the error appropriately instead of causing a panic, enhancing the robustness of the service.

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.

Suggested change
n, err := ak.AccountsModKeeper.NextAccountNumber(ctx)
n, err := ak.AccountsModKeeper.NextAccountNumber(ctx)
if err != nil {
return 0, err
}

return err
}
if currentNum > accNum {
return fmt.Errorf("cannot set number lower than current account number got %v while current account number is %v", accNum, currentNum)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider refining the error message in InitAccountNumberSeqUnsafe for clarity and accuracy.

-	return fmt.Errorf("cannot set number lower than current account number got %v while current account number is %v", accNum, currentNum)
+	return fmt.Errorf("attempted to set account number to %v, which is lower than the current account number %v", accNum, currentNum)

This change makes the error message more direct and easier to understand.

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.

Suggested change
return fmt.Errorf("cannot set number lower than current account number got %v while current account number is %v", accNum, currentNum)
return fmt.Errorf("attempted to set account number to %v, which is lower than the current account number %v", accNum, currentNum)

@sontrinh16 sontrinh16 added this pull request to the merge queue Jun 3, 2024
Merged via the queue into main with commit 74d89bf Jun 3, 2024
68 of 70 checks passed
@sontrinh16 sontrinh16 deleted the auth_accounts_use_same_acc_number branch June 3, 2024 13:56
alpe added a commit that referenced this pull request Jun 3, 2024
* main:
  refactor(x/feegrant): set environment in context (#20529)
  refactor(x/accounts)!: accounts and auth module use the same account number tracking (#20405)
  chore: remove sonar from simapp (#20528)
  docs: add docs on permissions (#20526)
  refactor(x/gov): set environment in context for legacy proposals (#20521)
  docs: migrate diagrams to mermaidjs (#20503)
  refactor(tools/hubl): don't use nil panic (#20515)
  refactor(x/authz): set environment in context (#20502)
  build(deps): Bump github.com/spf13/viper from 1.18.2 to 1.19.0 (#20519)
  feat(x/bank): Placing SendRestriction before Deduction of Coins in SendCoins (#20517)
  chore: sonar ignore directories with their own go.mods  (#20509)
  ci: run action in merge queue (#20508)
  refactor(server/v2/cometbft): update function comments (#20506)
@sontrinh16 sontrinh16 mentioned this pull request Jun 3, 2024
12 tasks
@testinginprod testinginprod mentioned this pull request Jun 3, 2024
44 tasks
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.

5 participants