diff --git a/x/auth/ante.go b/x/auth/ante.go index 5b2cdb155..46daf39dd 100644 --- a/x/auth/ante.go +++ b/x/auth/ante.go @@ -255,6 +255,3 @@ func deductFees(acc Account, fee StdFee) (Account, sdk.Result) { } return acc, sdk.Result{} } - -// BurnFeeHandler burns all fees (decreasing total supply) -func BurnFeeHandler(_ sdk.Context, _ sdk.Tx, _ sdk.Coins) {} diff --git a/x/auth/feekeeper.go b/x/auth/feekeeper.go index 3e03a81aa..ef8754809 100644 --- a/x/auth/feekeeper.go +++ b/x/auth/feekeeper.go @@ -20,7 +20,6 @@ type FeeCollectionKeeper struct { cdc *wire.Codec } -// NewFeeKeeper returns a new FeeKeeper func NewFeeCollectionKeeper(cdc *wire.Codec, key sdk.StoreKey) FeeCollectionKeeper { return FeeCollectionKeeper{ key: key, @@ -28,7 +27,7 @@ func NewFeeCollectionKeeper(cdc *wire.Codec, key sdk.StoreKey) FeeCollectionKeep } } -// Adds to Collected Fee Pool +// retrieves the collected fee pool func (fck FeeCollectionKeeper) GetCollectedFees(ctx sdk.Context) sdk.Coins { store := ctx.KVStore(fck.key) bz := store.Get(collectedFeesKey) @@ -41,14 +40,12 @@ func (fck FeeCollectionKeeper) GetCollectedFees(ctx sdk.Context) sdk.Coins { return *feePool } -// Sets to Collected Fee Pool func (fck FeeCollectionKeeper) setCollectedFees(ctx sdk.Context, coins sdk.Coins) { bz := fck.cdc.MustMarshalBinary(coins) store := ctx.KVStore(fck.key) store.Set(collectedFeesKey, bz) } -// Adds to Collected Fee Pool func (fck FeeCollectionKeeper) addCollectedFees(ctx sdk.Context, coins sdk.Coins) sdk.Coins { newCoins := fck.GetCollectedFees(ctx).Plus(coins) fck.setCollectedFees(ctx, newCoins) @@ -56,7 +53,7 @@ func (fck FeeCollectionKeeper) addCollectedFees(ctx sdk.Context, coins sdk.Coins return newCoins } -// Clears the collected Fee Pool +// clear the fee pool func (fck FeeCollectionKeeper) ClearCollectedFees(ctx sdk.Context) { fck.setCollectedFees(ctx, sdk.Coins{}) } diff --git a/x/distribution/begin_block.go b/x/distribution/begin_block.go new file mode 100644 index 000000000..7edfc2cf0 --- /dev/null +++ b/x/distribution/begin_block.go @@ -0,0 +1,9 @@ +package distribution + +import "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + +// slashing begin block functionality +func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, dk keeper.Keeper) (tags sdk.Tags) { + + return +} diff --git a/x/distribution/keeper/allocation.go b/x/distribution/keeper/allocation.go index 19d4e2e16..662d848b4 100644 --- a/x/distribution/keeper/allocation.go +++ b/x/distribution/keeper/allocation.go @@ -1,34 +1,48 @@ package keeper -import sdk "github.com/cosmos/cosmos-sdk/types" +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + abci "github.com/tendermint/tendermint/abci/types" +) // Allocate fees handles distribution of the collected fees -func (k Keeper) AllocateFees(ctx sdk.Context, _ sdk.Tx, feesCollected sdk.Coins, proposerAddr sdk.ConsAddress) { - - sumPowerPrecommitValidators := sdk.NewDec(1) // XXX TODO actually calculate this - communityTax := sdk.NewDecWithPrec(1, 2) // XXX TODO get from global params store - - feePool := k.GetFeePool(ctx) - stakePool := k.stakeKeeper.GetPool(ctx) +func (k Keeper) AllocateFees(ctx sdk.Context, req abci.RequestBeginBlock) { + // get the proposer of this block + proposerAddr := req.Header.Proposer.PubKey // XXX use address? proserValidator := k.stakeKeeper.GetValidatorFromConsAddr(ctx, proposerAddr) proposerDist := k.GetFeeDistribution(ctx, proserValidator.OperatorAddr) + // get the fees which have been getting collected through all the + // transactions in the block + feesCollected := k.FeeCollectionKeeper.GetCollectedFees(ctx) feesCollectedDec := NewDecCoins(feesCollected) + + // allocated rewards to proposer + stakePool := k.stakeKeeper.GetPool(ctx) + sumPowerPrecommitValidators := sdk.NewDec(1) // XXX TODO actually calculate this proposerMultiplier := sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(4, 2).Mul( sumPowerPrecommitValidators).Div(stakePool.BondedTokens)) proposerReward := feesCollectedDec.Mul(proposerMultiplier) + // apply commission commission := proposerReward.Mul(proserValidator.Commission) proposerDist.PoolCommission = proposerDist.PoolCommission.Add(commission) proposerDist.Pool = proposerDist.Pool.Add(proposerReward.Sub(commission)) + // allocate community funding + communityTax := sdk.NewDecWithPrec(1, 2) // XXX TODO get from global params store communityFunding := feesCollectedDec.Mul(communityTax) + feePool := k.GetFeePool(ctx) feePool.CommunityFund = feePool.CommunityFund.Add(communityFunding) + // set the global pool within the distribution module poolReceived := feesCollectedDec.Sub(proposerReward).Sub(communityFunding) feePool.Pool = feePool.Pool.Add(poolReceived) SetValidatorDistribution(proposerDist) SetFeePool(feePool) + + // clear the now distributed fees + k.FeeCollectionKeeper.ClearCollectedFees(ctx) } diff --git a/x/distribution/types/keepers.go b/x/distribution/types/keepers.go index 15a137718..7b0539216 100644 --- a/x/distribution/types/keepers.go +++ b/x/distribution/types/keepers.go @@ -12,6 +12,12 @@ type StakeKeeper interface { } // expected coin keeper -type CoinKeeper interface { +type BankKeeper interface { AddCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, sdk.Tags, sdk.Error) } + +// from ante handler +type FeeCollectionKeeper interface { + GetCollectedFees(ctx sdk.Context) sdk.Coins + ClearCollectedFees(ctx sdk.Context) +}