diff --git a/CHANGELOG.md b/CHANGELOG.md index d67aec55e..f2f43977f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## Unreleased +### Bug Fixes + +- [715](https://github.com/persistenceOne/pstake-native/pull/715) Fix stuck unbondings. + ## [v2.8.1] - 2023-12-21 ### Bug Fixes diff --git a/app/app.go b/app/app.go index 1d02344e0..ec37f0346 100644 --- a/app/app.go +++ b/app/app.go @@ -1018,6 +1018,31 @@ func (app *PstakeApp) RegisterUpgradeHandler() { app.UpgradeKeeper.SetUpgradeHandler( UpgradeName, func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + + // stuck unbonding epoch numbers + RemovableUnbondings := map[string]map[int64]any{"cosmoshub-4": {312: nil}, "osmosis-1": {429: nil, 432: nil}} + + // get the stuck unbondings from the store + unbondings := app.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 + app.LiquidStakeIBCKeeper.SetUnbonding(ctx, unbonding) + } + return app.mm.RunMigrations(ctx, app.configurator, fromVM) }, ) @@ -1029,7 +1054,7 @@ func (app *PstakeApp) RegisterUpgradeHandler() { if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { storeUpgrades := store.StoreUpgrades{ - Added: []string{ratesynctypes.StoreKey, liquidstaketypes.StoreKey}, + Added: []string{}, Deleted: []string{}, } diff --git a/app/const.go b/app/const.go index 99b55ed20..8ceac0ee5 100644 --- a/app/const.go +++ b/app/const.go @@ -2,5 +2,5 @@ package app const ( appName = "pStake" - UpgradeName = "v2.8.0" + UpgradeName = "v2.8.2" ) diff --git a/x/liquidstakeibc/keeper/hooks.go b/x/liquidstakeibc/keeper/hooks.go index 7135d91dc..713c62b8d 100644 --- a/x/liquidstakeibc/keeper/hooks.go +++ b/x/liquidstakeibc/keeper/hooks.go @@ -621,7 +621,21 @@ func (k *Keeper) UndelegationWorkflow(ctx sdk.Context, epoch int64) { "host_chain", hc.ChainId, ) - return + + // mark the unbonding as failed + unbonding.State = liquidstakeibctypes.Unbonding_UNBONDING_FAILED + k.SetUnbonding(ctx, unbonding) + + // emit an event for the undelegation confirmation + ctx.EventManager().EmitEvent( + sdk.NewEvent( + liquidstakeibctypes.EventUnsuccessfulUndelegationInitiation, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeEpoch, strconv.FormatInt(epoch, 10)), + ), + ) + + continue } // execute the ICA transactions @@ -637,7 +651,21 @@ func (k *Keeper) UndelegationWorkflow(ctx sdk.Context, epoch int64) { "host_chain", hc.ChainId, ) - return + + // mark the unbonding as failed + unbonding.State = liquidstakeibctypes.Unbonding_UNBONDING_FAILED + k.SetUnbonding(ctx, unbonding) + + // emit an event for the undelegation confirmation + ctx.EventManager().EmitEvent( + sdk.NewEvent( + liquidstakeibctypes.EventUnsuccessfulUndelegationInitiation, + sdk.NewAttribute(liquidstakeibctypes.AttributeChainID, hc.ChainId), + sdk.NewAttribute(liquidstakeibctypes.AttributeEpoch, strconv.FormatInt(epoch, 10)), + ), + ) + + continue } // update the unbonding ibc sequence id and state diff --git a/x/liquidstakeibc/types/events.go b/x/liquidstakeibc/types/events.go index 6f3fdb05c..9f25670c0 100644 --- a/x/liquidstakeibc/types/events.go +++ b/x/liquidstakeibc/types/events.go @@ -41,6 +41,7 @@ const ( EventSuccessfulRedelegation = "successful_redelegation" EventUnsuccessfulDelegation = "unsuccessful_delegation" EventUnsuccessfulUndelegation = "unsuccessful_undelegation" + EventUnsuccessfulUndelegationInitiation = "unsuccessful_undelegation_initiation" EventUnsuccessfulUndelegationTransfer = "unsuccessful_undelegation_transfer" EventUnsuccessfulValidatorUndelegationTransfer = "unsuccessful_validator_undelegation_transfer" EventUnsuccessfulLSMRedeem = "unsuccessful_lsm_redeem"