-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from scorpioborn/feature/upgrade-handler-v0.4…
…6.14 Feature / Upgrade handler of v0.46.14
- Loading branch information
Showing
4 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package v1 | ||
|
||
import ( | ||
store "github.com/cosmos/cosmos-sdk/store/types" | ||
"github.com/cosmos/cosmos-sdk/x/group" | ||
|
||
ibcfeetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types" | ||
|
||
"github.com/sge-network/sge/app/upgrades" | ||
) | ||
|
||
// UpgradeName defines the on-chain upgrade name for the v1.1.0 upgrade. | ||
const UpgradeName = "v1.1.0" | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
StoreUpgrades: store.StoreUpgrades{ | ||
Added: []string{ | ||
group.ModuleName, | ||
ibcfeetypes.StoreKey, | ||
}, | ||
Deleted: []string{}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package v1 | ||
|
||
import ( | ||
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" | ||
|
||
"github.com/sge-network/sge/app/keepers" | ||
) | ||
|
||
func setCommissionRate(stakingKeeper *stakingkeeper.Keeper, ctx sdk.Context) { | ||
// the minimal commission rate of 5% (0.05) | ||
// (default is needed to be set because of SDK store migrations that set the param) | ||
stakingtypes.DefaultMinCommissionRate = sdk.NewDecWithPrec(5, 2) | ||
|
||
stakingKeeper.IterateValidators(ctx, func(index int64, val stakingtypes.ValidatorI) (stop bool) { | ||
if val.GetCommission().LT(stakingtypes.DefaultMinCommissionRate) { | ||
validator, found := stakingKeeper.GetValidator(ctx, val.GetOperator()) | ||
if !found { | ||
ctx.Logger().Error("validator not found", val) | ||
return true | ||
} | ||
ctx.Logger().Info("update validator's commission rate to a minimal one", val) | ||
validator.Commission.Rate = stakingtypes.DefaultMinCommissionRate | ||
if validator.Commission.MaxRate.LT(stakingtypes.DefaultMinCommissionRate) { | ||
validator.Commission.MaxRate = stakingtypes.DefaultMinCommissionRate | ||
} | ||
stakingKeeper.SetValidator(ctx, validator) | ||
} | ||
return false | ||
}) | ||
} | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
keepers *keepers.AppKeepers, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
setCommissionRate(&keepers.StakingKeeper, ctx) | ||
|
||
return mm.RunMigrations(ctx, configurator, fromVM) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters