Skip to content

Commit

Permalink
Merge pull request #225 from AstraProtocol/release/v3.1.x
Browse files Browse the repository at this point in the history
chore: update mainnet upgradeHandler
  • Loading branch information
Thanh Nguyen authored Sep 20, 2023
2 parents 1a4654e + 5285628 commit cef27a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ func (app *Astra) setupUpgradeHandlers() {
v31.CreateUpgradeHandler(
app.mm,
app.configurator,
app.StakingKeeper,
),
)
}
6 changes: 5 additions & 1 deletion app/upgrades/v3/upgrades.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 ...")
Expand Down
23 changes: 23 additions & 0 deletions app/upgrades/v3_1/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
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"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v8.1
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
Expand All @@ -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)
}

0 comments on commit cef27a2

Please sign in to comment.