Store last total power as sdk.Int, not sdk.Dec
This commit is contained in:
parent
cd9373d6f3
commit
3d270babc0
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue