From 9bbde1c04b25c9cf6eac5c5aafdec15b0edd29a1 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Wed, 4 Sep 2024 11:40:11 -0400 Subject: [PATCH] add fixed block rewards to params --- .../zetachain/zetacore/emissions/params.proto | 4 + x/emissions/abci.go | 15 +-- .../types/message_update_params_test.go | 11 --- x/emissions/types/params.go | 19 +++- x/emissions/types/params.pb.go | 97 ++++++++++++++----- x/emissions/types/params_test.go | 6 ++ 6 files changed, 109 insertions(+), 43 deletions(-) diff --git a/proto/zetachain/zetacore/emissions/params.proto b/proto/zetachain/zetacore/emissions/params.proto index 384e205fe1..01958fb556 100644 --- a/proto/zetachain/zetacore/emissions/params.proto +++ b/proto/zetachain/zetacore/emissions/params.proto @@ -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; diff --git a/x/emissions/abci.go b/x/emissions/abci.go index 25f6705e79..515fc8ae8e 100644 --- a/x/emissions/abci.go +++ b/x/emissions/abci.go @@ -14,7 +14,15 @@ 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())) @@ -22,11 +30,6 @@ func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) { } // 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 diff --git a/x/emissions/types/message_update_params_test.go b/x/emissions/types/message_update_params_test.go index 44b37e8fa2..5a286d3ad2 100644 --- a/x/emissions/types/message_update_params_test.go +++ b/x/emissions/types/message_update_params_test.go @@ -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(), diff --git a/x/emissions/types/params.go b/x/emissions/types/params.go index 10477db82f..715c615b9d 100644 --- a/x/emissions/types/params.go +++ b/x/emissions/types/params.go @@ -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, } } @@ -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) } @@ -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 +} diff --git a/x/emissions/types/params.pb.go b/x/emissions/types/params.pb.go index e32f5bf55a..bcd6ada699 100644 --- a/x/emissions/types/params.pb.go +++ b/x/emissions/types/params.pb.go @@ -31,6 +31,7 @@ type Params struct { TssSignerEmissionPercentage string `protobuf:"bytes,7,opt,name=tss_signer_emission_percentage,json=tssSignerEmissionPercentage,proto3" json:"tss_signer_emission_percentage,omitempty"` ObserverSlashAmount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,9,opt,name=observer_slash_amount,json=observerSlashAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"observer_slash_amount"` BallotMaturityBlocks int64 `protobuf:"varint,10,opt,name=ballot_maturity_blocks,json=ballotMaturityBlocks,proto3" json:"ballot_maturity_blocks,omitempty"` + BlockRewardAmount github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,11,opt,name=block_reward_amount,json=blockRewardAmount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"block_reward_amount"` } func (m *Params) Reset() { *m = Params{} } @@ -102,30 +103,32 @@ func init() { } var fileDescriptor_259272924aec0acf = []byte{ - // 364 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xc1, 0x4e, 0xea, 0x40, - 0x14, 0x86, 0xdb, 0x7b, 0x81, 0x0b, 0xb3, 0x22, 0xbd, 0x68, 0x08, 0x62, 0x21, 0x2e, 0x0c, 0x26, - 0xd2, 0x2e, 0x74, 0xe5, 0x4a, 0x6b, 0x34, 0x91, 0xc4, 0x84, 0xc0, 0xce, 0x4d, 0x33, 0x2d, 0x93, - 0xd2, 0xd0, 0xf6, 0x34, 0x73, 0x06, 0x22, 0x3e, 0x85, 0x4b, 0x97, 0x3e, 0x0e, 0x4b, 0x96, 0xc6, - 0x05, 0x31, 0xf0, 0x20, 0x9a, 0x4e, 0x69, 0xc3, 0x02, 0x57, 0x33, 0xc9, 0xf9, 0xfe, 0x2f, 0x7f, - 0x72, 0x0e, 0x39, 0x7b, 0x61, 0x82, 0xba, 0x63, 0xea, 0x47,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, 0x00, 0xee, 0x04, 0xeb, 0xa4, 0xad, 0x76, 0xfe, 0x0e, 0x6a, 0xe9, 0xf4, 0x71, 0x3b, 0xb4, - 0xe4, 0xec, 0xaa, 0xf0, 0xf6, 0xde, 0x52, 0x7a, 0x85, 0xb2, 0x5a, 0x2d, 0xf6, 0x0a, 0xe5, 0x72, - 0xb5, 0x62, 0xdd, 0x2f, 0xd6, 0xba, 0xba, 0x5c, 0xeb, 0xea, 0xd7, 0x5a, 0x57, 0x5f, 0x37, 0xba, - 0xb2, 0xdc, 0xe8, 0xca, 0xc7, 0x46, 0x57, 0x9e, 0xce, 0x77, 0xea, 0x25, 0x0b, 0xed, 0xa6, 0x67, - 0x10, 0xc1, 0x88, 0x99, 0xcf, 0x3b, 0x47, 0x20, 0x8b, 0x3a, 0x25, 0xb9, 0xd0, 0x8b, 0x9f, 0x00, - 0x00, 0x00, 0xff, 0xff, 0xe6, 0x06, 0x30, 0xf9, 0x31, 0x02, 0x00, 0x00, + // 393 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xbb, 0x6e, 0xe2, 0x40, + 0x14, 0x86, 0x6d, 0x71, 0x59, 0x98, 0x6d, 0x58, 0xc3, 0xae, 0x10, 0xcb, 0x1a, 0xb4, 0xc5, 0x8a, + 0x95, 0x82, 0x5d, 0x24, 0x55, 0xaa, 0xc4, 0xb9, 0x48, 0x41, 0x8a, 0x84, 0x4c, 0x97, 0x22, 0xd6, + 0xd8, 0x1e, 0x19, 0x0b, 0xdb, 0x63, 0xcd, 0x19, 0x48, 0xc8, 0x53, 0xa4, 0x4c, 0x99, 0xc7, 0xa1, + 0xa4, 0x8c, 0x52, 0x90, 0x08, 0x5e, 0x24, 0xf2, 0x18, 0x5b, 0x14, 0xa4, 0x48, 0x35, 0x23, 0x9d, + 0xef, 0x7c, 0xe7, 0x2f, 0x7e, 0xf4, 0xff, 0x81, 0x70,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 0x3e, 0x65, 0x3e, 0x9f, 0x5b, 0x76, 0x40, 0x9d, 0x09, 0x34, 0x51, 0x57, 0xee, 0x15, 0xcc, 0x46, + 0x3a, 0xbd, 0xde, 0x0e, 0x0d, 0x31, 0x53, 0x6e, 0x51, 0x5d, 0x50, 0x16, 0x23, 0x77, 0x98, 0xb9, + 0x59, 0xae, 0xef, 0x5f, 0xce, 0x75, 0x4e, 0x1c, 0xf3, 0x87, 0x50, 0x99, 0xc2, 0x94, 0xa6, 0x3a, + 0x2e, 0x3e, 0x3d, 0x77, 0xa4, 0x41, 0xb1, 0x22, 0xd7, 0x4a, 0x83, 0x62, 0xa5, 0x52, 0xab, 0x1a, + 0x97, 0x8b, 0xb5, 0x2a, 0x2f, 0xd7, 0xaa, 0xfc, 0xbe, 0x56, 0xe5, 0xc7, 0x8d, 0x2a, 0x2d, 0x37, + 0xaa, 0xf4, 0xb2, 0x51, 0xa5, 0x9b, 0x83, 0x9d, 0x33, 0x49, 0x61, 0xfa, 0x69, 0xcd, 0x22, 0xea, + 0x12, 0xfd, 0x7e, 0xa7, 0x64, 0xe2, 0xa0, 0x5d, 0x16, 0x85, 0x39, 0xfc, 0x08, 0x00, 0x00, 0xff, + 0xff, 0xfa, 0xc0, 0x3f, 0x91, 0x91, 0x02, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -148,6 +151,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.BlockRewardAmount.Size() + i -= size + if _, err := m.BlockRewardAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x5a if m.BallotMaturityBlocks != 0 { i = encodeVarintParams(dAtA, i, uint64(m.BallotMaturityBlocks)) i-- @@ -221,6 +234,8 @@ func (m *Params) Size() (n int) { if m.BallotMaturityBlocks != 0 { n += 1 + sovParams(uint64(m.BallotMaturityBlocks)) } + l = m.BlockRewardAmount.Size() + n += 1 + l + sovParams(uint64(l)) return n } @@ -408,6 +423,40 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockRewardAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.BlockRewardAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/emissions/types/params_test.go b/x/emissions/types/params_test.go index a90c4d9e05..99e6dd0ff5 100644 --- a/x/emissions/types/params_test.go +++ b/x/emissions/types/params_test.go @@ -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()