This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package app // app.go | |
| func NewSimApp(...) *SimApp { | |
| // setupUpgradeHandlers should be called before `LoadLatestVersion()` | |
| // because StoreLoad is sealed after that | |
| app.setupUpgradeHandlers(configurator, app.BankKeeper) | |
| if loadLatest { | |
| if err := app.LoadLatestVersion(); err != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package v2 // upgrades.go | |
| var DenomMetadata = banktypes.Metadata{...} | |
| func CreateUpgradeHandler( | |
| mm *module.Manager, | |
| configurator module.Configurator, | |
| bk bankkeeper.Keeper, | |
| ) upgradetypes.UpgradeHandler { | |
| return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| x | |
| ├── foo | |
| │ ├── keepers | |
| │ │ └── migrations.go | |
| │ ├── migrations | |
| │ │ ├── v1 | |
| │ │ │ ├── tx.pb.go | |
| │ │ │ └── ... | |
| │ │ └── v2 | |
| │ │ └── migrations.go |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package keeper // migrations.go | |
| type Migrator struct { | |
| keeper Keeper | |
| } | |
| func NewMigrator(keeper Keeper) Migrator { | |
| return Migrator{keeper: keeper} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package v2 // migrations.go | |
| func UpdateParams(ctx sdk.Context, paramStore *paramtypes.Subspace) error { | |
| ... | |
| paramStore.Set(ctx, types.KeyValue, "foobar") | |
| return nil | |
| } | |
| func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package foo | |
| // RegisterServices registers a GRPC query service to respond to the | |
| // module-specific GRPC queries. | |
| func (am AppModule) RegisterServices(cfg module.Configurator) { | |
| ... | |
| migrator := keeper.NewMigrator(am.keeper) | |
| // register v1 -> v2 migration | |
| if err := cfg.RegisterMigration(types.ModuleName, 1, migrator.Migrate1to2); err != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM VersionMap) (VersionMap, error) { | |
| ... | |
| updatedVM := VersionMap{} | |
| for _, moduleName := range modules { | |
| module := m.Modules[moduleName] | |
| fromVersion, exists := fromVM[moduleName] | |
| toVersion := module.ConsensusVersion() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package app // upgrades.go | |
| func (app *App) setupUpgradeHandlers( | |
| configurator module.Configurator, | |
| ... | |
| ) { | |
| app.UpgradeKeeper.SetUpgradeHandler( | |
| v2.UpgradeName, | |
| v2.CreateUpgradeHandler(app.mm, configurator, ...), | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| export DAEMON_NAME=simappd | |
| export SIMAPPD_V1_HOME=/path/to/simappd-v1 | |
| export SIMAPPD_V2_HOME=/path/to/simappd-v2 | |
| export DAEMON_HOME=/path/to/simappd-home | |
| # Tmp cosmovisor directory. In this directory, we are going to | |
| # setup Cosmovisor directory structures and copy this directory | |
| # into $DAEMON_HOME |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| export SIMAPPD_V1_HOME=/path/to/simappd-v1 | |
| export SIMAPP_V1_BIN=$SIMAPPD_V1_HOME/cosmovisor/genesis/bin/cored | |
| export DAEMON_HOME=/path/to/simappd-home | |
| # Send SoftwareUpgrade proposal - Upgrade Name: v2.0.0 | |
| $SIMAPP_V1_BIN tx gov submit-proposal software-upgrade v2.0.0 --title v2.0.0 --description v2.0.0 --upgrade-height 40 --from validator1 --yes --home $DAEMON_HOME --chain-id app_9000-1 | |
| # Deposit for the proposal - Proposal ID: 1 |