Skip to content

Commit

Permalink
chore: pstake migration (#277)
Browse files Browse the repository at this point in the history
* pstake migration

* bump test upgrade name

* typo

* add testnet unbondings
  • Loading branch information
kruspy authored and Max committed Jan 10, 2024
1 parent c33a36e commit 696ed7d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 29 deletions.
31 changes: 4 additions & 27 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ import (

"github.com/persistenceOne/persistenceCore/v10/app/keepers"
"github.com/persistenceOne/persistenceCore/v10/app/upgrades"
v10 "github.com/persistenceOne/persistenceCore/v10/app/upgrades/v10"
v9_2_0 "github.com/persistenceOne/persistenceCore/v10/app/upgrades/v9.2.0"
v10_3_0 "github.com/persistenceOne/persistenceCore/v10/app/upgrades/v10.3.0"
)

var (
DefaultNodeHome string
UpgradesMainnet = []upgrades.Upgrade{v10.Upgrade}
UpgradesTestnet = []upgrades.Upgrade{v10.Upgrade}
Upgrades = []upgrades.Upgrade{v10_3_0.Upgrade}
ModuleBasics = module.NewBasicManager(keepers.AppModuleBasics...)
)

Expand Down Expand Up @@ -218,16 +216,8 @@ func NewApplication(

// setup postHandler in this method
// app.setupPostHandler()
if app.ChainID() == "test-core-2" {
app.setupUpgradeHandlers(UpgradesTestnet)
app.setupUpgradeStoreLoaders(UpgradesTestnet)
} else if app.ChainID() == "core-1" {
app.setupUpgradeHandlers(UpgradesMainnet)
app.setupUpgradeStoreLoaders(UpgradesMainnet)
} else {
app.setupUpgradeHandlers(UpgradesTestnet)
app.setupUpgradeStoreLoaders(UpgradesTestnet)
}
app.setupUpgradeHandlers(Upgrades)
app.setupUpgradeStoreLoaders(Upgrades)

// must be before Loading version
// requires the snapshot store to be created and registered as a BaseAppOption
Expand Down Expand Up @@ -390,19 +380,6 @@ func (app *Application) LegacyAmino() *codec.LegacyAmino {
}

func (app *Application) BeginBlocker(ctx sdk.Context, req abcitypes.RequestBeginBlock) abcitypes.ResponseBeginBlock {
if ctx.ChainID() == "core-1" && ctx.BlockHeight() == 13263217 {
v9_2_0.Fork(ctx, app.StakingKeeper)
v9_2_0.RemoveMainnetV9_2Prop(ctx, app.UpgradeKeeper)
}

if ctx.ChainID() == "test-core-2" && ctx.BlockHeight() == 1728710 {
v9_2_0.Fork(ctx, app.StakingKeeper)
}

if ctx.ChainID() == "ictest-core-1" {
v9_2_0.Fork(ctx, app.StakingKeeper)
}

return app.moduleManager.BeginBlock(ctx, req)
}

Expand Down
20 changes: 20 additions & 0 deletions app/upgrades/v10.3.0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v10_3_0

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

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

const (
// UpgradeName defines the on-chain upgrade name.
UpgradeName = "v10.3.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
},
}
47 changes: 47 additions & 0 deletions app/upgrades/v10.3.0/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package v10_3_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"
liquidstakeibctypes "github.com/persistenceOne/pstake-native/v2/x/liquidstakeibc/types"

"github.com/persistenceOne/persistenceCore/v10/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 handler")

// stuck unbonding epoch numbers
RemovableUnbondings := map[string]map[int64]any{
"cosmoshub-4": {312: nil},
"osmosis-1": {429: nil, 432: nil},
"theta-testnet-001": {104: nil, 128: nil, 140: nil, 148: nil},
"osmo-test-5": {193: nil, 194: nil, 201: nil},
}

// get the stuck unbondings from the store
unbondings := args.Keepers.LiquidStakeIBCKeeper.FilterUnbondings(
ctx,
func(u liquidstakeibctypes.Unbonding) bool {
_, chain := RemovableUnbondings[u.ChainId]
if chain {
_, epoch := RemovableUnbondings[u.ChainId][u.EpochNumber]
if epoch {
return true
}
}
return false
},
)

// mark the stuck unbondings as failed, so they can be processed
for _, unbonding := range unbondings {
unbonding.State = liquidstakeibctypes.Unbonding_UNBONDING_FAILED
args.Keepers.LiquidStakeIBCKeeper.SetUnbonding(ctx, unbonding)
}

return args.ModuleManager.RunMigrations(ctx, args.Configurator, vm)
}
}
4 changes: 2 additions & 2 deletions interchaintest/chain_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func TestPersistenceUpgradeBasic(t *testing.T) {
var (
chainName = "persistence"
upgradeRepo = PersistenceCoreImage.Repository
initialVersion = "v9.2.0"
initialVersion = "v10.2.1"
upgradeBranchVersion = PersistenceCoreImage.Version
upgradeName = "v10"
upgradeName = "v10.3.0"
)

CosmosChainUpgradeTest(
Expand Down

0 comments on commit 696ed7d

Please sign in to comment.