Skip to content

Conversation

@mmsqe
Copy link
Collaborator

@mmsqe mmsqe commented Feb 23, 2025

Description

Closes: #23741


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

    • Enabled legacy global account number support to ensure seamless account handling.
    • Enhanced account number sequencing for more consistent and reliable operations.
    • Expanded calculator functionality with an additional arithmetic operation and refined formula parameters.
  • Refactor

    • Standardized key usage in migration procedures for legacy account data to streamline processes.
    • Improved clarity in test functions by explicitly referencing constants for better maintainability.

@mmsqe mmsqe requested a review from a team February 23, 2025 13:59
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2025

📝 Walkthrough

Walkthrough

This pull request introduces legacy support for global account numbers in the x/auth module. It updates the Calculator class by adding a new method, modifying an existing method’s signature, and renaming a variable. The accounts module enhances the account number generation logic to retrieve a legacy account number from the KV store when the default account number is zero, with corresponding test coverage. In the auth module, the local legacy key is replaced by a reference to an imported constant, and a new legacy key variable is declared for future use.

Changes

File(s) Summary of Changes
CHANGELOG.md Updated summary to reflect legacy global AccountNumber support in the x/auth module.
src/calculator.py Added coderabbit_add(x, y) method, updated coderabbit_formula(x, y) to coderabbit_formula(x, y, z), and renamed variable from old_global_var to new_global_var.
x/accounts/keeper.go
x/accounts/keeper_test.go
Enhanced NextAccountNumber logic to retrieve the legacy account number from the KV store when the default account number is zero; added test function TestKeeper_NextAccountNumber to verify this behavior.
x/auth/migrations/v5/migrate.go
x/auth/types/keys.go
Removed the local LegacyGlobalAccountNumberKey variable in migrations and replaced its usage with authtypes.LegacyGlobalAccountNumberKey; added a new legacy key variable in auth types.
x/auth/migrations/v5/migrate_test.go Updated import statements and modified the TestMigrate function to use authtypes.LegacyGlobalAccountNumberKey.

Suggested labels

C:x/accounts/base

Suggested reviewers

  • facundomedica
  • testinginprod
  • sontrinh16
  • akhilkumarpilli
  • julienrbrt

Possibly related PRs

  • test: x/accounts systemtests #22320: The changes in the main PR, which involve adding support for legacy global account numbers in the x/auth module, are related to the retrieved PR that introduces system tests for migrating accounts from the x/auth module to the x/accounts module, as both involve handling legacy account numbers.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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

🧹 Nitpick comments (3)
CHANGELOG.md (3)

4-11: Improve changelog principles section formatting

The guiding principles section would be more readable with bullet points instead of a numbered list.

-Guiding Principles:
-
-Changelogs are for humans, not machines.
-There should be an entry for every single version.
-The same types of changes should be grouped.
-Versions and sections should be linkable.
-The latest version comes first.
-The release date of each version is displayed.
-Mention whether you follow Semantic Versioning.

+# Guiding Principles
+
+* Changelogs are for humans, not machines
+* There should be an entry for every single version
+* The same types of changes should be grouped
+* Versions and sections should be linkable
+* The latest version comes first
+* The release date of each version is displayed
+* Mention whether you follow Semantic Versioning

14-22: Improve usage section formatting

The usage section would be more readable with bullet points and better spacing.

-Change log entries are to be added to the Unreleased section under the
-appropriate stanza (see below). Each entry is required to include a tag and
-the Github issue reference in the following format:
-
-* (<tag>) \#<issue-number> message

+# Usage
+
+* Change log entries should be added to the "Unreleased" section under the appropriate stanza
+* Each entry must include:
+  * A tag in parentheses
+  * The GitHub issue reference number
+  * A descriptive message
+* Format: `* (<tag>) #<issue-number> message`

24-34: Improve stanza types section formatting

The stanza types section would be clearer with bullet points and descriptions.

-Types of changes (Stanzas):
-
-"Features" for new features.
-"Improvements" for changes in existing functionality.
-"Deprecated" for soon-to-be removed features.
-"Bug Fixes" for any bug fixes.
-"Client Breaking" for breaking Protobuf, gRPC and REST routes used by end-users.
-"CLI Breaking" for breaking CLI commands.
-"API Breaking" for breaking exported APIs used by developers building on SDK.
-"State Machine Breaking" for any changes that result in a different AppState given same genesisState and txList.

