Skip to content

Commit

Permalink
prepare v11.12.0 upgrade (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeet97 authored May 17, 2024
1 parent 5c02b48 commit de4841e
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ import (

"github.com/persistenceOne/persistenceCore/v11/app/keepers"
"github.com/persistenceOne/persistenceCore/v11/app/upgrades"
v11_12_0_rc0 "github.com/persistenceOne/persistenceCore/v11/app/upgrades/testnet/v11.12.0-rc0"
v11_12_0 "github.com/persistenceOne/persistenceCore/v11/app/upgrades/v11.12.0"
"github.com/persistenceOne/persistenceCore/v11/client/docs"
)

var (
DefaultNodeHome string
Upgrades = []upgrades.Upgrade{v11_12_0_rc0.Upgrade}
Upgrades = []upgrades.Upgrade{v11_12_0.Upgrade}
ModuleBasics = module.NewBasicManager(keepers.AppModuleBasics...)
)

Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/testnet/v11.12.0-rc0/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func DelegateLiquidStakeRewards(ctx sdk.Context, k *keepers.AppKeepers) {
whitelistedValsMap := liquidstaketypes.GetWhitelistedValsMap(whitelistedValidators)
activeLiquidVals := k.LiquidStakeKeeper.GetActiveLiquidValidators(ctx, whitelistedValsMap)

// currently auto compounding fee rate is zero, therefore fee logic is added here.
// currently auto compounding fee rate is zero, therefore fee logic is not added here.

err := k.LiquidStakeKeeper.LiquidDelegate(ctx, liquidstaketypes.LiquidStakeProxyAcc, activeLiquidVals, amountToDelegate, whitelistedValsMap)

Expand Down
18 changes: 18 additions & 0 deletions app/upgrades/v11.12.0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package v11_12_0

import (
store "github.com/cosmos/cosmos-sdk/store/types"

"github.com/persistenceOne/persistenceCore/v11/app/upgrades"
)

const (
// UpgradeName defines the on-chain upgrade name.
UpgradeName = "v11.12.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}
53 changes: 53 additions & 0 deletions app/upgrades/v11.12.0/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package v11_12_0

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
liquidstaketypes "github.com/persistenceOne/pstake-native/v2/x/liquidstake/types"

"github.com/persistenceOne/persistenceCore/v11/app/keepers"
"github.com/persistenceOne/persistenceCore/v11/app/upgrades"
)

func CreateUpgradeHandler(args upgrades.UpgradeHandlerArgs) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("running module migrations...")

DelegateLiquidStakeRewards(ctx, args.Keepers)

return args.ModuleManager.RunMigrations(ctx, args.Configurator, vm)
}
}

func DelegateLiquidStakeRewards(ctx sdk.Context, k *keepers.AppKeepers) {
proxyAccBalance := k.LiquidStakeKeeper.GetProxyAccBalance(ctx, liquidstaketypes.LiquidStakeProxyAcc)
amountToDelegate := proxyAccBalance.Amount

whitelistedValidators := k.LiquidStakeKeeper.GetParams(ctx).WhitelistedValidators
whitelistedValsMap := liquidstaketypes.GetWhitelistedValsMap(whitelistedValidators)
activeLiquidVals := k.LiquidStakeKeeper.GetActiveLiquidValidators(ctx, whitelistedValsMap)

// currently auto compounding fee rate is zero, therefore fee logic is not added here.

err := k.LiquidStakeKeeper.LiquidDelegate(ctx, liquidstaketypes.LiquidStakeProxyAcc, activeLiquidVals, amountToDelegate, whitelistedValsMap)

// if liquid delegate fails then try to delegate to any one active validator
if err != nil {
ctx.Logger().Info("failed to liquid delegate, trying to delegate to any one validator...", "error", err.Error())

for _, lv := range activeLiquidVals {
val, _ := k.StakingKeeper.GetValidator(ctx, lv.GetOperator())
err2 := k.LiquidStakeKeeper.DelegateWithCap(ctx, liquidstaketypes.LiquidStakeProxyAcc, val, amountToDelegate)
if err2 != nil {
ctx.Logger().Info("failed to delegate", "validator", val.GetOperator(), "error", err2.Error())
// continue with next val
} else {
// successfully delegated, exit
return
}
}

ctx.Logger().Error("failed to delegate to any of active val set")
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/cosmos/ibc-go/v7 v7.4.0
github.com/gorilla/mux v1.8.1
github.com/persistenceOne/persistence-sdk/v2 v2.2.0
github.com/persistenceOne/pstake-native/v2 v2.14.0-rc0
github.com/persistenceOne/pstake-native/v2 v2.14.0
github.com/prometheus/client_golang v1.16.0
github.com/skip-mev/pob v1.0.5
github.com/spf13/cast v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1034,8 +1034,8 @@ github.com/persistenceOne/cosmos-sdk v0.47.10-lsm-rc0 h1:lbSQZUdaaKIpoSAznVESl0v
github.com/persistenceOne/cosmos-sdk v0.47.10-lsm-rc0/go.mod h1:Q/eHvXB0Awenk3NCh77NvjpeKGPigawFHIXlz2ayfos=
github.com/persistenceOne/persistence-sdk/v2 v2.2.0 h1:ZsBsy/HElkwjPXoASI7CptMFY9C3C/d27G+8bxFDzQw=
github.com/persistenceOne/persistence-sdk/v2 v2.2.0/go.mod h1:8VgozZWTPLMdlzsyiuGI0+vLo2fvGYSj/YKM9kiJwrI=
github.com/persistenceOne/pstake-native/v2 v2.14.0-rc0 h1:4vHEFSM6aZ14GzhtT+nsO6jLiB2as/dy5aQT8w8zUfQ=
github.com/persistenceOne/pstake-native/v2 v2.14.0-rc0/go.mod h1:FcLbnTasZfKKKQJ6nzgzdkDqb3dUlIyraqcsj7DMTfE=
github.com/persistenceOne/pstake-native/v2 v2.14.0 h1:3FghzZZFA1UX/UrZNiVh5kPX2CSQUxZihZ5l80VWhms=
github.com/persistenceOne/pstake-native/v2 v2.14.0/go.mod h1:FcLbnTasZfKKKQJ6nzgzdkDqb3dUlIyraqcsj7DMTfE=
github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
Expand Down
2 changes: 1 addition & 1 deletion interchaintest/chain_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestPersistenceUpgradeBasic(t *testing.T) {
var (
chainName = "persistence"
initialVersion = "v11.11.0"
upgradeName = "v11.12.0-rc0"
upgradeName = "v11.12.0"
upgradeRepo = PersistenceCoreImage.Repository
upgradeBranchVersion = PersistenceCoreImage.Version
)
Expand Down

0 comments on commit de4841e

Please sign in to comment.