diff --git a/app/app.go b/app/app.go index d1b9234..3d3cbc0 100644 --- a/app/app.go +++ b/app/app.go @@ -1011,6 +1011,7 @@ func (app *Astra) setupUpgradeHandlers() { v31.CreateUpgradeHandler( app.mm, app.configurator, + app.StakingKeeper, ), ) } diff --git a/app/upgrades/v3/upgrades.go b/app/upgrades/v3/upgrades.go index 0525d06..04f40a6 100644 --- a/app/upgrades/v3/upgrades.go +++ b/app/upgrades/v3/upgrades.go @@ -1,6 +1,7 @@ package v3 import ( + "github.com/AstraProtocol/astra/v3/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -17,7 +18,10 @@ func CreateUpgradeHandler( return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { logger := ctx.Logger().With("upgrade", UpgradeName) - setMinCommissionRate(ctx, stakingKeeper) + // !mainnet only + if !types.IsMainnet(ctx.ChainID()) { + setMinCommissionRate(ctx, stakingKeeper) + } // Leave modules are as-is to avoid running InitGenesis. logger.Debug("running module migrations ...") diff --git a/app/upgrades/v3_1/upgrades.go b/app/upgrades/v3_1/upgrades.go index 2e55eea..58eb87b 100644 --- a/app/upgrades/v3_1/upgrades.go +++ b/app/upgrades/v3_1/upgrades.go @@ -1,8 +1,11 @@ package v31 import ( + "github.com/AstraProtocol/astra/v3/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -10,10 +13,15 @@ import ( func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, + stakingKeeper stakingkeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { logger := ctx.Logger().With("upgrade", UpgradeName) + // mainnet only + if types.IsMainnet(ctx.ChainID()) { + setMinCommissionRate(ctx, stakingKeeper) + } // Refs: // - https://docs.cosmos.network/master/building-modules/upgrade.html#registering-migrations // - https://docs.cosmos.network/master/migrations/chain-upgrade-guide-044.html#chain-upgrade @@ -23,3 +31,18 @@ func CreateUpgradeHandler( return mm.RunMigrations(ctx, configurator, vm) } } + +// setMinCommissionRate sets the minimum commission rate for validators +// to 5%. +func setMinCommissionRate(ctx sdk.Context, sk stakingkeeper.Keeper) { + stakingParams := stakingtypes.Params{ + UnbondingTime: sk.UnbondingTime(ctx), + MaxValidators: sk.MaxValidators(ctx), + MaxEntries: sk.MaxEntries(ctx), + HistoricalEntries: sk.HistoricalEntries(ctx), + BondDenom: sk.BondDenom(ctx), + MinCommissionRate: sdk.NewDecWithPrec(5, 2), // 5% + } + + sk.SetParams(ctx, stakingParams) +}