Address @rigelrozanski comments
This commit is contained in:
@@ -69,9 +69,9 @@ func (k Keeper) RemoveDelegatorWithdrawAddr(ctx sdk.Context, delAddr, withdrawAd
|
||||
|
||||
//___________________________________________________________________________________________
|
||||
|
||||
// Withdraw all the rewards for a single delegation.
|
||||
// Withdraw all the rewards for a single delegation
|
||||
// NOTE: This gets called "onDelegationSharesModified",
|
||||
// meaning any changes to bonded coins.
|
||||
// meaning any changes to bonded coins
|
||||
func (k Keeper) WithdrawDelegationReward(ctx sdk.Context, delegatorAddr sdk.AccAddress,
|
||||
valAddr sdk.ValAddress) sdk.Error {
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ func (coins DecCoins) AmountOf(denom string) sdk.Dec {
|
||||
}
|
||||
return sdk.ZeroDec()
|
||||
default:
|
||||
midIdx := len(coins) / 2 // 2:1, 3:1, 4:2
|
||||
midIdx := len(coins) / 2 // binary search
|
||||
coin := coins[midIdx]
|
||||
if denom < coin.Denom {
|
||||
return coins[:midIdx].AmountOf(denom)
|
||||
|
||||
@@ -23,11 +23,11 @@ func NewDelegationDistInfo(delegatorAddr sdk.AccAddress, valOperatorAddr sdk.Val
|
||||
|
||||
// Withdraw rewards from delegator.
|
||||
// Among many things, it does:
|
||||
// * updates validator info's total del accum.
|
||||
// * updates validator info's total del accum
|
||||
// * calls vi.TakeFeePoolRewards, which:
|
||||
// * updates validator info's FeePoolWithdrawalHeight, thus setting accum to 0.
|
||||
// * updates fee pool to latest height and total val accum w/ given totalBonded.
|
||||
// (see comment on TakeFeePoolRewards for more info).
|
||||
// * updates validator info's FeePoolWithdrawalHeight, thus setting accum to 0
|
||||
// * updates fee pool to latest height and total val accum w/ given totalBonded
|
||||
// (see comment on TakeFeePoolRewards for more info)
|
||||
func (di DelegationDistInfo) WithdrawRewards(fp FeePool, vi ValidatorDistInfo,
|
||||
height int64, totalBonded, vdTokens, totalDelShares, delegatorShares,
|
||||
commissionRate sdk.Dec) (DelegationDistInfo, ValidatorDistInfo, FeePool, DecCoins) {
|
||||
|
||||
@@ -31,15 +31,15 @@ func (vi ValidatorDistInfo) UpdateTotalDelAccum(height int64, totalDelShares sdk
|
||||
return vi
|
||||
}
|
||||
|
||||
// Move any available accumulated fees in the FeePool to the validator's pool.
|
||||
// * updates validator info's FeePoolWithdrawalHeight, thus setting accum to 0.
|
||||
// * updates fee pool to latest height and total val accum w/ given totalBonded.
|
||||
// Move any available accumulated fees in the FeePool to the validator's pool
|
||||
// - updates validator info's FeePoolWithdrawalHeight, thus setting accum to 0
|
||||
// - updates fee pool to latest height and total val accum w/ given totalBonded
|
||||
// This is the only way to update the FeePool's validator TotalAccum.
|
||||
// NOTE: This algorithm works as long as TakeFeePoolRewards is called after every power change.
|
||||
// - called in ValidationDistInfo.WithdrawCommission.
|
||||
// - called in DelegationDistInfo.WithdrawRewards.
|
||||
// - called in ValidationDistInfo.WithdrawCommission
|
||||
// - called in DelegationDistInfo.WithdrawRewards
|
||||
// NOTE: When a delegator unbonds, say, onDelegationSharesModified ->
|
||||
// WithdrawDelegationReward -> WithdrawRewards.
|
||||
// WithdrawDelegationReward -> WithdrawRewards
|
||||
func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBonded, vdTokens,
|
||||
commissionRate sdk.Dec) (ValidatorDistInfo, FeePool) {
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, paramspa
|
||||
return keeper
|
||||
}
|
||||
|
||||
// handle a validator signing two blocks at the same height.
|
||||
// power: power of the double-signing validator at the height of infraction.
|
||||
// handle a validator signing two blocks at the same height
|
||||
// power: power of the double-signing validator at the height of infraction
|
||||
func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractionHeight int64, timestamp time.Time, power int64) {
|
||||
logger := ctx.Logger().With("module", "x/slashing")
|
||||
time := ctx.BlockHeader().Time
|
||||
@@ -71,9 +71,9 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio
|
||||
revisedFraction := k.capBySlashingPeriod(ctx, consAddr, fraction, distributionHeight)
|
||||
logger.Info(fmt.Sprintf("Fraction slashed capped by slashing period from %v to %v", fraction, revisedFraction))
|
||||
|
||||
// Slash validator.
|
||||
// Slash validator
|
||||
// `power` is the int64 power of the validator as provided to/by
|
||||
// Tendermint. This value is validator.Tokens as sent to Tendermint via
|
||||
// Tendermint. This value is validator.Tokens as sent to Tendermint via
|
||||
// ABCI, and now received as evidence.
|
||||
// The revisedFraction (which is the new fraction to be slashed) is passed
|
||||
// in separately to separately slash unbonding and rebonding delegations.
|
||||
|
||||
@@ -108,18 +108,13 @@ func (k Keeper) GetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress)
|
||||
return
|
||||
}
|
||||
|
||||
func (k Keeper) powerToBytes(power sdk.Dec) []byte {
|
||||
bz := k.cdc.MustMarshalBinary(power)
|
||||
return bz
|
||||
}
|
||||
|
||||
// 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")
|
||||
}
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := k.powerToBytes(power)
|
||||
bz := k.cdc.MustMarshalBinary(power)
|
||||
store.Set(GetLastValidatorPowerKey(operator), bz)
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
|
||||
|
||||
// calculate the new power bytes
|
||||
newPower := validator.BondedTokens().RoundInt64()
|
||||
newPowerBytes := k.powerToBytes(sdk.NewDec(newPower))
|
||||
newPowerBytes := k.cdc.MustMarshalBinary(sdk.NewDec(newPower))
|
||||
// update the validator set if power has changed
|
||||
if !found || !bytes.Equal(oldPowerBytes, newPowerBytes) {
|
||||
updates = append(updates, validator.ABCIValidatorUpdate())
|
||||
|
||||
Reference in New Issue
Block a user