Skip to content

Commit

Permalink
fix: TotalLiquidShares nil handling logic in slashing
Browse files Browse the repository at this point in the history
Both TotalLiquidShares and TotalValidatorBondShares shouldn't be nil in state, this will be migrated in another place.
  • Loading branch information
Max committed Apr 25, 2023
1 parent 35f5aac commit 64ac006
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion x/lsnative/staking/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeigh
validator = k.RemoveValidatorTokens(ctx, validator, tokensToBurn)

// Proportionally deduct any liquid tokens from the global total
validatorLiquidRatio := validator.TotalLiquidShares.Quo(validator.DelegatorShares)
var validatorLiquidRatio sdk.Dec
if validator.TotalLiquidShares.IsNil() {
validatorLiquidRatio = sdk.ZeroDec()
} else {
validatorLiquidRatio = validator.TotalLiquidShares.Quo(validator.DelegatorShares)
}
slashedLiquidTokens := validatorLiquidRatio.Mul(sdk.NewDecFromInt(slashAmount)).TruncateInt()
k.DecreaseTotalLiquidStakedTokens(ctx, slashedLiquidTokens)

Expand Down

0 comments on commit 64ac006

Please sign in to comment.