Skip to content

Commit

Permalink
fix: Stuck unbondings (#715)
Browse files Browse the repository at this point in the history
* fail unbondings correctly + unstuck previous ones

* keep processing host chains when one errors out

* move code to migration

* migration to mark stuck unbondings as failed

* add events

* changelog

* bump upgrade name

* remove consensus bump + add logic to handler
  • Loading branch information
kruspy authored Jan 9, 2024
1 parent b020194 commit 215911a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
)
Expand All @@ -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{},
}

Expand Down
2 changes: 1 addition & 1 deletion app/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package app

const (
appName = "pStake"
UpgradeName = "v2.8.0"
UpgradeName = "v2.8.2"
)
32 changes: 30 additions & 2 deletions x/liquidstakeibc/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions x/liquidstakeibc/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 215911a

Please sign in to comment.