Skip to content

Commit

Permalink
refactor: use corestore.StoreUpgrades (backport #21259) (#21274)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko <marko@baricevic.me>
  • Loading branch information
mergify[bot] and tac0turtle authored Aug 13, 2024
1 parent 595daaf commit 43ce882
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
4 changes: 2 additions & 2 deletions simapp/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"cosmossdk.io/core/appmodule"
storetypes "cosmossdk.io/store/types"
corestore "cosmossdk.io/core/store"
"cosmossdk.io/x/accounts"
authkeeper "cosmossdk.io/x/auth/keeper"
epochstypes "cosmossdk.io/x/epochs/types"
Expand Down Expand Up @@ -42,7 +42,7 @@ func (app SimApp) RegisterUpgradeHandlers() {
}

if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
storeUpgrades := corestore.StoreUpgrades{
Added: []string{
accounts.StoreKey,
protocolpooltypes.StoreKey,
Expand Down
1 change: 1 addition & 0 deletions x/upgrade/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### API Breaking Changes

* [#19443](https://github.com/cosmos/cosmos-sdk/pull/19443) `NewKeeper` takes an `appmodule.Environment` instead of individual services.
* [#21259](https://github.com/cosmos/cosmos-sdk/pull/21259) Upgrade has been migrated to cosrestore.StoreUpgrades. Renaming keys support has been removed from the upgrade module.

### State Machine Breaking

Expand Down
11 changes: 8 additions & 3 deletions x/upgrade/types/storeloader.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package types

import (
corestore "cosmossdk.io/core/store"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/baseapp"
)

// UpgradeStoreLoader is used to prepare baseapp with a fixed StoreLoader
// pattern. This is useful for custom upgrade loading logic.
func UpgradeStoreLoader(upgradeHeight int64, storeUpgrades *storetypes.StoreUpgrades) baseapp.StoreLoader {
func UpgradeStoreLoader(upgradeHeight int64, storeUpgrades *corestore.StoreUpgrades) baseapp.StoreLoader {
return func(ms storetypes.CommitMultiStore) error {
if upgradeHeight == ms.LastCommitID().Version+1 {
// Check if the current commit version and upgrade height matches
if len(storeUpgrades.Renamed) > 0 || len(storeUpgrades.Deleted) > 0 || len(storeUpgrades.Added) > 0 {
return ms.LoadLatestVersionAndUpgrade(storeUpgrades)
if len(storeUpgrades.Deleted) > 0 || len(storeUpgrades.Added) > 0 {
stup := &storetypes.StoreUpgrades{
Added: storeUpgrades.Added,
Deleted: storeUpgrades.Deleted,
}
return ms.LoadLatestVersionAndUpgrade(stup)
}
}

Expand Down
16 changes: 0 additions & 16 deletions x/upgrade/types/storeloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
)

func useUpgradeLoader(height int64, upgrades *storetypes.StoreUpgrades) func(*baseapp.BaseApp) {
return func(app *baseapp.BaseApp) {
app.SetStoreLoader(UpgradeStoreLoader(height, upgrades))
}
}

func initStore(t *testing.T, db dbm.DB, storeKey string, k, v []byte) {
t.Helper()
rs := rootmulti.NewStore(db, coretesting.NewNopLogger(), metrics.NewNoOpMetrics())
Expand Down Expand Up @@ -93,16 +87,6 @@ func TestSetLoader(t *testing.T) {
origStoreKey: "foo",
loadStoreKey: "foo",
},
"rename with inline opts": {
setLoader: useUpgradeLoader(upgradeHeight, &storetypes.StoreUpgrades{
Renamed: []storetypes.StoreRename{{
OldKey: "foo",
NewKey: "bar",
}},
}),
origStoreKey: "foo",
loadStoreKey: "bar",
},
}

k := []byte("key")
Expand Down

0 comments on commit 43ce882

Please sign in to comment.