-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: ensure withdraw_rewards events are always emitted on reward withdrawal (backport #13323) #13340
fix: ensure withdraw_rewards events are always emitted on reward withdrawal (backport #13323) #13340
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import ( | |
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
@@ -162,13 +161,13 @@ func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val stakingtypes.Vali | |
) | ||
} | ||
|
||
// truncate coins, return remainder to community pool | ||
coins, remainder := rewards.TruncateDecimal() | ||
// truncate reward dec coins, return remainder to community pool | ||
finalRewards, remainder := rewards.TruncateDecimal() | ||
|
||
// add coins to user account | ||
if !coins.IsZero() { | ||
if !finalRewards.IsZero() { | ||
withdrawAddr := k.GetDelegatorWithdrawAddr(ctx, del.GetDelegatorAddr()) | ||
err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, coins) | ||
err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, withdrawAddr, finalRewards) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -189,5 +188,24 @@ func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val stakingtypes.Vali | |
// remove delegator starting info | ||
k.DeleteDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr()) | ||
|
||
return coins, nil | ||
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())} | ||
} | ||
Comment on lines
+191
to
+200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexanderbez I think this is state breaking? can we remove since it was out of scope of the pr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed out of band. Assured that this is not state machine breaking as it:
|
||
|
||
ctx.EventManager().EmitEvent( | ||
sdk.NewEvent( | ||
types.EventTypeWithdrawRewards, | ||
sdk.NewAttribute(sdk.AttributeKeyAmount, finalRewards.String()), | ||
sdk.NewAttribute(types.AttributeKeyValidator, val.GetOperator().String()), | ||
), | ||
) | ||
|
||
return finalRewards, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#13338 (comment)