Skip to content

Commit

Permalink
Add storeLoaders
Browse files Browse the repository at this point in the history
  • Loading branch information
pinosu committed Dec 6, 2022
1 parent a1a3903 commit 2d71ab4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ func NewTgradeApp(
app.twasmKeeper,
app.accountKeeper,
)

app.setupUpgradeStoreLoaders()

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand Down Expand Up @@ -710,6 +713,26 @@ func (app *TgradeApp) AppCodec() codec.Codec {
return app.appCodec
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
func (app *TgradeApp) setupUpgradeStoreLoaders() {
upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic("failed to read upgrade info from disk" + err.Error())
}

if app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

for _, upgrade := range Upgrades {
if upgradeInfo.Name == upgrade.UpgradeName {
app.SetStoreLoader(
upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades),
)
}
}
}

func (app *TgradeApp) setupUpgradeHandlers() {
for _, upgrade := range Upgrades {
app.upgradeKeeper.SetUpgradeHandler(
Expand Down
4 changes: 4 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package upgrades

import (
store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/types/module"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
Expand All @@ -16,4 +17,7 @@ type Upgrade struct {

// CreateUpgradeHandler defines the function that creates an upgrade handler
CreateUpgradeHandler func(*module.Manager, module.Configurator, authkeeper.AccountKeeper) upgradetypes.UpgradeHandler

// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
StoreUpgrades store.StoreUpgrades
}
5 changes: 5 additions & 0 deletions app/upgrades/v2/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v2

import (
"github.com/confio/tgrade/app/upgrades"
store "github.com/cosmos/cosmos-sdk/store/types"
)

// UpgradeName defines the on-chain upgrade name for the Tgrade v2 upgrade.
Expand All @@ -10,4 +11,8 @@ const UpgradeName = "v2"
var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
Deleted: []string{},
},
}
5 changes: 5 additions & 0 deletions app/upgrades/v3/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v3

import (
"github.com/confio/tgrade/app/upgrades"
store "github.com/cosmos/cosmos-sdk/store/types"
)

// UpgradeName defines the on-chain upgrade name for the Tgrade v3 upgrade.
Expand All @@ -10,4 +11,8 @@ const UpgradeName = "v3"
var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
Deleted: []string{},
},
}

0 comments on commit 2d71ab4

Please sign in to comment.