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/upgrade): migrate to appmodule.VersionMap #20485

Merged
merged 3 commits into from
May 30, 2024

Conversation

kocubinski
Copy link
Member

@kocubinski kocubinski commented May 29, 2024

Description

Part of: #20412
Refactor x/upgrade to use core/appmodule types from the aliased SDK type. Required for side-by-side compatibility with runtime/v2 providers and simapp/v2. Also removes a dependency on the SDK from x/upgrade.


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

  • Refactor

    • Updated various components to use appmodule.VersionMap instead of module.VersionMap for improved module structuring and clarity.
    • Modified function signatures and struct fields accordingly to maintain consistency and functionality.
  • Documentation

    • Updated CHANGELOG.md to reflect changes in function signatures and type usage related to appmodule.VersionMap.

Copy link
Contributor

coderabbitai bot commented May 29, 2024

Walkthrough

Walkthrough

The updates involve replacing references to module.VersionMap with appmodule.VersionMap across various files. This change reflects a restructuring or renaming of the VersionMap type within the appmodule package. The modifications impact function signatures, struct fields, and imports in testing, upgrade handling, and migration functions.

Changes

Files Change Summary
simapp/app_test.go Updated TestRunMigrations and TestInitGenesisOnMigration to use appmodule.VersionMap.
simapp/upgrades.go Added import appmodule and updated RegisterUpgradeHandlers to use appmodule.VersionMap.
types/module/module.go Updated RunMigrations and GetVersionMap functions to use appmodule.VersionMap.
x/upgrade/keeper/abci_test.go Replaced module.VersionMap with appmodule.VersionMap in SetUpgradeHandler function calls.
x/upgrade/keeper/grpc_query_test.go Added import appmodule and replaced module.VersionMap with appmodule.VersionMap in function calls.
x/upgrade/keeper/keeper.go Updated Keeper struct fields and related functions to use appmodule.VersionMap.
x/upgrade/keeper/keeper_test.go Added import appmodule and replaced module.VersionMap with appmodule.VersionMap in test functions.
x/upgrade/types/handler.go Changed import to appmodule and updated UpgradeHandler function signature to use appmodule.VersionMap.
simapp/CHANGELOG.md Documented the change in x/upgrade/types.UpgradeHandler to accept appmodule.VersionMap.

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.

@kocubinski kocubinski mentioned this pull request May 29, 2024
12 tasks
@kocubinski kocubinski marked this pull request as ready for review May 29, 2024 19:03
@kocubinski kocubinski requested a review from a team as a code owner May 29, 2024 19:03
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 ac49374 and e79f7c5.
Files selected for processing (8)
  • simapp/app_test.go (2 hunks)
  • simapp/upgrades.go (2 hunks)
  • types/module/module.go (3 hunks)
  • x/upgrade/keeper/abci_test.go (7 hunks)
  • x/upgrade/keeper/grpc_query_test.go (4 hunks)
  • x/upgrade/keeper/keeper.go (6 hunks)
  • x/upgrade/keeper/keeper_test.go (9 hunks)
  • x/upgrade/types/handler.go (2 hunks)
Additional Context Used
Path-based Instructions (8)
x/upgrade/types/handler.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/upgrade/keeper/grpc_query_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"

simapp/app_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/upgrade/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/upgrade/keeper/keeper.go (1)

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

x/upgrade/keeper/abci_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"

types/module/module.go (1)

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

Additional comments not posted (23)
x/upgrade/types/handler.go (2)

6-6: The import change from module.VersionMap to appmodule.VersionMap aligns with the PR's objective to refactor the x/upgrade module for better compatibility and reduced dependencies.


27-27: The function signature change for UpgradeHandler to use appmodule.VersionMap is consistent with the overall refactoring strategy. Ensure that all usages of this handler across the project are updated to pass the correct type.

Verification successful

