Skip to content

Commit

Permalink
fix!: revert PutUnbondingOnHold to desired behaviour (#1819)
Browse files Browse the repository at this point in the history
* fix!: revert PutUnbondingOnHold to desired behaviour

* fix: correctly change AfterUnbondingInitiated
  • Loading branch information
MSalopek authored Apr 25, 2024
1 parent 728a1e5 commit 2de60f5
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions x/ccv/provider/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,6 @@ func (h Hooks) AfterUnbondingInitiated(goCtx context.Context, id uint64) error {
// Do not put the unbonding op on hold if there are no consumer chains
return nil
}
// Call back into staking to tell it to stop this op from unbonding when the unbonding period is complete
if err := h.k.stakingKeeper.PutUnbondingOnHold(ctx, id); err != nil {
// Note: that in the case of a validator unbonding, AfterUnbondingInitiated is called
// from staking.EndBlock.

// In this case PutUnbondingOnHold fails if either the unbonding operation was
// not found or the UnbondingOnHoldRefCount is negative.

// This change should be updated for SDK v0.48 because it will include changes in handling
// check: https://github.com/cosmos/cosmos-sdk/pull/16043
h.k.Logger(ctx).Error("unbonding could not be put on hold: %w", err)
return nil
}

valsetUpdateID := h.k.GetValidatorSetUpdateId(ctx)
unbondingOp := providertypes.UnbondingOp{
Expand All @@ -76,22 +63,19 @@ func (h Hooks) AfterUnbondingInitiated(goCtx context.Context, id uint64) error {

h.k.SetUnbondingOp(ctx, unbondingOp)

// NOTE: This is a temporary fix for v0.47 -> we should not panic in this edge case
// since the AfterUnbondInitiatedHook can be called with a non-existing UnbondingEntry.id
// check: https://github.com/cosmos/cosmos-sdk/pull/16043
//
// Call back into staking to tell it to stop this op from unbonding when the unbonding period is complete
// if err := h.k.stakingKeeper.PutUnbondingOnHold(ctx, id); err != nil {
// // If there was an error putting the unbonding on hold, panic to end execution for
// // the current tx and prevent committal of this invalid state.
// //
// // Note: that in the case of a validator unbonding, AfterUnbondingInitiated is called
// // from staking.EndBlock, thus the following panic would halt the chain.
// // In this case PutUnbondingOnHold fails if either the unbonding operation was
// // not found or the UnbondingOnHoldRefCount is negative. In either cases,
// // the state of the x/staking module of cosmos-sdk is invalid.
// panic(fmt.Errorf("unbonding could not be put on hold: %w", err))
// }
if err := h.k.stakingKeeper.PutUnbondingOnHold(ctx, id); err != nil {
// If there was an error putting the unbonding on hold, panic to end execution for
// the current tx and prevent committal of this invalid state.
//
// Note: that in the case of a validator unbonding, AfterUnbondingInitiated is called
// from staking.EndBlock, thus the following panic would halt the chain.

// In this case PutUnbondingOnHold fails if either the unbonding operation was
// not found or the UnbondingOnHoldRefCount is negative. In either cases,
// the state of the x/staking module of cosmos-sdk is invalid.
panic(fmt.Errorf("unbonding could not be put on hold: %w", err))
}
return nil
}

Expand Down

0 comments on commit 2de60f5

Please sign in to comment.