diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index ad9330ba9..749588c43 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -168,7 +168,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/client/cli/tx.go b/x/distribution/client/cli/tx.go index 2cf293d89..d3fa22954 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -75,7 +75,7 @@ func GetCmdWithdrawRewards(cdc *codec.Codec) *cobra.Command { } // build and sign the transaction, then broadcast to Tendermint - return utils.SendTx(txBldr, cliCtx, []sdk.Msg{msg}) + return utils.CompleteAndBroadcastTxCli(txBldr, cliCtx, []sdk.Msg{msg}) }, } cmd.Flags().String(flagOnlyFromValidator, "", "only withdraw from this validator address (in bech)") @@ -110,7 +110,7 @@ func GetCmdSetWithdrawAddr(cdc *codec.Codec) *cobra.Command { msg := types.NewMsgSetWithdrawAddress(delAddr, withdrawAddr) // build and sign the transaction, then broadcast to Tendermint - return utils.SendTx(txBldr, cliCtx, []sdk.Msg{msg}) + return utils.CompleteAndBroadcastTxCli(txBldr, cliCtx, []sdk.Msg{msg}) }, } return cmd diff --git a/x/distribution/keeper/allocation.go b/x/distribution/keeper/allocation.go index 4174f8b17..03742fdac 100644 --- a/x/distribution/keeper/allocation.go +++ b/x/distribution/keeper/allocation.go @@ -1,22 +1,27 @@ package keeper import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/distribution/types" ) // Allocate fees handles distribution of the collected fees func (k Keeper) AllocateFees(ctx sdk.Context) { + fmt.Println("wackydebugoutput AllocateFees 0") // get the proposer of this block proposerConsAddr := k.GetProposerConsAddr(ctx) proposerValidator := k.stakeKeeper.ValidatorByConsAddr(ctx, proposerConsAddr) proposerDist := k.GetValidatorDistInfo(ctx, proposerValidator.GetOperator()) + fmt.Println("wackydebugoutput AllocateFees 1") // get the fees which have been getting collected through all the // transactions in the block feesCollected := k.feeCollectionKeeper.GetCollectedFees(ctx) feesCollectedDec := types.NewDecCoins(feesCollected) + fmt.Println("wackydebugoutput AllocateFees 2") // allocated rewards to proposer bondedTokens := k.stakeKeeper.TotalPower(ctx) @@ -24,25 +29,30 @@ func (k Keeper) AllocateFees(ctx sdk.Context) { proposerMultiplier := sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(4, 2).Mul( sumPowerPrecommitValidators).Quo(bondedTokens)) proposerReward := feesCollectedDec.Mul(proposerMultiplier) + fmt.Println("wackydebugoutput AllocateFees 3") // apply commission commission := proposerReward.Mul(proposerValidator.GetCommission()) remaining := proposerReward.Mul(sdk.OneDec().Sub(proposerValidator.GetCommission())) proposerDist.PoolCommission = proposerDist.PoolCommission.Plus(commission) proposerDist.Pool = proposerDist.Pool.Plus(remaining) + fmt.Println("wackydebugoutput AllocateFees 4") // allocate community funding communityTax := k.GetCommunityTax(ctx) communityFunding := feesCollectedDec.Mul(communityTax) feePool := k.GetFeePool(ctx) feePool.CommunityPool = feePool.CommunityPool.Plus(communityFunding) + fmt.Println("wackydebugoutput AllocateFees 5") // set the global pool within the distribution module poolReceived := feesCollectedDec.Mul(sdk.OneDec().Sub(proposerMultiplier).Sub(communityTax)) feePool.Pool = feePool.Pool.Plus(poolReceived) + fmt.Println("wackydebugoutput AllocateFees 0") k.SetValidatorDistInfo(ctx, proposerDist) k.SetFeePool(ctx, feePool) + fmt.Println("wackydebugoutput AllocateFees 6") // clear the now distributed fees k.feeCollectionKeeper.ClearCollectedFees(ctx) diff --git a/x/distribution/keeper/hooks.go b/x/distribution/keeper/hooks.go index f13daf03a..d503d54fb 100644 --- a/x/distribution/keeper/hooks.go +++ b/x/distribution/keeper/hooks.go @@ -1,6 +1,8 @@ package keeper import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/distribution/types" ) @@ -41,6 +43,7 @@ func (k Keeper) onDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, WithdrawalHeight: ctx.BlockHeight(), } k.SetDelegatorDistInfo(ctx, ddi) + ctx.Logger().With("module", "x/distribution").Error(fmt.Sprintf("ddi created: %v", ddi)) } // Withdrawal all validator rewards diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 31ce345b2..0803d2493 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -46,12 +46,10 @@ func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ps params.Setter, ck ty // get the global fee pool distribution info func (k Keeper) GetFeePool(ctx sdk.Context) (feePool types.FeePool) { store := ctx.KVStore(k.storeKey) - b := store.Get(FeePoolKey) if b == nil { panic("Stored fee pool should not have been nil") } - k.cdc.MustUnmarshalBinary(b, &feePool) return } diff --git a/x/distribution/keeper/key.go b/x/distribution/keeper/key.go index 771343f01..6162baf6d 100644 --- a/x/distribution/keeper/key.go +++ b/x/distribution/keeper/key.go @@ -6,10 +6,10 @@ import ( // keys/key-prefixes var ( - FeePoolKey = []byte{0x00} // key for global distribution state - ValidatorDistInfoKey = []byte{0x01} // prefix for each key to a validator distribution - DelegatorDistInfoKey = []byte{0x02} // prefix for each key to a delegation distribution - DelegatorWithdrawInfoKey = []byte{0x03} // prefix for each key to a delegator withdraw info + FeePoolKey = []byte{0x01} // key for global distribution state + ValidatorDistInfoKey = []byte{0x02} // prefix for each key to a validator distribution + DelegatorDistInfoKey = []byte{0x03} // prefix for each key to a delegation distribution + DelegatorWithdrawInfoKey = []byte{0x04} // prefix for each key to a delegator withdraw info // transient ProposerKey = []byte{0x00} // key for storing the proposer operator address diff --git a/x/distribution/keeper/validator.go b/x/distribution/keeper/validator.go index 0b58ca68c..45ff70fd9 100644 --- a/x/distribution/keeper/validator.go +++ b/x/distribution/keeper/validator.go @@ -13,7 +13,7 @@ func (k Keeper) GetValidatorDistInfo(ctx sdk.Context, b := store.Get(GetValidatorDistInfoKey(operatorAddr)) if b == nil { - panic("Stored delegation-distribution info should not have been nil") + panic("Stored validator-distribution info should not have been nil") } k.cdc.MustUnmarshalBinary(b, &vdi) diff --git a/x/distribution/types/delegator_info.go b/x/distribution/types/delegator_info.go index 4bb02e20c..608ef68d4 100644 --- a/x/distribution/types/delegator_info.go +++ b/x/distribution/types/delegator_info.go @@ -14,6 +14,10 @@ func (di DelegatorDistInfo) WithdrawRewards(fp FeePool, vi ValidatorDistInfo, height int64, totalBonded, vdTokens, totalDelShares, delegatorShares, commissionRate sdk.Dec) (DelegatorDistInfo, FeePool, DecCoins) { + if vi.DelAccum.Accum.IsZero() { + return di, fp, DecCoins{} + } + vi.UpdateTotalDelAccum(height, totalDelShares) vi, fp = vi.TakeFeePoolRewards(fp, height, totalBonded, vdTokens, commissionRate) diff --git a/x/distribution/types/validator_info.go b/x/distribution/types/validator_info.go index 7c41b7e50..1ea5fc27e 100644 --- a/x/distribution/types/validator_info.go +++ b/x/distribution/types/validator_info.go @@ -26,6 +26,10 @@ func (vi ValidatorDistInfo) TakeFeePoolRewards(fp FeePool, height int64, totalBo fp.UpdateTotalValAccum(height, totalBonded) + if fp.ValAccum.Accum.IsZero() { + return vi, fp + } + // update the validators pool blocks := height - vi.FeePoolWithdrawalHeight vi.FeePoolWithdrawalHeight = height diff --git a/x/stake/genesis.go b/x/stake/genesis.go index 58b7ed1b4..cddb3fb57 100644 --- a/x/stake/genesis.go +++ b/x/stake/genesis.go @@ -38,10 +38,13 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res [ if validator.Status == sdk.Bonded { keeper.SetValidatorBondedIndex(ctx, validator) } + + keeper.OnValidatorCreated(ctx, validator.OperatorAddr) } - for _, bond := range data.Bonds { - keeper.SetDelegation(ctx, bond) + for _, delegation := range data.Bonds { + keeper.SetDelegation(ctx, delegation) + keeper.OnDelegationCreated(ctx, delegation.DelegatorAddr, delegation.ValidatorAddr) } keeper.UpdateBondedValidatorsFull(ctx) diff --git a/x/stake/keeper/delegation.go b/x/stake/keeper/delegation.go index cc46646a7..888fe1570 100644 --- a/x/stake/keeper/delegation.go +++ b/x/stake/keeper/delegation.go @@ -336,7 +336,6 @@ func (k Keeper) unbond(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValA k.RemoveValidator(ctx, validator.OperatorAddr) } - k.OnDelegationSharesModified(ctx, delegation.DelegatorAddr, validator.OperatorAddr) return amount, nil }