Address @rigelrozanski comments
This commit is contained in:
parent
edd56be952
commit
306fb8fb6d
|
@ -17,7 +17,7 @@ import (
|
||||||
authsim "github.com/cosmos/cosmos-sdk/x/auth/simulation"
|
authsim "github.com/cosmos/cosmos-sdk/x/auth/simulation"
|
||||||
banksim "github.com/cosmos/cosmos-sdk/x/bank/simulation"
|
banksim "github.com/cosmos/cosmos-sdk/x/bank/simulation"
|
||||||
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||||
distributionsim "github.com/cosmos/cosmos-sdk/x/distribution/simulation"
|
distrsim "github.com/cosmos/cosmos-sdk/x/distribution/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
govsim "github.com/cosmos/cosmos-sdk/x/gov/simulation"
|
govsim "github.com/cosmos/cosmos-sdk/x/gov/simulation"
|
||||||
"github.com/cosmos/cosmos-sdk/x/mint"
|
"github.com/cosmos/cosmos-sdk/x/mint"
|
||||||
|
@ -108,10 +108,10 @@ func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation {
|
||||||
return []simulation.WeightedOperation{
|
return []simulation.WeightedOperation{
|
||||||
{5, authsim.SimulateDeductFee(app.accountKeeper, app.feeCollectionKeeper)},
|
{5, authsim.SimulateDeductFee(app.accountKeeper, app.feeCollectionKeeper)},
|
||||||
{100, banksim.SingleInputSendMsg(app.accountKeeper, app.bankKeeper)},
|
{100, banksim.SingleInputSendMsg(app.accountKeeper, app.bankKeeper)},
|
||||||
{50, distributionsim.SimulateMsgSetWithdrawAddress(app.accountKeeper, app.distrKeeper)},
|
{50, distrsim.SimulateMsgSetWithdrawAddress(app.accountKeeper, app.distrKeeper)},
|
||||||
{50, distributionsim.SimulateMsgWithdrawDelegatorRewardsAll(app.accountKeeper, app.distrKeeper)},
|
{50, distrsim.SimulateMsgWithdrawDelegatorRewardsAll(app.accountKeeper, app.distrKeeper)},
|
||||||
{50, distributionsim.SimulateMsgWithdrawDelegatorReward(app.accountKeeper, app.distrKeeper)},
|
{50, distrsim.SimulateMsgWithdrawDelegatorReward(app.accountKeeper, app.distrKeeper)},
|
||||||
{50, distributionsim.SimulateMsgWithdrawValidatorRewardsAll(app.accountKeeper, app.distrKeeper)},
|
{50, distrsim.SimulateMsgWithdrawValidatorRewardsAll(app.accountKeeper, app.distrKeeper)},
|
||||||
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, app.stakeKeeper)},
|
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, app.stakeKeeper)},
|
||||||
{100, govsim.SimulateMsgDeposit(app.govKeeper, app.stakeKeeper)},
|
{100, govsim.SimulateMsgDeposit(app.govKeeper, app.stakeKeeper)},
|
||||||
{100, stakesim.SimulateMsgCreateValidator(app.accountKeeper, app.stakeKeeper)},
|
{100, stakesim.SimulateMsgCreateValidator(app.accountKeeper, app.stakeKeeper)},
|
||||||
|
|
|
@ -247,7 +247,7 @@ func (d Dec) QuoInt(i Int) Dec {
|
||||||
return Dec{mul}
|
return Dec{mul}
|
||||||
}
|
}
|
||||||
|
|
||||||
// is integer, e.g. decimals are zero.
|
// is integer, e.g. decimals are zero
|
||||||
func (d Dec) IsInteger() bool {
|
func (d Dec) IsInteger() bool {
|
||||||
return new(big.Int).Rem(d.Int, precisionReuse).Sign() == 0
|
return new(big.Int).Rem(d.Int, precisionReuse).Sign() == 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -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",
|
// 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,
|
func (k Keeper) WithdrawDelegationReward(ctx sdk.Context, delegatorAddr sdk.AccAddress,
|
||||||
valAddr sdk.ValAddress) sdk.Error {
|
valAddr sdk.ValAddress) sdk.Error {
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ func (coins DecCoins) AmountOf(denom string) sdk.Dec {
|
||||||
}
|
}
|
||||||
return sdk.ZeroDec()
|
return sdk.ZeroDec()
|
||||||
default:
|
default:
|
||||||
midIdx := len(coins) / 2 // 2:1, 3:1, 4:2
|
midIdx := len(coins) / 2 // binary search
|
||||||
coin := coins[midIdx]
|
coin := coins[midIdx]
|
||||||
if denom < coin.Denom {
|
if denom < coin.Denom {
|
||||||
return coins[:midIdx].AmountOf(denom)
|
return coins[:midIdx].AmountOf(denom)
|
||||||
|
|
|
@ -23,11 +23,11 @@ func NewDelegationDistInfo(delegatorAddr sdk.AccAddress, valOperatorAddr sdk.Val
|
||||||
|
|
||||||
// Withdraw rewards from delegator.
|
// Withdraw rewards from delegator.
|
||||||
// Among many things, it does:
|
// Among many things, it does:
|
||||||
// * updates validator info's total del accum.
|
// * updates validator info's total del accum
|
||||||
// * calls vi.TakeFeePoolRewards, which:
|
// * calls vi.TakeFeePoolRewards, which:
|
||||||
// * updates validator info's FeePoolWithdrawalHeight, thus setting accum to 0.
|
// * updates validator info's FeePoolWithdrawalHeight, thus setting accum to 0
|
||||||
// * updates fee pool to latest height and total val accum w/ given totalBonded.
|
// * updates fee pool to latest height and total val accum w/ given totalBonded
|
||||||
// (see comment on TakeFeePoolRewards for more info).
|
// (see comment on TakeFeePoolRewards for more info)
|
||||||
func (di DelegationDistInfo) WithdrawRewards(fp FeePool, vi ValidatorDistInfo,
|
func (di DelegationDistInfo) WithdrawRewards(fp FeePool, vi ValidatorDistInfo,
|
||||||
height int64, totalBonded, vdTokens, totalDelShares, delegatorShares,
|
height int64, totalBonded, vdTokens, totalDelShares, delegatorShares,
|
||||||
commissionRate sdk.Dec) (DelegationDistInfo, ValidatorDistInfo, FeePool, DecCoins) {
|
commissionRate sdk.Dec) (DelegationDistInfo, ValidatorDistInfo, FeePool, DecCoins) {
|
||||||
|
|
|
@ -31,15 +31,15 @@ func (vi ValidatorDistInfo) UpdateTotalDelAccum(height int64, totalDelShares sdk
|
||||||
return vi
|
return vi
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move any available accumulated fees in the FeePool to the validator's pool.
|
// Move any available accumulated fees in the FeePool to the validator's pool
|
||||||
// * updates validator info's FeePoolWithdrawalHeight, thus setting accum to 0.
|
// - updates validator info's FeePoolWithdrawalHeight, thus setting accum to 0
|
||||||
// * updates fee pool to latest height and total val accum w/ given totalBonded.
|
// - 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.
|
// 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.
|
// NOTE: This algorithm works as long as TakeFeePoolRewards is called after every power change.
|
||||||
// - called in ValidationDistInfo.WithdrawCommission.
|
// - called in ValidationDistInfo.WithdrawCommission
|
||||||
// - called in DelegationDistInfo.WithdrawRewards.
|
// - called in DelegationDistInfo.WithdrawRewards
|
||||||
// NOTE: When a delegator unbonds, say, onDelegationSharesModified ->
|
// NOTE: When a delegator unbonds, say, onDelegationSharesModified ->
|
||||||
// WithdrawDelegationReward -> WithdrawRewards.
|
// WithdrawDelegationReward -> WithdrawRewards
|
||||||
func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBonded, vdTokens,
|
func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBonded, vdTokens,
|
||||||
commissionRate sdk.Dec) (ValidatorDistInfo, FeePool) {
|
commissionRate sdk.Dec) (ValidatorDistInfo, FeePool) {
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,8 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, vs sdk.ValidatorSet, paramspa
|
||||||
return keeper
|
return keeper
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle a validator signing two blocks at the same height.
|
// handle a validator signing two blocks at the same height
|
||||||
// power: power of the double-signing validator at the height of infraction.
|
// 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) {
|
func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractionHeight int64, timestamp time.Time, power int64) {
|
||||||
logger := ctx.Logger().With("module", "x/slashing")
|
logger := ctx.Logger().With("module", "x/slashing")
|
||||||
time := ctx.BlockHeader().Time
|
time := ctx.BlockHeader().Time
|
||||||
|
@ -71,7 +71,7 @@ func (k Keeper) handleDoubleSign(ctx sdk.Context, addr crypto.Address, infractio
|
||||||
revisedFraction := k.capBySlashingPeriod(ctx, consAddr, fraction, distributionHeight)
|
revisedFraction := k.capBySlashingPeriod(ctx, consAddr, fraction, distributionHeight)
|
||||||
logger.Info(fmt.Sprintf("Fraction slashed capped by slashing period from %v to %v", fraction, revisedFraction))
|
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
|
// `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.
|
// ABCI, and now received as evidence.
|
||||||
|
|
|
@ -108,18 +108,13 @@ func (k Keeper) GetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) powerToBytes(power sdk.Dec) []byte {
|
|
||||||
bz := k.cdc.MustMarshalBinary(power)
|
|
||||||
return bz
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the last validator power.
|
// Set the last validator power.
|
||||||
func (k Keeper) SetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress, power sdk.Dec) {
|
func (k Keeper) SetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress, power sdk.Dec) {
|
||||||
if !power.IsInteger() {
|
if !power.IsInteger() {
|
||||||
panic("input power must be whole integer")
|
panic("input power must be whole integer")
|
||||||
}
|
}
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := k.powerToBytes(power)
|
bz := k.cdc.MustMarshalBinary(power)
|
||||||
store.Set(GetLastValidatorPowerKey(operator), bz)
|
store.Set(GetLastValidatorPowerKey(operator), bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
|
||||||
|
|
||||||
// calculate the new power bytes
|
// calculate the new power bytes
|
||||||
newPower := validator.BondedTokens().RoundInt64()
|
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
|
// update the validator set if power has changed
|
||||||
if !found || !bytes.Equal(oldPowerBytes, newPowerBytes) {
|
if !found || !bytes.Equal(oldPowerBytes, newPowerBytes) {
|
||||||
updates = append(updates, validator.ABCIValidatorUpdate())
|
updates = append(updates, validator.ABCIValidatorUpdate())
|
||||||
|
|
Loading…
Reference in New Issue