The search results indicate that the new signature for UpgradeHandler is being used in all instances found. Here are the specific lines where UpgradeHandler is used:

  • x/upgrade/types/handler.go: Line 27
  • x/upgrade/keeper/keeper.go: Lines 27, 28, 30
  • x/upgrade/keeper/keeper_test.go: Lines 27, 28, 29, 30, 31, 32, 33
  • x/upgrade/keeper/grpc_query_test.go: Line 27
  • x/upgrade/keeper/abci_test.go: Lines 27, 28, 29, 30, 31, 32, 33
  • types/module/module.go: Lines 27, 28, 29
  • simapp/upgrades.go: Line 27
  • simapp/app_di.go: Lines 27, 28
  • simapp/app.go: Lines 27, 28
  • baseapp/params_legacy.go: Line 27

All these instances appear to use the new signature with appmodule.VersionMap.

Scripts Executed

The following scripts were executed for the analysis:


Script:

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

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

Length of output: 4010

simapp/upgrades.go (2)

6-6: The import of appmodule is necessary for the updated RegisterUpgradeHandlers function to use appmodule.VersionMap. This change is well-aligned with the PR's goals.


27-27: The lambda function passed to SetUpgradeHandler now correctly uses appmodule.VersionMap. This is a crucial update ensuring that the upgrade logic is compatible with the new module structure.

x/upgrade/keeper/grpc_query_test.go (3)

10-10: The addition of the appmodule import is necessary for the tests to utilize the updated VersionMap. This change is consistent with the modifications in the main codebase.


51-51: The test setup now correctly initializes ModuleVersionMap with appmodule.VersionMap. This ensures that the test environment reflects the changes made in the main application logic.


139-139: The test for SetUpgradeHandler within TestAppliedCurrentPlan now uses appmodule.VersionMap, aligning with the new type requirements. This is a critical update for maintaining the integrity of the test suite.

simapp/app_test.go (1)

199-199: The test functions TestRunMigrations and TestInitGenesisOnMigration now correctly use appmodule.VersionMap instead of module.VersionMap. This change is necessary to ensure that the tests are aligned with the new module structure and are testing the correct behavior.

Also applies to: 250-250

x/upgrade/keeper/keeper_test.go (2)

12-12: The import of appmodule in the test file is correctly updated to reflect the changes in the main codebase. This ensures that the test suite uses the correct VersionMap type.


170-170: The test functions in keeper_test.go that involve SetUpgradeHandler and ApplyUpgrade now correctly use appmodule.VersionMap. This is crucial for ensuring that the tests accurately reflect the behavior of the upgraded system and are compatible with the new module structure.

Also applies to: 292-294, 306-312, 339-339, 356-356, 381-381, 397-397

x/upgrade/keeper/keeper.go (5)

41-41: The initVersionMap field has been updated to use appmodule.VersionMap. This change aligns with the PR's objective to refactor the x/upgrade module for better compatibility and reduced dependencies.


77-77: The method SetInitVersionMap now correctly uses appmodule.VersionMap as per the refactoring goal. This ensures that the initial version map is set with the correct type.


83-83: The method GetInitVersionMap has been updated to return appmodule.VersionMap. This change is consistent with the overall refactoring effort and ensures that the getter returns the updated type.


95-95: The method SetModuleVersionMap now accepts and processes appmodule.VersionMap. This is a key part of the refactoring, ensuring that module version maps are handled using the new type. The implementation here is robust, with sorting of module names for deterministic iteration, which is good practice.


123-123: The method GetModuleVersionMap has been updated to return appmodule.VersionMap. The method correctly handles the iteration over the store and constructs the version map using the new type. This is crucial for maintaining consistency in how version maps are retrieved and used across the system.

Also applies to: 132-132

x/upgrade/keeper/abci_test.go (6)

54-54: Change to appmodule.VersionMap in SetUpgradeHandler aligns with the PR's objectives.


72-72: Consistent use of appmodule.VersionMap in SetUpgradeHandler.


177-177: Updated SetUpgradeHandler to use appmodule.VersionMap correctly.


423-423: Proper update to SetUpgradeHandler using appmodule.VersionMap.


474-474: Correct implementation of appmodule.VersionMap in SetUpgradeHandler.


489-489: Consistent update to SetUpgradeHandler using appmodule.VersionMap.

types/module/module.go (2)

660-660: Updated RunMigrations to use appmodule.VersionMap aligns with the refactor objectives.

Also applies to: 671-671


827-828: GetVersionMap correctly updated to return appmodule.VersionMap.

