diff --git a/cmd/gaia/app/sim_test.go b/cmd/gaia/app/sim_test.go index fb8060a2a..cbd90a723 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -17,7 +17,7 @@ import ( authsim "github.com/cosmos/cosmos-sdk/x/auth/simulation" banksim "github.com/cosmos/cosmos-sdk/x/bank/simulation" 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" govsim "github.com/cosmos/cosmos-sdk/x/gov/simulation" "github.com/cosmos/cosmos-sdk/x/mint" @@ -108,10 +108,10 @@ func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation { return []simulation.WeightedOperation{ {5, authsim.SimulateDeductFee(app.accountKeeper, app.feeCollectionKeeper)}, {100, banksim.SingleInputSendMsg(app.accountKeeper, app.bankKeeper)}, - {50, distributionsim.SimulateMsgSetWithdrawAddress(app.accountKeeper, app.distrKeeper)}, - {50, distributionsim.SimulateMsgWithdrawDelegatorRewardsAll(app.accountKeeper, app.distrKeeper)}, - {50, distributionsim.SimulateMsgWithdrawDelegatorReward(app.accountKeeper, app.distrKeeper)}, - {50, distributionsim.SimulateMsgWithdrawValidatorRewardsAll(app.accountKeeper, app.distrKeeper)}, + {50, distrsim.SimulateMsgSetWithdrawAddress(app.accountKeeper, app.distrKeeper)}, + {50, distrsim.SimulateMsgWithdrawDelegatorRewardsAll(app.accountKeeper, app.distrKeeper)}, + {50, distrsim.SimulateMsgWithdrawDelegatorReward(app.accountKeeper, app.distrKeeper)}, + {50, distrsim.SimulateMsgWithdrawValidatorRewardsAll(app.accountKeeper, app.distrKeeper)}, {5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, app.stakeKeeper)}, {100, govsim.SimulateMsgDeposit(app.govKeeper, app.stakeKeeper)}, {100, stakesim.SimulateMsgCreateValidator(app.accountKeeper, app.stakeKeeper)}, diff --git a/types/decimal.go b/types/decimal.go index 1514c2a22..3c0e89f60 100644 --- a/types/decimal.go +++ b/types/decimal.go @@ -247,7 +247,7 @@ func (d Dec) QuoInt(i Int) Dec { return Dec{mul} } -// is integer, e.g. decimals are zero. +// is integer, e.g. decimals are zero func (d Dec) IsInteger() bool { return new(big.Int).Rem(d.Int, precisionReuse).Sign() == 0 } diff --git a/x/distribution/keeper/delegation.go b/x/distribution/keeper/delegation.go index 784a75c79..1a1095b3a 100644 --- a/x/distribution/keeper/delegation.go +++ b/x/distribution/keeper/delegation.go @@ -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 { diff --git a/x/distribution/types/dec_coin.go b/x/distribution/types/dec_coin.go index 9e9313788..5eedad7e3 100644 --- a/x/distribution/types/dec_coin.go +++ b/x/distribution/types/dec_coin.go @@ -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) diff --git a/x/distribution/types/delegator_info.go b/x/distribution/types/delegator_info.go index 4667d66e0..7c2eaef76 100644 --- a/x/distribution/types/delegator_info.go +++ b/x/distribution/types/delegator_info.go @@ -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) { diff --git a/x/distribution/types/validator_info.go b/x/distribution/types/validator_info.go index c95d4786d..5fc86efcd 100644 --- a/x/distribution/types/validator_info.go +++ b/x/distribution/types/validator_info.go @@ -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) { diff --git a/x/slashing/keeper.go b/x/slashing/keeper.go index 4cd8ed91f..647a9df09 100644 --- a/x/slashing/keeper.go +++ b/x/slashing/keeper.go @@ -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. diff --git a/x/stake/keeper/keeper.go b/x/stake/keeper/keeper.go index 80aa27aea..3c209cc7a 100644 --- a/x/stake/keeper/keeper.go +++ b/x/stake/keeper/keeper.go @@ -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) } diff --git a/x/stake/keeper/val_state_change.go b/x/stake/keeper/val_state_change.go index 7d08d53b3..0c9ab368c 100644 --- a/x/stake/keeper/val_state_change.go +++ b/x/stake/keeper/val_state_change.go @@ -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())