From a71a1ebebe67920411adfed095984803b9f1d6ef Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Wed, 17 Jul 2024 10:23:39 +0700 Subject: [PATCH] add force finish unbonding --- app/upgrades/v1.1.5/upgrade.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/upgrades/v1.1.5/upgrade.go b/app/upgrades/v1.1.5/upgrade.go index 6dde83bc..d392c62f 100644 --- a/app/upgrades/v1.1.5/upgrade.go +++ b/app/upgrades/v1.1.5/upgrade.go @@ -45,6 +45,8 @@ func CreateUpgradeHandler( // unbond all delegations from account forceUnbondTokens(ctx, addr, bk, sk) + forceFinishUnbonding(ctx, addr, bk, sk) + // send to dao module account // vesting account should be able to send coins normaly after // we converted it back to a base account @@ -60,6 +62,25 @@ func CreateUpgradeHandler( } } +func forceFinishUnbonding(ctx sdk.Context, delAddr string, bk *bankkeeper.BaseKeeper, sk *stakingkeeper.Keeper) error { + ubdQueue := sk.GetAllUnbondingDelegations(ctx, sdk.AccAddress(delAddr)) + bondDenom := sk.BondDenom(ctx) + for _, ubd := range ubdQueue { + for _, entry := range ubd.Entries { + err := bk.UndelegateCoinsFromModuleToAccount(ctx, stakingtypes.NotBondedPoolName, sdk.AccAddress(delAddr), sdk.NewCoins(sdk.NewCoin(bondDenom, entry.Balance))) + if err != nil { + return err + } + } + + // empty out all entries + ubd.Entries = []stakingtypes.UnbondingDelegationEntry{} + sk.SetUnbondingDelegation(ctx, ubd) + } + + return nil +} + func forceUnbondTokens(ctx sdk.Context, delAddr string, bk *bankkeeper.BaseKeeper, sk *stakingkeeper.Keeper) error { delAccAddr := sdk.AccAddress(delAddr) dels := sk.GetDelegatorDelegations(ctx, delAccAddr, 100)