LastValidatorPower is also an Int
This commit is contained in:
parent
d666658ca9
commit
f756b40a01
|
@ -82,7 +82,7 @@ func (k Keeper) WithdrawDelegationReward(ctx sdk.Context, delegatorAddr sdk.AccA
|
|||
// TODO: Reconcile with duplicate code in getDelegatorRewardsAll.
|
||||
height := ctx.BlockHeight()
|
||||
lastTotalPower := sdk.NewDecFromInt(k.stakeKeeper.GetLastTotalPower(ctx))
|
||||
lastValPower := k.stakeKeeper.GetLastValidatorPower(ctx, valAddr)
|
||||
lastValPower := sdk.NewDecFromInt(k.stakeKeeper.GetLastValidatorPower(ctx, valAddr))
|
||||
feePool := k.GetFeePool(ctx)
|
||||
delInfo := k.GetDelegationDistInfo(ctx, delegatorAddr, valAddr)
|
||||
valInfo := k.GetValidatorDistInfo(ctx, valAddr)
|
||||
|
@ -133,7 +133,7 @@ func (k Keeper) getDelegatorRewardsAll(ctx sdk.Context, delAddr sdk.AccAddress,
|
|||
operationAtDelegation := func(_ int64, del sdk.Delegation) (stop bool) {
|
||||
feePool := k.GetFeePool(ctx)
|
||||
valAddr := del.GetValidatorAddr()
|
||||
lastValPower := k.stakeKeeper.GetLastValidatorPower(ctx, valAddr)
|
||||
lastValPower := sdk.NewDecFromInt(k.stakeKeeper.GetLastValidatorPower(ctx, valAddr))
|
||||
delInfo := k.GetDelegationDistInfo(ctx, delAddr, valAddr)
|
||||
valInfo := k.GetValidatorDistInfo(ctx, valAddr)
|
||||
validator := k.stakeKeeper.Validator(ctx, valAddr)
|
||||
|
|
|
@ -35,7 +35,7 @@ func TestWithdrawDelegationRewardBasic(t *testing.T) {
|
|||
// withdraw delegation
|
||||
ctx = ctx.WithBlockHeight(1)
|
||||
sk.SetLastTotalPower(ctx, sdk.NewInt(10))
|
||||
sk.SetLastValidatorPower(ctx, valOpAddr1, sdk.NewDec(10))
|
||||
sk.SetLastValidatorPower(ctx, valOpAddr1, sdk.NewInt(10))
|
||||
keeper.WithdrawDelegationReward(ctx, delAddr1, valOpAddr1)
|
||||
amt = accMapper.GetAccount(ctx, delAddr1).GetCoins().AmountOf(denom)
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ func (k Keeper) WithdrawValidatorRewardsAll(ctx sdk.Context, operatorAddr sdk.Va
|
|||
// withdraw self-delegation
|
||||
height := ctx.BlockHeight()
|
||||
validator := k.stakeKeeper.Validator(ctx, operatorAddr)
|
||||
lastValPower := k.stakeKeeper.GetLastValidatorPower(ctx, operatorAddr)
|
||||
lastValPower := sdk.NewDecFromInt(k.stakeKeeper.GetLastValidatorPower(ctx, operatorAddr))
|
||||
accAddr := sdk.AccAddress(operatorAddr.Bytes())
|
||||
withdraw := k.getDelegatorRewardsAll(ctx, accAddr, height)
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ type StakeKeeper interface {
|
|||
ValidatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) sdk.Validator
|
||||
TotalPower(ctx sdk.Context) sdk.Dec
|
||||
GetLastTotalPower(ctx sdk.Context) sdk.Int
|
||||
GetLastValidatorPower(ctx sdk.Context, valAddr sdk.ValAddress) sdk.Dec
|
||||
GetLastValidatorPower(ctx sdk.Context, valAddr sdk.ValAddress) sdk.Int
|
||||
}
|
||||
|
||||
// expected coin keeper
|
||||
|
|
|
@ -95,21 +95,18 @@ func (k Keeper) SetLastTotalPower(ctx sdk.Context, power sdk.Int) {
|
|||
|
||||
// Load the last validator power.
|
||||
// Returns zero if the operator was not a validator last block.
|
||||
func (k Keeper) GetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress) (power sdk.Dec) {
|
||||
func (k Keeper) GetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress) (power sdk.Int) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := store.Get(GetLastValidatorPowerKey(operator))
|
||||
if bz == nil {
|
||||
return sdk.ZeroDec()
|
||||
return sdk.ZeroInt()
|
||||
}
|
||||
k.cdc.MustUnmarshalBinary(bz, &power)
|
||||
return
|
||||
}
|
||||
|
||||
// Set the last validator power.
|
||||
func (k Keeper) SetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress, power sdk.Dec) {
|
||||
if !power.IsInteger() {
|
||||
panic("input power must be whole integer")
|
||||
}
|
||||
func (k Keeper) SetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress, power sdk.Int) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := k.cdc.MustMarshalBinary(power)
|
||||
store.Set(GetLastValidatorPowerKey(operator), bz)
|
||||
|
|
|
@ -73,13 +73,13 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
|
|||
|
||||
// calculate the new power bytes
|
||||
newPower := validator.BondedTokens().RoundInt64()
|
||||
newPowerBytes := k.cdc.MustMarshalBinary(sdk.NewDec(newPower))
|
||||
newPowerBytes := k.cdc.MustMarshalBinary(sdk.NewInt(newPower))
|
||||
// update the validator set if power has changed
|
||||
if !found || !bytes.Equal(oldPowerBytes, newPowerBytes) {
|
||||
updates = append(updates, validator.ABCIValidatorUpdate())
|
||||
|
||||
// set validator power on lookup index.
|
||||
k.SetLastValidatorPower(ctx, operator, sdk.NewDec(newPower))
|
||||
k.SetLastValidatorPower(ctx, operator, sdk.NewInt(newPower))
|
||||
}
|
||||
|
||||
// validator still in the validator set, so delete from the copy
|
||||
|
|
Loading…
Reference in New Issue