From 7b11bb89cc7458883c6eca4747fe574892216b50 Mon Sep 17 00:00:00 2001 From: Yarom Swisa Date: Wed, 13 Sep 2023 08:48:26 +0000 Subject: [PATCH 1/5] adding upgrade handler for v0.23.0 --- app/upgrades/empty_upgrades.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/app/upgrades/empty_upgrades.go b/app/upgrades/empty_upgrades.go index 37b465c33e..e13e9696b8 100644 --- a/app/upgrades/empty_upgrades.go +++ b/app/upgrades/empty_upgrades.go @@ -6,8 +6,11 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/lavanet/lava/app/keepers" + "github.com/lavanet/lava/common" + commontypes "github.com/lavanet/lava/common/types" v1 "github.com/lavanet/lava/x/downtime/v1" - "github.com/lavanet/lava/x/protocol/types" + dualstakingtypes "github.com/lavanet/lava/x/dualstaking/types" + protocoltypes "github.com/lavanet/lava/x/protocol/types" ) func defaultUpgradeHandler( @@ -50,7 +53,28 @@ func v0_22_0_UpgradeHandler( ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { lk.DowntimeKeeper.SetParams(ctx, v1.DefaultParams()) - lk.ProtocolKeeper.SetParams(ctx, types.DefaultParams()) + lk.ProtocolKeeper.SetParams(ctx, protocoltypes.DefaultParams()) + return m.RunMigrations(ctx, c, vm) + } +} + +var Upgrade_0_23_0 = Upgrade{ + UpgradeName: "v0.23.0", + CreateUpgradeHandler: v0_23_0_UpgradeHandler, + StoreUpgrades: store.StoreUpgrades{Added: []string{dualstakingtypes.StoreKey}}, +} + +func v0_23_0_UpgradeHandler( + m *module.Manager, + c module.Configurator, + bapm BaseAppParamManager, + lk *keepers.LavaKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + lk.DualstakingKeeper.InitDelegations(ctx, *common.DefaultGenesis()) + lk.DualstakingKeeper.InitDelegators(ctx, *common.DefaultGenesis()) + lk.DualstakingKeeper.InitUnbondings(ctx, []commontypes.RawMessage{}) + lk.PairingKeeper.InitProviderQoS(ctx, *common.DefaultGenesis()) return m.RunMigrations(ctx, c, vm) } } From 784fc8a1d523ed50110f1daf3d0244e9cff00e0f Mon Sep 17 00:00:00 2001 From: Yarom Swisa Date: Wed, 13 Sep 2023 08:49:12 +0000 Subject: [PATCH 2/5] add upgrade handler to app --- app/app.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/app.go b/app/app.go index c371650cb3..ca94104341 100644 --- a/app/app.go +++ b/app/app.go @@ -140,6 +140,7 @@ const ( // Upgrades add here future upgrades (upgrades.Upgrade) var Upgrades = []upgrades.Upgrade{ upgrades.Upgrade_0_22_0, + upgrades.Upgrade_0_23_0, } // this line is used by starport scaffolding # stargate/wasm/app/enabledProposals From a89ec9a47a13d8ea8f9d180f2cac8c32432a1bfc Mon Sep 17 00:00:00 2001 From: Yarom Swisa Date: Wed, 13 Sep 2023 09:57:53 +0000 Subject: [PATCH 3/5] fix upgrade handler --- app/upgrades/empty_upgrades.go | 4 ---- x/dualstaking/types/genesis.go | 10 +++++++++- x/epochstorage/keeper/migrations.go | 10 ---------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/upgrades/empty_upgrades.go b/app/upgrades/empty_upgrades.go index e13e9696b8..92ed495097 100644 --- a/app/upgrades/empty_upgrades.go +++ b/app/upgrades/empty_upgrades.go @@ -7,7 +7,6 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/lavanet/lava/app/keepers" "github.com/lavanet/lava/common" - commontypes "github.com/lavanet/lava/common/types" v1 "github.com/lavanet/lava/x/downtime/v1" dualstakingtypes "github.com/lavanet/lava/x/dualstaking/types" protocoltypes "github.com/lavanet/lava/x/protocol/types" @@ -71,9 +70,6 @@ func v0_23_0_UpgradeHandler( lk *keepers.LavaKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - lk.DualstakingKeeper.InitDelegations(ctx, *common.DefaultGenesis()) - lk.DualstakingKeeper.InitDelegators(ctx, *common.DefaultGenesis()) - lk.DualstakingKeeper.InitUnbondings(ctx, []commontypes.RawMessage{}) lk.PairingKeeper.InitProviderQoS(ctx, *common.DefaultGenesis()) return m.RunMigrations(ctx, c, vm) } diff --git a/x/dualstaking/types/genesis.go b/x/dualstaking/types/genesis.go index f2689b73ba..8825f3f286 100644 --- a/x/dualstaking/types/genesis.go +++ b/x/dualstaking/types/genesis.go @@ -1,5 +1,10 @@ package types +import ( + "github.com/lavanet/lava/common" + commontypes "github.com/lavanet/lava/common/types" +) + // DefaultIndex is the default global index const DefaultIndex uint64 = 1 @@ -7,7 +12,10 @@ const DefaultIndex uint64 = 1 func DefaultGenesis() *GenesisState { return &GenesisState{ // this line is used by starport scaffolding # genesis/types/default - Params: DefaultParams(), + Params: DefaultParams(), + DelegationsFS: *common.DefaultGenesis(), + DelegatorsFS: *common.DefaultGenesis(), + UnbondingsTS: []commontypes.RawMessage{}, } } diff --git a/x/epochstorage/keeper/migrations.go b/x/epochstorage/keeper/migrations.go index f5f0d3df76..0aeae8e3f4 100644 --- a/x/epochstorage/keeper/migrations.go +++ b/x/epochstorage/keeper/migrations.go @@ -50,16 +50,6 @@ func (m Migrator) Migrate3to4(ctx sdk.Context) error { allStakeStorage := m.keeper.GetAllStakeStorage(ctx) for _, storage := range allStakeStorage { - if storage.Index[:len(ProviderKey)] != ProviderKey { - utils.LavaFormatDebug("migrate: skip storage with key", - utils.Attribute{Key: "index", Value: storage.Index}) - continue - } - if len(storage.Index) <= len(ProviderKey) { - utils.LavaFormatDebug("migrate: skip storage with short key", - utils.Attribute{Key: "index", Value: storage.Index}) - continue - } utils.LavaFormatDebug("migrate: handle storage with key", utils.Attribute{Key: "index", Value: storage.Index}) for i := range storage.StakeEntries { From fcbe604c3ebd3ca245207ce9dd63861fe4f91ffe Mon Sep 17 00:00:00 2001 From: Yarom Swisa Date: Wed, 13 Sep 2023 10:55:32 +0000 Subject: [PATCH 4/5] update protocol version --- protocol/upgrade/protocol_version.go | 4 +-- x/protocol/keeper/migrations.go | 41 ++++++++++++++++++++++++++++ x/protocol/module.go | 11 +++++++- x/protocol/types/params.go | 4 +-- 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 x/protocol/keeper/migrations.go diff --git a/protocol/upgrade/protocol_version.go b/protocol/upgrade/protocol_version.go index 76f81fc76c..8778c200d5 100644 --- a/protocol/upgrade/protocol_version.go +++ b/protocol/upgrade/protocol_version.go @@ -14,8 +14,8 @@ type ProtocolVersion struct { } var lavaProtocolVersion = ProtocolVersion{ - ConsumerVersion: "0.22.3", - ProviderVersion: "0.22.3", + ConsumerVersion: protocoltypes.DefaultVersion.ConsumerTarget, + ProviderVersion: protocoltypes.DefaultVersion.ProviderTarget, } func GetCurrentVersion() ProtocolVersion { diff --git a/x/protocol/keeper/migrations.go b/x/protocol/keeper/migrations.go new file mode 100644 index 0000000000..222cec7b6d --- /dev/null +++ b/x/protocol/keeper/migrations.go @@ -0,0 +1,41 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/lavanet/lava/utils" + protocoltypes "github.com/lavanet/lava/x/protocol/types" + "github.com/lavanet/lava/x/spec/types" +) + +type Migrator struct { + keeper Keeper +} + +func NewMigrator(keeper Keeper) Migrator { + return Migrator{keeper: keeper} +} + +func (m Migrator) UpgradeProtocolVersionParams(ctx sdk.Context) { + params := m.keeper.GetParams(ctx) + params.Version = protocoltypes.DefaultGenesis().Params.Version + m.keeper.SetParams(ctx, params) + + details := []utils.Attribute{ + {Key: "param", Value: string(protocoltypes.KeyVersion)}, + {Key: "value", Value: params.Version.String()}, + } + + detailsMap := map[string]string{} + for _, atr := range details { + detailsMap[atr.Key] = fmt.Sprint(atr.Value) + } + 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 { + m.UpgradeProtocolVersionParams(ctx) + return nil +} diff --git a/x/protocol/module.go b/x/protocol/module.go index adbddb106d..f89dff6c18 100644 --- a/x/protocol/module.go +++ b/x/protocol/module.go @@ -121,6 +121,15 @@ func (am AppModule) Name() string { // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + + migrator := keeper.NewMigrator(am.keeper) + + // register v2 -> v3 migration + if err := cfg.RegisterMigration(types.ModuleName, 2, migrator.Migrate2to3); 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)) + } } // RegisterInvariants registers the capability module's invariants. @@ -145,7 +154,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 2 } +func (AppModule) ConsensusVersion() uint64 { return 3 } // 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/params.go b/x/protocol/types/params.go index f074cd4d50..dc195fdf4b 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.22.0", + ProviderTarget: "0.23.0", ProviderMin: "0.21.0", - ConsumerTarget: "0.22.0", + ConsumerTarget: "0.23.0", ConsumerMin: "0.21.0", } ) From e7050acdf7dae3a291d3b3bda6e742864f031859 Mon Sep 17 00:00:00 2001 From: Yarom Swisa Date: Wed, 13 Sep 2023 10:56:55 +0000 Subject: [PATCH 5/5] small fix --- x/protocol/keeper/migrations.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/x/protocol/keeper/migrations.go b/x/protocol/keeper/migrations.go index 222cec7b6d..b4ec34d9d7 100644 --- a/x/protocol/keeper/migrations.go +++ b/x/protocol/keeper/migrations.go @@ -1,8 +1,6 @@ package keeper import ( - "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/lavanet/lava/utils" protocoltypes "github.com/lavanet/lava/x/protocol/types" @@ -22,15 +20,11 @@ func (m Migrator) UpgradeProtocolVersionParams(ctx sdk.Context) { params.Version = protocoltypes.DefaultGenesis().Params.Version m.keeper.SetParams(ctx, params) - details := []utils.Attribute{ - {Key: "param", Value: string(protocoltypes.KeyVersion)}, - {Key: "value", Value: params.Version.String()}, + detailsMap := map[string]string{ + "param": string(protocoltypes.KeyVersion), + "value": params.Version.String(), } - detailsMap := map[string]string{} - for _, atr := range details { - detailsMap[atr.Key] = fmt.Sprint(atr.Value) - } utils.LogLavaEvent(ctx, m.keeper.Logger(ctx), types.ParamChangeEventName, detailsMap, "Gov Proposal Accepted Param Changed") }