From f8e3ed637efa41f3b7e96630a94008afbf5c7209 Mon Sep 17 00:00:00 2001 From: drklee3 Date: Wed, 13 Sep 2023 13:03:47 -0700 Subject: [PATCH 1/9] Add RewardsPerSecond param to community --- docs/core/proto-docs.md | 1 + proto/kava/community/v1beta1/params.proto | 3 + x/community/genesis_test.go | 18 +++- x/community/keeper/grpc_query_test.go | 5 +- x/community/keeper/params_test.go | 6 +- x/community/types/params.go | 17 +++- x/community/types/params.pb.go | 104 +++++++++++++++++----- x/community/types/params_test.go | 56 ++++++++++++ 8 files changed, 179 insertions(+), 31 deletions(-) create mode 100644 x/community/types/params_test.go diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index da7dd77bdc..8fad67dedc 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -2906,6 +2906,7 @@ Params defines the parameters of the community module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `upgrade_time_disable_inflation` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | | +| `rewards_per_second` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | diff --git a/proto/kava/community/v1beta1/params.proto b/proto/kava/community/v1beta1/params.proto index 78cf7db6c2..c2c5219405 100644 --- a/proto/kava/community/v1beta1/params.proto +++ b/proto/kava/community/v1beta1/params.proto @@ -1,6 +1,7 @@ syntax = "proto3"; package kava.community.v1beta1; +import "cosmos/base/v1beta1/coin.proto"; import "gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; @@ -12,4 +13,6 @@ message Params { (gogoproto.stdtime) = true, (gogoproto.nullable) = false ]; + + cosmos.base.v1beta1.Coin rewards_per_second = 2 [(gogoproto.nullable) = false]; } diff --git a/x/community/genesis_test.go b/x/community/genesis_test.go index 4904e45c48..59fa6ee78a 100644 --- a/x/community/genesis_test.go +++ b/x/community/genesis_test.go @@ -6,6 +6,8 @@ import ( "github.com/stretchr/testify/suite" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/kava-labs/kava/x/community" @@ -30,7 +32,10 @@ func (suite *genesisTestSuite) TestInitGenesis() { accountKeeper := suite.App.GetAccountKeeper() genesisState := types.NewGenesisState( - types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)), + types.NewParams( + time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), + sdk.NewCoin("ukava", sdkmath.NewInt(1000)), + ), ) suite.NotPanics(func() { @@ -49,8 +54,10 @@ func (suite *genesisTestSuite) TestInitGenesis() { } func (suite *genesisTestSuite) TestExportGenesis() { - - params := types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)) + params := types.NewParams( + time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), + sdk.NewCoin("ukava", sdkmath.NewInt(1000)), + ) suite.Keeper.SetParams(suite.Ctx, params) genesisState := community.ExportGenesis(suite.Ctx, suite.Keeper) @@ -60,7 +67,10 @@ func (suite *genesisTestSuite) TestExportGenesis() { func (suite *genesisTestSuite) TestInitExportIsLossless() { genesisState := types.NewGenesisState( - types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)), + types.NewParams( + time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), + sdk.NewCoin("ukava", sdkmath.NewInt(1000)), + ), ) community.InitGenesis(suite.Ctx, suite.Keeper, suite.App.GetAccountKeeper(), genesisState) diff --git a/x/community/keeper/grpc_query_test.go b/x/community/keeper/grpc_query_test.go index 7ab06051a8..f6c6b794be 100644 --- a/x/community/keeper/grpc_query_test.go +++ b/x/community/keeper/grpc_query_test.go @@ -34,7 +34,10 @@ func TestGrpcQueryTestSuite(t *testing.T) { } func (suite *grpcQueryTestSuite) TestGrpcQueryParams() { - p := types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)) + p := types.NewParams( + time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), + sdk.NewCoin("ukava", sdkmath.NewInt(1000)), + ) suite.Keeper.SetParams(suite.Ctx, p) res, err := suite.queryClient.Params(context.Background(), &types.QueryParamsRequest{}) diff --git a/x/community/keeper/params_test.go b/x/community/keeper/params_test.go index c0b4008f85..37189e3d05 100644 --- a/x/community/keeper/params_test.go +++ b/x/community/keeper/params_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -59,7 +60,10 @@ func (suite *StoreTestSuite) TestGetSetParams() { suite.Run("set overwrite previous value", func() { suite.Keeper.SetParams(suite.Ctx, types.DefaultParams()) - params := types.NewParams(time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)) + params := types.NewParams( + time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), + sdk.NewCoin("ukava", sdkmath.NewInt(1000)), + ) suite.Keeper.SetParams(suite.Ctx, params) storedParams, found := suite.Keeper.GetParams(suite.Ctx) diff --git a/x/community/types/params.go b/x/community/types/params.go index 9d6518b01e..ee3bd557c5 100644 --- a/x/community/types/params.go +++ b/x/community/types/params.go @@ -1,15 +1,23 @@ package types -import "time" +import ( + fmt "fmt" + "time" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) var ( DefaultUpgradeTimeDisableInflation = time.Time{} + DefaultRewardsPerSecond = sdk.NewCoin("ukava", sdkmath.ZeroInt()) ) // NewParams returns a new params object -func NewParams(upgradeTime time.Time) Params { +func NewParams(upgradeTime time.Time, rewardsPerSecond sdk.Coin) Params { return Params{ UpgradeTimeDisableInflation: upgradeTime, + RewardsPerSecond: rewardsPerSecond, } } @@ -17,10 +25,15 @@ func NewParams(upgradeTime time.Time) Params { func DefaultParams() Params { return NewParams( DefaultUpgradeTimeDisableInflation, + DefaultRewardsPerSecond, ) } // Validate checks the params are valid func (p Params) Validate() error { + if err := p.RewardsPerSecond.Validate(); err != nil { + return fmt.Errorf("invalid rewards per second: %w", err) + } + return nil } diff --git a/x/community/types/params.pb.go b/x/community/types/params.pb.go index bc31ad1c91..19905204cd 100644 --- a/x/community/types/params.pb.go +++ b/x/community/types/params.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" @@ -29,7 +30,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters of the community module. type Params struct { - UpgradeTimeDisableInflation time.Time `protobuf:"bytes,1,opt,name=upgrade_time_disable_inflation,json=upgradeTimeDisableInflation,proto3,stdtime" json:"upgrade_time_disable_inflation"` + UpgradeTimeDisableInflation time.Time `protobuf:"bytes,1,opt,name=upgrade_time_disable_inflation,json=upgradeTimeDisableInflation,proto3,stdtime" json:"upgrade_time_disable_inflation"` + RewardsPerSecond types.Coin `protobuf:"bytes,2,opt,name=rewards_per_second,json=rewardsPerSecond,proto3" json:"rewards_per_second"` } func (m *Params) Reset() { *m = Params{} } @@ -72,6 +74,13 @@ func (m *Params) GetUpgradeTimeDisableInflation() time.Time { return time.Time{} } +func (m *Params) GetRewardsPerSecond() types.Coin { + if m != nil { + return m.RewardsPerSecond + } + return types.Coin{} +} + func init() { proto.RegisterType((*Params)(nil), "kava.community.v1beta1.Params") } @@ -81,23 +90,27 @@ func init() { } var fileDescriptor_0a48475520900507 = []byte{ - // 251 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xc1, 0x4a, 0x03, 0x31, - 0x10, 0x86, 0x37, 0x97, 0x22, 0xeb, 0xad, 0x88, 0xc8, 0x0a, 0x59, 0xd1, 0x8b, 0x20, 0x26, 0x54, - 0xdf, 0xa0, 0xe8, 0xc1, 0x9b, 0x88, 0x27, 0x2f, 0xcb, 0xc4, 0xa6, 0x31, 0xb8, 0xd9, 0x84, 0xcd, - 0x6c, 0xb1, 0x6f, 0xd1, 0xc7, 0xea, 0xb1, 0x47, 0x4f, 0x2a, 0xbb, 0x2f, 0x22, 0x49, 0xba, 0xe2, - 0xed, 0x1f, 0xe6, 0xe3, 0x63, 0xfe, 0xc9, 0x2f, 0xde, 0x61, 0x05, 0xfc, 0xd5, 0x1a, 0xd3, 0x35, - 0x1a, 0xd7, 0x7c, 0x35, 0x13, 0x12, 0x61, 0xc6, 0x1d, 0xb4, 0x60, 0x3c, 0x73, 0xad, 0x45, 0x3b, - 0x3d, 0x0e, 0x10, 0xfb, 0x83, 0xd8, 0x1e, 0x2a, 0x8e, 0x94, 0x55, 0x36, 0x22, 0x3c, 0xa4, 0x44, - 0x17, 0xa5, 0xb2, 0x56, 0xd5, 0x92, 0xc7, 0x49, 0x74, 0x4b, 0x8e, 0xda, 0x48, 0x8f, 0x60, 0x5c, - 0x02, 0xce, 0x7d, 0x3e, 0x79, 0x8c, 0xfa, 0xa9, 0xce, 0x69, 0xe7, 0x54, 0x0b, 0x0b, 0x59, 0x05, - 0xa8, 0x5a, 0x68, 0x0f, 0xa2, 0x96, 0x95, 0x6e, 0x96, 0x35, 0xa0, 0xb6, 0xcd, 0x09, 0x39, 0x23, - 0x97, 0x87, 0x37, 0x05, 0x4b, 0x4e, 0x36, 0x3a, 0xd9, 0xf3, 0xe8, 0x9c, 0x1f, 0x6c, 0xbf, 0xca, - 0x6c, 0xf3, 0x5d, 0x92, 0xa7, 0xd3, 0xbd, 0x2b, 0xec, 0xee, 0x92, 0xe9, 0x61, 0x14, 0xcd, 0xef, - 0xb7, 0x3d, 0x25, 0xbb, 0x9e, 0x92, 0x9f, 0x9e, 0x92, 0xcd, 0x40, 0xb3, 0xdd, 0x40, 0xb3, 0xcf, - 0x81, 0x66, 0x2f, 0x57, 0x4a, 0xe3, 0x5b, 0x27, 0x42, 0x3f, 0x1e, 0x8a, 0x5e, 0xd7, 0x20, 0x7c, - 0x4c, 0xfc, 0xe3, 0xdf, 0x67, 0x70, 0xed, 0xa4, 0x17, 0x93, 0x78, 0xc1, 0xed, 0x6f, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x17, 0xd9, 0x52, 0x52, 0x38, 0x01, 0x00, 0x00, + // 314 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xc1, 0x4a, 0xc3, 0x30, + 0x1c, 0xc6, 0x1b, 0x91, 0x21, 0xf5, 0x22, 0x45, 0x64, 0x4e, 0xc8, 0x44, 0x2f, 0x82, 0x98, 0x30, + 0x7d, 0x83, 0xa9, 0x07, 0x0f, 0xc2, 0x98, 0x9e, 0xbc, 0x94, 0xa4, 0xcd, 0x6a, 0xb0, 0xed, 0x3f, + 0x24, 0xe9, 0x74, 0x6f, 0xb1, 0x67, 0xf2, 0xb4, 0xe3, 0x8e, 0x9e, 0x54, 0xd6, 0x17, 0x91, 0xa4, + 0xed, 0xf0, 0xf6, 0x25, 0xf9, 0xbe, 0x5f, 0xf8, 0xfe, 0xff, 0xf0, 0xfc, 0x8d, 0xcd, 0x19, 0x4d, + 0xa0, 0x28, 0xaa, 0x52, 0xda, 0x05, 0x9d, 0x8f, 0xb8, 0xb0, 0x6c, 0x44, 0x15, 0xd3, 0xac, 0x30, + 0x44, 0x69, 0xb0, 0x10, 0x1d, 0x39, 0x13, 0xd9, 0x9a, 0x48, 0x6b, 0x1a, 0xe0, 0x04, 0x4c, 0x01, + 0x86, 0x72, 0x66, 0xc4, 0x36, 0x99, 0x80, 0x2c, 0x9b, 0xdc, 0xe0, 0x30, 0x83, 0x0c, 0xbc, 0xa4, + 0x4e, 0xb5, 0xb7, 0xc3, 0x0c, 0x20, 0xcb, 0x05, 0xf5, 0x27, 0x5e, 0xcd, 0xa8, 0x95, 0x85, 0x30, + 0x96, 0x15, 0xaa, 0x31, 0x9c, 0x7d, 0xa2, 0xb0, 0x37, 0xf1, 0xff, 0x47, 0x32, 0xc4, 0x95, 0xca, + 0x34, 0x4b, 0x45, 0xec, 0x5c, 0x71, 0x2a, 0x0d, 0xe3, 0xb9, 0x88, 0x65, 0x39, 0xcb, 0x99, 0x95, + 0x50, 0xf6, 0xd1, 0x29, 0xba, 0xd8, 0xbf, 0x1e, 0x90, 0x06, 0x4a, 0x3a, 0x28, 0x79, 0xee, 0xa0, + 0xe3, 0xbd, 0xd5, 0xf7, 0x30, 0x58, 0xfe, 0x0c, 0xd1, 0xf4, 0xa4, 0x65, 0xb9, 0xb7, 0xbb, 0x86, + 0xf4, 0xd0, 0x81, 0xa2, 0xc7, 0x30, 0xd2, 0xe2, 0x9d, 0xe9, 0xd4, 0xc4, 0x4a, 0xe8, 0xd8, 0x88, + 0x04, 0xca, 0xb4, 0xbf, 0xe3, 0xf1, 0xc7, 0xa4, 0x69, 0x4a, 0x5c, 0xd3, 0xae, 0x3e, 0xb9, 0x05, + 0x59, 0x8e, 0x77, 0x1d, 0x7d, 0x7a, 0xd0, 0x46, 0x27, 0x42, 0x3f, 0xf9, 0xe0, 0xf8, 0x7e, 0xb5, + 0xc1, 0x68, 0xbd, 0xc1, 0xe8, 0x77, 0x83, 0xd1, 0xb2, 0xc6, 0xc1, 0xba, 0xc6, 0xc1, 0x57, 0x8d, + 0x83, 0x97, 0xcb, 0x4c, 0xda, 0xd7, 0x8a, 0xbb, 0x79, 0x52, 0x37, 0xd8, 0xab, 0x9c, 0x71, 0xe3, + 0x15, 0xfd, 0xf8, 0xb7, 0x09, 0xbb, 0x50, 0xc2, 0xf0, 0x9e, 0x2f, 0x74, 0xf3, 0x17, 0x00, 0x00, + 0xff, 0xff, 0x11, 0x8a, 0x61, 0x75, 0xa8, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -120,12 +133,22 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.UpgradeTimeDisableInflation, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.UpgradeTimeDisableInflation):]) - if err1 != nil { - return 0, err1 + { + size, err := m.RewardsPerSecond.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.UpgradeTimeDisableInflation, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.UpgradeTimeDisableInflation):]) + if err2 != nil { + return 0, err2 } - i -= n1 - i = encodeVarintParams(dAtA, i, uint64(n1)) + i -= n2 + i = encodeVarintParams(dAtA, i, uint64(n2)) i-- dAtA[i] = 0xa return len(dAtA) - i, nil @@ -150,6 +173,8 @@ func (m *Params) Size() (n int) { _ = l l = github_com_gogo_protobuf_types.SizeOfStdTime(m.UpgradeTimeDisableInflation) n += 1 + l + sovParams(uint64(l)) + l = m.RewardsPerSecond.Size() + n += 1 + l + sovParams(uint64(l)) return n } @@ -221,6 +246,39 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardsPerSecond", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.RewardsPerSecond.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/community/types/params_test.go b/x/community/types/params_test.go new file mode 100644 index 0000000000..2b093a7b99 --- /dev/null +++ b/x/community/types/params_test.go @@ -0,0 +1,56 @@ +package types_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/community/types" +) + +func TestParamsValidate(t *testing.T) { + testCases := []struct { + name string + params types.Params + expectedErr string + }{ + { + name: "valid parms", + params: types.Params{ + UpgradeTimeDisableInflation: time.Time{}, + RewardsPerSecond: sdk.NewCoin( + "ukava", + sdkmath.NewInt(1000), + ), + }, + expectedErr: "", + }, + { + name: "invalid rewards per second", + params: types.Params{ + UpgradeTimeDisableInflation: time.Time{}, + RewardsPerSecond: sdk.Coin{ + Denom: "ukava", + Amount: sdkmath.NewInt(-1), + }, + }, + expectedErr: "invalid rewards per second: negative coin amount: -1", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := tc.params.Validate() + + if tc.expectedErr == "" { + require.NoError(t, err) + } else { + require.Error(t, err) + require.Contains(t, err.Error(), tc.expectedErr) + } + }) + } +} From 2371f72c0b5ed79affa9f4da752643ea475c233c Mon Sep 17 00:00:00 2001 From: drklee3 Date: Thu, 14 Sep 2023 11:39:36 -0700 Subject: [PATCH 2/9] Update rewards per second param to int --- docs/core/proto-docs.md | 2 +- proto/kava/community/v1beta1/params.proto | 8 ++- x/community/genesis_test.go | 7 +- x/community/keeper/grpc_query_test.go | 2 +- x/community/keeper/params_test.go | 2 +- x/community/types/params.go | 15 +++-- x/community/types/params.pb.go | 82 +++++++++++------------ x/community/types/params_test.go | 23 ++++--- 8 files changed, 72 insertions(+), 69 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 8fad67dedc..0cc1d2bea3 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -2906,7 +2906,7 @@ Params defines the parameters of the community module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `upgrade_time_disable_inflation` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | | -| `rewards_per_second` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `rewards_per_second` | [string](#string) | | | diff --git a/proto/kava/community/v1beta1/params.proto b/proto/kava/community/v1beta1/params.proto index c2c5219405..fd4aefd621 100644 --- a/proto/kava/community/v1beta1/params.proto +++ b/proto/kava/community/v1beta1/params.proto @@ -1,7 +1,7 @@ syntax = "proto3"; package kava.community.v1beta1; -import "cosmos/base/v1beta1/coin.proto"; +import "cosmos_proto/cosmos.proto"; import "gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; @@ -14,5 +14,9 @@ message Params { (gogoproto.nullable) = false ]; - cosmos.base.v1beta1.Coin rewards_per_second = 2 [(gogoproto.nullable) = false]; + string rewards_per_second = 2 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; } diff --git a/x/community/genesis_test.go b/x/community/genesis_test.go index 59fa6ee78a..aa780115c4 100644 --- a/x/community/genesis_test.go +++ b/x/community/genesis_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/suite" sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/kava-labs/kava/x/community" @@ -34,7 +33,7 @@ func (suite *genesisTestSuite) TestInitGenesis() { genesisState := types.NewGenesisState( types.NewParams( time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), - sdk.NewCoin("ukava", sdkmath.NewInt(1000)), + sdkmath.NewInt(1000), ), ) @@ -56,7 +55,7 @@ func (suite *genesisTestSuite) TestInitGenesis() { func (suite *genesisTestSuite) TestExportGenesis() { params := types.NewParams( time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), - sdk.NewCoin("ukava", sdkmath.NewInt(1000)), + sdkmath.NewInt(1000), ) suite.Keeper.SetParams(suite.Ctx, params) @@ -69,7 +68,7 @@ func (suite *genesisTestSuite) TestInitExportIsLossless() { genesisState := types.NewGenesisState( types.NewParams( time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), - sdk.NewCoin("ukava", sdkmath.NewInt(1000)), + sdkmath.NewInt(1000), ), ) diff --git a/x/community/keeper/grpc_query_test.go b/x/community/keeper/grpc_query_test.go index f6c6b794be..d414a77986 100644 --- a/x/community/keeper/grpc_query_test.go +++ b/x/community/keeper/grpc_query_test.go @@ -36,7 +36,7 @@ func TestGrpcQueryTestSuite(t *testing.T) { func (suite *grpcQueryTestSuite) TestGrpcQueryParams() { p := types.NewParams( time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), - sdk.NewCoin("ukava", sdkmath.NewInt(1000)), + sdkmath.NewInt(1000), ) suite.Keeper.SetParams(suite.Ctx, p) diff --git a/x/community/keeper/params_test.go b/x/community/keeper/params_test.go index 37189e3d05..ec744dca8c 100644 --- a/x/community/keeper/params_test.go +++ b/x/community/keeper/params_test.go @@ -62,7 +62,7 @@ func (suite *StoreTestSuite) TestGetSetParams() { params := types.NewParams( time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC), - sdk.NewCoin("ukava", sdkmath.NewInt(1000)), + sdkmath.NewInt(1000), ) suite.Keeper.SetParams(suite.Ctx, params) diff --git a/x/community/types/params.go b/x/community/types/params.go index ee3bd557c5..4c32d20160 100644 --- a/x/community/types/params.go +++ b/x/community/types/params.go @@ -1,20 +1,19 @@ package types import ( - fmt "fmt" + "errors" "time" sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" ) var ( DefaultUpgradeTimeDisableInflation = time.Time{} - DefaultRewardsPerSecond = sdk.NewCoin("ukava", sdkmath.ZeroInt()) + DefaultRewardsPerSecond = sdkmath.ZeroInt() ) // NewParams returns a new params object -func NewParams(upgradeTime time.Time, rewardsPerSecond sdk.Coin) Params { +func NewParams(upgradeTime time.Time, rewardsPerSecond sdkmath.Int) Params { return Params{ UpgradeTimeDisableInflation: upgradeTime, RewardsPerSecond: rewardsPerSecond, @@ -31,8 +30,12 @@ func DefaultParams() Params { // Validate checks the params are valid func (p Params) Validate() error { - if err := p.RewardsPerSecond.Validate(); err != nil { - return fmt.Errorf("invalid rewards per second: %w", err) + if p.RewardsPerSecond.IsNil() { + return errors.New("rewards per second should not be nil") + } + + if p.RewardsPerSecond.IsNegative() { + return errors.New("rewards per second should not be negative") } return nil diff --git a/x/community/types/params.pb.go b/x/community/types/params.pb.go index 19905204cd..af9efc942d 100644 --- a/x/community/types/params.pb.go +++ b/x/community/types/params.pb.go @@ -4,8 +4,9 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" - types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-proto" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" @@ -30,8 +31,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters of the community module. type Params struct { - UpgradeTimeDisableInflation time.Time `protobuf:"bytes,1,opt,name=upgrade_time_disable_inflation,json=upgradeTimeDisableInflation,proto3,stdtime" json:"upgrade_time_disable_inflation"` - RewardsPerSecond types.Coin `protobuf:"bytes,2,opt,name=rewards_per_second,json=rewardsPerSecond,proto3" json:"rewards_per_second"` + UpgradeTimeDisableInflation time.Time `protobuf:"bytes,1,opt,name=upgrade_time_disable_inflation,json=upgradeTimeDisableInflation,proto3,stdtime" json:"upgrade_time_disable_inflation"` + RewardsPerSecond cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=rewards_per_second,json=rewardsPerSecond,proto3,customtype=cosmossdk.io/math.Int" json:"rewards_per_second"` } func (m *Params) Reset() { *m = Params{} } @@ -74,13 +75,6 @@ func (m *Params) GetUpgradeTimeDisableInflation() time.Time { return time.Time{} } -func (m *Params) GetRewardsPerSecond() types.Coin { - if m != nil { - return m.RewardsPerSecond - } - return types.Coin{} -} - func init() { proto.RegisterType((*Params)(nil), "kava.community.v1beta1.Params") } @@ -90,27 +84,28 @@ func init() { } var fileDescriptor_0a48475520900507 = []byte{ - // 314 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xc1, 0x4a, 0xc3, 0x30, - 0x1c, 0xc6, 0x1b, 0x91, 0x21, 0xf5, 0x22, 0x45, 0x64, 0x4e, 0xc8, 0x44, 0x2f, 0x82, 0x98, 0x30, - 0x7d, 0x83, 0xa9, 0x07, 0x0f, 0xc2, 0x98, 0x9e, 0xbc, 0x94, 0xa4, 0xcd, 0x6a, 0xb0, 0xed, 0x3f, - 0x24, 0xe9, 0x74, 0x6f, 0xb1, 0x67, 0xf2, 0xb4, 0xe3, 0x8e, 0x9e, 0x54, 0xd6, 0x17, 0x91, 0xa4, - 0xed, 0xf0, 0xf6, 0x25, 0xf9, 0xbe, 0x5f, 0xf8, 0xfe, 0xff, 0xf0, 0xfc, 0x8d, 0xcd, 0x19, 0x4d, - 0xa0, 0x28, 0xaa, 0x52, 0xda, 0x05, 0x9d, 0x8f, 0xb8, 0xb0, 0x6c, 0x44, 0x15, 0xd3, 0xac, 0x30, - 0x44, 0x69, 0xb0, 0x10, 0x1d, 0x39, 0x13, 0xd9, 0x9a, 0x48, 0x6b, 0x1a, 0xe0, 0x04, 0x4c, 0x01, - 0x86, 0x72, 0x66, 0xc4, 0x36, 0x99, 0x80, 0x2c, 0x9b, 0xdc, 0xe0, 0x30, 0x83, 0x0c, 0xbc, 0xa4, - 0x4e, 0xb5, 0xb7, 0xc3, 0x0c, 0x20, 0xcb, 0x05, 0xf5, 0x27, 0x5e, 0xcd, 0xa8, 0x95, 0x85, 0x30, - 0x96, 0x15, 0xaa, 0x31, 0x9c, 0x7d, 0xa2, 0xb0, 0x37, 0xf1, 0xff, 0x47, 0x32, 0xc4, 0x95, 0xca, - 0x34, 0x4b, 0x45, 0xec, 0x5c, 0x71, 0x2a, 0x0d, 0xe3, 0xb9, 0x88, 0x65, 0x39, 0xcb, 0x99, 0x95, - 0x50, 0xf6, 0xd1, 0x29, 0xba, 0xd8, 0xbf, 0x1e, 0x90, 0x06, 0x4a, 0x3a, 0x28, 0x79, 0xee, 0xa0, - 0xe3, 0xbd, 0xd5, 0xf7, 0x30, 0x58, 0xfe, 0x0c, 0xd1, 0xf4, 0xa4, 0x65, 0xb9, 0xb7, 0xbb, 0x86, - 0xf4, 0xd0, 0x81, 0xa2, 0xc7, 0x30, 0xd2, 0xe2, 0x9d, 0xe9, 0xd4, 0xc4, 0x4a, 0xe8, 0xd8, 0x88, - 0x04, 0xca, 0xb4, 0xbf, 0xe3, 0xf1, 0xc7, 0xa4, 0x69, 0x4a, 0x5c, 0xd3, 0xae, 0x3e, 0xb9, 0x05, - 0x59, 0x8e, 0x77, 0x1d, 0x7d, 0x7a, 0xd0, 0x46, 0x27, 0x42, 0x3f, 0xf9, 0xe0, 0xf8, 0x7e, 0xb5, - 0xc1, 0x68, 0xbd, 0xc1, 0xe8, 0x77, 0x83, 0xd1, 0xb2, 0xc6, 0xc1, 0xba, 0xc6, 0xc1, 0x57, 0x8d, - 0x83, 0x97, 0xcb, 0x4c, 0xda, 0xd7, 0x8a, 0xbb, 0x79, 0x52, 0x37, 0xd8, 0xab, 0x9c, 0x71, 0xe3, - 0x15, 0xfd, 0xf8, 0xb7, 0x09, 0xbb, 0x50, 0xc2, 0xf0, 0x9e, 0x2f, 0x74, 0xf3, 0x17, 0x00, 0x00, - 0xff, 0xff, 0x11, 0x8a, 0x61, 0x75, 0xa8, 0x01, 0x00, 0x00, + // 328 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xc1, 0x4e, 0xc2, 0x30, + 0x18, 0xc7, 0x57, 0x0f, 0x44, 0xe7, 0xc5, 0x2c, 0x6a, 0x10, 0x93, 0x8e, 0xe8, 0x85, 0x84, 0xd0, + 0x06, 0x7d, 0x03, 0xa2, 0x07, 0x6e, 0x04, 0xbd, 0xe8, 0x65, 0xe9, 0x58, 0x19, 0x0d, 0xeb, 0xba, + 0xb4, 0x1d, 0xca, 0x5b, 0xf0, 0x30, 0x3e, 0x04, 0x27, 0x43, 0x3c, 0x19, 0x0f, 0x68, 0xe0, 0x45, + 0x4c, 0xdb, 0xcd, 0x78, 0xfb, 0xbe, 0xaf, 0xbf, 0xfe, 0x9a, 0xff, 0x57, 0xff, 0x7a, 0x4e, 0x16, + 0x04, 0x4f, 0x04, 0xe7, 0x65, 0xce, 0xf4, 0x12, 0x2f, 0xfa, 0x31, 0xd5, 0xa4, 0x8f, 0x0b, 0x22, + 0x09, 0x57, 0xa8, 0x90, 0x42, 0x8b, 0xe0, 0xdc, 0x40, 0xe8, 0x0f, 0x42, 0x15, 0xd4, 0xba, 0x98, + 0x08, 0xc5, 0x85, 0x8a, 0x2c, 0x85, 0x5d, 0xe3, 0xae, 0xb4, 0x4e, 0x53, 0x91, 0x0a, 0x37, 0x37, + 0x55, 0x35, 0x0d, 0x53, 0x21, 0xd2, 0x8c, 0x62, 0xdb, 0xc5, 0xe5, 0x14, 0x6b, 0xc6, 0xa9, 0xd2, + 0x84, 0x17, 0x0e, 0xb8, 0x7a, 0x07, 0x7e, 0x63, 0x64, 0x9f, 0x0e, 0x98, 0x0f, 0xcb, 0x22, 0x95, + 0x24, 0xa1, 0x91, 0xa1, 0xa2, 0x84, 0x29, 0x12, 0x67, 0x34, 0x62, 0xf9, 0x34, 0x23, 0x9a, 0x89, + 0xbc, 0x09, 0xda, 0xa0, 0x73, 0x7c, 0xd3, 0x42, 0x4e, 0x8a, 0x6a, 0x29, 0x7a, 0xac, 0xa5, 0x83, + 0xc3, 0xf5, 0x36, 0xf4, 0x56, 0xdf, 0x21, 0x18, 0x5f, 0x56, 0x2e, 0x73, 0x76, 0xe7, 0x4c, 0xc3, + 0x5a, 0x14, 0x3c, 0xf9, 0x81, 0xa4, 0x2f, 0x44, 0x26, 0x2a, 0x2a, 0xa8, 0x8c, 0x14, 0x9d, 0x88, + 0x3c, 0x69, 0x1e, 0xb4, 0x41, 0xe7, 0x68, 0xd0, 0x35, 0x8a, 0xaf, 0x6d, 0x78, 0xe6, 0xe2, 0xa9, + 0x64, 0x8e, 0x98, 0xc0, 0x9c, 0xe8, 0x19, 0x1a, 0xe6, 0xfa, 0xe3, 0xad, 0xe7, 0x57, 0xb9, 0x87, + 0xb9, 0x1e, 0x9f, 0x54, 0x9a, 0x11, 0x95, 0x0f, 0x56, 0x32, 0xb8, 0x5f, 0xef, 0x20, 0xd8, 0xec, + 0x20, 0xf8, 0xd9, 0x41, 0xb0, 0xda, 0x43, 0x6f, 0xb3, 0x87, 0xde, 0xe7, 0x1e, 0x7a, 0xcf, 0xdd, + 0x94, 0xe9, 0x59, 0x19, 0x9b, 0xb5, 0x62, 0xb3, 0xdf, 0x5e, 0x46, 0x62, 0x65, 0x2b, 0xfc, 0xfa, + 0xef, 0x43, 0xf4, 0xb2, 0xa0, 0x2a, 0x6e, 0xd8, 0x70, 0xb7, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, + 0xc2, 0x53, 0xf7, 0x41, 0xaf, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -134,21 +129,21 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size, err := m.RewardsPerSecond.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { + size := m.RewardsPerSecond.Size() + i -= size + if _, err := m.RewardsPerSecond.MarshalTo(dAtA[i:]); err != nil { return 0, err } - i -= size i = encodeVarintParams(dAtA, i, uint64(size)) } i-- dAtA[i] = 0x12 - n2, err2 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.UpgradeTimeDisableInflation, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.UpgradeTimeDisableInflation):]) - if err2 != nil { - return 0, err2 + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.UpgradeTimeDisableInflation, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.UpgradeTimeDisableInflation):]) + if err1 != nil { + return 0, err1 } - i -= n2 - i = encodeVarintParams(dAtA, i, uint64(n2)) + i -= n1 + i = encodeVarintParams(dAtA, i, uint64(n1)) i-- dAtA[i] = 0xa return len(dAtA) - i, nil @@ -250,7 +245,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field RewardsPerSecond", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowParams @@ -260,15 +255,16 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthParams } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthParams } diff --git a/x/community/types/params_test.go b/x/community/types/params_test.go index 2b093a7b99..b6152fc903 100644 --- a/x/community/types/params_test.go +++ b/x/community/types/params_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/kava-labs/kava/x/community/types" ) @@ -21,23 +20,25 @@ func TestParamsValidate(t *testing.T) { name: "valid parms", params: types.Params{ UpgradeTimeDisableInflation: time.Time{}, - RewardsPerSecond: sdk.NewCoin( - "ukava", - sdkmath.NewInt(1000), - ), + RewardsPerSecond: sdkmath.NewInt(1000), }, expectedErr: "", }, { - name: "invalid rewards per second", + name: "nil rewards per second", params: types.Params{ UpgradeTimeDisableInflation: time.Time{}, - RewardsPerSecond: sdk.Coin{ - Denom: "ukava", - Amount: sdkmath.NewInt(-1), - }, + RewardsPerSecond: sdkmath.Int{}, }, - expectedErr: "invalid rewards per second: negative coin amount: -1", + expectedErr: "rewards per second should not be nil", + }, + { + name: "negative rewards per second", + params: types.Params{ + UpgradeTimeDisableInflation: time.Time{}, + RewardsPerSecond: sdkmath.NewInt(-5), + }, + expectedErr: "rewards per second should not be negative", }, } From 974caac4c6059a88b06a8f2b6b057b14e9142eef Mon Sep 17 00:00:00 2001 From: drklee3 Date: Thu, 14 Sep 2023 11:43:51 -0700 Subject: [PATCH 3/9] Add rewards_per_second to protonet genesis --- ci/env/kava-protonet/genesis.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/env/kava-protonet/genesis.json b/ci/env/kava-protonet/genesis.json index f3a94a101e..06d11c7caa 100644 --- a/ci/env/kava-protonet/genesis.json +++ b/ci/env/kava-protonet/genesis.json @@ -1316,7 +1316,8 @@ }, "community": { "params": { - "upgrade_time_disable_inflation": "2023-11-01T00:00:00Z" + "upgrade_time_disable_inflation": "2023-11-01T00:00:00Z", + "rewards_per_second": "744191" } }, "crisis": { From 179fdaf6f3f71140a818a5fff81435c016bff9b2 Mon Sep 17 00:00:00 2001 From: drklee3 Date: Thu, 14 Sep 2023 12:17:35 -0700 Subject: [PATCH 4/9] Use default rewards per second of 744191 --- x/community/types/params.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/community/types/params.go b/x/community/types/params.go index 4c32d20160..43d501c781 100644 --- a/x/community/types/params.go +++ b/x/community/types/params.go @@ -9,7 +9,8 @@ import ( var ( DefaultUpgradeTimeDisableInflation = time.Time{} - DefaultRewardsPerSecond = sdkmath.ZeroInt() + // DefaultRewardsPerSecond is ~4.6 KAVA per block, 6.3s block time + DefaultRewardsPerSecond = sdkmath.NewInt(744191) ) // NewParams returns a new params object From e42800355b624212f811cb538eb9d003f371e09d Mon Sep 17 00:00:00 2001 From: drklee3 Date: Thu, 14 Sep 2023 12:37:01 -0700 Subject: [PATCH 5/9] Include value if negative in Validate error --- x/community/types/params.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x/community/types/params.go b/x/community/types/params.go index 43d501c781..0b74f40c51 100644 --- a/x/community/types/params.go +++ b/x/community/types/params.go @@ -2,6 +2,7 @@ package types import ( "errors" + fmt "fmt" "time" sdkmath "cosmossdk.io/math" @@ -36,7 +37,7 @@ func (p Params) Validate() error { } if p.RewardsPerSecond.IsNegative() { - return errors.New("rewards per second should not be negative") + return fmt.Errorf("rewards per second should not be negative: %s", p.RewardsPerSecond) } return nil From 8759febc1909424ff8f5970a506a5e2f1bcb24fc Mon Sep 17 00:00:00 2001 From: drklee3 Date: Thu, 14 Sep 2023 13:39:25 -0700 Subject: [PATCH 6/9] Rename RewardsPerSecond param to StakingRewardsPerSecond --- proto/kava/community/v1beta1/params.proto | 2 +- x/community/types/params.go | 21 +++++---- x/community/types/params.pb.go | 56 +++++++++++------------ x/community/types/params_test.go | 10 ++-- 4 files changed, 46 insertions(+), 43 deletions(-) diff --git a/proto/kava/community/v1beta1/params.proto b/proto/kava/community/v1beta1/params.proto index fd4aefd621..57a29bc8ff 100644 --- a/proto/kava/community/v1beta1/params.proto +++ b/proto/kava/community/v1beta1/params.proto @@ -14,7 +14,7 @@ message Params { (gogoproto.nullable) = false ]; - string rewards_per_second = 2 [ + string staking_rewards_per_second = 2 [ (cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false diff --git a/x/community/types/params.go b/x/community/types/params.go index 0b74f40c51..aed1553187 100644 --- a/x/community/types/params.go +++ b/x/community/types/params.go @@ -10,15 +10,18 @@ import ( var ( DefaultUpgradeTimeDisableInflation = time.Time{} - // DefaultRewardsPerSecond is ~4.6 KAVA per block, 6.3s block time - DefaultRewardsPerSecond = sdkmath.NewInt(744191) + // DefaultStakingRewardsPerSecond is ~4.6 KAVA per block, 6.3s block time + DefaultStakingRewardsPerSecond = sdkmath.NewInt(744191) ) // NewParams returns a new params object -func NewParams(upgradeTime time.Time, rewardsPerSecond sdkmath.Int) Params { +func NewParams( + upgradeTime time.Time, + stakingRewardsPerSecond sdkmath.Int, +) Params { return Params{ UpgradeTimeDisableInflation: upgradeTime, - RewardsPerSecond: rewardsPerSecond, + StakingRewardsPerSecond: stakingRewardsPerSecond, } } @@ -26,18 +29,18 @@ func NewParams(upgradeTime time.Time, rewardsPerSecond sdkmath.Int) Params { func DefaultParams() Params { return NewParams( DefaultUpgradeTimeDisableInflation, - DefaultRewardsPerSecond, + DefaultStakingRewardsPerSecond, ) } // Validate checks the params are valid func (p Params) Validate() error { - if p.RewardsPerSecond.IsNil() { - return errors.New("rewards per second should not be nil") + if p.StakingRewardsPerSecond.IsNil() { + return errors.New("StakingRewardsPerSecond should not be nil") } - if p.RewardsPerSecond.IsNegative() { - return fmt.Errorf("rewards per second should not be negative: %s", p.RewardsPerSecond) + if p.StakingRewardsPerSecond.IsNegative() { + return fmt.Errorf("StakingRewardsPerSecond should not be negative: %s", p.StakingRewardsPerSecond) } return nil diff --git a/x/community/types/params.pb.go b/x/community/types/params.pb.go index af9efc942d..a1be284e86 100644 --- a/x/community/types/params.pb.go +++ b/x/community/types/params.pb.go @@ -32,7 +32,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters of the community module. type Params struct { UpgradeTimeDisableInflation time.Time `protobuf:"bytes,1,opt,name=upgrade_time_disable_inflation,json=upgradeTimeDisableInflation,proto3,stdtime" json:"upgrade_time_disable_inflation"` - RewardsPerSecond cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=rewards_per_second,json=rewardsPerSecond,proto3,customtype=cosmossdk.io/math.Int" json:"rewards_per_second"` + StakingRewardsPerSecond cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=staking_rewards_per_second,json=stakingRewardsPerSecond,proto3,customtype=cosmossdk.io/math.Int" json:"staking_rewards_per_second"` } func (m *Params) Reset() { *m = Params{} } @@ -84,28 +84,28 @@ func init() { } var fileDescriptor_0a48475520900507 = []byte{ - // 328 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xc1, 0x4e, 0xc2, 0x30, - 0x18, 0xc7, 0x57, 0x0f, 0x44, 0xe7, 0xc5, 0x2c, 0x6a, 0x10, 0x93, 0x8e, 0xe8, 0x85, 0x84, 0xd0, - 0x06, 0x7d, 0x03, 0xa2, 0x07, 0x6e, 0x04, 0xbd, 0xe8, 0x65, 0xe9, 0x58, 0x19, 0x0d, 0xeb, 0xba, - 0xb4, 0x1d, 0xca, 0x5b, 0xf0, 0x30, 0x3e, 0x04, 0x27, 0x43, 0x3c, 0x19, 0x0f, 0x68, 0xe0, 0x45, - 0x4c, 0xdb, 0xcd, 0x78, 0xfb, 0xbe, 0xaf, 0xbf, 0xfe, 0x9a, 0xff, 0x57, 0xff, 0x7a, 0x4e, 0x16, - 0x04, 0x4f, 0x04, 0xe7, 0x65, 0xce, 0xf4, 0x12, 0x2f, 0xfa, 0x31, 0xd5, 0xa4, 0x8f, 0x0b, 0x22, - 0x09, 0x57, 0xa8, 0x90, 0x42, 0x8b, 0xe0, 0xdc, 0x40, 0xe8, 0x0f, 0x42, 0x15, 0xd4, 0xba, 0x98, - 0x08, 0xc5, 0x85, 0x8a, 0x2c, 0x85, 0x5d, 0xe3, 0xae, 0xb4, 0x4e, 0x53, 0x91, 0x0a, 0x37, 0x37, - 0x55, 0x35, 0x0d, 0x53, 0x21, 0xd2, 0x8c, 0x62, 0xdb, 0xc5, 0xe5, 0x14, 0x6b, 0xc6, 0xa9, 0xd2, - 0x84, 0x17, 0x0e, 0xb8, 0x7a, 0x07, 0x7e, 0x63, 0x64, 0x9f, 0x0e, 0x98, 0x0f, 0xcb, 0x22, 0x95, - 0x24, 0xa1, 0x91, 0xa1, 0xa2, 0x84, 0x29, 0x12, 0x67, 0x34, 0x62, 0xf9, 0x34, 0x23, 0x9a, 0x89, - 0xbc, 0x09, 0xda, 0xa0, 0x73, 0x7c, 0xd3, 0x42, 0x4e, 0x8a, 0x6a, 0x29, 0x7a, 0xac, 0xa5, 0x83, - 0xc3, 0xf5, 0x36, 0xf4, 0x56, 0xdf, 0x21, 0x18, 0x5f, 0x56, 0x2e, 0x73, 0x76, 0xe7, 0x4c, 0xc3, - 0x5a, 0x14, 0x3c, 0xf9, 0x81, 0xa4, 0x2f, 0x44, 0x26, 0x2a, 0x2a, 0xa8, 0x8c, 0x14, 0x9d, 0x88, - 0x3c, 0x69, 0x1e, 0xb4, 0x41, 0xe7, 0x68, 0xd0, 0x35, 0x8a, 0xaf, 0x6d, 0x78, 0xe6, 0xe2, 0xa9, - 0x64, 0x8e, 0x98, 0xc0, 0x9c, 0xe8, 0x19, 0x1a, 0xe6, 0xfa, 0xe3, 0xad, 0xe7, 0x57, 0xb9, 0x87, - 0xb9, 0x1e, 0x9f, 0x54, 0x9a, 0x11, 0x95, 0x0f, 0x56, 0x32, 0xb8, 0x5f, 0xef, 0x20, 0xd8, 0xec, - 0x20, 0xf8, 0xd9, 0x41, 0xb0, 0xda, 0x43, 0x6f, 0xb3, 0x87, 0xde, 0xe7, 0x1e, 0x7a, 0xcf, 0xdd, - 0x94, 0xe9, 0x59, 0x19, 0x9b, 0xb5, 0x62, 0xb3, 0xdf, 0x5e, 0x46, 0x62, 0x65, 0x2b, 0xfc, 0xfa, - 0xef, 0x43, 0xf4, 0xb2, 0xa0, 0x2a, 0x6e, 0xd8, 0x70, 0xb7, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, - 0xc2, 0x53, 0xf7, 0x41, 0xaf, 0x01, 0x00, 0x00, + // 336 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xcf, 0x4e, 0x2a, 0x31, + 0x14, 0x87, 0xa7, 0x77, 0x41, 0xae, 0xe3, 0x8e, 0xf8, 0x07, 0xc7, 0x64, 0x86, 0xe8, 0x86, 0x84, + 0xd0, 0x06, 0x7d, 0x03, 0xa2, 0x0b, 0x76, 0x04, 0x5d, 0xb9, 0x69, 0x3a, 0x4c, 0x29, 0x0d, 0xd3, + 0x76, 0xd2, 0x76, 0x50, 0xde, 0x82, 0x87, 0xf1, 0x21, 0x58, 0x12, 0x57, 0xc6, 0x44, 0x34, 0xf0, + 0x22, 0xa6, 0xd3, 0xc1, 0xb8, 0x3b, 0xe7, 0xf4, 0xeb, 0xd7, 0xfc, 0x4e, 0xc3, 0xeb, 0x39, 0x59, + 0x10, 0x34, 0x51, 0x42, 0x94, 0x92, 0xdb, 0x25, 0x5a, 0xf4, 0x53, 0x6a, 0x49, 0x1f, 0x15, 0x44, + 0x13, 0x61, 0x60, 0xa1, 0x95, 0x55, 0xcd, 0x33, 0x07, 0xc1, 0x5f, 0x08, 0xd6, 0x50, 0x74, 0x31, + 0x51, 0x46, 0x28, 0x83, 0x2b, 0x0a, 0xf9, 0xc6, 0x5f, 0x89, 0x4e, 0x98, 0x62, 0xca, 0xcf, 0x5d, + 0x55, 0x4f, 0x13, 0xa6, 0x14, 0xcb, 0x29, 0xaa, 0xba, 0xb4, 0x9c, 0x22, 0xcb, 0x05, 0x35, 0x96, + 0x88, 0xc2, 0x03, 0x57, 0x9f, 0x20, 0x6c, 0x8c, 0xaa, 0xa7, 0x9b, 0x3c, 0x8c, 0xcb, 0x82, 0x69, + 0x92, 0x51, 0xec, 0x28, 0x9c, 0x71, 0x43, 0xd2, 0x9c, 0x62, 0x2e, 0xa7, 0x39, 0xb1, 0x5c, 0xc9, + 0x16, 0x68, 0x83, 0xce, 0xf1, 0x4d, 0x04, 0xbd, 0x14, 0x1e, 0xa4, 0xf0, 0xf1, 0x20, 0x1d, 0xfc, + 0x5f, 0x6f, 0x93, 0x60, 0xf5, 0x95, 0x80, 0xf1, 0x65, 0xed, 0x72, 0x67, 0x77, 0xde, 0x34, 0x3c, + 0x88, 0x9a, 0xb3, 0x30, 0x32, 0x96, 0xcc, 0xb9, 0x64, 0x58, 0xd3, 0x67, 0xa2, 0x33, 0x83, 0x0b, + 0xaa, 0xb1, 0xa1, 0x13, 0x25, 0xb3, 0xd6, 0xbf, 0x36, 0xe8, 0x1c, 0x0d, 0xba, 0x4e, 0xf5, 0xb1, + 0x4d, 0x4e, 0x7d, 0x4c, 0x93, 0xcd, 0x21, 0x57, 0x48, 0x10, 0x3b, 0x83, 0x43, 0x69, 0xdf, 0x5e, + 0x7b, 0x61, 0x9d, 0x7f, 0x28, 0xed, 0xf8, 0xbc, 0xd6, 0x8d, 0xbd, 0x6d, 0x44, 0xf5, 0x43, 0xe5, + 0x1a, 0xdc, 0xaf, 0x77, 0x31, 0xd8, 0xec, 0x62, 0xf0, 0xbd, 0x8b, 0xc1, 0x6a, 0x1f, 0x07, 0x9b, + 0x7d, 0x1c, 0xbc, 0xef, 0xe3, 0xe0, 0xa9, 0xcb, 0xb8, 0x9d, 0x95, 0xa9, 0xdb, 0x32, 0x72, 0xeb, + 0xee, 0xe5, 0x24, 0x35, 0x55, 0x85, 0x5e, 0xfe, 0xfc, 0x8f, 0x5d, 0x16, 0xd4, 0xa4, 0x8d, 0x2a, + 0xeb, 0xed, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc5, 0xad, 0xf1, 0xc6, 0xbe, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -129,9 +129,9 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l { - size := m.RewardsPerSecond.Size() + size := m.StakingRewardsPerSecond.Size() i -= size - if _, err := m.RewardsPerSecond.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.StakingRewardsPerSecond.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintParams(dAtA, i, uint64(size)) @@ -168,7 +168,7 @@ func (m *Params) Size() (n int) { _ = l l = github_com_gogo_protobuf_types.SizeOfStdTime(m.UpgradeTimeDisableInflation) n += 1 + l + sovParams(uint64(l)) - l = m.RewardsPerSecond.Size() + l = m.StakingRewardsPerSecond.Size() n += 1 + l + sovParams(uint64(l)) return n } @@ -243,7 +243,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RewardsPerSecond", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field StakingRewardsPerSecond", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -271,7 +271,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.RewardsPerSecond.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.StakingRewardsPerSecond.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/community/types/params_test.go b/x/community/types/params_test.go index b6152fc903..9b141c524e 100644 --- a/x/community/types/params_test.go +++ b/x/community/types/params_test.go @@ -20,7 +20,7 @@ func TestParamsValidate(t *testing.T) { name: "valid parms", params: types.Params{ UpgradeTimeDisableInflation: time.Time{}, - RewardsPerSecond: sdkmath.NewInt(1000), + StakingRewardsPerSecond: sdkmath.NewInt(1000), }, expectedErr: "", }, @@ -28,17 +28,17 @@ func TestParamsValidate(t *testing.T) { name: "nil rewards per second", params: types.Params{ UpgradeTimeDisableInflation: time.Time{}, - RewardsPerSecond: sdkmath.Int{}, + StakingRewardsPerSecond: sdkmath.Int{}, }, - expectedErr: "rewards per second should not be nil", + expectedErr: "StakingRewardsPerSecond should not be nil", }, { name: "negative rewards per second", params: types.Params{ UpgradeTimeDisableInflation: time.Time{}, - RewardsPerSecond: sdkmath.NewInt(-5), + StakingRewardsPerSecond: sdkmath.NewInt(-5), }, - expectedErr: "rewards per second should not be negative", + expectedErr: "StakingRewardsPerSecond should not be negative", }, } From d88a0273aed0e3e6c65503e38729eee016d27afd Mon Sep 17 00:00:00 2001 From: drklee3 Date: Thu, 14 Sep 2023 14:25:22 -0700 Subject: [PATCH 7/9] Add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79ba058520..75ab30e095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## State Machine Breaking - (community) [#1704] Add param to control when inflation will be disabled +- (community) [#1707] Default staking rewards per second set to `744191` ## [v0.24.0] @@ -284,6 +285,7 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md). - [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run large-scale simulations remotely using aws-batch +[#1707]: https://github.com/Kava-Labs/kava/pull/1707 [#1668]: https://github.com/Kava-Labs/kava/pull/1668 [#1669]: https://github.com/Kava-Labs/kava/pull/1669 [#1655]: https://github.com/Kava-Labs/kava/pull/1655 From ec9dbcd92025d04115945e4058531e5e0ee29283 Mon Sep 17 00:00:00 2001 From: drklee3 Date: Thu, 14 Sep 2023 15:42:24 -0700 Subject: [PATCH 8/9] Add param migration, update consensus version to 2 --- x/community/keeper/migrations.go | 27 ++++++++++++++ x/community/migrations/v2/store.go | 38 ++++++++++++++++++++ x/community/migrations/v2/store_test.go | 48 +++++++++++++++++++++++++ x/community/module.go | 11 +++++- 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 x/community/keeper/migrations.go create mode 100644 x/community/migrations/v2/store.go create mode 100644 x/community/migrations/v2/store_test.go diff --git a/x/community/keeper/migrations.go b/x/community/keeper/migrations.go new file mode 100644 index 0000000000..036c56fe12 --- /dev/null +++ b/x/community/keeper/migrations.go @@ -0,0 +1,27 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + v2 "github.com/kava-labs/kava/x/community/migrations/v2" +) + +// Migrator is a struct for handling in-place store migrations. +type Migrator struct { + keeper Keeper +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper Keeper) Migrator { + return Migrator{ + keeper: keeper, + } +} + +// Migrate1to2 migrates from version 1 to 2. +func (m Migrator) Migrate1to2(ctx sdk.Context) error { + return v2.Migrate( + ctx, + ctx.KVStore(m.keeper.key), + m.keeper.cdc, + ) +} diff --git a/x/community/migrations/v2/store.go b/x/community/migrations/v2/store.go new file mode 100644 index 0000000000..5fb978927e --- /dev/null +++ b/x/community/migrations/v2/store.go @@ -0,0 +1,38 @@ +package v2 + +import ( + "time" + + storetypes "github.com/cosmos/cosmos-sdk/store/types" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/x/community/types" +) + +const ( + ModuleName = "mint" +) + +// Migrate migrates the x/community module state from the consensus version 1 to +// version 2. Specifically, sets new parameters in the module state. +func Migrate( + ctx sdk.Context, + store storetypes.KVStore, + cdc codec.BinaryCodec, +) error { + params := types.NewParams( + // 2023-11-01T00:00:00Z + time.Date(2023, 11, 1, 0, 0, 0, 0, time.UTC), + sdk.NewInt(744191), + ) + + if err := params.Validate(); err != nil { + return err + } + + bz := cdc.MustMarshal(¶ms) + store.Set(types.ParamsKey, bz) + + return nil +} diff --git a/x/community/migrations/v2/store_test.go b/x/community/migrations/v2/store_test.go new file mode 100644 index 0000000000..7b189dbc06 --- /dev/null +++ b/x/community/migrations/v2/store_test.go @@ -0,0 +1,48 @@ +package v2_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/kava-labs/kava/app" + v2 "github.com/kava-labs/kava/x/community/migrations/v2" + "github.com/kava-labs/kava/x/community/types" +) + +func TestMigrateStore(t *testing.T) { + tApp := app.NewTestApp() + cdc := tApp.AppCodec() + storeKey := sdk.NewKVStoreKey("community") + ctx := testutil.DefaultContext(storeKey, sdk.NewTransientStoreKey("transient_test")) + store := ctx.KVStore(storeKey) + + require.Nil( + t, + store.Get(types.ParamsKey), + "params shouldn't exist in store before migration", + ) + + require.NoError(t, v2.Migrate(ctx, store, cdc)) + + paramsBytes := store.Get(types.ParamsKey) + require.NotNil(t, paramsBytes, "params should be in store after migration") + + var params types.Params + cdc.MustUnmarshal(paramsBytes, ¶ms) + + t.Logf("params: %+v", params) + + require.Equal( + t, + types.NewParams( + time.Date(2023, 11, 1, 0, 0, 0, 0, time.UTC), + sdk.NewInt(744191), + ), + params, + "params should be correct after migration", + ) +} diff --git a/x/community/module.go b/x/community/module.go index 2b1bfbecbe..ec409a2ec0 100644 --- a/x/community/module.go +++ b/x/community/module.go @@ -3,6 +3,7 @@ package community import ( "context" "encoding/json" + "fmt" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -20,6 +21,9 @@ import ( "github.com/kava-labs/kava/x/community/types" ) +// ConsensusVersion defines the current module consensus version. +const ConsensusVersion = 2 + var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} @@ -119,12 +123,17 @@ func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 1 } +func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper)) + + m := keeper.NewMigrator(am.keeper) + if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil { + panic(fmt.Sprintf("failed to migrate x/community from version 1 to 2: %v", err)) + } } // InitGenesis module init-genesis From d1f9748fee629e6047991a203f3d429cef844310 Mon Sep 17 00:00:00 2001 From: drklee3 Date: Thu, 14 Sep 2023 15:46:06 -0700 Subject: [PATCH 9/9] Update proto docs --- docs/core/proto-docs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 0cc1d2bea3..507aeb44e2 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -2906,7 +2906,7 @@ Params defines the parameters of the community module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `upgrade_time_disable_inflation` | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | | -| `rewards_per_second` | [string](#string) | | | +| `staking_rewards_per_second` | [string](#string) | | |