Skip to content

Commit

Permalink
Merge pull request #788 from lavanet/CNS-590-delegator-integration-on…
Browse files Browse the repository at this point in the history
…-staging

Cns 590 delegator integration on staging
  • Loading branch information
Yaroms authored Sep 13, 2023
2 parents b9cf6de + bdfb656 commit 5ab38c9
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 18 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions app/upgrades/empty_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ 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"
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(
Expand Down Expand Up @@ -50,7 +52,25 @@ 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.PairingKeeper.InitProviderQoS(ctx, *common.DefaultGenesis())
return m.RunMigrations(ctx, c, vm)
}
}
4 changes: 2 additions & 2 deletions protocol/upgrade/protocol_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion x/dualstaking/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
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

// DefaultGenesis returns the default genesis state
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{},
}
}

Expand Down
10 changes: 0 additions & 10 deletions x/epochstorage/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 35 additions & 0 deletions x/protocol/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package keeper

import (
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)

detailsMap := map[string]string{
"param": string(protocoltypes.KeyVersion),
"value": params.Version.String(),
}

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
}
11 changes: 10 additions & 1 deletion x/protocol/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 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.22.3",
ProviderTarget: "0.23.0",
ProviderMin: "0.21.0",
ConsumerTarget: "0.22.3",
ConsumerTarget: "0.23.0",
ConsumerMin: "0.21.0",
}
)
Expand Down

0 comments on commit 5ab38c9

Please sign in to comment.