Skip to content

Commit

Permalink
Merge pull request #240 from scorpioborn/feature/upgrade-handler-v0.4…
Browse files Browse the repository at this point in the history
…6.14

Feature /  Upgrade handler of v0.46.14
  • Loading branch information
3eyedraga authored Aug 21, 2023
2 parents 44d87d5 + daa26bd commit 031b1b1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/sge-network/sge/app/keepers"
sgeappparams "github.com/sge-network/sge/app/params"
"github.com/sge-network/sge/app/upgrades"
v1 "github.com/sge-network/sge/app/upgrades/v1"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand Down Expand Up @@ -65,7 +66,7 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string
Upgrades = []upgrades.Upgrade{}
Upgrades = []upgrades.Upgrade{v1.Upgrade}
)

var (
Expand Down
25 changes: 25 additions & 0 deletions app/upgrades/v1/consts.go
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{},
},
}
46 changes: 46 additions & 0 deletions app/upgrades/v1/upgrades.go
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)
}
}
2 changes: 1 addition & 1 deletion proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: v1
name: buf.build/osmosis-labs/osmosis
name: buf.build/sge-network/sge
deps:
- buf.build/cosmos/cosmos-sdk
- buf.build/cosmos/cosmos-proto
Expand Down

0 comments on commit 031b1b1

Please sign in to comment.