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

fix(simapp,systemtests): fix chain upgrade #22669

Merged
merged 1 commit into from
Nov 27, 2024
Merged

fix(simapp,systemtests): fix chain upgrade #22669

merged 1 commit into from
Nov 27, 2024

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Nov 27, 2024

Description

Closes: #22146


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

    • Streamlined upgrade process focusing on the bankv2 module.
  • Bug Fixes

    • Enhanced clarity of error messages related to store loading and deletion, improving debugging.
  • Tests

    • Updated test for chain upgrade to use a more specific legacy binary version, ensuring accurate testing of the upgrade process.

Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request primarily involve modifications to the simapp/upgrades.go, store/rootmulti/store.go, and tests/systemtests/upgrade_test.go files. The upgrades.go file has had several import statements and functions related to account migration and store upgrades removed, streamlining the upgrade process to focus on the bankv2 module. The error handling in the loadVersion method of store.go has been improved for better clarity in error messages. Additionally, the test for chain upgrades has been updated to reference a more specific legacy binary version.

Changes

File Path Change Summary
simapp/upgrades.go Removed imports for accounts, epochs, and protocolpool. Removed MigrateAccountNumberUnsafe call. Updated store upgrade configuration to focus on bankv2.
store/rootmulti/store.go Enhanced error messages in loadVersion method for clarity on store loading and deletion failures.
tests/systemtests/upgrade_test.go Updated legacyBinary version from "v0.52" to "0.52.0-beta.3". Removed line skipping test execution.

Assessment against linked issues

