From 17dc8127493e2d5e04504dc4c894457506a2d2e4 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Thu, 4 Oct 2018 20:20:43 -0400 Subject: [PATCH] fix distribution endblocker issues --- cmd/gaia/app/app.go | 5 +++-- x/distribution/genesis.go | 12 ++++-------- x/distribution/keeper/genesis.go | 6 +++--- x/distribution/keeper/keeper.go | 3 ++- x/distribution/types/genesis.go | 16 +++++++++++----- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index 5f5b542ef8..69f957ec96 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -124,11 +124,12 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio // initialize BaseApp app.SetInitChainer(app.initChainer) app.SetBeginBlocker(app.BeginBlocker) - app.SetEndBlocker(app.EndBlocker) app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, app.feeCollectionKeeper)) app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyStake, app.keyDistr, app.keySlashing, app.keyGov, app.keyFeeCollection, app.keyParams) app.MountStoresTransient(app.tkeyParams, app.tkeyStake, app.tkeyDistr) + app.SetEndBlocker(app.EndBlocker) + err := app.LoadLatestVersion(app.keyMain) if err != nil { cmn.Exit(err.Error()) @@ -168,7 +169,7 @@ func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.R validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper) // distribute rewards - //distr.EndBlocker(ctx, app.distrKeeper) + distr.EndBlocker(ctx, app.distrKeeper) // Add these new validators to the addr -> pubkey map. app.slashingKeeper.AddValidators(ctx, validatorUpdates) diff --git a/x/distribution/genesis.go b/x/distribution/genesis.go index c7636c80c0..119c9b8270 100644 --- a/x/distribution/genesis.go +++ b/x/distribution/genesis.go @@ -8,6 +8,7 @@ import ( // InitGenesis sets distribution information for genesis func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) { keeper.SetFeePool(ctx, data.FeePool) + keeper.SetCommunityTax(ctx, data.CommunityTax) for _, vdi := range data.ValidatorDistInfos { keeper.SetValidatorDistInfo(ctx, vdi) @@ -24,14 +25,9 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) { // GenesisState will contain the pool, and validator/delegator distribution info's func WriteGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState { feePool := keeper.GetFeePool(ctx) + communityTax := keeper.GetCommunityTax(ctx) vdis := keeper.GetAllVDIs(ctx) ddis := keeper.GetAllDDIs(ctx) - dws := keeper.GetAllDWs(ctx) - - return GenesisState{ - FeePool: feePool, - ValidatorDistInfos: vdis, - DelegatorDistInfos: ddis, - DelegatorWithdrawInfos: dws, - } + dwis := keeper.GetAllDWIs(ctx) + return NewGenesisState(feePool, communityTax, vdis, ddis, dwis) } diff --git a/x/distribution/keeper/genesis.go b/x/distribution/keeper/genesis.go index ab010f277e..954c44336a 100644 --- a/x/distribution/keeper/genesis.go +++ b/x/distribution/keeper/genesis.go @@ -34,7 +34,7 @@ func (k Keeper) GetAllDDIs(ctx sdk.Context) (ddis []types.DelegatorDistInfo) { } // Get the set of all delegator-withdraw addresses with no limits, used during genesis dump -func (k Keeper) GetAllDWs(ctx sdk.Context) (dws []types.DelegatorWithdrawInfo) { +func (k Keeper) GetAllDWIs(ctx sdk.Context) (dwis []types.DelegatorWithdrawInfo) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, DelegatorDistInfoKey) defer iterator.Close() @@ -44,7 +44,7 @@ func (k Keeper) GetAllDWs(ctx sdk.Context) (dws []types.DelegatorWithdrawInfo) { DelegatorAddr: sdk.AccAddress(iterator.Key()), WithdrawAddr: sdk.AccAddress(iterator.Value()), } - dws = append(dws, dw) + dwis = append(dwis, dw) } - return dws + return dwis } diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index e49793ddcd..22932065bb 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -33,6 +33,7 @@ func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ps params.Setter, ck ty storeKey: key, storeTKey: tkey, cdc: cdc, + ps: ps, bankKeeper: ck, stakeKeeper: sk, feeCollectionKeeper: fck, @@ -94,6 +95,6 @@ func (k Keeper) GetCommunityTax(ctx sdk.Context) sdk.Dec { } // nolint: errcheck -func (k Keeper) setCommunityTax(ctx sdk.Context, communityTax sdk.Dec) { +func (k Keeper) SetCommunityTax(ctx sdk.Context, communityTax sdk.Dec) { k.ps.Set(ctx, ParamStoreKeyCommunityTax, &communityTax) } diff --git a/x/distribution/types/genesis.go b/x/distribution/types/genesis.go index f01d1b781e..abce9dec48 100644 --- a/x/distribution/types/genesis.go +++ b/x/distribution/types/genesis.go @@ -12,22 +12,28 @@ type DelegatorWithdrawInfo struct { // GenesisState - all distribution state that must be provided at genesis type GenesisState struct { FeePool FeePool `json:"fee_pool"` + CommunityTax sdk.Dec `json:"community_tax"` ValidatorDistInfos []ValidatorDistInfo `json:"validator_dist_infos"` DelegatorDistInfos []DelegatorDistInfo `json:"delegator_dist_infos"` DelegatorWithdrawInfos []DelegatorWithdrawInfo `json:"delegator_withdraw_infos"` } -func NewGenesisState(feePool FeePool, vdis []ValidatorDistInfo, ddis []DelegatorDistInfo) GenesisState { +func NewGenesisState(feePool FeePool, communityTax sdk.Dec, + vdis []ValidatorDistInfo, ddis []DelegatorDistInfo, dwis []DelegatorWithdrawInfo) GenesisState { + return GenesisState{ - FeePool: feePool, - ValidatorDistInfos: vdis, - DelegatorDistInfos: ddis, + FeePool: feePool, + CommunityTax: communityTax, + ValidatorDistInfos: vdis, + DelegatorDistInfos: ddis, + DelegatorWithdrawInfos: dwis, } } // get raw genesis raw message for testing func DefaultGenesisState() GenesisState { return GenesisState{ - FeePool: InitialFeePool(), + FeePool: InitialFeePool(), + CommunityTax: sdk.NewDecWithPrec(2, 2), // 2% } }