Skip to content

Commit

Permalink
fix: set min commission back to 5% (#349)
Browse files Browse the repository at this point in the history
Co-authored-by: nghuyenthevinh2000 <[email protected]>
  • Loading branch information
fragwuerdig and nghuyenthevinh2000 authored Sep 21, 2023
1 parent 65c24d2 commit fef5b36
Show file tree
Hide file tree
Showing 6 changed files with 75 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 @@ -52,6 +52,7 @@ import (
customauthtx "github.com/classic-terra/core/v2/custom/auth/tx"

"github.com/CosmWasm/wasmd/x/wasm"
"github.com/classic-terra/core/v2/app/upgrades/forks"

// unnamed import of statik for swagger UI support
_ "github.com/classic-terra/core/v2/client/docs/statik"
Expand All @@ -67,7 +68,7 @@ var (
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade, v5.Upgrade}

// Forks defines forks to be applied to the network
Forks = []upgrades.Fork{}
Forks = []upgrades.Fork{forks.FixMinCommissionFork, forks.FixMinCommissionForkRebel}
)

// Verify app interface at compile time
Expand Down
12 changes: 12 additions & 0 deletions app/upgrades/forks/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ var VersionMapEnableFork = upgrades.Fork{
UpgradeHeight: fork.VersionMapEnableHeight,
BeginForkLogic: runForkLogicVersionMapEnable,
}

var FixMinCommissionFork = upgrades.Fork{
UpgradeName: "v2.2.1",
UpgradeHeight: fork.FixMinCommissionHeight,
BeginForkLogic: runForkLogicFixMinCommission,
}

var FixMinCommissionForkRebel = upgrades.Fork{
UpgradeName: "v2.2.1",
UpgradeHeight: fork.FixMinCommissionHeightRebel,
BeginForkLogic: runForkLogicFixMinCommissionRebel,
}
56 changes: 56 additions & 0 deletions app/upgrades/forks/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (

"github.com/classic-terra/core/v2/app/keepers"
core "github.com/classic-terra/core/v2/types"
"github.com/classic-terra/core/v2/x/market/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
)
Expand Down Expand Up @@ -62,3 +64,57 @@ func runForkLogicVersionMapEnable(ctx sdk.Context, keppers *keepers.AppKeepers,
keppers.UpgradeKeeper.SetModuleVersionMap(ctx, mm.GetVersionMap())
}
}

func forkLogicFixMinCommission(ctx sdk.Context, keepers *keepers.AppKeepers, mm *module.Manager) {
MinCommissionRate := sdk.NewDecWithPrec(5, 2)

space, exist := keepers.ParamsKeeper.GetSubspace(stakingtypes.StoreKey)
if !exist {
panic("staking subspace is not found, breaking the chain anyway so panic")
}

if space.HasKeyTable() {
space.Set(ctx, stakingtypes.KeyMinCommissionRate, MinCommissionRate)
} else {
space.WithKeyTable(types.ParamKeyTable())
space.Set(ctx, stakingtypes.KeyMinCommissionRate, MinCommissionRate)
}

keepers.StakingKeeper.IterateValidators(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
val := validator.(stakingtypes.Validator)
rate := val.Commission.Rate
maxRate := val.Commission.MaxRate

if maxRate.LT(MinCommissionRate) {
maxRate = MinCommissionRate
}

if rate.LT(MinCommissionRate) {
rate = MinCommissionRate
}

val.Commission = stakingtypes.NewCommission(
rate,
maxRate,
val.Commission.MaxChangeRate,
)

keepers.StakingKeeper.SetValidator(ctx, val)

return false
})
}

func runForkLogicFixMinCommission(ctx sdk.Context, keepers *keepers.AppKeepers, mm *module.Manager) {
if ctx.ChainID() != core.ColumbusChainID {
return
}
forkLogicFixMinCommission(ctx, keepers, mm)
}

func runForkLogicFixMinCommissionRebel(ctx sdk.Context, keepers *keepers.AppKeepers, mm *module.Manager) {
if ctx.ChainID() != core.RebelChainID {
return
}
forkLogicFixMinCommission(ctx, keepers, mm)
}
2 changes: 1 addition & 1 deletion scripts/upgrade-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
FORK=${FORK:-"false"}

# $(curl --silent "https://api.github.com/repos/classic-terra/core/releases/latest" | jq -r '.tag_name')
OLD_VERSION=v2.1.2
OLD_VERSION=v2.2.1
UPGRADE_WAIT=${UPGRADE_WAIT:-20}
HOME=mytestnet
ROOT=$(pwd)
Expand Down
1 change: 1 addition & 0 deletions types/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
Bech32PrefixConsPub = util.Bech32PrefixConsPub
ColumbusChainID = "columbus-5"
BombayChainID = "bombay-12"
RebelChainID = "rebel-2"
OsmoIbcDenom = "ibc/0ef15df2f02480ade0bb6e85d9ebb5daea2836d3860e9f97f9aade4f57a31aa0"
)

Expand Down
3 changes: 3 additions & 0 deletions types/fork/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ const (
// v1.0.5
// VersionMapEnableHeight - set the version map to enable software upgrades, approximately February 14, 2023
VersionMapEnableHeight = int64(11_543_150)
// Revert Min Commission slip during v2.2.0 upgrade
FixMinCommissionHeight = int64(14_665_190)
FixMinCommissionHeightRebel = int64(16_260_000)
)

0 comments on commit fef5b36

Please sign in to comment.