From 7bc1f2bf464aeaf0fe6574146b2ac0f2fc8e7da9 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 25 Apr 2023 12:35:27 +0200 Subject: [PATCH] fix: TotalLiquidShares nil handling logic in slashing Both TotalLiquidShares and TotalValidatorBondShares shouldn't be nil in state, this will be migrated in another place. --- x/lsnative/staking/keeper/slash.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x/lsnative/staking/keeper/slash.go b/x/lsnative/staking/keeper/slash.go index 834a3e3c2..14e9c8b4a 100644 --- a/x/lsnative/staking/keeper/slash.go +++ b/x/lsnative/staking/keeper/slash.go @@ -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)