Skip to content

Commit

Permalink
Add comment outlining safety of commission-withdraw (cosmos#3175)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes authored and jackzampolin committed Dec 19, 2018
1 parent 45a48f4 commit 3387261
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions x/distribution/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ func (k Keeper) onDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddre
// Withdrawal all validator distribution rewards and cleanup the distribution record
func (k Keeper) onDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress,
valAddr sdk.ValAddress) {
// Withdraw validator commission when validator self-bond is removed.
// Because we maintain the invariant that all delegations must be removed
// before a validator is deleted, this ensures that commission will be withdrawn
// before the validator is deleted (and the corresponding ValidatorDistInfo removed).
// If we change other parts of the code such that a self-delegation might remain after
// a validator is deleted, this logic will no longer be safe.
// TODO: Consider instead implementing this in a "BeforeValidatorRemoved" hook.
if valAddr.Equals(sdk.ValAddress(delAddr)) {
feePool, commission := k.withdrawValidatorCommission(ctx, valAddr)
k.WithdrawToDelegator(ctx, feePool, delAddr, commission)
Expand Down

0 comments on commit 3387261

Please sign in to comment.