Skip to content

Commit

Permalink
rollback state breaking SDK update - cosmos#13340
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-yeo committed Oct 14, 2022
1 parent 55dabec commit 996da0f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
39 changes: 21 additions & 18 deletions x/distribution/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,27 @@ func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val stakingtypes.Vali
// remove delegator starting info
k.DeleteDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr())

if finalRewards.IsZero() {
baseDenom, _ := sdk.GetBaseDenom()
if baseDenom == "" {
baseDenom = sdk.DefaultBondDenom
}

// Note, we do not call the NewCoins constructor as we do not want the zero
// coin removed.
finalRewards = sdk.Coins{sdk.NewCoin(baseDenom, sdk.ZeroInt())}
}

ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeWithdrawRewards,
sdk.NewAttribute(sdk.AttributeKeyAmount, finalRewards.String()),
sdk.NewAttribute(types.AttributeKeyValidator, val.GetOperator().String()),
),
)
// TODO - rollback https://github.com/cosmos/cosmos-sdk/pull/13340
// to prevent state breaking
//
// if finalRewards.IsZero() {
// baseDenom, _ := sdk.GetBaseDenom()
// if baseDenom == "" {
// baseDenom = sdk.DefaultBondDenom
// }

// // Note, we do not call the NewCoins constructor as we do not want the zero
// // coin removed.
// finalRewards = sdk.Coins{sdk.NewCoin(baseDenom, sdk.ZeroInt())}
// }

// ctx.EventManager().EmitEvent(
// sdk.NewEvent(
// types.EventTypeWithdrawRewards,
// sdk.NewAttribute(sdk.AttributeKeyAmount, finalRewards.String()),
// sdk.NewAttribute(types.AttributeKeyValidator, val.GetOperator().String()),
// ),
// )

return finalRewards, nil
}
11 changes: 11 additions & 0 deletions x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ func (k Keeper) WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddres
return nil, err
}

// TODO - rollback https://github.com/cosmos/cosmos-sdk/pull/13340
// to prevent state breaking
//
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeWithdrawRewards,
sdk.NewAttribute(sdk.AttributeKeyAmount, rewards.String()),
sdk.NewAttribute(types.AttributeKeyValidator, valAddr.String()),
),
)

// reinitialize the delegation
k.initializeDelegation(ctx, valAddr, delAddr)
return rewards, nil
Expand Down

0 comments on commit 996da0f

Please sign in to comment.