diff --git a/app/app.go b/app/app.go index bdc732f57a..a94c325c05 100644 --- a/app/app.go +++ b/app/app.go @@ -144,6 +144,7 @@ var Upgrades = []upgrades.Upgrade{ upgrades.Upgrade_0_23_2, upgrades.Upgrade_0_23_4, upgrades.Upgrade_0_23_5, + upgrades.Upgrade_0_24_0, } // this line is used by starport scaffolding # stargate/wasm/app/enabledProposals diff --git a/app/upgrades/empty_upgrades.go b/app/upgrades/empty_upgrades.go index e03934316d..6592a37da3 100644 --- a/app/upgrades/empty_upgrades.go +++ b/app/upgrades/empty_upgrades.go @@ -92,3 +92,9 @@ var Upgrade_0_23_5 = Upgrade{ CreateUpgradeHandler: v0_23_0_UpgradeHandler, StoreUpgrades: store.StoreUpgrades{Added: []string{dualstakingtypes.StoreKey}}, } + +var Upgrade_0_24_0 = Upgrade{ + UpgradeName: "v0.24.0", + CreateUpgradeHandler: defaultUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{}, +} diff --git a/x/protocol/keeper/migrations.go b/x/protocol/keeper/migrations.go index b4ec34d9d7..e5b3134d72 100644 --- a/x/protocol/keeper/migrations.go +++ b/x/protocol/keeper/migrations.go @@ -28,8 +28,8 @@ func (m Migrator) UpgradeProtocolVersionParams(ctx sdk.Context) { utils.LogLavaEvent(ctx, m.keeper.Logger(ctx), types.ParamChangeEventName, detailsMap, "Gov Proposal Accepted Param Changed") } -// Migrate2to3 implements store migration from v2 to v3: -func (m Migrator) Migrate2to3(ctx sdk.Context) error { +// MigrateVersion implements store migration: update protocol version +func (m Migrator) MigrateVersion(ctx sdk.Context) error { m.UpgradeProtocolVersionParams(ctx) return nil } diff --git a/x/protocol/module.go b/x/protocol/module.go index 3b37d5e230..71e0c22f35 100644 --- a/x/protocol/module.go +++ b/x/protocol/module.go @@ -128,7 +128,13 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { migrator := keeper.NewMigrator(am.keeper) // register v2 -> v3 migration - if err := cfg.RegisterMigration(types.ModuleName, 2, migrator.Migrate2to3); err != nil { + if err := cfg.RegisterMigration(types.ModuleName, 2, migrator.MigrateVersion); err != nil { + // panic:ok: at start up, migration cannot proceed anyhow + panic(fmt.Errorf("%s: failed to register migration to v3: %w", types.ModuleName, err)) + } + + // register v3 -> v4 migration + if err := cfg.RegisterMigration(types.ModuleName, 3, migrator.MigrateVersion); err != nil { // panic:ok: at start up, migration cannot proceed anyhow panic(fmt.Errorf("%s: failed to register migration to v3: %w", types.ModuleName, err)) } @@ -156,7 +162,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 3 } +func (AppModule) ConsensusVersion() uint64 { return 4 } // BeginBlock executes all ABCI BeginBlock logic respective to the capability module. func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { diff --git a/x/protocol/types/genesis.go b/x/protocol/types/genesis.go index 5692118277..268605e2cb 100644 --- a/x/protocol/types/genesis.go +++ b/x/protocol/types/genesis.go @@ -16,5 +16,5 @@ func DefaultGenesis() *GenesisState { func (gs GenesisState) Validate() error { // this line is used by starport scaffolding # genesis/types/validate - return gs.Params.Validate() + return gs.Params.Validate(true) } diff --git a/x/protocol/types/params.go b/x/protocol/types/params.go index 6743113827..01baa3b01e 100644 --- a/x/protocol/types/params.go +++ b/x/protocol/types/params.go @@ -14,9 +14,9 @@ var _ paramtypes.ParamSet = (*Params)(nil) var ( KeyVersion = []byte("Version") DefaultVersion = Version{ - ProviderTarget: "0.23.5", + ProviderTarget: "0.24.0", ProviderMin: "0.21.0", - ConsumerTarget: "0.23.5", + ConsumerTarget: "0.24.0", ConsumerMin: "0.21.0", } ) @@ -109,9 +109,15 @@ func versionToInteger(v string) (int, error) { } // Validate validates the set of params -func (p Params) Validate() error { - if err := validateVersion(p.Version); err != nil { - return err +func (p Params) Validate(genesis bool) error { + if genesis { + if err := validateVersionGenesis(p.Version); err != nil { + return err + } + } else { + if err := validateVersion(p.Version); err != nil { + return err + } } return nil @@ -192,3 +198,40 @@ func validateVersion(v interface{}) error { return nil } + +// validateVersion validates the Version param from genesis +func validateVersionGenesis(v interface{}) error { + version, ok := v.(Version) + if !ok { + return fmt.Errorf("invalid parameter type: %T", v) + } + + newProviderTarget, err := versionToInteger(version.ProviderTarget) + if err != nil { + return fmt.Errorf("provider target version: %w", err) + } + newProviderMin, err := versionToInteger(version.ProviderMin) + if err != nil { + return fmt.Errorf("provider min version: %w", err) + } + newConsumerTarget, err := versionToInteger(version.ConsumerTarget) + if err != nil { + return fmt.Errorf("consumer target version: %w", err) + } + newConsumerMin, err := versionToInteger(version.ConsumerMin) + if err != nil { + return fmt.Errorf("consumer min version: %w", err) + } + + // min version may not exceed target version + if newProviderMin > newProviderTarget { + return fmt.Errorf("provider min version exceeds target version: %d > %d", + newProviderMin, newProviderTarget) + } + if newConsumerMin > newConsumerTarget { + return fmt.Errorf("consumer min version exceeds target version: %d > %d", + newConsumerMin, newConsumerTarget) + } + + return nil +}