Skip to content

Commit

Permalink
add fixed block rewards to params
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Sep 4, 2024
1 parent 83b25ea commit 9bbde1c
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 43 deletions.
4 changes: 4 additions & 0 deletions proto/zetachain/zetacore/emissions/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ message Params {
(gogoproto.nullable) = false
];
int64 ballot_maturity_blocks = 10;
string block_reward_amount = 11 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// not used. do not edit.
reserved 1 to 4;
Expand Down
15 changes: 9 additions & 6 deletions x/emissions/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ import (

func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) {
emissionPoolBalance := keeper.GetReservesFactor(ctx)
blockRewards := types.BlockReward

// Get the block rewards from the params
params, found := keeper.GetParams(ctx)
if !found {
return
}

// Use the fixed block reward amount set in params.
blockRewards := params.BlockRewardAmount
if blockRewards.GT(emissionPoolBalance) {
ctx.Logger().
Info(fmt.Sprintf("Block rewards %s are greater than emission pool balance %s", blockRewards.String(), emissionPoolBalance.String()))
return
}

// Get the distribution of rewards
params, found := keeper.GetParams(ctx)
if !found {
return
}

validatorRewards, observerRewards, tssSignerRewards := types.GetRewardsDistributions(params)

// Use a tmpCtx, which is a cache-wrapped context to avoid writing to the store
Expand Down
11 changes: 0 additions & 11 deletions x/emissions/types/message_update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) {
require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress)
})

t.Run("invalid if params are invalid", func(t *testing.T) {
params := types.NewParams()
params.MaxBondFactor = "1.50"
msg := types.MsgUpdateParams{
Authority: sample.AccAddress(),
Params: params,
}
err := msg.ValidateBasic()
require.ErrorContains(t, err, "max bond factor cannot be higher that 1.25")
})

t.Run("valid", func(t *testing.T) {
msg := types.MsgUpdateParams{
Authority: sample.AccAddress(),
Expand Down
19 changes: 17 additions & 2 deletions x/emissions/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ func NewParams() Params {
ValidatorEmissionPercentage: "00.50",
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
BallotMaturityBlocks: 100,
ObserverSlashAmount: ObserverSlashAmount,
BallotMaturityBlocks: int64(BallotMaturityBlocks),
BlockRewardAmount: BlockReward,
}
}

Expand All @@ -38,6 +39,9 @@ func (p Params) Validate() error {
if err := validateBallotMaturityBlocks(p.BallotMaturityBlocks); err != nil {
return err
}
if err := validateBlockRewardsAmount(p.BlockRewardAmount); err != nil {
return err
}
return validateObserverSlashAmount(p.ObserverSlashAmount)
}

Expand Down Expand Up @@ -118,3 +122,14 @@ func validateBallotMaturityBlocks(i interface{}) error {

return nil
}

func validateBlockRewardsAmount(i interface{}) error {
v, ok := i.(sdkmath.LegacyDec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.LT(sdkmath.LegacyZeroDec()) {
return fmt.Errorf("block reward amount cannot be less than 0")
}
return nil
}
97 changes: 73 additions & 24 deletions x/emissions/types/params.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions x/emissions/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func TestValidate(t *testing.T) {
params.BallotMaturityBlocks = -100
require.Error(t, params.Validate())
})

t.Run("should error for negative block reward amount", func(t *testing.T) {
params := NewParams()
params.BlockRewardAmount = sdkmath.LegacyMustNewDecFromStr("-1.30")
require.ErrorContains(t, params.Validate(), "block reward amount cannot be less than 0")
})
}
func TestParamsString(t *testing.T) {
params := DefaultParams()
Expand Down

0 comments on commit 9bbde1c

Please sign in to comment.