fix distribution endblocker issues

This commit is contained in:
rigelrozanski 2018-10-04 20:20:43 -04:00
parent 20a51e587c
commit 17dc812749
5 changed files with 23 additions and 19 deletions

View File

@ -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)

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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%
}
}