Skip to content

Commit

Permalink
fix: Unbondings claim loop (#720)
Browse files Browse the repository at this point in the history
* do not block unbondings when one fails

* changelog

* add events

* log error

---------

Co-authored-by: Puneet <[email protected]>
  • Loading branch information
kruspy and puneet2019 authored Jan 12, 2024
1 parent d7b62b9 commit c53c0a7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

- [720](https://github.com/persistenceOne/pstake-native/pull/720) Fix unbondings loop.
- [719](https://github.com/persistenceOne/pstake-native/pull/719) Fix afterEpoch hooks to take LiquidStake feature
instead of LiquidStakeIBC

Expand Down
34 changes: 32 additions & 2 deletions x/liquidstakeibc/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,25 @@ func (k *Keeper) DoClaim(ctx sdk.Context, hc *types.HostChain) {
for _, userUnbonding := range userUnbondings {
address, err := sdk.AccAddressFromBech32(userUnbonding.Address)
if err != nil {
return
k.Logger(ctx).Error(
"could not send unbonded tokens from module account to delegator",
"host_chain",
hc.ChainId,
"epoch",
userUnbonding.EpochNumber,
)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventFailedClaimUnbondings,
sdk.NewAttribute(types.AttributeChainID, hc.ChainId),
sdk.NewAttribute(types.AttributeEpoch, strconv.FormatInt(epochNumber, 10)),
sdk.NewAttribute(types.AttributeClaimAddress, userUnbonding.Address),
sdk.NewAttribute(types.AttributeClaimStatus, unbonding.State.String()),
),
)

continue
}

var claimableCoins sdk.Coins
Expand Down Expand Up @@ -168,7 +186,19 @@ func (k *Keeper) DoClaim(ctx sdk.Context, hc *types.HostChain) {
"epoch",
userUnbonding.EpochNumber,
)
return

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventFailedClaimUnbondings,
sdk.NewAttribute(types.AttributeChainID, hc.ChainId),
sdk.NewAttribute(types.AttributeEpoch, strconv.FormatInt(epochNumber, 10)),
sdk.NewAttribute(types.AttributeClaimAmount, eventAmount.String()),
sdk.NewAttribute(types.AttributeClaimAddress, userUnbonding.Address),
sdk.NewAttribute(types.AttributeClaimStatus, unbonding.State.String()),
),
)

continue
}

// update the unbonding remaining amount and delete it if it reaches zero
Expand Down
2 changes: 2 additions & 0 deletions x/liquidstakeibc/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
EventUnsuccessfulValidatorUndelegationTransfer = "unsuccessful_validator_undelegation_transfer"
EventUnsuccessfulLSMRedeem = "unsuccessful_lsm_redeem"
EventUnsuccessfulRedelegate = "unsuccessful_redelegate"
EventFailedClaimUnbondings = "failed_claim_unbondings"

AttributeInputAmount = "input_amount"
AttributeOutputAmount = "output_amount"
Expand Down Expand Up @@ -77,6 +78,7 @@ const (
AttributeICAMessages = "ica_messages"
AttributeClaimAmount = "claimed_amount"
AttributeClaimAddress = "claim_address"
AttributeClaimStatus = "claim_status"
AttributeModuleMintedAmount = "minted_amount"
AttributeModuleLSMTokenizedAmount = "lsm_tokenized_amount" //nolint:gosec
AttributeModuleStakedAmount = "staked_amount"
Expand Down

0 comments on commit c53c0a7

Please sign in to comment.