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

[Documentation]: Upgrade directly from cosmos sdk 0.46.5 to cosmos sdk 0.50.4 #20160

Closed
QuocThi opened this issue Apr 23, 2024 · 8 comments
Closed
Labels
T:Docs Changes and features related to documentation.

Comments

@QuocThi
Copy link

QuocThi commented Apr 23, 2024

Summary

Hi,

I am upgrading from cosmos sdk 0.46.5 to cosmos sdk version 0.50.4. Currently my upgrade handler is merged from this (version 0.47.5) and this to upgrade directly from version 0.46.5 to version 0.50.4, here is the code:

const UpgradeName = "v046-to-v050"

func (app App) RegisterUpgradeHandlers() {
         baseAppLegacySS := app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
	app.UpgradeKeeper.SetUpgradeHandler(
		UpgradeName,
		func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
			baseapp.MigrateParams(ctx.(sdk.Context), baseAppLegacySS, app.ConsensusParamsKeeper.ParamsStore)
			consensusParams := baseapp.GetConsensusParams(ctx.(sdk.Context), baseAppLegacySS)
			// make sure the consensus params are set
			if consensusParams.Block == nil || consensusParams.Evidence == nil || consensusParams.Validator == nil {
				defaultParams := tmtypes.DefaultConsensusParams().ToProto()
				app.ConsensusParamsKeeper.ParamsStore.Set(ctx.(sdk.Context), defaultParams)
			}

			storesvc := runtime.NewKVStoreService(app.GetKey("upgrade"))
			consensuskeeper := consensuskeeper.NewKeeper(
				app.appCodec,
				storesvc,
				app.AccountKeeper.GetAuthority(),
				runtime.EventService{},
			)

			params, err := consensuskeeper.ParamsStore.Get(ctx)
			if err != nil {
				return nil, err
			}

			err = app.ConsensusParamsKeeper.ParamsStore.Set(ctx, params)
			if err != nil {
				return nil, err
			}

			return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
		},
	)

	upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
	if err != nil {
		panic(err)
	}

	if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
		storeUpgrades := storetypes.StoreUpgrades{
			Added: []string{
				consensustypes.ModuleName,
				crisistypes.ModuleName,
				circuittypes.ModuleName,
				ibcfee.ModuleName,
			},
		}

		// configure store loader that checks if version == upgradeHeight and applies store upgrades
		app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
	}
}

But I got this error when start the new binary (use cosmos sdk 0.50.4) after gov upgrade proposal pass and reach the upgrade height:

10:15PM INF Replay last block using real app module=consensus
10:15PM ERR failed to get consensus params err="collections: not found: key 'no_key' of type github.com/cosmos/gogoproto/tendermint.types.ConsensusParams" module=server
10:15PM ERR failed to get consensus params err="collections: not found: key 'no_key' of type github.com/cosmos/gogoproto/tendermint.types.ConsensusParams" module=server
10:15PM ERR error in proxyAppConn.FinalizeBlock err="collections: not found: key 'no_key' of type github.com/cosmos/gogoproto/cosmos.distribution.v1beta1.Params" module=consensus
10:15PM INF Closing application.db module=server
10:15PM INF Closing snapshots/metadata.db module=server
Error: error during handshake: error on replay: collections: not found: key 'no_key' of type github.com/cosmos/gogoproto/cosmos.distribution.v1beta1.Params

In my code above I already apply the code follow this command from a related issue: #18733 (comment)

Can I upgrade the binary using cosmos sdk 0.46.5 to use cosmos sdk 0.50.4 directly (skip upgrade to version 0.47 before upgrade to 0.50.4)? Or any mistake in my code?

Thanks!

@QuocThi QuocThi added the T:Docs Changes and features related to documentation. label Apr 23, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Cosmos-SDK Apr 23, 2024
@johnletey
Copy link
Contributor