Objective Addressed Explanation
Fix the chain upgrade failure when using v0.52 binary (#22146)

Possibly related PRs

Suggested labels

C:Store, C:x/accounts, backport/v0.52.x

Suggested reviewers

  • kocubinski
  • facundomedica
  • julienrbrt
  • tac0turtle
  • hieuvubk

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

@alpe your pull request is missing a changelog!

@@ -253,7 +253,7 @@ func (rs *Store) loadVersion(ver int64, upgrades *types.StoreUpgrades) error {

store, err := rs.loadCommitStoreFromParams(key, commitID, storeParams)
if err != nil {
return errorsmod.Wrap(err, "failed to load store")
return errorsmod.Wrapf(err, "failed to load store for %s", key.Name())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is not needed for the fix but it adds some very valuable debug output

@julienrbrt julienrbrt changed the title fix: chain upgrade fix(simapp,systemtests): fix chain upgrade Nov 27, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (4)
tests/systemtests/upgrade_test.go (3)

Line range hint 89-98: Enhance post-upgrade validation

The current smoke test only verifies basic transaction functionality. Consider adding:

  1. Version verification after upgrade
  2. State migration validation
  3. Negative test cases (e.g., invalid upgrade height)

Example addition:

 got = cli.Run("tx", "protocolpool", "fund-community-pool", "100stake", "--from=node0")
 systest.RequireTxSuccess(t, got)
+
+// Verify chain version after upgrade
+version := cli.CustomQuery("q", "upgrade", "version")
+require.Contains(t, version, "0.54", "expected chain to be upgraded to v0.54")
+
+// Verify state migration
+// Add specific state checks here based on what should be migrated

Line range hint 35-39: Improve test reliability and cleanup

The test setup could be improved for better reliability and isolation:

  1. The 5-second voting period might be too short for CI environments
  2. Missing proper cleanup in case of test failures

Consider these improvements:

+defer func() {
+    systest.Sut.StopChain()
+    systest.Sut.SetExecBinary(currentBranchBinary)
+    systest.Sut.SetTestnetInitializer(currentInitializer)
+}()
+
 votingPeriod := 5 * time.Second // enough time to vote
+if os.Getenv("CI") == "true" {
+    votingPeriod = 15 * time.Second // longer timeout for CI
+}

Line range hint 76-86: Enhance upgrade validation checks

The upgrade process validation could be strengthened by:

  1. Validating upgrade plan details before proceeding
  2. Adding configurable timeouts for CI environments
  3. Checking chain halt status

Example improvements:

 raw = cli.CustomQuery("q", "gov", "proposal", proposalID)
 proposalStatus := gjson.Get(raw, "proposal.status").String()
 require.Equal(t, "PROPOSAL_STATUS_PASSED", proposalStatus, raw)
+
+// Validate upgrade plan details
+upgradePlan := cli.CustomQuery("q", "upgrade", "plan")
+require.Equal(t, upgradeName, gjson.Get(upgradePlan, "plan.name").String())
+require.Equal(t, fmt.Sprint(upgradeHeight), gjson.Get(upgradePlan, "plan.height").String())
+
+// Verify chain halt status
+nodeStatus := cli.CustomQuery("status")
+require.True(t, gjson.Get(nodeStatus, "sync_info.catching_up").Bool(), "expected chain to be halted")
store/rootmulti/store.go (1)

256-256: Improved error handling with store context

The enhanced error message now includes the store name, making it easier to identify which store failed during version loading. This improvement is particularly valuable for debugging chain upgrade issues.

Consider standardizing this error handling pattern across other store operations for consistency. For example:

-if err := deleteKVStore(store.(types.KVStore)); err != nil {
-  return errorsmod.Wrapf(err, "failed to delete store %s", key.Name())
-}
+if err := deleteKVStore(store.(types.KVStore)); err != nil {
+  return errorsmod.Wrapf(err, "failed to delete store %q", key.Name())
+}
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b5b2f49 and f7ddd57.

📒 Files selected for processing (3)
  • simapp/upgrades.go (1 hunks)
  • store/rootmulti/store.go (1 hunks)
  • tests/systemtests/upgrade_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
simapp/upgrades.go (1)

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

store/rootmulti/store.go (1)

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

tests/systemtests/upgrade_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 (3)
simapp/upgrades.go (3)

Line range hint 8-15: LGTM! Well-documented upgrade name constant.

The documentation clearly explains the purpose of this upgrade and its version scope.


35-36: Verify store upgrade changes

The simplified store upgrades configuration aligns with the PR objective of fixing version mismatch issues. However, please ensure:

  1. The removal of previously included store keys won't impact the upgrade process
  2. The empty Deleted array is intentional and won't leave any deprecated stores
✅ Verification successful

Store upgrade configuration is appropriate

The store upgrade configuration is correct and safe:

  • The bankv2types.StoreKey addition is the only required change for this upgrade
  • No store deletions are needed as this is adding a new store version rather than removing old stores
  • The empty Deleted array is intentional and correct for this scenario
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any store key references that might need migration
rg -A 3 'StoreKey.*=.*"(accounts|protocolpool|epochs|crisis)"'

# Look for any store deletion patterns in upgrade handlers
ast-grep --pattern 'Deleted.*=.*\[.*\]'

Length of output: 106


Script:

#!/bin/bash
# Search for store keys in the codebase
rg -A 3 'StoreKey.*=.*".*"'

# Look for store upgrade configurations in other upgrade handlers
rg -A 5 'StoreUpgrades.*=' 

# Check for any store-related imports and configurations
rg -l 'storetypes\.StoreUpgrades'

Length of output: 17795


Script:

#!/bin/bash
# Check for bankv2 store key references
rg -A 3 'bankv2.*StoreKey'

# Look for previous store upgrade configurations
rg -A 5 'StoreUpgrades.*=' simapp/

# Check for any bank module store migrations
rg -l 'bank.*Migrate'

Length of output: 348


Line range hint 17-33: Verify completeness of migration handlers

The upgrade handler implementation looks correct, but given this is a critical upgrade path from v0.52, we should verify that all necessary module migrations are properly registered in the ModuleManager.

✅ Verification successful

Let me gather more information about module migrations to verify completeness.


Based on the search results, I can now provide a definitive response about the upgrade handler implementation.

Migration handler implementation is complete and correct

The upgrade handler correctly uses ModuleManager.RunMigrations which automatically handles all registered module migrations. The search results show:

  1. The upgrade name "v052-to-v054" is properly defined and used consistently
  2. The handler correctly implements store upgrades by adding the new bank store key
  3. All core modules have properly registered their migrations through RegisterMigrations, including:
    • x/auth
    • x/bank
    • x/distribution
    • x/gov (with v5 to v6 migrations)
    • x/staking
    • x/authz
    • x/feegrant
    • x/group
    • x/mint
    • x/slashing

The implementation follows the standard upgrade pattern and includes all necessary components for a complete upgrade from v0.52 to v0.54.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any migration registrations in the codebase
ast-grep --pattern 'RegisterMigration($_, $_)'

# Look for any other upgrade handlers that might be relevant
rg -A 5 'SetUpgradeHandler|RegisterUpgradeHandler'

Length of output: 20160


Script:

#!/bin/bash
# Search for module consensus versions and migrations
ast-grep --pattern 'ConsensusVersion() uint64'

# Look for any module migration registrations
rg -A 5 'RegisterMigration|MigrateStore'

# Check for any module version changes in the upgrade
rg -A 5 'v052-to-v054|UpgradeName'

Length of output: 32775

// Scenario:
// start a legacy chain with some state
// when a chain upgrade proposal is executed
// then the chain upgrades successfully
systest.Sut.StopChain()

legacyBinary := FetchExecutable(t, "v0.52")
legacyBinary := FetchExecutable(t, "0.52.0-beta.3")
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

The choice of legacy binary version 0.52.0-beta.3 needs to be updated

The current version choice appears incorrect for the following reasons:

  • The issue description specifically mentions testing with v0.52 from the release/v0.52.x branch
  • The upgrade test is designed to test migration from v0.52.x to v0.54.x (as seen in simapp/upgrades.go)
  • The available beta versions (v0.52.0-beta.1, v0.52.0-beta.2, v0.52.0-beta.3) are pre-release versions and not the final v0.52.x release

Recommendation:

  • Use the binary built from release/v0.52.x branch as specified in the issue reproduction steps instead of a beta version
🔗 Analysis chain

Verify the choice of legacy binary version

The change to use a specific beta version 0.52.0-beta.3 improves test reproducibility. However, we should verify if this is the correct version that exhibits the upgrade issue mentioned in #22146.


Let me gather more information about the upgrade test implementation to better understand the version choice.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the issue occurs with this specific version
gh issue view 22146 --json body | jq -r '.body' | grep -A 5 -B 5 "0.52"

# Check available versions
curl -s https://api.github.com/repos/cosmos/cosmos-sdk/releases | jq -r '.[].tag_name' | grep "^v0.52"

Length of output: 509


Script:

#!/bin/bash
# Check the upgrade test implementation
cat tests/systemtests/upgrade_test.go

# Check if there are any other references to v0.52 in the codebase
rg "0\.52" --type go

Length of output: 5505

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Chain upgrade from v0.52 fails in system tests
6 participants