Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: adjusting the parameters of the ica module #2918

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 1 addition & 40 deletions app/upgrades/v300/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,5 @@ var (
// the portion of a chain's total stake can be liquid
GlobalLiquidStakingCap = sdk.MustNewDecFromStr("0.25") // 25%

allowMessages = []string{
"/cosmos.authz.v1beta1.MsgExec",
"/cosmos.authz.v1beta1.MsgGrant",
"/cosmos.authz.v1beta1.MsgRevoke",
"/cosmos.bank.v1beta1.MsgSend",
"/cosmos.bank.v1beta1.MsgMultiSend",
"/cosmos.distribution.v1beta1.MsgSetWithdrawAddress",
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission",
"/cosmos.distribution.v1beta1.MsgFundCommunityPool",
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
"/cosmos.feegrant.v1beta1.MsgGrantAllowance",
"/cosmos.feegrant.v1beta1.MsgRevokeAllowance",
"/cosmos.gov.v1beta1.MsgVoteWeighted",
"/cosmos.gov.v1beta1.MsgSubmitProposal",
"/cosmos.gov.v1beta1.MsgDeposit",
"/cosmos.gov.v1beta1.MsgVote",
"/cosmos.gov.v1.MsgVoteWeighted",
"/cosmos.gov.v1.MsgSubmitProposal",
"/cosmos.gov.v1.MsgDeposit",
"/cosmos.gov.v1.MsgVote",
"/cosmos.staking.v1beta1.MsgEditValidator",
"/cosmos.staking.v1beta1.MsgDelegate",
"/cosmos.staking.v1beta1.MsgUndelegate",
"/cosmos.staking.v1beta1.MsgBeginRedelegate",
"/cosmos.staking.v1beta1.MsgCreateValidator",
"/cosmos.vesting.v1beta1.MsgCreateVestingAccount",
"/ibc.applications.transfer.v1.MsgTransfer",
"/irismod.nft.MsgIssueDenom",
"/irismod.nft.MsgTransferDenom",
"/irismod.nft.MsgMintNFT",
"/irismod.nft.MsgEditNFT",
"/irismod.nft.MsgTransferNFT",
"/irismod.nft.MsgBurnNFT",
"/irismod.mt.MsgIssueDenom",
"/irismod.mt.MsgTransferDenom",
"/irismod.mt.MsgMintMT",
"/irismod.mt.MsgEditMT",
"/irismod.mt.MsgTransferMT",
"/irismod.mt.MsgBurnMT",
}
allowMessages = []string{"*"}
)
30 changes: 16 additions & 14 deletions app/upgrades/v300/lsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ type keeper interface {
SetParams(ctx sdk.Context, params types.Params) error
}