+# Types of Changes (Stanzas)
+
+* **Features**: New functionality additions
+* **Improvements**: Enhancements to existing features
+* **Deprecated**: Features planned for removal
+* **Bug Fixes**: Corrections to existing functionality
+* **Client Breaking**: Breaking changes to Protobuf/gRPC/REST APIs affecting end users
+* **CLI Breaking**: Breaking changes to command line interfaces
+* **API Breaking**: Breaking changes to exported APIs used by developers
+* **State Machine Breaking**: Changes affecting AppState determinism
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0a98b65 and 34e0ed9.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • x/accounts/keeper.go (2 hunks)
  • x/accounts/keeper_test.go (2 hunks)
  • x/auth/migrations/v5/migrate.go (2 hunks)
  • x/auth/types/keys.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
`**/*.go`: Review the Golang code for conformity with the Ub...

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

  • x/auth/types/keys.go
  • x/auth/migrations/v5/migrate.go
  • x/accounts/keeper_test.go
  • x/accounts/keeper.go
`**/*_test.go`: "Assess the unit test code assessing suffici...

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

  • x/accounts/keeper_test.go
`**/*.md`: "Assess the documentation for misspellings, gramm...

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

  • CHANGELOG.md
🪛 golangci-lint (1.62.2)
x/accounts/keeper_test.go

6-6: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


7-7: ST1019: package "github.com/cosmos/gogoproto/types" is being imported more than once

(stylecheck)


8-8: ST1019(related information): other import of "github.com/cosmos/gogoproto/types"

(stylecheck)

x/accounts/keeper.go

26-26: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)

🪛 GitHub Actions: Lint
x/accounts/keeper_test.go

[error] 6-6: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order (gci)


[error] 13-13: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order (gci)


[error] 7-7: ST1019: package "github.com/cosmos/gogoproto/types" is being imported more than once (stylecheck)

x/accounts/keeper.go

[error] 11-11: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order (gci)


[error] 26-26: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order (gci)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: tests (01)
  • GitHub Check: tests (00)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (8)
x/auth/types/keys.go (1)

32-33: LGTM!

The new variable LegacyGlobalAccountNumberKey is well-defined and properly documented.

x/auth/migrations/v5/migrate.go (1)

15-15: LGTM!

The migration code correctly uses the imported constant authtypes.LegacyGlobalAccountNumberKey instead of a local variable.

Also applies to: 39-39

x/accounts/keeper_test.go (1)

96-122: LGTM!

The test function thoroughly validates the NextAccountNumber functionality, including the legacy account number retrieval.

CHANGELOG.md (5)

1-3: LGTM: Clear and concise title and description

The changelog title and description provide a clear overview of the project and its purpose.


39-41: LGTM: Clear unreleased section header

The unreleased section header is well formatted and includes a clear note about module changelogs.


43-49: LGTM: Well organized features section

The features section is well organized with clear bullet points and issue references.


51-56: LGTM: Clear bug fixes section

The bug fixes section clearly documents the issues fixed with proper references.


57-60: LGTM: Clear removed section

The removed section clearly documents removed functionality with proper references.

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

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34e0ed9 and 874dd00.