@QuocThi Are you using app wiring? I was running into this exact issue when upgrading from v0.45.x, and it was because I wasn't registering the x/upgrade Pre Blocker.

@QuocThi
Copy link
Author

QuocThi commented Apr 24, 2024

Hi @johnletey , can you give me some docs about registering the x/upgrade Pre Blocker.

@QuocThi
Copy link
Author

QuocThi commented May 7, 2024

Hi @johnletey, I just finish switch to use app wiring, and also has bellow code in app_config.go,
PreBlockers: []string{ upgradetypes.ModuleName, },
But the issue still happen.

@QuocThi
Copy link
Author

QuocThi commented May 7, 2024

From the code I could see this issue is expected from 0.46 to 0.50:

// This could happen while migrating from v0.45/v0.46 to v0.50, we should

But my binary still crashed after that.

@QuocThi
Copy link
Author

QuocThi commented May 8, 2024

I found that this issue doesn't cause the binary crashed, so the case can be close here.

@vladimir-trifonov
Copy link

I had the same exact issue and after registering the x/upgrade Pre Blocker and after adding QuocThi's upgrade handler I managed to fix it. Thx!

@QuocThi
Copy link
Author

QuocThi commented Jul 17, 2024

Hi @vladimir-trifonov, I updated the upgrade handler and this is the currently working for me:

const UpgradeName = "v045-to-v050"

func setupLegacyKeyTables(k *paramskeeper.Keeper) {
	for _, subspace := range k.GetSubspaces() {
		subspace := subspace

		var keyTable paramstypes.KeyTable
		switch subspace.Name() {
		case authtypes.ModuleName:
			keyTable = authtypes.ParamKeyTable() //nolint:staticcheck
		case banktypes.ModuleName:
			keyTable = banktypes.ParamKeyTable() //nolint:staticcheck
		case stakingtypes.ModuleName:
			keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck
		case minttypes.ModuleName:
			keyTable = minttypes.ParamKeyTable() //nolint:staticcheck
		case distrtypes.ModuleName:
			keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck
		case slashingtypes.ModuleName:
			keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck
		case govtypes.ModuleName:
			keyTable = govv1.ParamKeyTable() //nolint:staticcheck
		case crisistypes.ModuleName:
			keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck
			// wasm
		case wasmtypes.ModuleName:
			keyTable = v2.ParamKeyTable() //nolint:staticcheck
		case ibcexported.ModuleName:
			keyTable = ibcclienttypes.ParamKeyTable()
			keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
		case icatypes.SubModuleName:
			keyTable = icatypes.ParamKeyTable() //nolint:staticcheck
		case icacontrollertypes.SubModuleName:
			keyTable = icacontrollertypes.ParamKeyTable() //nolint:staticcheck
		case ibctransfertypes.ModuleName:
			keyTable = ibctransfertypes.ParamKeyTable() //nolint:staticcheck
		default:
			continue
		}

		if !subspace.HasKeyTable() {
			subspace.WithKeyTable(keyTable)
		}
	}

	// sdk 47
	k.Subspace(baseapp.Paramspace).
		WithKeyTable(paramstypes.ConsensusParamsKeyTable())
}

func (app App) RegisterUpgradeHandlers() {
	setupLegacyKeyTables(&app.ParamsKeeper)
	
	app.UpgradeKeeper.SetUpgradeHandler(
		UpgradeName,
		func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
			return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
		},
	)

	upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
	if err != nil {
		panic(err)
	}

	if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
		storeUpgrades := storetypes.StoreUpgrades{
			Added: []string{
				consensustypes.ModuleName,
				crisistypes.ModuleName,
				circuittypes.ModuleName,
				ibcfee.ModuleName,
				capabilitytypes.MemStoreKey,
				nft.ModuleName,
			},
		}

		// configure store loader that checks if version == upgradeHeight and applies store upgrades
		app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T:Docs Changes and features related to documentation.
Projects
None yet
Development

No branches or pull requests

3 participants