// MigrateParamsStore migrates the params store to the latest version.
// migrateParamsStore migrates the params store to the latest version.
//
// ctx - sdk context
// k - keeper
func MigrateParamsStore(ctx sdk.Context, k keeper) {
func migrateParamsStore(ctx sdk.Context, k keeper) error {
params := k.GetParams(ctx)
params.ValidatorBondFactor = ValidatorBondFactor
params.ValidatorLiquidStakingCap = ValidatorLiquidStakingCap
params.GlobalLiquidStakingCap = GlobalLiquidStakingCap
k.SetParams(ctx, params)
return k.SetParams(ctx, params)
}

// MigrateValidators Set each validator's ValidatorBondShares and LiquidShares to 0
func MigrateValidators(ctx sdk.Context, k keeper) {
// migrateValidators Set each validator's ValidatorBondShares and LiquidShares to 0
func migrateValidators(ctx sdk.Context, k keeper) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error handling to the migrateValidators and migrateDelegations functions. While the current changes align with the migration objectives, incorporating error handling could enhance the robustness and consistency of the migration process.

Also applies to: 46-46

for _, validator := range k.GetAllValidators(ctx) {
validator.ValidatorBondShares = sdk.ZeroDec()
validator.LiquidShares = sdk.ZeroDec()
k.SetValidator(ctx, validator)
}
}

// MigrateDelegations Set each delegation's ValidatorBond field to false
func MigrateDelegations(ctx sdk.Context, k keeper) {
// migrateDelegations Set each delegation's ValidatorBond field to false
func migrateDelegations(ctx sdk.Context, k keeper) {
for _, delegation := range k.GetAllDelegations(ctx) {
delegation.ValidatorBond = false
k.SetDelegation(ctx, delegation)
Expand All @@ -52,7 +52,7 @@ func MigrateDelegations(ctx sdk.Context, k keeper) {

// MigrateUBDEntries will remove the ubdEntries with same creation_height
// and create a new ubdEntry with updated balance and initial_balance
func MigrateUBDEntries(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
func migrateUBDEntries(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
iterator := sdk.KVStorePrefixIterator(store, types.UnbondingDelegationKey)
defer iterator.Close()

Expand Down Expand Up @@ -108,25 +108,27 @@ func setUBDToStore(_ sdk.Context, store storetypes.KVStore, cdc codec.BinaryCode
store.Set(key, bz)
}

// MigrateStore performs the in-place store migration for adding LSM support to v0.45.16-ics, including:
// migrateStore performs the in-place store migration for adding LSM support to v0.45.16-ics, including:
// - Adding params ValidatorBondFactor, GlobalLiquidStakingCap, ValidatorLiquidStakingCap
// - Setting each validator's ValidatorBondShares and LiquidShares to 0
// - Setting each delegation's ValidatorBond field to false
// - Calculating the total liquid staked by summing the delegations from ICA accounts
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, k keeper) error {
func migrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, k keeper) error {
store := ctx.KVStore(storeKey)

ctx.Logger().Info("Staking LSM Migration: Migrating param store")
MigrateParamsStore(ctx, k)
if err := migrateParamsStore(ctx, k); err != nil {
return err
}

ctx.Logger().Info("Staking LSM Migration: Migrating validators")
MigrateValidators(ctx, k)
migrateValidators(ctx, k)

ctx.Logger().Info("Staking LSM Migration: Migrating delegations")
MigrateDelegations(ctx, k)
migrateDelegations(ctx, k)

ctx.Logger().Info("Staking LSM Migration: Migrating UBD entries")
if err := MigrateUBDEntries(ctx, store, cdc); err != nil {
if err := migrateUBDEntries(ctx, store, cdc); err != nil {
return err
}

Expand Down
10 changes: 6 additions & 4 deletions app/upgrades/v300/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
var Upgrade = upgrades.Upgrade{
UpgradeName: "v3.0",
UpgradeName: "v3",
UpgradeHandlerConstructor: upgradeHandlerConstructor,
StoreUpgrades: &storetypes.StoreUpgrades{
Added: []string{icahosttypes.StoreKey},
Expand All @@ -34,7 +34,9 @@ func upgradeHandlerConstructor(
initICAModule(ctx, m, fromVM)

// merge liquid staking module
mergeLSModule(ctx, box)
if err := mergeLSModule(ctx, box); err != nil {
return nil, err
}
return box.ModuleManager.RunMigrations(ctx, c, fromVM)
}
}
Expand All @@ -52,9 +54,9 @@ func initICAModule(ctx sdk.Context, m *module.Manager, fromVM module.VersionMap)
icaModule.InitModule(ctx, controllerParams, hostParams)
}

func mergeLSModule(ctx sdk.Context, box upgrades.Toolbox) {
func mergeLSModule(ctx sdk.Context, box upgrades.Toolbox) error {
ctx.Logger().Info("start to run lsm module migrations...")

storeKey := box.GetKey(stakingtypes.StoreKey)
MigrateStore(ctx, storeKey, box.AppCodec, box.StakingKeeper)
return migrateStore(ctx, storeKey, box.AppCodec, box.StakingKeeper)
}
Loading