📒 Files selected for processing (2)
  • x/accounts/keeper_test.go (2 hunks)
  • x/auth/migrations/v5/migrate_test.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.go`: Review the Golang code for conformity with the Ub...

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

  • x/accounts/keeper_test.go
  • x/auth/migrations/v5/migrate_test.go
`**/*_test.go`: "Assess the unit test code assessing suffici...

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

  • x/accounts/keeper_test.go
  • x/auth/migrations/v5/migrate_test.go
🪛 golangci-lint (1.62.2)
x/accounts/keeper_test.go

6-6: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)

x/auth/migrations/v5/migrate_test.go

10-10: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)

🪛 GitHub Actions: Lint
x/accounts/keeper_test.go

[error] 6-6: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order (gci)


[error] 12-12: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order (gci)

⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: tests (01)
  • GitHub Check: test-x-mint
  • GitHub Check: test-x-epochs
  • GitHub Check: test-x-consensus
  • GitHub Check: test-tools-benchmark
  • GitHub Check: test-x-upgrade
  • GitHub Check: test-x-tx
  • GitHub Check: test-x-staking
  • GitHub Check: test-x-accounts
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: test-integration
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (3)
x/auth/migrations/v5/migrate_test.go (1)

26-26: LGTM!

The change improves code clarity by making the source of the constant explicit through the authtypes package.

x/accounts/keeper_test.go (2)

6-8: Fix duplicate import of gogoproto/types package.

The package "github.com/cosmos/gogoproto/types" is being imported twice.

🧰 Tools
🪛 golangci-lint (1.62.2)

6-6: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)

🪛 GitHub Actions: Lint

[error] 6-6: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order (gci)


95-121: LGTM! Comprehensive test coverage.

The test thoroughly validates the NextAccountNumber method by:

  1. Testing initial zero account number scenario
  2. Testing legacy global account number retrieval
  3. Including proper error handling and assertions

Co-authored-by: yihuang <huang@crypto.com>
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

🧹 Nitpick comments (1)
x/accounts/keeper.go (1)

140-161: Consider adding error documentation.

The changes to NextAccountNumber method look good, but consider documenting the error types that can be returned in the function's documentation.

Add documentation for error types:

 func (k Keeper) NextAccountNumber(
 	ctx context.Context,
-) (accNum uint64, err error) {
+) (accNum uint64, err error) {
+	// Returns collections.ErrNotFound if no account number exists and legacy account number retrieval fails
+	// Returns error if setting the next account number fails
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9842c5b and 25cfaff.

📒 Files selected for processing (1)
  • x/accounts/keeper.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Golang code for conformity with the Ub...

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

  • x/accounts/keeper.go
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: tests (01)
  • GitHub Check: tests (00)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-system-v2
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: test-integration
  • GitHub Check: Analyze
  • GitHub Check: build (amd64)
  • GitHub Check: Summary
🔇 Additional comments (3)
x/accounts/keeper.go (3)

12-12: LGTM! Import statements are well-organized.

The new imports gogotypes and authtypes are correctly added and necessary for the legacy account number support.

Also applies to: 26-26


127-138: LGTM! Error handling follows best practices.

The GetAccountNumberLegacy method properly handles errors and provides descriptive error messages. The implementation correctly retrieves and unmarshals the legacy account number from the KV store.


144-150: LGTM! Fallback mechanism for historical states.

The fallback to legacy account numbers when collections.ErrNotFound is encountered is well-implemented. The comments clearly explain the behavior and its implications for state machine migration.

@julienrbrt
Copy link
Contributor

julienrbrt commented Feb 24, 2025

Is it still happening if your put x/auth first in the module manager:

func (m *Manager) SetOrderMigrations(moduleNames ...string) {

@yihuang yihuang changed the title fix(auth): support legacy global AccountNumber fix(auth): support legacy global AccountNumber when query historical state Feb 24, 2025
@yihuang
Copy link
Collaborator

yihuang commented Feb 24, 2025

Is it still happening if your put x/auth first in the module manager:

func (m *Manager) SetOrderMigrations(moduleNames ...string) {

the issue is when using latest binary to query historical state that is before the migration, to keep it compatible with that situation, because account-number is very commonly used.

@julienrbrt
Copy link
Contributor

Is it still happening if your put x/auth first in the module manager:

func (m *Manager) SetOrderMigrations(moduleNames ...string) {

the issue is when using latest binary to query historical state that is before the migration, to keep it compatible with that situation, because account-number is very commonly used.

Okay, yeah adding this fallback for such a common query makes sense. Usually, we tell people to use the previous binary, but that exception makes sense.

@aljo242 aljo242 merged commit fa82101 into cosmos:main Feb 25, 2025
68 of 71 checks passed
@julienrbrt
Copy link
Contributor

This should be backported to 0.53 btw

@skosito
Copy link

skosito commented Apr 16, 2025

@julienrbrt will this be released with 0.53? i quickly checked and i dont see it included yet in 0.53 rc
thanks!

mmsqe added a commit to mmsqe/cosmos-sdk that referenced this pull request Apr 16, 2025
github-merge-queue bot pushed a commit that referenced this pull request Apr 23, 2025
…state (port #23743) (#24533)

Co-authored-by: HuangYi <huang@crypto.com>
Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
akhilkumarpilli pushed a commit to cheqd/cosmos-sdk that referenced this pull request Jun 5, 2025
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.

[Bug]: Unable to get AccountNumber for block before migrate auth from 4 to 5

6 participants