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

feat: add update minCommissionRate to validators #1379

Merged
merged 12 commits into from
Sep 15, 2022
41 changes: 40 additions & 1 deletion app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/nft"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

stakingKeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
bech32ibckeeper "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/keeper"
bech32ibctypes "github.com/osmosis-labs/bech32-ibc/x/bech32ibc/types"
leveragetypes "github.com/umee-network/umee/v3/x/leverage/types"
Expand All @@ -30,7 +31,21 @@ func (app UmeeApp) RegisterUpgradeHandlers() {
}

ctx.Logger().Info("Upgrade handler execution finished, running migrations", "name", UpgradeV3_0Plan)
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
vm, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
if err != nil {
return vm, err
}

ctx.Logger().Info("Upgrade handler execution finished, updatiing minimum commission rate to validators",
gsk967 marked this conversation as resolved.
Show resolved Hide resolved
"name", UpgradeV3_0Plan)
err = setMinimumCommissionRateToValidatros(app.StakingKeeper, ctx)
if err != nil {
return vm, sdkerrors.Wrapf(
err, "Calypso %q Upgrade: Unable to upgrade, failied to update minimum commission rate to validatos",
toteki marked this conversation as resolved.
Show resolved Hide resolved
UpgradeV3_0Plan)
}

return vm, err
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
Expand All @@ -54,6 +69,30 @@ func (app UmeeApp) RegisterUpgradeHandlers() {
}
}

// setMinimumCommissionRateToValidatros is update the minimum commission rate to the validators rate
// whose commission rate is below the minimum commission rate.
func setMinimumCommissionRateToValidatros(keeper *stakingKeeper.Keeper, ctx sdk.Context) error {
validators := keeper.GetAllValidators(ctx)

for _, validator := range validators {
params := keeper.GetParams(ctx)
gsk967 marked this conversation as resolved.
Show resolved Hide resolved
if validator.Commission.Rate.GTE(params.MinCommissionRate) {
continue
}

if err := keeper.BeforeValidatorModified(ctx, validator.GetOperator()); err != nil {
return err
}

validator.Commission.Rate = params.MinCommissionRate
validator.Commission.UpdateTime = ctx.BlockTime()

keeper.SetValidator(ctx, validator)
}

return nil
}

// Sets up bech32ibc module by setting the native account prefix to "umee".
// Failing to set the native prefix will cause a chain halt on init genesis or
// in the firstBeginBlocker assertions.
Expand Down