diff --git a/x/distribution/keeper/delegation.go b/x/distribution/keeper/delegation.go index 1a1095b3a4..c3a6cfa54e 100644 --- a/x/distribution/keeper/delegation.go +++ b/x/distribution/keeper/delegation.go @@ -81,7 +81,7 @@ func (k Keeper) WithdrawDelegationReward(ctx sdk.Context, delegatorAddr sdk.AccA // TODO: Reconcile with duplicate code in getDelegatorRewardsAll. height := ctx.BlockHeight() - lastTotalPower := k.stakeKeeper.GetLastTotalPower(ctx) + lastTotalPower := sdk.NewDecFromInt(k.stakeKeeper.GetLastTotalPower(ctx)) lastValPower := k.stakeKeeper.GetLastValidatorPower(ctx, valAddr) feePool := k.GetFeePool(ctx) delInfo := k.GetDelegationDistInfo(ctx, delegatorAddr, valAddr) @@ -126,7 +126,7 @@ func (k Keeper) WithdrawDelegationRewardsAll(ctx sdk.Context, delegatorAddr sdk. func (k Keeper) getDelegatorRewardsAll(ctx sdk.Context, delAddr sdk.AccAddress, height int64) types.DecCoins { withdraw := types.DecCoins{} - lastTotalPower := k.stakeKeeper.GetLastTotalPower(ctx) + lastTotalPower := sdk.NewDecFromInt(k.stakeKeeper.GetLastTotalPower(ctx)) // iterate over all the delegations // TODO: Reconcile with duplicate code in WithdrawDelegationReward. diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index 8060fcdf2d..6d1f46df91 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -34,7 +34,7 @@ func TestWithdrawDelegationRewardBasic(t *testing.T) { // withdraw delegation ctx = ctx.WithBlockHeight(1) - sk.SetLastTotalPower(ctx, sdk.NewDec(10)) + sk.SetLastTotalPower(ctx, sdk.NewInt(10)) sk.SetLastValidatorPower(ctx, valOpAddr1, sdk.NewDec(10)) keeper.WithdrawDelegationReward(ctx, delAddr1, valOpAddr1) amt = accMapper.GetAccount(ctx, delAddr1).GetCoins().AmountOf(denom) diff --git a/x/distribution/keeper/validator.go b/x/distribution/keeper/validator.go index d8ec7ea7fd..a71249d6b4 100644 --- a/x/distribution/keeper/validator.go +++ b/x/distribution/keeper/validator.go @@ -55,7 +55,7 @@ func (k Keeper) WithdrawValidatorRewardsAll(ctx sdk.Context, operatorAddr sdk.Va withdraw := k.getDelegatorRewardsAll(ctx, accAddr, height) // withdrawal validator commission rewards - lastTotalPower := k.stakeKeeper.GetLastTotalPower(ctx) + lastTotalPower := sdk.NewDecFromInt(k.stakeKeeper.GetLastTotalPower(ctx)) valInfo := k.GetValidatorDistInfo(ctx, operatorAddr) feePool := k.GetFeePool(ctx) valInfo, feePool, commission := valInfo.WithdrawCommission(feePool, height, lastTotalPower, diff --git a/x/distribution/types/keepers.go b/x/distribution/types/keepers.go index 5009c6b5af..818d3dd5a6 100644 --- a/x/distribution/types/keepers.go +++ b/x/distribution/types/keepers.go @@ -10,7 +10,7 @@ type StakeKeeper interface { Validator(ctx sdk.Context, valAddr sdk.ValAddress) sdk.Validator ValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) sdk.Validator TotalPower(ctx sdk.Context) sdk.Dec - GetLastTotalPower(ctx sdk.Context) sdk.Dec + GetLastTotalPower(ctx sdk.Context) sdk.Int GetLastValidatorPower(ctx sdk.Context, valAddr sdk.ValAddress) sdk.Dec } diff --git a/x/stake/keeper/keeper.go b/x/stake/keeper/keeper.go index 3c209cc7a8..50de8e325c 100644 --- a/x/stake/keeper/keeper.go +++ b/x/stake/keeper/keeper.go @@ -74,21 +74,18 @@ func (k Keeper) SetPool(ctx sdk.Context, pool types.Pool) { //_______________________________________________________________________ // Load the last total validator power. -func (k Keeper) GetLastTotalPower(ctx sdk.Context) (power sdk.Dec) { +func (k Keeper) GetLastTotalPower(ctx sdk.Context) (power sdk.Int) { store := ctx.KVStore(k.storeKey) b := store.Get(LastTotalPowerKey) if b == nil { - return sdk.ZeroDec() + return sdk.ZeroInt() } k.cdc.MustUnmarshalBinary(b, &power) return } // Set the last total validator power. -func (k Keeper) SetLastTotalPower(ctx sdk.Context, power sdk.Dec) { - if !power.IsInteger() { - panic("input power must be whole integer") - } +func (k Keeper) SetLastTotalPower(ctx sdk.Context, power sdk.Int) { store := ctx.KVStore(k.storeKey) b := k.cdc.MustMarshalBinary(power) store.Set(LastTotalPowerKey, b) diff --git a/x/stake/keeper/val_state_change.go b/x/stake/keeper/val_state_change.go index 0c9ab368c6..c62120758b 100644 --- a/x/stake/keeper/val_state_change.go +++ b/x/stake/keeper/val_state_change.go @@ -27,7 +27,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab store := ctx.KVStore(k.storeKey) maxValidators := k.GetParams(ctx).MaxValidators - totalPower := int64(0) + totalPower := sdk.ZeroInt() // Retrieve the last validator set. // The persistent set is updated later in this function. @@ -87,7 +87,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab // keep count count++ - totalPower += newPower + totalPower = totalPower.Add(sdk.NewInt(newPower)) } // sort the no-longer-bonded validators @@ -116,7 +116,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab // set total power on lookup index if there are any updates if len(updates) > 0 { - k.SetLastTotalPower(ctx, sdk.NewDec(totalPower)) + k.SetLastTotalPower(ctx, totalPower) } return updates