@@ -24,7 +24,7 @@ const UpgradeName = "v050-to-v051"
func (app SimApp) RegisterUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
func(ctx context.Context, _ upgradetypes.Plan, fromVM appmodule.VersionMap) (appmodule.VersionMap, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a changelog under simapp/CHANGELOD.md, as this wiring changes needs to happen for users as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I also make a CHANGELOG entry in x/upgrade? It's not breaking except for usages of the function delegate UpgradeHandler. In other words module.VersionMap is interchangeable with appmodule.VersionMap but function type with each of those as parameters is not.

@kocubinski kocubinski enabled auto-merge May 30, 2024 19:12
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 (2)
simapp/CHANGELOG.md (2)

36-36: Clarify the changelog entry for better understanding.

Consider rephrasing the changelog entry to enhance clarity and precision. Here's a suggested revision:

- [#20485](https://github.com/cosmos/cosmos-sdk/pull/20485) Updated the `x/upgrade/types.UpgradeHandler` signature to accept `appmodule.VersionMap` instead of `module.VersionMap`. Adjust your usage of `UpgradeKeeper.SetUpgradeHandler` accordingly.

Line range hint 52-52: Remove extra blank line to improve formatting.

<!-- TODO: move changelog.md elements to here -->
-
## v0.47 to v0.50
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e79f7c5 and bac51bc.

Files selected for processing (1)
  • simapp/CHANGELOG.md (1 hunks)
Additional context used
Path-based instructions (1)
simapp/CHANGELOG.md (1)

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

LanguageTool
simapp/CHANGELOG.md

[uncategorized] ~28-~28: This verb may not be in the correct form. Consider using a different form for this context.
Context: ...application. This changelog is aimed to help developers understand the wiring change...

Markdownlint
simapp/CHANGELOG.md

52-52: Expected: 1; Actual: 2
Multiple consecutive blank lines

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

Line range hint 28-28: The verb form is correct in this context.

LanguageTool flagged this as a potential issue, but the usage of "aimed" is appropriate here, indicating the purpose of the changelog.

@kocubinski kocubinski added this pull request to the merge queue May 30, 2024
Merged via the queue into main with commit 7dbbc07 May 30, 2024
64 of 65 checks passed
@kocubinski kocubinski deleted the kocu/core-versionmap branch May 30, 2024 19:21
alpe added a commit that referenced this pull request May 31, 2024
* main:
  feat(server/v2): introduce cometbft v2 (#20483)
  refactor(x/upgrade): migrate to appmodule.VersionMap (#20485)
  docs: code guidelines changes (#20482)
  feat(cosmovisor): load cosmovisor configuration from toml file (#19995)
  perf(math): Significantly speedup Dec quo truncate and quo Roundup (#20034)
  fix: Bump CometBFT versions (#20481)
alpe added a commit that referenced this pull request May 31, 2024
* main: (120 commits)
  chore: update protoc-gen-swagger to protoc-gen-openapiv2 (#20448)
  ci: Add GitHub Action for go mod tidy and mocks (#20501)
  chore: Address linter issues (#20486)
  fix: wrap errors in auto CLI service registration (#20493)
  chore: fix comment (#20498)
  chore: fix the note box syntax error (#20499)
  feat(server/v2): introduce cometbft v2 (#20483)
  refactor(x/upgrade): migrate to appmodule.VersionMap (#20485)
  docs: code guidelines changes (#20482)
  feat(cosmovisor): load cosmovisor configuration from toml file (#19995)
  perf(math): Significantly speedup Dec quo truncate and quo Roundup (#20034)
  fix: Bump CometBFT versions (#20481)
  refactor(core): remove redundant ExecMode (#20322)
  feat(store/v2): pruning manager (#20430)
  chore: force reload sonar cloud  (#20480)
  refactor(x/accounts): reuse calculated sum in `func safeAdd` (#20458)
  refactor: remove `defer` in loop (#20223)
  ci: remove livness test (#20474)
  build(deps): Bump bufbuild/buf-setup-action from 1.32.1 to 1.32.2 (#20477)
  chore: migrate a few diagrams to mermaid (#20473)
  ...
@coderabbitai coderabbitai bot mentioned this pull request Dec 6, 2024
12 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.

3 participants