From d4ae1d26af09714c6dc0267bd7fc4b87c5019327 Mon Sep 17 00:00:00 2001 From: puneetmahajan Date: Wed, 27 Nov 2024 20:22:28 +0530 Subject: [PATCH] prepare v11.16.0 --- app/app.go | 4 +- app/upgrades/v11.16.0/constants.go | 18 +++++++++ app/upgrades/v11.16.0/upgrades.go | 55 ++++++++++++++++++++++++++ app/upgrades/v11.16.0/upgrades_test.go | 32 +++++++++++++++ interchaintest/chain_upgrade_test.go | 4 +- 5 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 app/upgrades/v11.16.0/constants.go create mode 100644 app/upgrades/v11.16.0/upgrades.go create mode 100644 app/upgrades/v11.16.0/upgrades_test.go diff --git a/app/app.go b/app/app.go index 4fe51043..ca90a8b5 100644 --- a/app/app.go +++ b/app/app.go @@ -56,13 +56,13 @@ import ( "github.com/persistenceOne/persistenceCore/v11/app/keepers" "github.com/persistenceOne/persistenceCore/v11/app/upgrades" - v11_15_0 "github.com/persistenceOne/persistenceCore/v11/app/upgrades/v11.15.0" + v11_16_0 "github.com/persistenceOne/persistenceCore/v11/app/upgrades/v11.16.0" "github.com/persistenceOne/persistenceCore/v11/client/docs" ) var ( DefaultNodeHome string - Upgrades = []upgrades.Upgrade{v11_15_0.Upgrade} + Upgrades = []upgrades.Upgrade{v11_16_0.Upgrade} ModuleBasics = module.NewBasicManager(keepers.AppModuleBasics...) ) diff --git a/app/upgrades/v11.16.0/constants.go b/app/upgrades/v11.16.0/constants.go new file mode 100644 index 00000000..016c7d93 --- /dev/null +++ b/app/upgrades/v11.16.0/constants.go @@ -0,0 +1,18 @@ +package v11_16_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.16.0" +) + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{}, +} diff --git a/app/upgrades/v11.16.0/upgrades.go b/app/upgrades/v11.16.0/upgrades.go new file mode 100644 index 00000000..c0aeae41 --- /dev/null +++ b/app/upgrades/v11.16.0/upgrades.go @@ -0,0 +1,55 @@ +package v11_16_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" + "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/keeper" + liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types" + + "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 upgrade instructions...") + RemoveUnbondedBalance(ctx, args.Keepers.LiquidStakeIBCKeeper, + "cosmoshub-4", 636, + sdk.NewInt64Coin("stk/uatom", 1), sdk.NewInt64Coin("uatom", 3244853), + "persistence1dedp3sl7tu79s50ksfss42tddzh6w3xqzee4nt") + RemoveUnbondedBalance(ctx, args.Keepers.LiquidStakeIBCKeeper, + "chihuahua-1", 704, + sdk.NewInt64Coin("stk/uhuahua", 1), sdk.NewInt64Coin("uhuahua", 4445702485942), + "persistence174tktspp3r6x3ew9806tw8s9sx5ver87p6qdq9") + + ctx.Logger().Info("completed upgrade instructions...") + ctx.Logger().Info("running module migrations...") + return args.ModuleManager.RunMigrations(ctx, args.Configurator, vm) + } +} + +// as per https://github.com/persistenceOne/pstake-native/issues/853 +func RemoveUnbondedBalance(ctx sdk.Context, liquidStakeIBCKeeper *keeper.Keeper, + chainID string, epoch int64, stkAmt sdk.Coin, unbondAmt sdk.Coin, refillerAddr string) { + ctx.Logger().Info("unbonding for", "chain-id", chainID, "epoch", epoch, + "unbondAmount", unbondAmt.String(), "refillerAddr", refillerAddr) + ctx.Logger().Info("set user unbonding...") + liquidStakeIBCKeeper.SetUserUnbonding(ctx, &liquidstakeibctypes.UserUnbonding{ + ChainId: chainID, + EpochNumber: epoch, + Address: refillerAddr, + StkAmount: stkAmt, + UnbondAmount: unbondAmt, + }) + + ctx.Logger().Info("set epoch unbonding...") + liquidStakeIBCKeeper.SetUnbonding(ctx, &liquidstakeibctypes.Unbonding{ + ChainId: chainID, + EpochNumber: epoch, + MatureTime: ctx.BlockTime(), + BurnAmount: stkAmt, + UnbondAmount: unbondAmt, + IbcSequenceId: "", + State: 2, + }) +} diff --git a/app/upgrades/v11.16.0/upgrades_test.go b/app/upgrades/v11.16.0/upgrades_test.go new file mode 100644 index 00000000..73b617cf --- /dev/null +++ b/app/upgrades/v11.16.0/upgrades_test.go @@ -0,0 +1,32 @@ +package v11_16_0_test + +import ( + "testing" + + "github.com/CosmWasm/wasmd/x/wasm" + dbm "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/libs/log" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + "github.com/cosmos/cosmos-sdk/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + "github.com/persistenceOne/persistenceCore/v11/app" + v11_16_0 "github.com/persistenceOne/persistenceCore/v11/app/upgrades/v11.16.0" +) + +func TestRemoveUnbondedBalance(t *testing.T) { + testApp := app.NewApplication(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(""), []wasm.Option{}) + ctx := testApp.NewContext(true, tmproto.Header{}) + v11_16_0.RemoveUnbondedBalance(ctx, testApp.LiquidStakeIBCKeeper, + "chihuahua-1", 704, sdk.NewInt64Coin("stk/uhuahua", 5000000), sdk.NewInt64Coin("uhuahua", 5010101), "persistence1fp6qhht94pmfdq9h94dvw0tnmnlf2vutnlu7pt") + + unbonding, ok := testApp.LiquidStakeIBCKeeper.GetUnbonding(ctx, "chihuahua-1", 704) + require.True(t, ok) + require.Equal(t, types.NewInt(5010101), unbonding.UnbondAmount.Amount) + + userUnbonding, ok := testApp.LiquidStakeIBCKeeper.GetUserUnbonding(ctx, "chihuahua-1", "persistence1fp6qhht94pmfdq9h94dvw0tnmnlf2vutnlu7pt", 704) + require.True(t, ok) + require.Equal(t, types.NewInt(5010101), userUnbonding.UnbondAmount.Amount) +} diff --git a/interchaintest/chain_upgrade_test.go b/interchaintest/chain_upgrade_test.go index dee5387c..4d2f0b8a 100644 --- a/interchaintest/chain_upgrade_test.go +++ b/interchaintest/chain_upgrade_test.go @@ -29,8 +29,8 @@ const ( func TestPersistenceUpgradeBasic(t *testing.T) { var ( chainName = "persistence" - initialVersion = "v11.14.0" - upgradeName = "v11.15.0" + initialVersion = "v11.15.0" + upgradeName = "v11.16.0" upgradeRepo = PersistenceCoreImage.Repository upgradeBranchVersion = PersistenceCoreImage.Version )