Skip to content

Commit

Permalink
set custom migration order via app config
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Dec 7, 2022
1 parent 95e848d commit 7d53ceb
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 53 deletions.
192 changes: 165 additions & 27 deletions api/cosmos/app/runtime/v1alpha1/module.pulsar.go

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions api/cosmos/consensus/v1/query.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/cosmos/consensus/v1/tx.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ require (
)

replace (
// temporarily until tagging new api
cosmossdk.io/api => ./api

github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
// TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
cloud.google.com/go/storage v1.27.0 h1:YOO045NZI9RKfCj1c5A/ZtuuENUc8OAW+gHdGnDgyMQ=
cloud.google.com/go/storage v1.27.0/go.mod h1:x9DOL8TK/ygDUMieqwfhdpQryTeEkhGKMi80i/iqR2s=
cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks=
cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw=
cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ=
cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc=
cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw=
Expand Down
5 changes: 5 additions & 0 deletions proto/cosmos/app/runtime/v1alpha1/module.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ message Module {
// override_store_keys is an optional list of overrides for the module store keys
// to be used in keeper construction.
repeated StoreKeyConfig override_store_keys = 6;

// order_migrations defines the order in which module migrations are performed
// If this is left empty, it uses the default migration order
// https://pkg.go.dev/github.com/cosmos/cosmos-sdk@v0.47.0-alpha2/types/module#DefaultMigrationsOrder
repeated string order_migrations = 7;
}

// StoreKeyConfig may be supplied to override the default module store key, which
Expand Down
5 changes: 5 additions & 0 deletions runtime/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (a *App) Load(loadLatest bool) error {

if len(a.config.InitGenesis) != 0 {
a.ModuleManager.SetOrderInitGenesis(a.config.InitGenesis...)
a.SetInitChainer(a.InitChainer)
}

if len(a.config.ExportGenesis) != 0 {
Expand All @@ -103,6 +104,10 @@ func (a *App) Load(loadLatest bool) error {
a.SetEndBlocker(a.EndBlocker)
}

if len(a.config.OrderMigrations) != 0 {
a.ModuleManager.SetOrderMigrations(a.config.OrderMigrations...)
}

if loadLatest {
if err := a.LoadLatestVersion(); err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions runtime/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ type AppInputs struct {
}

func SetupAppBuilder(inputs AppInputs) {
mm := module.NewManagerFromMap(inputs.Modules)
app := inputs.AppBuilder.app
app.baseAppOptions = inputs.BaseAppOptions
app.config = inputs.Config
app.ModuleManager = mm
app.ModuleManager = module.NewManagerFromMap(inputs.Modules)
app.appConfig = inputs.AppConfig

for name, mod := range inputs.Modules {
Expand Down
2 changes: 2 additions & 0 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ var (
// When ExportGenesis is not specified, the export genesis module order
// is equal to the init genesis order
// ExportGenesis: genesisModuleOrder,
// Uncomment if you want to set a custom migration order here.
// OrderMigrations: nil,
}),
},
{
Expand Down
14 changes: 0 additions & 14 deletions simapp/app_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os"
"path/filepath"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

Expand All @@ -27,7 +26,6 @@ import (
"github.com/cosmos/cosmos-sdk/store/streaming"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
Expand Down Expand Up @@ -262,9 +260,6 @@ func NewSimApp(
// Sets the version setter for the upgrade module
app.UpgradeKeeper.SetVersionSetter(app.BaseApp)

// Uncomment if you want to set a custom migration order here.
// app.ModuleManager.SetOrderMigrations(custom order)

app.ModuleManager.RegisterInvariants(app.CrisisKeeper)

// RegisterUpgradeHandlers is used for registering any on-chain upgrades.
Expand All @@ -288,9 +283,6 @@ func NewSimApp(
// initialize stores
app.MountKVStores(app.keys)

// initialize BaseApp
app.SetInitChainer(app.InitChainer)

if err := app.Load(loadLatest); err != nil {
panic(err)
}
Expand All @@ -301,12 +293,6 @@ func NewSimApp(
// Name returns the name of the App
func (app *SimApp) Name() string { return app.BaseApp.Name() }

// InitChainer application update at chain initialization
func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap())
return app.App.InitChainer(ctx, req)
}

// LoadHeight loads a particular height
func (app *SimApp) LoadHeight(height int64) error {
return app.LoadVersion(height)
Expand Down
3 changes: 3 additions & 0 deletions simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ require (
)

replace (
// temporarily until tagging new api
cosmossdk.io/api => ../api

github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// Simapp always use the latest version of the cosmos-sdk
github.com/cosmos/cosmos-sdk => ../.
Expand Down
2 changes: 0 additions & 2 deletions simapp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
cloud.google.com/go/storage v1.27.0 h1:YOO045NZI9RKfCj1c5A/ZtuuENUc8OAW+gHdGnDgyMQ=
cloud.google.com/go/storage v1.27.0/go.mod h1:x9DOL8TK/ygDUMieqwfhdpQryTeEkhGKMi80i/iqR2s=
cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks=
cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw=
cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ=
cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc=
cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw=
Expand Down
7 changes: 5 additions & 2 deletions x/consensus/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/consensus/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d53ceb

Please sign in to comment.