Skip to content

Commit

Permalink
upgrade handler for v0.24.0 (#834)
Browse files Browse the repository at this point in the history
* upgrade handler for v0.24.0

* remove validate from genesis for protocol version

* add check

* add another check

---------

Co-authored-by: Yarom Swisa <[email protected] git config --global user.name Yarom>
  • Loading branch information
Yaroms and Yarom Swisa authored Sep 27, 2023
1 parent a51660a commit 61e5b7b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/empty_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
}
4 changes: 2 additions & 2 deletions x/protocol/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 8 additions & 2 deletions x/protocol/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion x/protocol/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
53 changes: 48 additions & 5 deletions x/protocol/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 61e5b7b

Please sign in to comment.