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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions simapp/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ import (

"cosmossdk.io/core/appmodule"
corestore "cosmossdk.io/core/store"
"cosmossdk.io/x/accounts"
bankv2types "cosmossdk.io/x/bank/v2/types"
epochstypes "cosmossdk.io/x/epochs/types"
protocolpooltypes "cosmossdk.io/x/protocolpool/types"
upgradetypes "cosmossdk.io/x/upgrade/types"

authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
)

// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade
Expand All @@ -26,12 +21,6 @@ func (app SimApp) RegisterUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
func(ctx context.Context, _ upgradetypes.Plan, fromVM appmodule.VersionMap) (appmodule.VersionMap, error) {
// sync accounts and auth module account number
err := authkeeper.MigrateAccountNumberUnsafe(ctx, &app.AuthKeeper)
if err != nil {
return nil, err
}

return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
},
)
Expand All @@ -43,13 +32,8 @@ func (app SimApp) RegisterUpgradeHandlers() {

if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := corestore.StoreUpgrades{
Added: []string{
accounts.StoreKey,
protocolpooltypes.StoreKey,
epochstypes.StoreKey,
bankv2types.ModuleName,
},
Deleted: []string{"crisis"}, // The SDK discontinued the crisis module in v0.52.0
Added: []string{bankv2types.StoreKey},
Deleted: []string{},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
Expand Down
2 changes: 1 addition & 1 deletion store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

newStores[key] = store
Expand Down
5 changes: 1 addition & 4 deletions tests/systemtests/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ import (
)

func TestChainUpgrade(t *testing.T) {
// err> panic: failed to load latest version: failed to load store: initial version set to 22, but found earlier version 1 [cosmossdk.io/[email protected]/rootmulti/store.go:256]
t.Skip("Skipped until any v052 artifact is available AND main branch handles the store upgrade proper")

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

t.Logf("+++ legacy binary: %s\n", legacyBinary)
currentBranchBinary := systest.Sut.ExecBinary()
currentInitializer := systest.Sut.TestnetInitializer()
Expand Down
Loading