diff --git a/x/distribution/genesis.go b/x/distribution/genesis.go index 2c44a0339..2872359c7 100644 --- a/x/distribution/genesis.go +++ b/x/distribution/genesis.go @@ -26,8 +26,11 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) { func WriteGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState { feePool := keeper.GetFeePool(ctx) communityTax := keeper.GetCommunityTax(ctx) + baseProposerRewards := keeper.GetBaseProposerReward(ctx) + bonusProposerRewards := keeper.GetBonusProposerReward(ctx) vdis := keeper.GetAllValidatorDistInfos(ctx) ddis := keeper.GetAllDelegationDistInfos(ctx) dwis := keeper.GetAllDelegatorWithdrawInfos(ctx) - return NewGenesisState(feePool, communityTax, vdis, ddis, dwis) + return NewGenesisState(feePool, communityTax, baseProposerRewards, + bonusProposerRewards, vdis, ddis, dwis) } diff --git a/x/distribution/keeper/allocation.go b/x/distribution/keeper/allocation.go index 545285ae7..bd083adeb 100644 --- a/x/distribution/keeper/allocation.go +++ b/x/distribution/keeper/allocation.go @@ -23,8 +23,9 @@ func (k Keeper) AllocateFees(ctx sdk.Context) { // allocated rewards to proposer percentVotes := k.GetPercentPrecommitVotes(ctx) - - proposerMultiplier := sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(4, 2).Mul(percentVotes)) + baseProposerReward := k.GetBaseProposerReward(ctx) + bonusProposerReward := k.GetBonusProposerReward(ctx) + proposerMultiplier := baseProposerReward.Add(bonusProposerReward.Mul(percentVotes)) proposerReward := feesCollectedDec.MulDec(proposerMultiplier) // apply commission diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 67d0cea62..356e33312 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -108,18 +108,46 @@ func (k Keeper) SetPercentPrecommitVotes(ctx sdk.Context, percentPrecommitVotes func ParamTypeTable() params.TypeTable { return params.NewTypeTable( ParamStoreKeyCommunityTax, sdk.Dec{}, + ParamStoreKeyBaseProposerReward, sdk.Dec{}, + ParamStoreKeyBonusProposerReward, sdk.Dec{}, ) } // Returns the current CommunityTax rate from the global param store // nolint: errcheck func (k Keeper) GetCommunityTax(ctx sdk.Context) sdk.Dec { - var communityTax sdk.Dec - k.paramSpace.Get(ctx, ParamStoreKeyCommunityTax, &communityTax) - return communityTax + var percent sdk.Dec + k.paramSpace.Get(ctx, ParamStoreKeyCommunityTax, &percent) + return percent } // nolint: errcheck -func (k Keeper) SetCommunityTax(ctx sdk.Context, communityTax sdk.Dec) { - k.paramSpace.Set(ctx, ParamStoreKeyCommunityTax, &communityTax) +func (k Keeper) SetCommunityTax(ctx sdk.Context, percent sdk.Dec) { + k.paramSpace.Set(ctx, ParamStoreKeyCommunityTax, &percent) +} + +// Returns the current BaseProposerReward rate from the global param store +// nolint: errcheck +func (k Keeper) GetBaseProposerReward(ctx sdk.Context) sdk.Dec { + var percent sdk.Dec + k.paramSpace.Get(ctx, ParamStoreKeyBaseProposerReward, &percent) + return percent +} + +// nolint: errcheck +func (k Keeper) SetBaseProposerReward(ctx sdk.Context, percent sdk.Dec) { + k.paramSpace.Set(ctx, ParamStoreKeyBaseProposerReward, &percent) +} + +// Returns the current BaseProposerReward rate from the global param store +// nolint: errcheck +func (k Keeper) GetBonusProposerReward(ctx sdk.Context) sdk.Dec { + var percent sdk.Dec + k.paramSpace.Get(ctx, ParamStoreKeyBonusProposerReward, &percent) + return percent +} + +// nolint: errcheck +func (k Keeper) SetBonusProposerReward(ctx sdk.Context, percent sdk.Dec) { + k.paramSpace.Set(ctx, ParamStoreKeyBonusProposerReward, &percent) } diff --git a/x/distribution/keeper/key.go b/x/distribution/keeper/key.go index e1fc44e77..0f9644f77 100644 --- a/x/distribution/keeper/key.go +++ b/x/distribution/keeper/key.go @@ -16,7 +16,9 @@ var ( PercentPrecommitVotesKey = []byte{0x01} // key for storing the power of the precommit validators // params store - ParamStoreKeyCommunityTax = []byte("distr/community-tax") + ParamStoreKeyCommunityTax = []byte("community-tax") + ParamStoreKeyBaseProposerReward = []byte("base-proposer-reward") + ParamStoreKeyBonusProposerReward = []byte("bonus-proposer-reward") ) const ( diff --git a/x/distribution/keeper/test_common.go b/x/distribution/keeper/test_common.go index ec7fc0350..871812a11 100644 --- a/x/distribution/keeper/test_common.go +++ b/x/distribution/keeper/test_common.go @@ -138,6 +138,8 @@ func CreateTestInputAdvanced(t *testing.T, isCheckTx bool, initCoins int64, // set genesis items required for distribution keeper.SetFeePool(ctx, types.InitialFeePool()) keeper.SetCommunityTax(ctx, communityTax) + keeper.SetBaseProposerReward(ctx, sdk.NewDecWithPrec(1, 2)) + keeper.SetBonusProposerReward(ctx, sdk.NewDecWithPrec(4, 2)) return ctx, accountMapper, keeper, sk, fck } diff --git a/x/distribution/types/genesis.go b/x/distribution/types/genesis.go index 9921818b2..528295e5c 100644 --- a/x/distribution/types/genesis.go +++ b/x/distribution/types/genesis.go @@ -13,17 +13,21 @@ type DelegatorWithdrawInfo struct { type GenesisState struct { FeePool FeePool `json:"fee_pool"` CommunityTax sdk.Dec `json:"community_tax"` + BaseProposerReward sdk.Dec `json:"base_proposer_reward"` + BonusProposerReward sdk.Dec `json:"bonus_proposer_reward"` ValidatorDistInfos []ValidatorDistInfo `json:"validator_dist_infos"` DelegationDistInfos []DelegationDistInfo `json:"delegator_dist_infos"` DelegatorWithdrawInfos []DelegatorWithdrawInfo `json:"delegator_withdraw_infos"` } -func NewGenesisState(feePool FeePool, communityTax sdk.Dec, +func NewGenesisState(feePool FeePool, communityTax, baseProposerReward, bonusProposerReward sdk.Dec, vdis []ValidatorDistInfo, ddis []DelegationDistInfo, dwis []DelegatorWithdrawInfo) GenesisState { return GenesisState{ FeePool: feePool, CommunityTax: communityTax, + BaseProposerReward: baseProposerReward, + BonusProposerReward: bonusProposerReward, ValidatorDistInfos: vdis, DelegationDistInfos: ddis, DelegatorWithdrawInfos: dwis, @@ -33,8 +37,10 @@ func NewGenesisState(feePool FeePool, communityTax sdk.Dec, // get raw genesis raw message for testing func DefaultGenesisState() GenesisState { return GenesisState{ - FeePool: InitialFeePool(), - CommunityTax: sdk.NewDecWithPrec(2, 2), // 2% + FeePool: InitialFeePool(), + CommunityTax: sdk.NewDecWithPrec(2, 2), // 2% + BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1% + BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4% } } @@ -53,6 +59,8 @@ func DefaultGenesisWithValidators(valAddrs []sdk.ValAddress) GenesisState { return GenesisState{ FeePool: InitialFeePool(), CommunityTax: sdk.NewDecWithPrec(2, 2), // 2% + BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1% + BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4% ValidatorDistInfos: vdis, DelegationDistInfos: ddis, }