diff --git a/x/distribution/keeper/hooks.go b/x/distribution/keeper/hooks.go index 721a26db1d..6031d056b5 100644 --- a/x/distribution/keeper/hooks.go +++ b/x/distribution/keeper/hooks.go @@ -14,16 +14,18 @@ func (k Keeper) onValidatorCreated(ctx sdk.Context, addr sdk.ValAddress) { vdi := types.ValidatorDistInfo{ OperatorAddr: addr, FeePoolWithdrawalHeight: height, - Pool: types.DecCoins{}, - PoolCommission: types.DecCoins{}, - DelAccum: types.NewTotalAccum(height), + Pool: types.DecCoins{}, + PoolCommission: types.DecCoins{}, + DelAccum: types.NewTotalAccum(height), } k.SetValidatorDistInfo(ctx, vdi) } // Withdrawal all validator rewards func (k Keeper) onValidatorCommissionChange(ctx sdk.Context, addr sdk.ValAddress) { - k.WithdrawValidatorRewardsAll(ctx, addr) + if err := k.WithdrawValidatorRewardsAll(ctx, addr); err != nil { + panic(err) + } } // Withdrawal all validator distribution rewards and cleanup the distribution record @@ -50,7 +52,9 @@ func (k Keeper) onDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, func (k Keeper) onDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) { - k.WithdrawDelegationReward(ctx, delAddr, valAddr) + if err := k.WithdrawDelegationReward(ctx, delAddr, valAddr); err != nil { + panic(err) + } } // Withdrawal all validator distribution rewards and cleanup the distribution record diff --git a/x/distribution/keeper/validator.go b/x/distribution/keeper/validator.go index bbc2a732ed..8b38b0f6a0 100644 --- a/x/distribution/keeper/validator.go +++ b/x/distribution/keeper/validator.go @@ -74,6 +74,7 @@ func (k Keeper) WithdrawValidatorRewardsAll(ctx sdk.Context, operatorAddr sdk.Va return nil } +// iterate over all the validator distribution infos (inefficient, just used to check invariants) func (k Keeper) IterateValidatorDistInfos(ctx sdk.Context, fn func(index int64, distInfo types.ValidatorDistInfo) (stop bool)) { store := ctx.KVStore(k.storeKey) iter := sdk.KVStorePrefixIterator(store, ValidatorDistInfoKey) diff --git a/x/stake/simulation/sim_test.go b/x/stake/simulation/sim_test.go index 6aa7801139..207f42e616 100644 --- a/x/stake/simulation/sim_test.go +++ b/x/stake/simulation/sim_test.go @@ -8,7 +8,9 @@ import ( abci "github.com/tendermint/tendermint/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/mock" "github.com/cosmos/cosmos-sdk/x/mock/simulation" "github.com/cosmos/cosmos-sdk/x/params" @@ -22,13 +24,17 @@ func TestStakeWithRandomMessages(t *testing.T) { bank.RegisterCodec(mapp.Cdc) mapper := mapp.AccountMapper bankKeeper := bank.NewBaseKeeper(mapper) + feeKey := sdk.NewKVStoreKey("fee") stakeKey := sdk.NewKVStoreKey("stake") stakeTKey := sdk.NewTransientStoreKey("transient_stake") paramsKey := sdk.NewKVStoreKey("params") paramsTKey := sdk.NewTransientStoreKey("transient_params") + distrKey := sdk.NewKVStoreKey("distr") - paramstore := params.NewKeeper(mapp.Cdc, paramsKey, paramsTKey).Subspace(stake.DefaultParamspace) - stakeKeeper := stake.NewKeeper(mapp.Cdc, stakeKey, stakeTKey, bankKeeper, paramstore, stake.DefaultCodespace) + feeCollectionKeeper := auth.NewFeeCollectionKeeper(mapp.Cdc, feeKey) + paramstore := params.NewKeeper(mapp.Cdc, paramsKey, paramsTKey) + stakeKeeper := stake.NewKeeper(mapp.Cdc, stakeKey, stakeTKey, bankKeeper, paramstore.Subspace(stake.DefaultParamspace), stake.DefaultCodespace) + distrKeeper := distribution.NewKeeper(mapp.Cdc, distrKey, paramstore.Subspace(distribution.DefaultParamspace), bankKeeper, stakeKeeper, feeCollectionKeeper, distribution.DefaultCodespace) mapp.Router().AddRoute("stake", stake.NewHandler(stakeKeeper)) mapp.SetEndBlocker(func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { validatorUpdates := stake.EndBlocker(ctx, stakeKeeper) @@ -58,7 +64,7 @@ func TestStakeWithRandomMessages(t *testing.T) { }, []simulation.RandSetup{ Setup(mapp, stakeKeeper), }, []simulation.Invariant{ - AllInvariants(bankKeeper, stakeKeeper, mapp.AccountMapper), + AllInvariants(bankKeeper, stakeKeeper, distrKeeper, mapp.AccountMapper), }, 10, 100, false, )