From 2e68bc271c3cc3c971c4e2460f0ecf93ca343b26 Mon Sep 17 00:00:00 2001 From: John Letey Date: Mon, 20 Mar 2023 14:30:42 +0100 Subject: [PATCH 1/6] refactor: switch to `sdk.Dec` --- app/app.go | 1 - proto/kyve/bundles/v1beta1/params.proto | 5 +- proto/kyve/delegation/v1beta1/params.proto | 17 +- util/validate.go | 39 +++-- x/bundles/keeper/getters_params.go | 2 +- x/bundles/keeper/keeper.go | 2 - .../keeper_suite_invalid_bundles_test.go | 8 +- x/bundles/keeper/keeper_suite_points_test.go | 2 +- .../keeper/keeper_suite_stakers_leave_test.go | 6 +- .../keeper/keeper_suite_valid_bundles_test.go | 16 +- .../keeper_suite_zero_delegation_test.go | 8 +- x/bundles/keeper/logic_bundles.go | 6 +- ...ic_end_block_handle_upload_timeout_test.go | 4 +- .../keeper/msg_server_update_params_test.go | 4 +- x/bundles/types/params.go | 31 +--- x/bundles/types/params.pb.go | 74 +++++---- x/delegation/keeper/getters_params.go | 12 +- .../keeper/msg_server_undelegate_test.go | 11 +- .../keeper/msg_server_update_params_test.go | 12 +- x/delegation/types/params.go | 19 +-- x/delegation/types/params.pb.go | 148 +++++++++--------- x/stakers/types/params.go | 4 +- 22 files changed, 208 insertions(+), 223 deletions(-) diff --git a/app/app.go b/app/app.go index 0a4d969a..169df7d3 100644 --- a/app/app.go +++ b/app/app.go @@ -448,7 +448,6 @@ func NewKYVEApp( app.PoolKeeper, app.StakersKeeper, app.DelegationKeeper, - app.UpgradeKeeper, ) // Create IBC Keepers diff --git a/proto/kyve/bundles/v1beta1/params.proto b/proto/kyve/bundles/v1beta1/params.proto index e2f2d93d..b31a4d25 100644 --- a/proto/kyve/bundles/v1beta1/params.proto +++ b/proto/kyve/bundles/v1beta1/params.proto @@ -16,7 +16,10 @@ message Params { (gogoproto.nullable) = false ]; // network_fee ... - string network_fee = 3; + string network_fee = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; // max_points ... uint64 max_points = 4; } diff --git a/proto/kyve/delegation/v1beta1/params.proto b/proto/kyve/delegation/v1beta1/params.proto index 1cf3053b..86ff72de 100644 --- a/proto/kyve/delegation/v1beta1/params.proto +++ b/proto/kyve/delegation/v1beta1/params.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package kyve.delegation.v1beta1; +import "gogoproto/gogo.proto"; + option go_package = "github.com/KYVENetwork/chain/x/delegation/types"; // Params defines the delegation module parameters. @@ -13,9 +15,18 @@ message Params { // unbonding_delegation_time ... uint64 redelegation_max_amount = 3; // vote_slash ... - string vote_slash = 4; + string vote_slash = 4 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; // upload_slash ... - string upload_slash = 5; + string upload_slash = 5 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; // timeout_slash ... - string timeout_slash = 6; + string timeout_slash = 6 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; } diff --git a/util/validate.go b/util/validate.go index b218e277..082652e9 100644 --- a/util/validate.go +++ b/util/validate.go @@ -3,33 +3,42 @@ package util import ( "fmt" + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" ) -func ValidateUint64(v interface{}) error { - _, ok := v.(uint64) +func ValidateDecimal(i interface{}) error { + v, ok := i.(sdk.Dec) if !ok { - return fmt.Errorf("invalid parameter type: %T", v) + return fmt.Errorf("invalid type: %T", i) + } + + if v.IsNil() || v.IsNegative() { + return fmt.Errorf("invalid decimal: %s", v) } + return nil } -func ValidatePercentage(v interface{}) error { - val, ok := v.(string) - if !ok { - return fmt.Errorf("invalid parameter type: %T", v) - } +func ValidateNumber(i uint64) error { + v := math.NewIntFromUint64(i) - parsedVal, err := sdk.NewDecFromStr(val) - if err != nil { - return fmt.Errorf("invalid decimal representation: %T", v) + if v.IsNil() || v.IsNegative() { + return fmt.Errorf("invalid number: %s", v) } - if parsedVal.LT(sdk.NewDec(0)) { - return fmt.Errorf("percentage should be greater than or equal to 0") + return nil +} + +func ValidatePercentage(i interface{}) error { + v, ok := i.(sdk.Dec) + if !ok { + return fmt.Errorf("invalid type: %T", i) } - if parsedVal.GT(sdk.NewDec(1)) { - return fmt.Errorf("percentage should be less than or equal to 1") + + if v.IsNil() || v.IsNegative() || v.GT(sdk.OneDec()) { + return fmt.Errorf("invalid percentage: %s", v) } return nil diff --git a/x/bundles/keeper/getters_params.go b/x/bundles/keeper/getters_params.go index 825ce6c7..ffe082e3 100644 --- a/x/bundles/keeper/getters_params.go +++ b/x/bundles/keeper/getters_params.go @@ -29,7 +29,7 @@ func (k Keeper) GetStorageCost(ctx sdk.Context) (res sdk.Dec) { } // GetNetworkFee returns the NetworkFee param -func (k Keeper) GetNetworkFee(ctx sdk.Context) (res string) { +func (k Keeper) GetNetworkFee(ctx sdk.Context) (res sdk.Dec) { return k.GetParams(ctx).NetworkFee } diff --git a/x/bundles/keeper/keeper.go b/x/bundles/keeper/keeper.go index 59c40483..69d0b6cb 100644 --- a/x/bundles/keeper/keeper.go +++ b/x/bundles/keeper/keeper.go @@ -25,7 +25,6 @@ type ( poolKeeper types.PoolKeeper stakerKeeper types.StakerKeeper delegationKeeper types.DelegationKeeper - upgradeKeeper types.UpgradeKeeper } ) @@ -42,7 +41,6 @@ func NewKeeper( poolKeeper types.PoolKeeper, stakerKeeper types.StakerKeeper, delegationKeeper types.DelegationKeeper, - upgradeKeeper types.UpgradeKeeper, ) *Keeper { return &Keeper{ cdc: cdc, diff --git a/x/bundles/keeper/keeper_suite_invalid_bundles_test.go b/x/bundles/keeper/keeper_suite_invalid_bundles_test.go index 2bdb65b0..8dfc69c4 100644 --- a/x/bundles/keeper/keeper_suite_invalid_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_invalid_bundles_test.go @@ -196,7 +196,7 @@ var _ = Describe("invalid bundles", Ordered, func() { Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeZero()) // calculate uploader slashes - fraction, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetUploadSlash(s.Ctx())) + fraction := s.App().DelegationKeeper.GetUploadSlash(s.Ctx()) slashAmount := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(100*i.KYVE - slashAmount)) @@ -338,7 +338,7 @@ var _ = Describe("invalid bundles", Ordered, func() { Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeZero()) // calculate uploader slashes - fraction, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetUploadSlash(s.Ctx())) + fraction := s.App().DelegationKeeper.GetUploadSlash(s.Ctx()) slashAmountUploader := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) slashAmountDelegator := uint64(sdk.NewDec(int64(300 * i.KYVE)).Mul(fraction).TruncateInt64()) @@ -510,7 +510,7 @@ var _ = Describe("invalid bundles", Ordered, func() { Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeZero()) // calculate uploader slashes - fraction, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetUploadSlash(s.Ctx())) + fraction := s.App().DelegationKeeper.GetUploadSlash(s.Ctx()) slashAmountUploader := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) slashAmountDelegator1 := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) @@ -518,7 +518,7 @@ var _ = Describe("invalid bundles", Ordered, func() { Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.ALICE)).To(Equal(100*i.KYVE - slashAmountDelegator1)) // calculate voter slashes - fraction, _ = sdk.NewDecFromStr(s.App().DelegationKeeper.GetVoteSlash(s.Ctx())) + fraction = s.App().DelegationKeeper.GetVoteSlash(s.Ctx()) slashAmountVoter := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) slashAmountDelegator2 := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) diff --git a/x/bundles/keeper/keeper_suite_points_test.go b/x/bundles/keeper/keeper_suite_points_test.go index 3e44a2b2..0fe53c3f 100644 --- a/x/bundles/keeper/keeper_suite_points_test.go +++ b/x/bundles/keeper/keeper_suite_points_test.go @@ -310,7 +310,7 @@ var _ = Describe("points", Ordered, func() { Expect(valaccountFound).To(BeFalse()) // check if voter got slashed - slashAmountRatio, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx())) + slashAmountRatio := s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx()) expectedBalance := 50*i.KYVE - uint64(sdk.NewDec(int64(50*i.KYVE)).Mul(slashAmountRatio).TruncateInt64()) Expect(expectedBalance).To(Equal(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1))) diff --git a/x/bundles/keeper/keeper_suite_stakers_leave_test.go b/x/bundles/keeper/keeper_suite_stakers_leave_test.go index 99707ca3..eaeb6d29 100644 --- a/x/bundles/keeper/keeper_suite_stakers_leave_test.go +++ b/x/bundles/keeper/keeper_suite_stakers_leave_test.go @@ -218,7 +218,7 @@ var _ = Describe("stakers leave", Ordered, func() { balanceUploader := s.GetBalanceFromAddress(i.STAKER_0) totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost - networkFee, _ := sdk.NewDecFromStr(s.App().BundlesKeeper.GetNetworkFee(s.Ctx())) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) @@ -309,7 +309,7 @@ var _ = Describe("stakers leave", Ordered, func() { Expect(valaccountFound).To(BeFalse()) // check if next uploader got slashed - fraction, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetUploadSlash(s.Ctx())) + fraction := s.App().DelegationKeeper.GetUploadSlash(s.Ctx()) slashAmount := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(100*i.KYVE - slashAmount)) @@ -402,7 +402,7 @@ var _ = Describe("stakers leave", Ordered, func() { Expect(valaccountFound).To(BeFalse()) // check if voter got slashed - fraction, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetVoteSlash(s.Ctx())) + fraction := s.App().DelegationKeeper.GetVoteSlash(s.Ctx()) slashAmount := uint64(sdk.NewDec(int64(50 * i.KYVE)).Mul(fraction).TruncateInt64()) Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(Equal(50*i.KYVE - slashAmount)) diff --git a/x/bundles/keeper/keeper_suite_valid_bundles_test.go b/x/bundles/keeper/keeper_suite_valid_bundles_test.go index 74188ab8..c571f993 100644 --- a/x/bundles/keeper/keeper_suite_valid_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_valid_bundles_test.go @@ -179,7 +179,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost - networkFee, _ := sdk.NewDecFromStr(s.App().BundlesKeeper.GetNetworkFee(s.Ctx())) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) @@ -295,7 +295,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost - networkFee, _ := sdk.NewDecFromStr(s.App().BundlesKeeper.GetNetworkFee(s.Ctx())) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) @@ -444,7 +444,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost - networkFee, _ := sdk.NewDecFromStr(s.App().BundlesKeeper.GetNetworkFee(s.Ctx())) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) @@ -599,7 +599,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost - networkFee, _ := sdk.NewDecFromStr(s.App().BundlesKeeper.GetNetworkFee(s.Ctx())) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) @@ -759,7 +759,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost - networkFee, _ := sdk.NewDecFromStr(s.App().BundlesKeeper.GetNetworkFee(s.Ctx())) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) @@ -927,7 +927,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost - networkFee, _ := sdk.NewDecFromStr(s.App().BundlesKeeper.GetNetworkFee(s.Ctx())) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) @@ -1084,7 +1084,7 @@ var _ = Describe("valid bundles", Ordered, func() { uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), valaccountUploader.Staker) // calculate voter slashes - fraction, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetVoteSlash(s.Ctx())) + fraction := s.App().DelegationKeeper.GetVoteSlash(s.Ctx()) slashAmountVoter := uint64(sdk.NewDec(int64(200 * i.KYVE)).Mul(fraction).TruncateInt64()) slashAmountDelegator := uint64(sdk.NewDec(int64(100 * i.KYVE)).Mul(fraction).TruncateInt64()) @@ -1105,7 +1105,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost - networkFee, _ := sdk.NewDecFromStr(s.App().BundlesKeeper.GetNetworkFee(s.Ctx())) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) diff --git a/x/bundles/keeper/keeper_suite_zero_delegation_test.go b/x/bundles/keeper/keeper_suite_zero_delegation_test.go index 432e4464..e4d2c634 100644 --- a/x/bundles/keeper/keeper_suite_zero_delegation_test.go +++ b/x/bundles/keeper/keeper_suite_zero_delegation_test.go @@ -234,7 +234,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) // calculate voter slashes - fraction, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetVoteSlash(s.Ctx())) + fraction := s.App().DelegationKeeper.GetVoteSlash(s.Ctx()) slashAmountVoter := uint64(sdk.NewDec(int64(0 * i.KYVE)).Mul(fraction).TruncateInt64()) Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(Equal(0*i.KYVE - slashAmountVoter)) @@ -385,7 +385,7 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost - networkFee, _ := sdk.NewDecFromStr(s.App().BundlesKeeper.GetNetworkFee(s.Ctx())) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) totalUploaderReward := totalReward - treasuryReward @@ -529,7 +529,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeZero()) // calculate uploader slashes - fraction, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetUploadSlash(s.Ctx())) + fraction := s.App().DelegationKeeper.GetUploadSlash(s.Ctx()) slashAmount := uint64(sdk.NewDec(int64(0 * i.KYVE)).Mul(fraction).TruncateInt64()) Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(0*i.KYVE - slashAmount)) @@ -643,7 +643,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(valaccountFound).To(BeFalse()) // check if voter got slashed - slashAmountRatio, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx())) + slashAmountRatio := s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx()) expectedBalance := 0*i.KYVE - uint64(sdk.NewDec(int64(0*i.KYVE)).Mul(slashAmountRatio).TruncateInt64()) Expect(expectedBalance).To(Equal(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1))) diff --git a/x/bundles/keeper/logic_bundles.go b/x/bundles/keeper/logic_bundles.go index 2d6d1691..93b84763 100644 --- a/x/bundles/keeper/logic_bundles.go +++ b/x/bundles/keeper/logic_bundles.go @@ -238,12 +238,8 @@ func (k Keeper) calculatePayouts(ctx sdk.Context, poolId uint64) (bundleReward t // formula for calculating the rewards bundleReward.Total = pool.OperatingCost + uint64(k.GetStorageCost(ctx).MulInt64(int64(bundleProposal.DataSize)).TruncateInt64()) - networkFee, err := sdk.NewDecFromStr(k.GetNetworkFee(ctx)) - if err != nil { - util.PanicHalt(k.upgradeKeeper, ctx, "Network Fee unparasable - "+k.GetNetworkFee(ctx)) - } // Add fee to treasury - bundleReward.Treasury = uint64(sdk.NewDec(int64(bundleReward.Total)).Mul(networkFee).TruncateInt64()) + bundleReward.Treasury = uint64(sdk.NewDec(int64(bundleReward.Total)).Mul(k.GetNetworkFee(ctx)).TruncateInt64()) // Remaining rewards to be split between staker and its delegators totalNodeReward := bundleReward.Total - bundleReward.Treasury diff --git a/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go b/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go index d1d97f63..06a3c019 100644 --- a/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go +++ b/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go @@ -537,7 +537,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 0)).To(Equal(100 * i.KYVE)) // check if next uploader not got slashed - slashAmountRatio, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx())) + slashAmountRatio := s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx()) expectedBalance := 50*i.KYVE - uint64(sdk.NewDec(int64(50*i.KYVE)).Mul(slashAmountRatio).TruncateInt64()) Expect(expectedBalance).To(Equal(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1))) @@ -986,7 +986,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Expect(s.App().DelegationKeeper.GetDelegationOfPool(s.Ctx(), 1)).To(Equal(100 * i.KYVE)) // check if next uploader not got slashed - slashAmountRatio, _ := sdk.NewDecFromStr(s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx())) + slashAmountRatio := s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx()) expectedBalance := 50*i.KYVE - uint64(sdk.NewDec(int64(50*i.KYVE)).Mul(slashAmountRatio).TruncateInt64()) Expect(expectedBalance).To(Equal(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_2, i.STAKER_2))) diff --git a/x/bundles/keeper/msg_server_update_params_test.go b/x/bundles/keeper/msg_server_update_params_test.go index 3ffc04ba..9940ebf8 100644 --- a/x/bundles/keeper/msg_server_update_params_test.go +++ b/x/bundles/keeper/msg_server_update_params_test.go @@ -139,7 +139,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(updatedParams.UploadTimeout).To(Equal(uint64(20))) Expect(updatedParams.StorageCost).To(Equal(sdk.MustNewDecFromStr("0.05"))) - Expect(updatedParams.NetworkFee).To(Equal("0.05")) + Expect(updatedParams.NetworkFee).To(Equal(sdk.MustNewDecFromStr("0.05"))) Expect(updatedParams.MaxPoints).To(Equal(uint64(15))) }) @@ -385,7 +385,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(updatedParams.UploadTimeout).To(Equal(types.DefaultUploadTimeout)) Expect(updatedParams.StorageCost).To(Equal(types.DefaultStorageCost)) - Expect(updatedParams.NetworkFee).To(Equal("0.05")) + Expect(updatedParams.NetworkFee).To(Equal(sdk.MustNewDecFromStr("0.05"))) Expect(updatedParams.MaxPoints).To(Equal(types.DefaultMaxPoints)) }) diff --git a/x/bundles/types/params.go b/x/bundles/types/params.go index dc7992a4..9b3d2877 100644 --- a/x/bundles/types/params.go +++ b/x/bundles/types/params.go @@ -1,8 +1,6 @@ package types import ( - "fmt" - "github.com/KYVENetwork/chain/util" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -14,7 +12,7 @@ var DefaultUploadTimeout = uint64(600) var DefaultStorageCost = sdk.MustNewDecFromStr("0.025") // DefaultNetworkFee ... -var DefaultNetworkFee = "0.01" +var DefaultNetworkFee = sdk.MustNewDecFromStr("0.01") // DefaultMaxPoints ... var DefaultMaxPoints = uint64(24) @@ -23,7 +21,7 @@ var DefaultMaxPoints = uint64(24) func NewParams( uploadTimeout uint64, storageCost sdk.Dec, - networkFee string, + networkFee sdk.Dec, maxPoints uint64, ) Params { return Params{ @@ -46,11 +44,11 @@ func DefaultParams() Params { // Validate validates the set of params func (p Params) Validate() error { - if err := util.ValidateUint64(p.UploadTimeout); err != nil { + if err := util.ValidateNumber(p.UploadTimeout); err != nil { return err } - if err := validateStorageCost(p.StorageCost); err != nil { + if err := util.ValidateDecimal(p.StorageCost); err != nil { return err } @@ -58,28 +56,9 @@ func (p Params) Validate() error { return err } - if err := util.ValidateUint64(p.MaxPoints); err != nil { + if err := util.ValidateNumber(p.MaxPoints); err != nil { return err } return nil } - -// validateStorageCost ... -func validateStorageCost(i interface{}) error { - v, ok := i.(sdk.Dec) - - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - if v.IsNil() { - return fmt.Errorf("invalid parameter: nil") - } - - if v.IsNegative() { - return fmt.Errorf("value cannot be negative: %s", i) - } - - return nil -} diff --git a/x/bundles/types/params.pb.go b/x/bundles/types/params.pb.go index 0a2382ff..7cff9951 100644 --- a/x/bundles/types/params.pb.go +++ b/x/bundles/types/params.pb.go @@ -31,7 +31,7 @@ type Params struct { // storage_cost ... StorageCost github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=storage_cost,json=storageCost,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"storage_cost"` // network_fee ... - NetworkFee string `protobuf:"bytes,3,opt,name=network_fee,json=networkFee,proto3" json:"network_fee,omitempty"` + NetworkFee github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=network_fee,json=networkFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"network_fee"` // max_points ... MaxPoints uint64 `protobuf:"varint,4,opt,name=max_points,json=maxPoints,proto3" json:"max_points,omitempty"` } @@ -76,13 +76,6 @@ func (m *Params) GetUploadTimeout() uint64 { return 0 } -func (m *Params) GetNetworkFee() string { - if m != nil { - return m.NetworkFee - } - return "" -} - func (m *Params) GetMaxPoints() uint64 { if m != nil { return m.MaxPoints @@ -97,26 +90,26 @@ func init() { func init() { proto.RegisterFile("kyve/bundles/v1beta1/params.proto", fileDescriptor_cfd3a74b72a01aaa) } var fileDescriptor_cfd3a74b72a01aaa = []byte{ - // 298 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x41, 0x4b, 0xc3, 0x30, - 0x18, 0x86, 0x1b, 0x1d, 0x83, 0x65, 0xea, 0xa1, 0xec, 0x50, 0x04, 0xb3, 0x29, 0x28, 0x3b, 0x68, - 0xc2, 0xf0, 0x1f, 0x4c, 0xdd, 0x45, 0x90, 0x39, 0x44, 0xd0, 0x4b, 0x49, 0xbb, 0xcf, 0xae, 0x6c, - 0xe9, 0x57, 0x9a, 0x74, 0x6e, 0xff, 0xc2, 0xdf, 0xe4, 0x69, 0xc7, 0x1d, 0xc5, 0xc3, 0x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xcb, 0xc8, 0xcf, 0x96, 0x91, 0x8f, 0x1d, 0x73, 0xd6, 0x3b, 0xe6, 0x7c, - 0xed, 0x98, 0xf3, 0x7a, 0xf9, 0xaf, 0xce, 0xfd, 0xcb, 0xf3, 0xdd, 0x43, 0x99, 0x29, 0xc2, 0x89, - 0x8c, 0x13, 0xb1, 0xf8, 0xdb, 0xd1, 0x16, 0x0b, 0xea, 0x76, 0x93, 0xeb, 0xdf, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xc8, 0x63, 0x93, 0xce, 0x64, 0x01, 0x00, 0x00, + // 300 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x90, 0xc1, 0x4a, 0xc3, 0x30, + 0x1c, 0xc6, 0x1b, 0x1d, 0x83, 0x65, 0xea, 0xa1, 0xec, 0x50, 0x04, 0xb3, 0x29, 0x28, 0x3b, 0x68, + 0xc2, 0xf0, 0x0d, 0xa6, 0xee, 0x22, 0xe8, 0x1c, 0x22, 0xe8, 0xa5, 0xa4, 0xdd, 0xdf, 0xae, 0x6c, + 0xe9, 0xbf, 0x34, 0xe9, 0xdc, 0xde, 0xc2, 0xc7, 0xda, 0x71, 0x47, 0xf1, 0x30, 0x64, 0x7b, 0x03, + 0x9f, 0x40, 0x96, 0x16, 0xf1, 0xec, 0x29, 0xe1, 0xe3, 0x97, 0xdf, 0x47, 0x3e, 0x7a, 0x3c, 0x9e, + 0x4f, 0x41, 0x04, 0x79, 0x32, 0x9c, 0x80, 0x16, 0xd3, 0x4e, 0x00, 0x46, 0x76, 0x44, 0x2a, 0x33, + 0xa9, 0x34, 0x4f, 0x33, 0x34, 0xe8, 0x36, 0xb6, 0x08, 0x2f, 0x11, 0x5e, 0x22, 0x87, 0x8d, 0x08, + 0x23, 0xb4, 0x80, 0xd8, 0xde, 0x0a, 0xf6, 0xe4, 0x9b, 0xd0, 0x6a, 0xdf, 0x3e, 0x76, 0x4f, 0xe9, + 0x41, 0x9e, 0x4e, 0x50, 0x0e, 0x7d, 0x13, 0x2b, 0xc0, 0xdc, 0x78, 0xa4, 0x45, 0xda, 0x95, 0xc1, + 0x7e, 0x91, 0x3e, 0x16, 0xa1, 0xfb, 0x40, 0xf7, 0xb4, 0xc1, 0x4c, 0x46, 0xe0, 0x87, 0xa8, 0x8d, + 0xb7, 0xd3, 0x22, 0xed, 0x5a, 0x97, 0x2f, 0x56, 0x4d, 0xe7, 0x73, 0xd5, 0x3c, 0x8b, 0x62, 0x33, + 0xca, 0x03, 0x1e, 0xa2, 0x12, 0x21, 0x6a, 0x85, 0xba, 0x3c, 0x2e, 0xf4, 0x70, 0x2c, 0xcc, 0x3c, + 0x05, 0xcd, 0xaf, 0x21, 0x1c, 0xd4, 0x4b, 0xc7, 0x15, 0x6a, 0xe3, 0xde, 0xd3, 0x7a, 0x02, 0xe6, + 0x0d, 0xb3, 0xb1, 0xff, 0x0a, 0xe0, 0xed, 0xfe, 0xcb, 0x48, 0x4b, 0x45, 0x0f, 0xc0, 0x3d, 0xa2, + 0x54, 0xc9, 0x99, 0x9f, 0x62, 0x9c, 0x18, 0xed, 0x55, 0xec, 0x37, 0x6a, 0x4a, 0xce, 0xfa, 0x36, + 0xe8, 0xf6, 0x16, 0x6b, 0x46, 0x96, 0x6b, 0x46, 0xbe, 0xd6, 0x8c, 0xbc, 0x6f, 0x98, 0xb3, 0xdc, + 0x30, 0xe7, 0x63, 0xc3, 0x9c, 0x97, 0xf3, 0x3f, 0x65, 0xb7, 0xcf, 0x4f, 0x37, 0x77, 0x85, 0x53, + 0x84, 0x23, 0x19, 0x27, 0x62, 0xf6, 0xbb, 0xbb, 0xad, 0x0d, 0xaa, 0x76, 0xc3, 0xcb, 0x9f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x7b, 0x35, 0x55, 0xa9, 0x94, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -144,13 +137,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x20 } - if len(m.NetworkFee) > 0 { - i -= len(m.NetworkFee) - copy(dAtA[i:], m.NetworkFee) - i = encodeVarintParams(dAtA, i, uint64(len(m.NetworkFee))) - i-- - dAtA[i] = 0x1a + { + size := m.NetworkFee.Size() + i -= size + if _, err := m.NetworkFee.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x1a { size := m.StorageCost.Size() i -= size @@ -191,10 +187,8 @@ func (m *Params) Size() (n int) { } l = m.StorageCost.Size() n += 1 + l + sovParams(uint64(l)) - l = len(m.NetworkFee) - if l > 0 { - n += 1 + l + sovParams(uint64(l)) - } + l = m.NetworkFee.Size() + n += 1 + l + sovParams(uint64(l)) if m.MaxPoints != 0 { n += 1 + sovParams(uint64(m.MaxPoints)) } @@ -319,7 +313,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.NetworkFee = string(dAtA[iNdEx:postIndex]) + if err := m.NetworkFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 4: if wireType != 0 { diff --git a/x/delegation/keeper/getters_params.go b/x/delegation/keeper/getters_params.go index 4099ba44..2c315b77 100644 --- a/x/delegation/keeper/getters_params.go +++ b/x/delegation/keeper/getters_params.go @@ -34,17 +34,17 @@ func (k Keeper) GetRedelegationMaxAmount(ctx sdk.Context) (res uint64) { } // GetVoteSlash returns the VoteSlash param -func (k Keeper) GetVoteSlash(ctx sdk.Context) (res string) { +func (k Keeper) GetVoteSlash(ctx sdk.Context) (res sdk.Dec) { return k.GetParams(ctx).VoteSlash } // GetUploadSlash returns the UploadSlash param -func (k Keeper) GetUploadSlash(ctx sdk.Context) (res string) { +func (k Keeper) GetUploadSlash(ctx sdk.Context) (res sdk.Dec) { return k.GetParams(ctx).UploadSlash } // GetTimeoutSlash returns the TimeoutSlash param -func (k Keeper) GetTimeoutSlash(ctx sdk.Context) (res string) { +func (k Keeper) GetTimeoutSlash(ctx sdk.Context) (res sdk.Dec) { return k.GetParams(ctx).TimeoutSlash } @@ -52,11 +52,11 @@ func (k Keeper) getSlashFraction(ctx sdk.Context, slashType types.SlashType) (sl // Retrieve slash fraction from params switch slashType { case types.SLASH_TYPE_TIMEOUT: - slashAmountRatio, _ = sdk.NewDecFromStr(k.GetTimeoutSlash(ctx)) + slashAmountRatio = k.GetTimeoutSlash(ctx) case types.SLASH_TYPE_VOTE: - slashAmountRatio, _ = sdk.NewDecFromStr(k.GetVoteSlash(ctx)) + slashAmountRatio = k.GetVoteSlash(ctx) case types.SLASH_TYPE_UPLOAD: - slashAmountRatio, _ = sdk.NewDecFromStr(k.GetUploadSlash(ctx)) + slashAmountRatio = k.GetUploadSlash(ctx) } return } diff --git a/x/delegation/keeper/msg_server_undelegate_test.go b/x/delegation/keeper/msg_server_undelegate_test.go index 93cabec4..7c2225c1 100644 --- a/x/delegation/keeper/msg_server_undelegate_test.go +++ b/x/delegation/keeper/msg_server_undelegate_test.go @@ -2,6 +2,7 @@ package keeper_test import ( pooltypes "github.com/KYVENetwork/chain/x/pool/types" + sdk "github.com/cosmos/cosmos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -244,7 +245,7 @@ var _ = Describe("msg_server_undelegate.go", Ordered, func() { }) params := s.App().DelegationKeeper.GetParams(s.Ctx()) - params.UploadSlash = "0.1" + params.UploadSlash = sdk.MustNewDecFromStr("0.1") s.App().DelegationKeeper.SetParams(s.Ctx(), params) s.App().DelegationKeeper.SlashDelegators(s.Ctx(), 0, i.ALICE, types.SLASH_TYPE_UPLOAD) @@ -413,7 +414,7 @@ var _ = Describe("msg_server_undelegate.go", Ordered, func() { // Slash 10% params := s.App().DelegationKeeper.GetParams(s.Ctx()) - params.UploadSlash = "0.1" + params.UploadSlash = sdk.MustNewDecFromStr("0.1") s.App().DelegationKeeper.SetParams(s.Ctx(), params) s.App().DelegationKeeper.SlashDelegators(s.Ctx(), 0, i.ALICE, types.SLASH_TYPE_UPLOAD) @@ -464,7 +465,7 @@ var _ = Describe("msg_server_undelegate.go", Ordered, func() { }) params := s.App().DelegationKeeper.GetParams(s.Ctx()) - params.UploadSlash = "0.5" + params.UploadSlash = sdk.MustNewDecFromStr("0.5") s.App().DelegationKeeper.SetParams(s.Ctx(), params) s.PerformValidityChecks() @@ -512,7 +513,7 @@ var _ = Describe("msg_server_undelegate.go", Ordered, func() { // ACT params := s.App().DelegationKeeper.GetParams(s.Ctx()) - params.UploadSlash = "0.5" + params.UploadSlash = sdk.MustNewDecFromStr("0.5") s.App().DelegationKeeper.SetParams(s.Ctx(), params) // Slash 50% twice @@ -557,7 +558,7 @@ var _ = Describe("msg_server_undelegate.go", Ordered, func() { // ACT params := s.App().DelegationKeeper.GetParams(s.Ctx()) - params.UploadSlash = "0.5" + params.UploadSlash = sdk.MustNewDecFromStr("0.5") s.App().DelegationKeeper.SetParams(s.Ctx(), params) s.App().DelegationKeeper.SlashDelegators(s.Ctx(), 0, i.ALICE, types.SLASH_TYPE_UPLOAD) s.App().DelegationKeeper.SlashDelegators(s.Ctx(), 0, i.ALICE, types.SLASH_TYPE_UPLOAD) diff --git a/x/delegation/keeper/msg_server_update_params_test.go b/x/delegation/keeper/msg_server_update_params_test.go index caa8990c..f6a2f702 100644 --- a/x/delegation/keeper/msg_server_update_params_test.go +++ b/x/delegation/keeper/msg_server_update_params_test.go @@ -152,9 +152,9 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(updatedParams.UnbondingDelegationTime).To(Equal(uint64(3600))) Expect(updatedParams.RedelegationCooldown).To(Equal(uint64(3600))) Expect(updatedParams.RedelegationMaxAmount).To(Equal(uint64(1))) - Expect(updatedParams.VoteSlash).To(Equal("0.05")) - Expect(updatedParams.UploadSlash).To(Equal("0.05")) - Expect(updatedParams.TimeoutSlash).To(Equal("0.05")) + Expect(updatedParams.VoteSlash).To(Equal(sdk.MustNewDecFromStr("0.05"))) + Expect(updatedParams.UploadSlash).To(Equal(sdk.MustNewDecFromStr("0.05"))) + Expect(updatedParams.TimeoutSlash).To(Equal(sdk.MustNewDecFromStr("0.05"))) }) It("Update no param", func() { @@ -488,7 +488,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(updatedParams.RedelegationMaxAmount).To(Equal(types.DefaultRedelegationMaxAmount)) Expect(updatedParams.UploadSlash).To(Equal(types.DefaultUploadSlash)) Expect(updatedParams.TimeoutSlash).To(Equal(types.DefaultTimeoutSlash)) - Expect(updatedParams.VoteSlash).To(Equal("0.05")) + Expect(updatedParams.VoteSlash).To(Equal(sdk.MustNewDecFromStr("0.05"))) }) It("Update vote slash with invalid value", func() { @@ -561,7 +561,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(updatedParams.UnbondingDelegationTime).To(Equal(types.DefaultUnbondingDelegationTime)) Expect(updatedParams.RedelegationCooldown).To(Equal(types.DefaultRedelegationCooldown)) Expect(updatedParams.RedelegationMaxAmount).To(Equal(types.DefaultRedelegationMaxAmount)) - Expect(updatedParams.UploadSlash).To(Equal("0.05")) + Expect(updatedParams.UploadSlash).To(Equal(sdk.MustNewDecFromStr("0.05"))) Expect(updatedParams.TimeoutSlash).To(Equal(types.DefaultTimeoutSlash)) Expect(updatedParams.VoteSlash).To(Equal(types.DefaultVoteSlash)) }) @@ -636,7 +636,7 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { Expect(updatedParams.RedelegationCooldown).To(Equal(types.DefaultRedelegationCooldown)) Expect(updatedParams.RedelegationMaxAmount).To(Equal(types.DefaultRedelegationMaxAmount)) Expect(updatedParams.UploadSlash).To(Equal(types.DefaultUploadSlash)) - Expect(updatedParams.TimeoutSlash).To(Equal("0.05")) + Expect(updatedParams.TimeoutSlash).To(Equal(sdk.MustNewDecFromStr("0.05"))) Expect(updatedParams.VoteSlash).To(Equal(types.DefaultVoteSlash)) }) diff --git a/x/delegation/types/params.go b/x/delegation/types/params.go index 6cd04f4b..fe707569 100644 --- a/x/delegation/types/params.go +++ b/x/delegation/types/params.go @@ -2,6 +2,7 @@ package types import ( "github.com/KYVENetwork/chain/util" + sdk "github.com/cosmos/cosmos-sdk/types" ) // DefaultUnbondingDelegationTime ... @@ -14,22 +15,22 @@ var DefaultRedelegationCooldown = uint64(60 * 60 * 24 * 5) var DefaultRedelegationMaxAmount = uint64(5) // DefaultVoteSlash ... -var DefaultVoteSlash = "0.1" +var DefaultVoteSlash = sdk.MustNewDecFromStr("0.1") // DefaultUploadSlash ... -var DefaultUploadSlash = "0.2" +var DefaultUploadSlash = sdk.MustNewDecFromStr("0.2") // DefaultTimeoutSlash ... -var DefaultTimeoutSlash = "0.02" +var DefaultTimeoutSlash = sdk.MustNewDecFromStr("0.02") // NewParams creates a new Params instance func NewParams( unbondingDelegationTime uint64, redelegationCooldown uint64, redelegationMaxAmount uint64, - voteSlash string, - uploadSlash string, - timeoutSlash string, + voteSlash sdk.Dec, + uploadSlash sdk.Dec, + timeoutSlash sdk.Dec, ) Params { return Params{ UnbondingDelegationTime: unbondingDelegationTime, @@ -55,15 +56,15 @@ func DefaultParams() Params { // Validate validates the set of params func (p Params) Validate() error { - if err := util.ValidateUint64(p.UnbondingDelegationTime); err != nil { + if err := util.ValidateNumber(p.UnbondingDelegationTime); err != nil { return err } - if err := util.ValidateUint64(p.RedelegationCooldown); err != nil { + if err := util.ValidateNumber(p.RedelegationCooldown); err != nil { return err } - if err := util.ValidateUint64(p.RedelegationMaxAmount); err != nil { + if err := util.ValidateNumber(p.RedelegationMaxAmount); err != nil { return err } diff --git a/x/delegation/types/params.pb.go b/x/delegation/types/params.pb.go index 89fde3a9..fffc1de2 100644 --- a/x/delegation/types/params.pb.go +++ b/x/delegation/types/params.pb.go @@ -5,6 +5,8 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -31,11 +33,11 @@ type Params struct { // unbonding_delegation_time ... RedelegationMaxAmount uint64 `protobuf:"varint,3,opt,name=redelegation_max_amount,json=redelegationMaxAmount,proto3" json:"redelegation_max_amount,omitempty"` // vote_slash ... - VoteSlash string `protobuf:"bytes,4,opt,name=vote_slash,json=voteSlash,proto3" json:"vote_slash,omitempty"` + VoteSlash github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,4,opt,name=vote_slash,json=voteSlash,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"vote_slash"` // upload_slash ... - UploadSlash string `protobuf:"bytes,5,opt,name=upload_slash,json=uploadSlash,proto3" json:"upload_slash,omitempty"` + UploadSlash github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,5,opt,name=upload_slash,json=uploadSlash,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"upload_slash"` // timeout_slash ... - TimeoutSlash string `protobuf:"bytes,6,opt,name=timeout_slash,json=timeoutSlash,proto3" json:"timeout_slash,omitempty"` + TimeoutSlash github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=timeout_slash,json=timeoutSlash,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"timeout_slash"` } func (m *Params) Reset() { *m = Params{} } @@ -92,27 +94,6 @@ func (m *Params) GetRedelegationMaxAmount() uint64 { return 0 } -func (m *Params) GetVoteSlash() string { - if m != nil { - return m.VoteSlash - } - return "" -} - -func (m *Params) GetUploadSlash() string { - if m != nil { - return m.UploadSlash - } - return "" -} - -func (m *Params) GetTimeoutSlash() string { - if m != nil { - return m.TimeoutSlash - } - return "" -} - func init() { proto.RegisterType((*Params)(nil), "kyve.delegation.v1beta1.Params") } @@ -122,27 +103,29 @@ func init() { } var fileDescriptor_17019e1d49c878a9 = []byte{ - // 307 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0xd1, 0xbb, 0x4e, 0xf3, 0x30, - 0x1c, 0x05, 0xf0, 0xba, 0x5f, 0xbf, 0x4a, 0x35, 0x65, 0xb1, 0x40, 0x0d, 0x03, 0x56, 0xb9, 0x0c, - 0x9d, 0x62, 0x55, 0x95, 0x18, 0xd8, 0xb8, 0x0d, 0x08, 0x81, 0x50, 0x41, 0x48, 0xb0, 0x44, 0x4e, - 0x63, 0xb5, 0x56, 0x63, 0xff, 0xa3, 0xc4, 0xe9, 0xe5, 0x2d, 0x18, 0x79, 0x24, 0xc6, 0x8e, 0x8c, - 0x28, 0x79, 0x11, 0x14, 0x37, 0x6a, 0xd3, 0xf5, 0x9c, 0xdf, 0xb1, 0x64, 0xfd, 0xf1, 0xf9, 0x74, - 0x39, 0x13, 0x2c, 0x10, 0xa1, 0x18, 0x73, 0x23, 0x41, 0xb3, 0x59, 0xdf, 0x17, 0x86, 0xf7, 0x59, - 0xc4, 0x63, 0xae, 0x12, 0x37, 0x8a, 0xc1, 0x00, 0xe9, 0x14, 0xca, 0xdd, 0x2a, 0xb7, 0x54, 0xa7, - 0x5f, 0x75, 0xdc, 0x7c, 0xb6, 0x92, 0x5c, 0xe2, 0xa3, 0x54, 0xfb, 0xa0, 0x03, 0xa9, 0xc7, 0xde, - 0x96, 0x7a, 0x46, 0x2a, 0xe1, 0xa0, 0x2e, 0xea, 0x35, 0x86, 0x9d, 0x0d, 0xb8, 0xdd, 0xf4, 0xaf, - 0x52, 0x09, 0x32, 0xc0, 0x87, 0xb1, 0xa8, 0x6c, 0x46, 0x00, 0x61, 0x00, 0x73, 0xed, 0xd4, 0xed, - 0xee, 0xa0, 0x5a, 0xde, 0x94, 0x1d, 0xb9, 0xc0, 0x9d, 0x9d, 0x91, 0xe2, 0x0b, 0x8f, 0x2b, 0x48, - 0xb5, 0x71, 0xfe, 0xd9, 0xd9, 0xce, 0x9b, 0x8f, 0x7c, 0x71, 0x65, 0x4b, 0x72, 0x8c, 0xf1, 0x0c, - 0x8c, 0xf0, 0x92, 0x90, 0x27, 0x13, 0xa7, 0xd1, 0x45, 0xbd, 0xd6, 0xb0, 0x55, 0x24, 0x2f, 0x45, - 0x40, 0x4e, 0x70, 0x3b, 0x8d, 0x42, 0xe0, 0x41, 0x09, 0xfe, 0x5b, 0xb0, 0xb7, 0xce, 0xd6, 0xe4, - 0x0c, 0xef, 0x17, 0xbf, 0x82, 0xd4, 0x94, 0xa6, 0x69, 0x4d, 0xbb, 0x0c, 0x2d, 0xba, 0xbe, 0xff, - 0xce, 0x28, 0x5a, 0x65, 0x14, 0xfd, 0x66, 0x14, 0x7d, 0xe6, 0xb4, 0xb6, 0xca, 0x69, 0xed, 0x27, - 0xa7, 0xb5, 0x0f, 0x36, 0x96, 0x66, 0x92, 0xfa, 0xee, 0x08, 0x14, 0x7b, 0x78, 0x7f, 0xbb, 0x7b, - 0x12, 0x66, 0x0e, 0xf1, 0x94, 0x8d, 0x26, 0x5c, 0x6a, 0xb6, 0xa8, 0x5e, 0xc3, 0x2c, 0x23, 0x91, - 0xf8, 0x4d, 0x7b, 0x85, 0xc1, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x87, 0x17, 0x6d, 0x46, 0xad, - 0x01, 0x00, 0x00, + // 350 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0xd2, 0x3f, 0x4f, 0xfa, 0x40, + 0x1c, 0x06, 0xf0, 0xf6, 0x07, 0x3f, 0x12, 0x4e, 0x5c, 0x1a, 0x0c, 0xd5, 0xa1, 0x10, 0x63, 0x0c, + 0x8b, 0xbd, 0x10, 0x12, 0x07, 0x37, 0x11, 0x07, 0x63, 0x30, 0x0a, 0xc6, 0x44, 0x97, 0xe6, 0xda, + 0x5e, 0x4a, 0x43, 0x7b, 0xdf, 0xa6, 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76, 0x80, 0x87, 0xc0, 0xb3, + 0xcf, 0x15, 0x77, 0x47, 0x58, 0xcc, 0x22, 0xca, 0xcd, 0x2e, 0x75, 0xfa, 0xe5, 0x54, 0x18, 0xa4, + 0x80, 0xf6, 0x82, 0x2a, 0x49, 0x14, 0x00, 0x71, 0x33, 0xf0, 0xff, 0x41, 0xe0, 0xd1, 0xc6, 0xd8, + 0x90, 0x03, 0x74, 0x9c, 0x9e, 0x1a, 0x24, 0x22, 0x33, 0x4b, 0x07, 0x99, 0x95, 0x0c, 0x91, 0x68, + 0xe7, 0x61, 0xbe, 0x32, 0xd4, 0xc5, 0xca, 0x50, 0x7f, 0x57, 0x86, 0xfa, 0xb9, 0x36, 0x94, 0xc5, + 0xda, 0x50, 0xbe, 0xd7, 0x86, 0xf2, 0x81, 0x73, 0xde, 0xe3, 0xfb, 0xdb, 0xfd, 0x13, 0x15, 0x13, + 0x88, 0x47, 0xd8, 0x19, 0x12, 0x9f, 0xe1, 0x69, 0xfe, 0xcd, 0x48, 0xdc, 0x2e, 0xc9, 0xcb, 0x6f, + 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0x45, 0xa8, 0x27, 0x47, 0x53, 0x02, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -165,27 +148,36 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.TimeoutSlash) > 0 { - i -= len(m.TimeoutSlash) - copy(dAtA[i:], m.TimeoutSlash) - i = encodeVarintParams(dAtA, i, uint64(len(m.TimeoutSlash))) - i-- - dAtA[i] = 0x32 + { + size := m.TimeoutSlash.Size() + i -= size + if _, err := m.TimeoutSlash.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) } - if len(m.UploadSlash) > 0 { - i -= len(m.UploadSlash) - copy(dAtA[i:], m.UploadSlash) - i = encodeVarintParams(dAtA, i, uint64(len(m.UploadSlash))) - i-- - dAtA[i] = 0x2a + i-- + dAtA[i] = 0x32 + { + size := m.UploadSlash.Size() + i -= size + if _, err := m.UploadSlash.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) } - if len(m.VoteSlash) > 0 { - i -= len(m.VoteSlash) - copy(dAtA[i:], m.VoteSlash) - i = encodeVarintParams(dAtA, i, uint64(len(m.VoteSlash))) - i-- - dAtA[i] = 0x22 + i-- + dAtA[i] = 0x2a + { + size := m.VoteSlash.Size() + i -= size + if _, err := m.VoteSlash.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x22 if m.RedelegationMaxAmount != 0 { i = encodeVarintParams(dAtA, i, uint64(m.RedelegationMaxAmount)) i-- @@ -230,18 +222,12 @@ func (m *Params) Size() (n int) { if m.RedelegationMaxAmount != 0 { n += 1 + sovParams(uint64(m.RedelegationMaxAmount)) } - l = len(m.VoteSlash) - if l > 0 { - n += 1 + l + sovParams(uint64(l)) - } - l = len(m.UploadSlash) - if l > 0 { - n += 1 + l + sovParams(uint64(l)) - } - l = len(m.TimeoutSlash) - if l > 0 { - n += 1 + l + sovParams(uint64(l)) - } + l = m.VoteSlash.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.UploadSlash.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.TimeoutSlash.Size() + n += 1 + l + sovParams(uint64(l)) return n } @@ -367,7 +353,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.VoteSlash = string(dAtA[iNdEx:postIndex]) + if err := m.VoteSlash.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 5: if wireType != 2 { @@ -399,7 +387,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.UploadSlash = string(dAtA[iNdEx:postIndex]) + if err := m.UploadSlash.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 6: if wireType != 2 { @@ -431,7 +421,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.TimeoutSlash = string(dAtA[iNdEx:postIndex]) + if err := m.TimeoutSlash.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/stakers/types/params.go b/x/stakers/types/params.go index 76a01b9b..2ecb0884 100644 --- a/x/stakers/types/params.go +++ b/x/stakers/types/params.go @@ -31,11 +31,11 @@ func DefaultParams() Params { // Validate validates the set of params func (p Params) Validate() error { - if err := util.ValidateUint64(p.CommissionChangeTime); err != nil { + if err := util.ValidateNumber(p.CommissionChangeTime); err != nil { return err } - if err := util.ValidateUint64(p.LeavePoolTime); err != nil { + if err := util.ValidateNumber(p.LeavePoolTime); err != nil { return err } From 53ea26e28ab4df0906ef7a1a931e790bd75e4acd Mon Sep 17 00:00:00 2001 From: John Letey Date: Mon, 20 Mar 2023 14:36:37 +0100 Subject: [PATCH 2/6] chore: update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee9d9d30..5b2d9988 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,11 @@ - Emit an event when updating module parameters. +### State Machine Breaking + +- (`x/bundles`) [#19](https://github.com/KYVENetwork/chain/pull/19) Migrate `NetworkFee` param to type `sdk.Dec`. +- (`x/delegation`) [#19](https://github.com/KYVENetwork/chain/pull/19) Migrate `VoteSlash`, `UploadSlash`, `TimeoutSlash` params to type `sdk.Dec`. + ## [v1.0.0](https://github.com/KYVENetwork/chain/releases/tag/v1.0.0) - 2023-03-10 Release for the KYVE network launch. From f08974608073a6bd7e739e95fac162d472db7e91 Mon Sep 17 00:00:00 2001 From: John Letey Date: Thu, 23 Mar 2023 12:10:46 +0100 Subject: [PATCH 3/6] refactor: switch protocol validator commission to `sdk.Dec` --- CHANGELOG.md | 1 + proto/kyve/query/v1beta1/query.proto | 11 +- proto/kyve/stakers/v1beta1/events.proto | 5 +- proto/kyve/stakers/v1beta1/stakers.proto | 12 +- proto/kyve/stakers/v1beta1/tx.proto | 6 +- .../keeper/keeper_suite_stakers_leave_test.go | 3 +- .../keeper/keeper_suite_valid_bundles_test.go | 21 +-- x/query/types/query.pb.go | 159 +++++++++--------- x/stakers/client/cli/tx_update_commission.go | 8 +- x/stakers/keeper/exported_functions.go | 7 +- x/stakers/keeper/getters_staker.go | 2 +- x/stakers/keeper/logic_commission.go | 2 +- .../keeper/msg_server_update_commission.go | 10 -- .../msg_server_update_commission_test.go | 62 +++---- x/stakers/types/errors.go | 1 - x/stakers/types/events.pb.go | 93 +++++----- x/stakers/types/keys.go | 8 +- x/stakers/types/message_update_commission.go | 35 ++-- x/stakers/types/stakers.pb.go | 129 +++++++------- x/stakers/types/tx.pb.go | 113 +++++++------ 20 files changed, 339 insertions(+), 349 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7b31e48..e3f521b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - (`x/bundles`) [#19](https://github.com/KYVENetwork/chain/pull/19) Migrate `NetworkFee` param to type `sdk.Dec`. - (`x/delegation`) [#19](https://github.com/KYVENetwork/chain/pull/19) Migrate `VoteSlash`, `UploadSlash`, `TimeoutSlash` params to type `sdk.Dec`. +- (`x/stakers`) [#19](https://github.com/KYVENetwork/chain/pull/19) Migrate protocol validator `Commission` to type `sdk.Dec`. ## [v1.0.0](https://github.com/KYVENetwork/chain/releases/tag/v1.0.0) - 2023-03-10 diff --git a/proto/kyve/query/v1beta1/query.proto b/proto/kyve/query/v1beta1/query.proto index 88fa9dfb..04be74af 100644 --- a/proto/kyve/query/v1beta1/query.proto +++ b/proto/kyve/query/v1beta1/query.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package kyve.query.v1beta1; +import "gogoproto/gogo.proto"; import "kyve/pool/v1beta1/pool.proto"; option go_package = "github.com/KYVENetwork/chain/x/query/types"; @@ -94,7 +95,10 @@ message StakerMetadata { // commission is the percentage of the rewards that will // get transferred to the staker before the remaining // rewards are split across all delegators - string commission = 1; + string commission = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; // moniker is a human-readable name for displaying // the staker in the UI @@ -119,7 +123,10 @@ message StakerMetadata { message CommissionChangeEntry { // commission is the new commission that will // become active once the change-time is over - string commission = 1; + string commission = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; // creation_date is the UNIX-timestamp (in seconds) // of when the entry was created. diff --git a/proto/kyve/stakers/v1beta1/events.proto b/proto/kyve/stakers/v1beta1/events.proto index 47a68197..5bc47f03 100644 --- a/proto/kyve/stakers/v1beta1/events.proto +++ b/proto/kyve/stakers/v1beta1/events.proto @@ -46,7 +46,10 @@ message EventUpdateCommission { // staker is the account address of the protocol node. string staker = 1; // commission ... - string commission = 2; + string commission = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; } // EventJoinPool ... diff --git a/proto/kyve/stakers/v1beta1/stakers.proto b/proto/kyve/stakers/v1beta1/stakers.proto index 66ac6513..bc7c85fd 100644 --- a/proto/kyve/stakers/v1beta1/stakers.proto +++ b/proto/kyve/stakers/v1beta1/stakers.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package kyve.stakers.v1beta1; +import "gogoproto/gogo.proto"; + option go_package = "github.com/KYVENetwork/chain/x/stakers/types"; // Staker contains all metadata for a staker @@ -10,7 +12,10 @@ message Staker { // address ... string address = 1; // commission ... - string commission = 2; + string commission = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; // moniker ... string moniker = 3; // website ... @@ -50,7 +55,10 @@ message CommissionChangeEntry { string staker = 2; // commission is the new commission which will // be applied after the waiting time is over. - string commission = 3; + string commission = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; // creation_date is the UNIX-timestamp in seconds // when the entry was created. int64 creation_date = 4; diff --git a/proto/kyve/stakers/v1beta1/tx.proto b/proto/kyve/stakers/v1beta1/tx.proto index 729f36ae..cda550d1 100644 --- a/proto/kyve/stakers/v1beta1/tx.proto +++ b/proto/kyve/stakers/v1beta1/tx.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package kyve.stakers.v1beta1; import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; option go_package = "github.com/KYVENetwork/chain/x/stakers/types"; @@ -55,7 +56,10 @@ message MsgUpdateCommission { // creator ... string creator = 1; // commission ... - string commission = 2; + string commission = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; } // MsgUpdateCommissionResponse ... diff --git a/x/bundles/keeper/keeper_suite_stakers_leave_test.go b/x/bundles/keeper/keeper_suite_stakers_leave_test.go index eaeb6d29..213799ba 100644 --- a/x/bundles/keeper/keeper_suite_stakers_leave_test.go +++ b/x/bundles/keeper/keeper_suite_stakers_leave_test.go @@ -219,12 +219,11 @@ var _ = Describe("stakers leave", Ordered, func() { totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) totalUploaderReward := totalReward - treasuryReward - uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(commission).TruncateInt64()) + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward // assert payout transfer diff --git a/x/bundles/keeper/keeper_suite_valid_bundles_test.go b/x/bundles/keeper/keeper_suite_valid_bundles_test.go index c571f993..82948132 100644 --- a/x/bundles/keeper/keeper_suite_valid_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_valid_bundles_test.go @@ -180,12 +180,11 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) totalUploaderReward := totalReward - treasuryReward - uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(commission).TruncateInt64()) + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward // assert payout transfer @@ -296,12 +295,11 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) totalUploaderReward := totalReward - treasuryReward - uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(commission).TruncateInt64()) + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) totalDelegationReward := totalUploaderReward - uploaderPayoutReward // divide with 4 because uploader only has 25% of total delegation @@ -445,12 +443,11 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) totalUploaderReward := totalReward - treasuryReward - uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(commission).TruncateInt64()) + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward // assert payout transfer @@ -600,12 +597,11 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) totalUploaderReward := totalReward - treasuryReward - uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(commission).TruncateInt64()) + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) totalDelegationReward := totalUploaderReward - uploaderPayoutReward // divide with 4 because uploader only has 25% of total delegation @@ -760,12 +756,11 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) totalUploaderReward := totalReward - treasuryReward - uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(commission).TruncateInt64()) + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) totalDelegationReward := totalUploaderReward - uploaderPayoutReward // divide with 4 because uploader only has 25% of total delegation @@ -928,12 +923,11 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) totalUploaderReward := totalReward - treasuryReward - uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(commission).TruncateInt64()) + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) totalDelegationReward := totalUploaderReward - uploaderPayoutReward // divide with 4 because uploader only has 25% of total delegation @@ -1106,12 +1100,11 @@ var _ = Describe("valid bundles", Ordered, func() { // calculate uploader rewards totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - commission, _ := sdk.NewDecFromStr(uploader.Commission) treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) totalUploaderReward := totalReward - treasuryReward - uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(commission).TruncateInt64()) + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) totalDelegationReward := totalUploaderReward - uploaderPayoutReward // divide with 4 because uploader only has 25% of total delegation diff --git a/x/query/types/query.pb.go b/x/query/types/query.pb.go index 775dae00..efd01080 100644 --- a/x/query/types/query.pb.go +++ b/x/query/types/query.pb.go @@ -6,6 +6,8 @@ package types import ( fmt "fmt" types "github.com/KYVENetwork/chain/x/pool/types" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -260,7 +262,7 @@ type StakerMetadata struct { // commission is the percentage of the rewards that will // get transferred to the staker before the remaining // rewards are split across all delegators - Commission string `protobuf:"bytes,1,opt,name=commission,proto3" json:"commission,omitempty"` + Commission github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=commission,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"commission"` // moniker is a human-readable name for displaying // the staker in the UI Moniker string `protobuf:"bytes,2,opt,name=moniker,proto3" json:"moniker,omitempty"` @@ -309,13 +311,6 @@ func (m *StakerMetadata) XXX_DiscardUnknown() { var xxx_messageInfo_StakerMetadata proto.InternalMessageInfo -func (m *StakerMetadata) GetCommission() string { - if m != nil { - return m.Commission - } - return "" -} - func (m *StakerMetadata) GetMoniker() string { if m != nil { return m.Moniker @@ -349,7 +344,7 @@ func (m *StakerMetadata) GetPendingCommissionChange() *CommissionChangeEntry { type CommissionChangeEntry struct { // commission is the new commission that will // become active once the change-time is over - Commission string `protobuf:"bytes,1,opt,name=commission,proto3" json:"commission,omitempty"` + Commission github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=commission,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"commission"` // creation_date is the UNIX-timestamp (in seconds) // of when the entry was created. CreationDate int64 `protobuf:"varint,2,opt,name=creation_date,json=creationDate,proto3" json:"creation_date,omitempty"` @@ -388,13 +383,6 @@ func (m *CommissionChangeEntry) XXX_DiscardUnknown() { var xxx_messageInfo_CommissionChangeEntry proto.InternalMessageInfo -func (m *CommissionChangeEntry) GetCommission() string { - if m != nil { - return m.Commission - } - return "" -} - func (m *CommissionChangeEntry) GetCreationDate() int64 { if m != nil { return m.CreationDate @@ -505,49 +493,52 @@ func init() { func init() { proto.RegisterFile("kyve/query/v1beta1/query.proto", fileDescriptor_6b41255feae93a15) } var fileDescriptor_6b41255feae93a15 = []byte{ - // 671 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x94, 0xc1, 0x6e, 0xd3, 0x4c, - 0x10, 0xc7, 0xeb, 0x24, 0x4d, 0x9b, 0xc9, 0xd7, 0xf4, 0xd3, 0x4a, 0x50, 0x17, 0x51, 0x53, 0x05, - 0xa1, 0xb6, 0x1c, 0x12, 0xb5, 0x08, 0x09, 0x71, 0xe0, 0xd0, 0xb4, 0x95, 0x10, 0x14, 0x21, 0x23, - 0x90, 0x40, 0x48, 0xd6, 0xda, 0xde, 0x26, 0xab, 0xd8, 0xbb, 0x66, 0x77, 0x9d, 0x92, 0xb7, 0xe0, - 0x51, 0x38, 0xf0, 0x10, 0x1c, 0x7b, 0x84, 0x13, 0xa8, 0x7d, 0x11, 0xb4, 0xbb, 0xb6, 0x49, 0x4a, - 0x10, 0x37, 0xcf, 0x7f, 0xfe, 0x33, 0xc9, 0xfc, 0x66, 0x6c, 0xf0, 0xc6, 0xd3, 0x09, 0xe9, 0x7f, - 0xc8, 0x89, 0x98, 0xf6, 0x27, 0xfb, 0x21, 0x51, 0x78, 0xdf, 0x46, 0xbd, 0x4c, 0x70, 0xc5, 0x11, - 0xd2, 0xf9, 0x9e, 0x55, 0x8a, 0xfc, 0xad, 0xdb, 0xa6, 0x26, 0xe3, 0x3c, 0xa9, 0x4a, 0x74, 0x60, - 0x2b, 0xba, 0x9f, 0x6b, 0xd0, 0x3a, 0xc4, 0x92, 0x46, 0x2f, 0x39, 0x4f, 0x50, 0x07, 0x6a, 0x34, - 0x76, 0x9d, 0x6d, 0x67, 0xb7, 0xe1, 0xd7,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 0xe2, 0x11, 0x56, 0xa4, 0xfb, 0xc5, 0x81, 0xce, 0x3c, 0x59, 0xb4, - 0x0f, 0x0d, 0xcd, 0xd6, 0x74, 0x6c, 0x97, 0x37, 0x3e, 0x3f, 0x42, 0xf5, 0x01, 0xf0, 0x8d, 0x15, - 0xdd, 0x84, 0x66, 0xc6, 0x29, 0x53, 0xd2, 0xfc, 0x46, 0xc3, 0x2f, 0x22, 0xb4, 0x05, 0x40, 0x65, - 0x90, 0x10, 0x3c, 0xd1, 0x87, 0xa5, 0x99, 0xae, 0xfa, 0x2d, 0x2a, 0x9f, 0x5b, 0x41, 0x4f, 0x30, - 0xc1, 0x49, 0xf9, 0x32, 0x58, 0xb6, 0x33, 0x8a, 0xde, 0x47, 0x88, 0x13, 0xcc, 0x22, 0x52, 0x5c, - 0x58, 0x19, 0x1e, 0x1e, 0x7d, 0xbd, 0xf4, 0x9c, 0x8b, 0x4b, 0xcf, 0xf9, 0x79, 0xe9, 0x39, 0x9f, - 0xae, 0xbc, 0xa5, 0x8b, 0x2b, 0x6f, 0xe9, 0xdb, 0x95, 0xb7, 0xf4, 0xee, 0xfe, 0x90, 0xaa, 0x51, - 0x1e, 0xf6, 0x22, 0x9e, 0xf6, 0x9f, 0xbd, 0x7d, 0x73, 0xfc, 0x82, 0xa8, 0x73, 0x2e, 0xc6, 0xfd, - 0x68, 0x84, 0x29, 0xeb, 0x7f, 0x2c, 0xbe, 0x85, 0x6a, 0x9a, 0x11, 0x19, 0x36, 0xcd, 0x27, 0xed, - 0xc1, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x55, 0xa5, 0xc1, 0x00, 0x26, 0x05, 0x00, 0x00, + // 719 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0xcf, 0x6e, 0xd3, 0x4a, + 0x14, 0xc6, 0xe3, 0x24, 0x4d, 0x9b, 0x93, 0xdb, 0xf4, 0x6a, 0x74, 0xef, 0xad, 0x5b, 0xdd, 0xba, + 0x55, 0x10, 0xb4, 0x45, 0xc2, 0x51, 0x8b, 0x90, 0x10, 0x0b, 0x16, 0x4d, 0x5a, 0x09, 0x41, 0x2b, + 0x64, 0x04, 0x12, 0x6c, 0xac, 0x89, 0x3d, 0x75, 0x46, 0xb1, 0x67, 0x8c, 0x67, 0x9c, 0x92, 0x77, + 0x40, 0x82, 0x47, 0x61, 0xc1, 0x43, 0x74, 0xd9, 0x25, 0xb0, 0xa8, 0x50, 0xfb, 0x22, 0x68, 0xc6, + 0x7f, 0x48, 0x4a, 0xd8, 0xb1, 0xca, 0x9c, 0xef, 0x7c, 0x73, 0xe2, 0xf9, 0x9d, 0x33, 0x03, 0xd6, + 0x68, 0x32, 0x26, 0xdd, 0xb7, 0x29, 0x49, 0x26, 0xdd, 0xf1, 0xde, 0x80, 0x48, 0xbc, 0x97, 0x45, + 0x76, 0x9c, 0x70, 0xc9, 0x11, 0x52, 0x79, 0x3b, 0x53, 0xf2, 0xfc, 0xfa, 0x3f, 0x01, 0x0f, 0xb8, + 0x4e, 0x77, 0xd5, 0x2a, 0x73, 0xae, 0xff, 0xaf, 0x2b, 0xc5, 0x9c, 0x87, 0x65, 0x21, 0x15, 0x64, + 0xd9, 0xce, 0xa7, 0x2a, 0x34, 0x0f, 0xb0, 0xa0, 0xde, 0x73, 0xce, 0x43, 0xd4, 0x86, 0x2a, 0xf5, + 0x4d, 0x63, 0xcb, 0xd8, 0xa9, 0x3b, 0x55, 0xea, 0x23, 0x04, 0x75, 0x86, 0x23, 0x62, 0x56, 0xb7, + 0x8c, 0x9d, 0xa6, 0xa3, 0xd7, 0xc8, 0x84, 0xc5, 0x24, 0x65, 0x92, 0x46, 0xc4, 0xac, 0x69, 0xb9, + 0x08, 0x95, 0x3b, 0xe4, 0x01, 0x37, 0xeb, 0x99, 0x5b, 0xad, 0xd1, 0x6d, 0x68, 0xf3, 0x98, 0x24, + 0x58, 0x52, 0x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 0x6c, 0x40, 0x7b, 0xb6, 0x75, 0x68, 0x0f, 0xea, 0xaa, 0x79, 0xfa, 0x0b, 0x5a, 0xc5, 0x25, + 0x9a, 0x3d, 0x73, 0xf9, 0xc2, 0x38, 0xda, 0x8a, 0xfe, 0x83, 0x46, 0xcc, 0x29, 0x93, 0x42, 0xff, + 0x47, 0xdd, 0xc9, 0x23, 0xb4, 0x01, 0x40, 0x85, 0x1b, 0x12, 0x3c, 0x56, 0x93, 0xab, 0x9a, 0xb0, + 0xe4, 0x34, 0xa9, 0x78, 0x96, 0x09, 0xc8, 0x02, 0x18, 0xe3, 0xb0, 0xb8, 0x6d, 0x59, 0x33, 0xa6, + 0x14, 0xd5, 0xc0, 0x01, 0x0e, 0x31, 0xf3, 0x48, 0x3e, 0xc2, 0x45, 0x78, 0xd0, 0x3f, 0xbf, 0xb2, + 0x8c, 0x8b, 0x2b, 0xcb, 0xf8, 0x7e, 0x65, 0x19, 0x1f, 0xaf, 0xad, 0xca, 0xc5, 0xb5, 0x55, 0xf9, + 0x72, 0x6d, 0x55, 0xde, 0xdc, 0x9d, 0x22, 0xf5, 0xf4, 0xf5, 0xab, 0xc3, 0x13, 0x22, 0xcf, 0x78, + 0x32, 0xea, 0x7a, 0x43, 0x4c, 0x59, 0xf7, 0x5d, 0xfe, 0x04, 0x6b, 0x62, 0x83, 0x86, 0x7e, 0x33, + 0xef, 0xff, 0x08, 0x00, 0x00, 0xff, 0xff, 0x97, 0x7e, 0xc8, 0xa1, 0x9d, 0x05, 0x00, 0x00, } func (m *BasicPool) Marshal() (dAtA []byte, err error) { @@ -753,13 +744,16 @@ func (m *StakerMetadata) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if len(m.Commission) > 0 { - i -= len(m.Commission) - copy(dAtA[i:], m.Commission) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Commission))) - i-- - dAtA[i] = 0xa + { + size := m.Commission.Size() + i -= size + if _, err := m.Commission.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -788,13 +782,16 @@ func (m *CommissionChangeEntry) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x10 } - if len(m.Commission) > 0 { - i -= len(m.Commission) - copy(dAtA[i:], m.Commission) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Commission))) - i-- - dAtA[i] = 0xa + { + size := m.Commission.Size() + i -= size + if _, err := m.Commission.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -951,10 +948,8 @@ func (m *StakerMetadata) Size() (n int) { } var l int _ = l - l = len(m.Commission) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } + l = m.Commission.Size() + n += 1 + l + sovQuery(uint64(l)) l = len(m.Moniker) if l > 0 { n += 1 + l + sovQuery(uint64(l)) @@ -980,10 +975,8 @@ func (m *CommissionChangeEntry) Size() (n int) { } var l int _ = l - l = len(m.Commission) - if l > 0 { - n += 1 + l + sovQuery(uint64(l)) - } + l = m.Commission.Size() + n += 1 + l + sovQuery(uint64(l)) if m.CreationDate != 0 { n += 1 + sovQuery(uint64(m.CreationDate)) } @@ -1569,7 +1562,9 @@ func (m *StakerMetadata) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Commission = string(dAtA[iNdEx:postIndex]) + if err := m.Commission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 2: if wireType != 2 { @@ -1783,7 +1778,9 @@ func (m *CommissionChangeEntry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Commission = string(dAtA[iNdEx:postIndex]) + if err := m.Commission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 2: if wireType != 0 { diff --git a/x/stakers/client/cli/tx_update_commission.go b/x/stakers/client/cli/tx_update_commission.go index 4bf925a5..9274fc34 100644 --- a/x/stakers/client/cli/tx_update_commission.go +++ b/x/stakers/client/cli/tx_update_commission.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" ) @@ -19,9 +20,14 @@ func CmdUpdateCommission() *cobra.Command { return err } + commission, err := sdk.NewDecFromStr(args[0]) + if err != nil { + return err + } + msg := types.MsgUpdateCommission{ Creator: clientCtx.GetFromAddress().String(), - Commission: args[0], + Commission: commission, } if err := msg.ValidateBasic(); err != nil { diff --git a/x/stakers/keeper/exported_functions.go b/x/stakers/keeper/exported_functions.go index d53765e6..901666d9 100644 --- a/x/stakers/keeper/exported_functions.go +++ b/x/stakers/keeper/exported_functions.go @@ -2,7 +2,6 @@ package keeper import ( "cosmossdk.io/math" - "github.com/KYVENetwork/chain/util" sdk "github.com/cosmos/cosmos-sdk/types" // Gov @@ -41,11 +40,7 @@ func (k Keeper) GetAllStakerAddressesOfPool(ctx sdk.Context, poolId uint64) (sta // GetCommission returns the commission of a staker as a parsed sdk.Dec func (k Keeper) GetCommission(ctx sdk.Context, stakerAddress string) sdk.Dec { staker, _ := k.GetStaker(ctx, stakerAddress) - uploaderCommission, err := sdk.NewDecFromStr(staker.Commission) - if err != nil { - util.PanicHalt(k.upgradeKeeper, ctx, "Commission not parsable: "+staker.Commission) - } - return uploaderCommission + return staker.Commission } // AssertValaccountAuthorized checks if the given `valaddress` is allowed to vote in pool diff --git a/x/stakers/keeper/getters_staker.go b/x/stakers/keeper/getters_staker.go index 32d7641e..db8436c7 100644 --- a/x/stakers/keeper/getters_staker.go +++ b/x/stakers/keeper/getters_staker.go @@ -24,7 +24,7 @@ func (k Keeper) UpdateStakerMetadata(ctx sdk.Context, address string, moniker st } // UpdateStakerCommission ... -func (k Keeper) UpdateStakerCommission(ctx sdk.Context, address string, commission string) { +func (k Keeper) UpdateStakerCommission(ctx sdk.Context, address string, commission sdk.Dec) { staker, found := k.GetStaker(ctx, address) if found { staker.Commission = commission diff --git a/x/stakers/keeper/logic_commission.go b/x/stakers/keeper/logic_commission.go index 1d888adc..894ff913 100644 --- a/x/stakers/keeper/logic_commission.go +++ b/x/stakers/keeper/logic_commission.go @@ -9,7 +9,7 @@ import ( // The queue is checked in every endBlock and when the commissionChangeTime // is over the new commission will be applied to the user. // If another entry is currently in the queue it will be removed. -func (k Keeper) orderNewCommissionChange(ctx sdk.Context, staker string, commission string) { +func (k Keeper) orderNewCommissionChange(ctx sdk.Context, staker string, commission sdk.Dec) { // Remove existing queue entry queueEntry, found := k.GetCommissionChangeEntryByIndex2(ctx, staker) if found { diff --git a/x/stakers/keeper/msg_server_update_commission.go b/x/stakers/keeper/msg_server_update_commission.go index 36ae8af8..0eb30c8d 100644 --- a/x/stakers/keeper/msg_server_update_commission.go +++ b/x/stakers/keeper/msg_server_update_commission.go @@ -21,16 +21,6 @@ func (k msgServer) UpdateCommission(goCtx context.Context, msg *types.MsgUpdateC return nil, errors.Wrap(errorsTypes.ErrUnauthorized, types.ErrNoStaker.Error()) } - // Validate commission. - commission, err := sdk.NewDecFromStr(msg.Commission) - if err != nil { - return nil, errors.Wrapf(errorsTypes.ErrLogic, types.ErrInvalidCommission.Error(), msg.Commission) - } - - if commission.LT(sdk.NewDec(int64(0))) || commission.GT(sdk.NewDec(int64(1))) { - return nil, errors.Wrapf(errorsTypes.ErrLogic, types.ErrInvalidCommission.Error(), msg.Commission) - } - // Insert commission change into queue k.orderNewCommissionChange(ctx, msg.Creator, msg.Commission) diff --git a/x/stakers/keeper/msg_server_update_commission_test.go b/x/stakers/keeper/msg_server_update_commission_test.go index 852a20a5..c0772682 100644 --- a/x/stakers/keeper/msg_server_update_commission_test.go +++ b/x/stakers/keeper/msg_server_update_commission_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + sdk "github.com/cosmos/cosmos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -53,7 +54,7 @@ var _ = Describe("msg_server_update_commission.go", Ordered, func() { // ACT s.RunTxStakersSuccess(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_0, - Commission: "0.5", + Commission: sdk.MustNewDecFromStr("0.5"), }) s.PerformValidityChecks() @@ -66,14 +67,14 @@ var _ = Describe("msg_server_update_commission.go", Ordered, func() { s.CommitAfterSeconds(1) staker, _ = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - Expect(staker.Commission).To(Equal("0.5")) + Expect(staker.Commission).To(Equal(sdk.MustNewDecFromStr("0.5"))) }) It("Update commission to 0% from previously default commission", func() { // ACT s.RunTxStakersSuccess(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_0, - Commission: "0", + Commission: sdk.ZeroDec(), }) s.PerformValidityChecks() @@ -86,14 +87,14 @@ var _ = Describe("msg_server_update_commission.go", Ordered, func() { s.CommitAfterSeconds(1) staker, _ = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - Expect(staker.Commission).To(Equal("0")) + Expect(staker.Commission).To(Equal(sdk.ZeroDec())) }) It("Update commission to 100% from previously default commission", func() { // ACT s.RunTxStakersSuccess(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_0, - Commission: "1", + Commission: sdk.OneDec(), }) s.PerformValidityChecks() @@ -106,27 +107,28 @@ var _ = Describe("msg_server_update_commission.go", Ordered, func() { s.CommitAfterSeconds(1) staker, _ = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - Expect(staker.Commission).To(Equal("1")) + Expect(staker.Commission).To(Equal(sdk.OneDec())) }) - It("Update commission with an invalid number from previously default commission", func() { - // ACT - s.RunTxStakersError(&stakerstypes.MsgUpdateCommission{ - Creator: i.STAKER_0, - Commission: "teset", - }) - s.PerformValidityChecks() - - // ASSERT - staker, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - Expect(staker.Commission).To(Equal(stakerstypes.DefaultCommission)) - }) + // TODO(@troy): In theory we don't need this test anymore. + //It("Update commission with an invalid number from previously default commission", func() { + // // ACT + // s.RunTxStakersError(&stakerstypes.MsgUpdateCommission{ + // Creator: i.STAKER_0, + // Commission: "teset", + // }) + // s.PerformValidityChecks() + // + // // ASSERT + // staker, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + // Expect(staker.Commission).To(Equal(stakerstypes.DefaultCommission)) + //}) It("Update commission with a negative number from previously default commission", func() { // ACT s.RunTxStakersError(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_0, - Commission: "-0.5", + Commission: sdk.MustNewDecFromStr("-0.5"), }) s.PerformValidityChecks() @@ -139,7 +141,7 @@ var _ = Describe("msg_server_update_commission.go", Ordered, func() { // ACT s.RunTxStakersError(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_0, - Commission: "2", + Commission: sdk.NewDec(2), }) s.PerformValidityChecks() @@ -152,19 +154,19 @@ var _ = Describe("msg_server_update_commission.go", Ordered, func() { // ACT s.RunTxStakersSuccess(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_0, - Commission: "0.5", + Commission: sdk.MustNewDecFromStr("0.5"), }) s.PerformValidityChecks() s.RunTxStakersSuccess(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_0, - Commission: "0.2", + Commission: sdk.MustNewDecFromStr("0.2"), }) s.PerformValidityChecks() s.RunTxStakersSuccess(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_0, - Commission: "0.3", + Commission: sdk.MustNewDecFromStr("0.3"), }) s.PerformValidityChecks() @@ -177,19 +179,19 @@ var _ = Describe("msg_server_update_commission.go", Ordered, func() { s.CommitAfterSeconds(1) staker, _ = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - Expect(staker.Commission).To(Equal("0.3")) + Expect(staker.Commission).To(Equal(sdk.MustNewDecFromStr("0.3"))) }) It("Update commission multiple times during the commission change time with the same value", func() { // ACT s.RunTxStakersSuccess(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_0, - Commission: "0.5", + Commission: sdk.MustNewDecFromStr("0.5"), }) s.RunTxStakersSuccess(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_0, - Commission: "0.2", + Commission: sdk.MustNewDecFromStr("0.2"), }) s.RunTxStakersSuccess(&stakerstypes.MsgUpdateCommission{ @@ -220,12 +222,12 @@ var _ = Describe("msg_server_update_commission.go", Ordered, func() { // ACT s.RunTxStakersSuccess(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_0, - Commission: "0.5", + Commission: sdk.MustNewDecFromStr("0.5"), }) s.RunTxStakersSuccess(&stakerstypes.MsgUpdateCommission{ Creator: i.STAKER_1, - Commission: "0.5", + Commission: sdk.MustNewDecFromStr("0.5"), }) s.PerformValidityChecks() @@ -242,9 +244,9 @@ var _ = Describe("msg_server_update_commission.go", Ordered, func() { s.CommitAfterSeconds(1) staker0, _ = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - Expect(staker0.Commission).To(Equal("0.5")) + Expect(staker0.Commission).To(Equal(sdk.MustNewDecFromStr("0.5"))) staker1, _ = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_1) - Expect(staker1.Commission).To(Equal("0.5")) + Expect(staker1.Commission).To(Equal(sdk.MustNewDecFromStr("0.5"))) }) }) diff --git a/x/stakers/types/errors.go b/x/stakers/types/errors.go index f12025f8..35a19780 100644 --- a/x/stakers/types/errors.go +++ b/x/stakers/types/errors.go @@ -17,7 +17,6 @@ var ( ErrValaddressSameAsStaker = errors.Register(ModuleName, 1111, "Valaddress has same address as Valaddress") ErrCanNotJoinDisabledPool = errors.Register(ModuleName, 1112, "can not join disabled pool") - ErrInvalidCommission = errors.Register(ModuleName, 1116, "invalid commission %v") ErrPoolLeaveAlreadyInProgress = errors.Register(ModuleName, 1117, "Pool leave is already in progress") ErrValaccountUnauthorized = errors.Register(ModuleName, 1118, "valaccount unauthorized") ) diff --git a/x/stakers/types/events.pb.go b/x/stakers/types/events.pb.go index 0e705fb8..c865279a 100644 --- a/x/stakers/types/events.pb.go +++ b/x/stakers/types/events.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" @@ -224,7 +225,7 @@ type EventUpdateCommission struct { // staker is the account address of the protocol node. Staker string `protobuf:"bytes,1,opt,name=staker,proto3" json:"staker,omitempty"` // commission ... - Commission string `protobuf:"bytes,2,opt,name=commission,proto3" json:"commission,omitempty"` + Commission github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=commission,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"commission"` } func (m *EventUpdateCommission) Reset() { *m = EventUpdateCommission{} } @@ -267,13 +268,6 @@ func (m *EventUpdateCommission) GetStaker() string { return "" } -func (m *EventUpdateCommission) GetCommission() string { - if m != nil { - return m.Commission - } - return "" -} - // EventJoinPool ... // emitted_by: MsgJoinPool type EventJoinPool struct { @@ -417,34 +411,36 @@ func init() { func init() { proto.RegisterFile("kyve/stakers/v1beta1/events.proto", fileDescriptor_7a1b3dc9634155a0) } var fileDescriptor_7a1b3dc9634155a0 = []byte{ - // 429 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0xdf, 0x6a, 0xd4, 0x40, - 0x14, 0xc6, 0x37, 0x6b, 0xd8, 0x65, 0x47, 0x14, 0x8c, 0x55, 0x43, 0x91, 0x58, 0x73, 0xd5, 0x0b, - 0x49, 0xa8, 0x3e, 0x41, 0xbb, 0x54, 0xf0, 0x7f, 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c, 0xea, 0x59, 0xeb, 0x65, 0x89, 0x2a, 0x1d, 0x99, 0xe7, 0xfc, 0xe2, 0x77, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xa8, 0x67, 0x6b, 0x55, 0x42, 0x03, 0x00, 0x00, + // 462 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x93, 0xdf, 0x6a, 0xd4, 0x40, + 0x14, 0xc6, 0x37, 0x6b, 0xd8, 0x65, 0x8f, 0x28, 0x18, 0xab, 0x86, 0x22, 0x69, 0xcd, 0x85, 0xf4, + 0x42, 0x13, 0xaa, 0x4f, 0xd0, 0x5d, 0x2b, 0xf8, 0xaf, 0x94, 0x88, 0x82, 0xde, 0x94, 0xb3, 0x99, + 0xc3, 0x36, 0x6c, 0x92, 0x13, 0x32, 0xb3, 0xd9, 0xee, 0x95, 0xaf, 0xe0, 0xbb, 0xf8, 0x12, 0xbd, + 0xec, 0xa5, 0x78, 0x51, 0x64, 0xf7, 0x45, 0x24, 0x93, 0xd9, 0x9a, 0x42, 0x17, 0xc4, 0xab, 0xcc, + 0x37, 0xf3, 0xe5, 0xf7, 0x7d, 0x73, 0x48, 0xe0, 0xc9, 0x74, 0x51, 0x51, 0x28, 0x15, 0x4e, 0xa9, + 0x94, 0x61, 0xb5, 0x3f, 0x26, 0x85, 0xfb, 0x21, 0x55, 0x94, 0x2b, 0x19, 0x14, 0x25, 0x2b, 0x76, + 0xb6, 0x6a, 0x4b, 0x60, 0x2c, 0x81, 0xb1, 0x6c, 0x6f, 0x4d, 0x78, 0xc2, 0xda, 0x10, 0xd6, 0xab, + 0xc6, 0xbb, 0x7d, 0x33, 0xae, 0xc0, 0x12, 0x33, 0x83, 0xf3, 0x7f, 0x58, 0x70, 0xef, 0xb0, 0xe6, + 0x7f, 0x2a, 0x04, 0x2a, 0x3a, 0xd6, 0x67, 0xce, 0x01, 0x00, 0xa7, 0xe2, 0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, 0x3b, 0xba, 0xc0, 0x5b, 0x4e, 0xf2, 0x63, 0xe6, 0xd4, 0x79, 0x04, 0xfd, 0x82, 0x39, + 0x3d, 0x49, 0x84, 0x4e, 0xb6, 0xa3, 0x5e, 0x2d, 0xdf, 0x88, 0x56, 0xa3, 0xee, 0xb5, 0x46, 0x1e, + 0x40, 0x85, 0x29, 0x0a, 0x51, 0x92, 0x94, 0xe6, 0xce, 0xad, 0x9d, 0xd6, 0xc4, 0xed, 0x6b, 0x13, + 0x3f, 0x80, 0xbb, 0x3a, 0xf9, 0x3d, 0x61, 0x45, 0xff, 0x15, 0x3d, 0x7c, 0x7d, 0xbe, 0xf4, 0xac, + 0x8b, 0xa5, 0x67, 0xfd, 0x5e, 0x7a, 0xd6, 0xf7, 0x95, 0xd7, 0xb9, 0x58, 0x79, 0x9d, 0x9f, 0x2b, + 0xaf, 0xf3, 0xf5, 0x59, 0x6b, 0x14, 0xef, 0xbe, 0x7c, 0x3e, 0x3c, 0x22, 0x35, 0xe7, 0x72, 0x1a, + 0xc6, 0xa7, 0x98, 0xe4, 0xe1, 0xd9, 0xd5, 0x6f, 0xa0, 0x87, 0x32, 0xee, 0xe9, 0xcf, 0xff, 0xe5, + 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x69, 0xd7, 0xac, 0xc1, 0x72, 0x03, 0x00, 0x00, } func (m *EventUpdateParams) Marshal() (dAtA []byte, err error) { @@ -603,13 +599,16 @@ func (m *EventUpdateCommission) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Commission) > 0 { - i -= len(m.Commission) - copy(dAtA[i:], m.Commission) - i = encodeVarintEvents(dAtA, i, uint64(len(m.Commission))) - i-- - dAtA[i] = 0x12 + { + size := m.Commission.Size() + i -= size + if _, err := m.Commission.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintEvents(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 if len(m.Staker) > 0 { i -= len(m.Staker) copy(dAtA[i:], m.Staker) @@ -781,10 +780,8 @@ func (m *EventUpdateCommission) Size() (n int) { if l > 0 { n += 1 + l + sovEvents(uint64(l)) } - l = len(m.Commission) - if l > 0 { - n += 1 + l + sovEvents(uint64(l)) - } + l = m.Commission.Size() + n += 1 + l + sovEvents(uint64(l)) return n } @@ -1351,7 +1348,9 @@ func (m *EventUpdateCommission) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Commission = string(dAtA[iNdEx:postIndex]) + if err := m.Commission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/stakers/types/keys.go b/x/stakers/types/keys.go index 01295ead..0e3c4084 100644 --- a/x/stakers/types/keys.go +++ b/x/stakers/types/keys.go @@ -2,6 +2,7 @@ package types import ( "github.com/KYVENetwork/chain/util" + sdk "github.com/cosmos/cosmos-sdk/types" ) const ( @@ -59,10 +60,9 @@ var ( QUEUE_IDENTIFIER_LEAVE QUEUE_IDENTIFIER = []byte{30, 3} ) -const ( - MaxStakers = 50 - DefaultCommission = "0.9" -) +const MaxStakers = 50 + +var DefaultCommission = sdk.MustNewDecFromStr("0.9") // StakerKey returns the store Key to retrieve a Staker from the index fields func StakerKey(staker string) []byte { diff --git a/x/stakers/types/message_update_commission.go b/x/stakers/types/message_update_commission.go index bf8dd513..e8fb1aed 100644 --- a/x/stakers/types/message_update_commission.go +++ b/x/stakers/types/message_update_commission.go @@ -2,39 +2,28 @@ package types import ( "cosmossdk.io/errors" + "github.com/KYVENetwork/chain/util" sdk "github.com/cosmos/cosmos-sdk/types" errorsTypes "github.com/cosmos/cosmos-sdk/types/errors" ) -const TypeMsgUpdateCommission = "update_commission" - var _ sdk.Msg = &MsgUpdateCommission{} -func (msg *MsgUpdateCommission) Route() string { - return RouterKey -} - -func (msg *MsgUpdateCommission) Type() string { - return TypeMsgUpdateCommission -} - +// GetSigners returns the expected signers for a MsgUpdateCommission message. func (msg *MsgUpdateCommission) GetSigners() []sdk.AccAddress { - creator, err := sdk.AccAddressFromBech32(msg.Creator) - if err != nil { - panic(err) - } - return []sdk.AccAddress{creator} -} - -func (msg *MsgUpdateCommission) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(msg) - return sdk.MustSortJSON(bz) + validator, _ := sdk.AccAddressFromBech32(msg.Creator) + return []sdk.AccAddress{validator} } +// ValidateBasic does a sanity check on the provided data. func (msg *MsgUpdateCommission) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(msg.Creator) - if err != nil { - return errors.Wrapf(errorsTypes.ErrInvalidAddress, "invalid creator address (%s)", err) + if _, err := sdk.AccAddressFromBech32(msg.Creator); err != nil { + return errors.Wrapf(errorsTypes.ErrInvalidAddress, "invalid validator address: %s", err) } + + if util.ValidatePercentage(msg.Commission) != nil { + return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid commission") + } + return nil } diff --git a/x/stakers/types/stakers.pb.go b/x/stakers/types/stakers.pb.go index 11d4cc75..879a0ceb 100644 --- a/x/stakers/types/stakers.pb.go +++ b/x/stakers/types/stakers.pb.go @@ -5,6 +5,8 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -28,7 +30,7 @@ type Staker struct { // address ... Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` // commission ... - Commission string `protobuf:"bytes,2,opt,name=commission,proto3" json:"commission,omitempty"` + Commission github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=commission,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"commission"` // moniker ... Moniker string `protobuf:"bytes,3,opt,name=moniker,proto3" json:"moniker,omitempty"` // website ... @@ -77,13 +79,6 @@ func (m *Staker) GetAddress() string { return "" } -func (m *Staker) GetCommission() string { - if m != nil { - return m.Commission - } - return "" -} - func (m *Staker) GetMoniker() string { if m != nil { return m.Moniker @@ -204,7 +199,7 @@ type CommissionChangeEntry struct { Staker string `protobuf:"bytes,2,opt,name=staker,proto3" json:"staker,omitempty"` // commission is the new commission which will // be applied after the waiting time is over. - Commission string `protobuf:"bytes,3,opt,name=commission,proto3" json:"commission,omitempty"` + Commission github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=commission,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"commission"` // creation_date is the UNIX-timestamp in seconds // when the entry was created. CreationDate int64 `protobuf:"varint,4,opt,name=creation_date,json=creationDate,proto3" json:"creation_date,omitempty"` @@ -257,13 +252,6 @@ func (m *CommissionChangeEntry) GetStaker() string { return "" } -func (m *CommissionChangeEntry) GetCommission() string { - if m != nil { - return m.Commission - } - return "" -} - func (m *CommissionChangeEntry) GetCreationDate() int64 { if m != nil { return m.CreationDate @@ -421,34 +409,37 @@ func init() { } var fileDescriptor_d209d1a2a74d375d = []byte{ - // 429 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x41, 0x8b, 0xd3, 0x40, - 0x14, 0xc7, 0x9b, 0x6d, 0xb7, 0xbb, 0x7d, 0xa8, 0x87, 0x61, 0xd5, 0x80, 0x6c, 0x90, 0x7a, 0xf1, - 0x20, 0x0d, 0x8b, 0xdf, 0xc0, 0x75, 0xc5, 0x45, 0x11, 0xed, 0xc2, 0x82, 0x5e, 0xca, 0x34, 0x79, - 0x24, 0x43, 0xa7, 0xf3, 0x42, 0x66, 0x92, 0x6c, 0xc1, 0x4f, 0xe0, 0xc9, 0x83, 0x1f, 0xca, 0xe3, - 0x1e, 0x3d, 0x4a, 0xfb, 0x45, 0x64, 0x26, 0x93, 0x12, 0x11, 0x44, 0xbc, 0xe5, 0xff, 0xff, 0xcf, - 0x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0, 0xa7, 0x19, 0xce, 0xf0, 0x5c, 0x73, 0x8d, 0xec, + 0x29, 0x0c, 0x72, 0x5a, 0x8c, 0xdb, 0xdd, 0x77, 0x73, 0x5a, 0x9c, 0x5a, 0x03, 0x7b, 0x00, 0xa9, + 0x48, 0xd2, 0x5a, 0xdd, 0xb2, 0xea, 0xc0, 0x30, 0x56, 0x3e, 0x7c, 0x7b, 0xb5, 0xf2, 0x9c, 0xeb, + 0x95, 0xe7, 0xfc, 0x5e, 0x79, 0xce, 0xb7, 0xb5, 0xd7, 0xb9, 0x5e, 0x7b, 0x9d, 0x9f, 0x6b, 0xaf, + 0xf3, 0xe5, 0x55, 0x2b, 0xba, 0xf7, 0x9f, 0x2f, 0x4e, 0xce, 0x50, 0x2f, 0xa8, 0xcc, 0x82, 0x28, + 0xe5, 0x42, 0x06, 0x97, 0xb7, 0xcb, 0x65, 0x43, 0x9c, 0xf4, 0xed, 0x9e, 0xbc, 0xf9, 0x13, 0x00, + 0x00, 0xff, 0xff, 0xbc, 0x83, 0xaf, 0xf4, 0x79, 0x03, 0x00, 0x00, } func (m *Staker) Marshal() (dAtA []byte, err error) { @@ -492,13 +483,16 @@ func (m *Staker) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1a } - if len(m.Commission) > 0 { - i -= len(m.Commission) - copy(dAtA[i:], m.Commission) - i = encodeVarintStakers(dAtA, i, uint64(len(m.Commission))) - i-- - dAtA[i] = 0x12 + { + size := m.Commission.Size() + i -= size + if _, err := m.Commission.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintStakers(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 if len(m.Address) > 0 { i -= len(m.Address) copy(dAtA[i:], m.Address) @@ -591,13 +585,16 @@ func (m *CommissionChangeEntry) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x20 } - if len(m.Commission) > 0 { - i -= len(m.Commission) - copy(dAtA[i:], m.Commission) - i = encodeVarintStakers(dAtA, i, uint64(len(m.Commission))) - i-- - dAtA[i] = 0x1a + { + size := m.Commission.Size() + i -= size + if _, err := m.Commission.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintStakers(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x1a if len(m.Staker) > 0 { i -= len(m.Staker) copy(dAtA[i:], m.Staker) @@ -712,10 +709,8 @@ func (m *Staker) Size() (n int) { if l > 0 { n += 1 + l + sovStakers(uint64(l)) } - l = len(m.Commission) - if l > 0 { - n += 1 + l + sovStakers(uint64(l)) - } + l = m.Commission.Size() + n += 1 + l + sovStakers(uint64(l)) l = len(m.Moniker) if l > 0 { n += 1 + l + sovStakers(uint64(l)) @@ -770,10 +765,8 @@ func (m *CommissionChangeEntry) Size() (n int) { if l > 0 { n += 1 + l + sovStakers(uint64(l)) } - l = len(m.Commission) - if l > 0 { - n += 1 + l + sovStakers(uint64(l)) - } + l = m.Commission.Size() + n += 1 + l + sovStakers(uint64(l)) if m.CreationDate != 0 { n += 1 + sovStakers(uint64(m.CreationDate)) } @@ -914,7 +907,9 @@ func (m *Staker) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Commission = string(dAtA[iNdEx:postIndex]) + if err := m.Commission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 3: if wireType != 2 { @@ -1315,7 +1310,9 @@ func (m *CommissionChangeEntry) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Commission = string(dAtA[iNdEx:postIndex]) + if err := m.Commission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 4: if wireType != 0 { diff --git a/x/stakers/types/tx.pb.go b/x/stakers/types/tx.pb.go index 5058724c..3dede3d2 100644 --- a/x/stakers/types/tx.pb.go +++ b/x/stakers/types/tx.pb.go @@ -7,6 +7,8 @@ import ( context "context" fmt "fmt" _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" @@ -235,7 +237,7 @@ type MsgUpdateCommission struct { // creator ... Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` // commission ... - Commission string `protobuf:"bytes,2,opt,name=commission,proto3" json:"commission,omitempty"` + Commission github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=commission,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"commission"` } func (m *MsgUpdateCommission) Reset() { *m = MsgUpdateCommission{} } @@ -278,13 +280,6 @@ func (m *MsgUpdateCommission) GetCreator() string { return "" } -func (m *MsgUpdateCommission) GetCommission() string { - if m != nil { - return m.Commission - } - return "" -} - // MsgUpdateCommissionResponse ... type MsgUpdateCommissionResponse struct { } @@ -634,43 +629,46 @@ func init() { func init() { proto.RegisterFile("kyve/stakers/v1beta1/tx.proto", fileDescriptor_f52b730e69b9fb06) } var fileDescriptor_f52b730e69b9fb06 = []byte{ - // 568 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xcb, 0x6e, 0xd3, 0x40, - 0x14, 0xad, 0x69, 0xd4, 0x90, 0x4b, 0xc4, 0xc3, 0x84, 0xd6, 0x71, 0x55, 0xab, 0x58, 0xaa, 0x68, - 0x11, 0xb5, 0x15, 0x90, 0xd8, 0xb7, 0x11, 0x48, 0x3c, 0x0c, 0x55, 0x2a, 0x10, 0x8f, 0x45, 0x35, - 0xb1, 0x47, 0x8e, 0x49, 0xec, 0x6b, 0x79, 0x26, 0x69, 0xf2, 0x17, 0x7c, 0x0c, 0x1f, 0xc1, 0xb2, - 0x62, 0xc5, 0x12, 0x25, 0x12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0xe1, 0x15, 0xc2, 0xdd, 0x6b, 0x91, 0x3d, 0x5a, 0x21, 0x32, 0xa6, 0xaa, 0xb5, 0xb5, 0xa9, 0xc2, - 0xf1, 0x13, 0xdc, 0x14, 0xa1, 0x7d, 0xb8, 0xb0, 0x3d, 0xa7, 0xa8, 0x47, 0x2b, 0x29, 0x42, 0xf9, - 0x2b, 0x94, 0xc6, 0xe9, 0xd3, 0x17, 0xf6, 0x09, 0x8e, 0xfa, 0x78, 0x35, 0x47, 0x88, 0x3b, 0x50, - 0x9e, 0xca, 0xdf, 0xc1, 0x8a, 0xcd, 0x53, 0xda, 0x92, 0xab, 0x9f, 0x17, 0xb4, 0xd3, 0x97, 0x3f, - 0x87, 0x9a, 0x74, 0x35, 0xd4, 0xa4, 0x3f, 0x43, 0x4d, 0xfa, 0x3e, 0xd2, 0x36, 0xae, 0x46, 0xda, - 0xc6, 0xef, 0x91, 0xb6, 0xf1, 0xe5, 0x89, 0xeb, 0xf1, 0x56, 0xb7, 0x69, 0xd8, 0xe8, 0x9b, 0x6f, - 0x3e, 0x7f, 0x7c, 0xf1, 0x8e, 0xf2, 0x4b, 0x8c, 0xda, 0xa6, 0xdd, 0x22, 0x5e, 0x60, 0xf6, 0xc5, - 0xe3, 0xcd, 0x07, 0x21, 0x65, 0xcd, 0xad, 0xe4, 0x1d, 0x7e, 0xf6, 0x2f, 0x00, 0x00, 0xff, 0xff, - 0x89, 0xab, 0x3b, 0x78, 0xd9, 0x05, 0x00, 0x00, + // 613 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcb, 0x6e, 0xd3, 0x4c, + 0x18, 0x8d, 0xff, 0x46, 0xed, 0x9f, 0x8f, 0x8a, 0x8b, 0x09, 0xad, 0xeb, 0xaa, 0x6e, 0xb1, 0x54, + 0x68, 0x11, 0xb1, 0x15, 0x90, 0xd8, 0x37, 0x01, 0x24, 0x2e, 0xae, 0x2a, 0x57, 0x20, 0x2e, 0x8b, + 0x6a, 0x62, 0x8f, 0x1c, 0x93, 0xd8, 0x63, 0x79, 0x26, 0x69, 0xb2, 0xe2, 0x15, 0x78, 0x18, 0x1e, + 0xa2, 0xcb, 0x8a, 0x15, 0x62, 0x51, 0xa1, 0x44, 0xe2, 0x39, 0x90, 0x6f, 0x13, 0x27, 0xcd, 0x4d, + 0xac, 0xe2, 0x6f, 0xbe, 0x33, 0xe7, 0x9c, 0x99, 0x39, 0x33, 0x81, 0x9d, 0x56, 0xbf, 0x8b, 0x75, + 0xca, 0x50, 0x0b, 0x87, 0x54, 0xef, 0x56, 0x1b, 0x98, 0xa1, 0xaa, 0xce, 0x7a, 0x5a, 0x10, 0x12, + 0x46, 0xc4, 0x72, 0xd4, 0xd6, 0xd2, 0xb6, 0x96, 0xb6, 0xe5, 0x2d, 0x8b, 0x50, 0x8f, 0xd0, 0xb3, + 0x18, 0xa3, 0x27, 0x45, 0x32, 0x41, 0x2e, 0x3b, 0xc4, 0x21, 0xc9, 0x78, 0xf4, 0x95, 0x8c, 0xaa, + 0x75, 0xb8, 0x65, 0x50, 0xa7, 0x1e, 0x62, 0xc4, 0xf0, 0x69, 0x4c, 0x26, 0x4a, 0xb0, 0x66, 0x45, + 0x35, 0x09, 0x25, 0x61, 0x4f, 0x38, 0x28, 0x99, 0x59, 0x29, 0x6e, 0xc0, 0x2a, 0xf2, 0x48, 0xc7, + 0x67, 0xd2, 0x7f, 0x7b, 0xc2, 0x41, 0xd1, 0x4c, 0x2b, 0x75, 0x0b, 0x36, 0x27, 0x48, 0x4c, 0x4c, + 0x03, 0xe2, 0x53, 0xac, 0x76, 0xe0, 0x8e, 0x41, 0x9d, 0x77, 0x81, 0x8d, 0x18, 0x36, 0x30, 0x43, + 0x36, 0x62, 0x68, 0x8e, 0x82, 0x04, 0x6b, 0x1e, 0xf1, 0xdd, 0x16, 0x0e, 0x63, 0x89, 0x92, 0x99, + 0x95, 0x51, 0xe7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 0x05, 0xc4, + 0x6f, 0x49, 0x63, 0x35, 0x7e, 0xb7, 0x9f, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x8b, 0x5f, 0x6e, + 0x89, 0x1f, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1099,13 +1097,16 @@ func (m *MsgUpdateCommission) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Commission) > 0 { - i -= len(m.Commission) - copy(dAtA[i:], m.Commission) - i = encodeVarintTx(dAtA, i, uint64(len(m.Commission))) - i-- - dAtA[i] = 0x12 + { + size := m.Commission.Size() + i -= size + if _, err := m.Commission.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 if len(m.Creator) > 0 { i -= len(m.Creator) copy(dAtA[i:], m.Creator) @@ -1407,10 +1408,8 @@ func (m *MsgUpdateCommission) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.Commission) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } + l = m.Commission.Size() + n += 1 + l + sovTx(uint64(l)) return n } @@ -1982,7 +1981,9 @@ func (m *MsgUpdateCommission) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Commission = string(dAtA[iNdEx:postIndex]) + if err := m.Commission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex From dfa52bf7af8186d20f359bde92189460b9cec95b Mon Sep 17 00:00:00 2001 From: John Letey Date: Thu, 23 Mar 2023 12:11:53 +0100 Subject: [PATCH 4/6] chore: update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3f521b9..c43b0598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ - (`x/bundles`) [#19](https://github.com/KYVENetwork/chain/pull/19) Migrate `NetworkFee` param to type `sdk.Dec`. - (`x/delegation`) [#19](https://github.com/KYVENetwork/chain/pull/19) Migrate `VoteSlash`, `UploadSlash`, `TimeoutSlash` params to type `sdk.Dec`. -- (`x/stakers`) [#19](https://github.com/KYVENetwork/chain/pull/19) Migrate protocol validator `Commission` to type `sdk.Dec`. +- (`x/stakers`) [#19](https://github.com/KYVENetwork/chain/pull/19) Migrate `Commission` to type `sdk.Dec`. ## [v1.0.0](https://github.com/KYVENetwork/chain/releases/tag/v1.0.0) - 2023-03-10 From 96405fb5476c33f3aa7b8754796fef25795a41a0 Mon Sep 17 00:00:00 2001 From: mbreithecker Date: Fri, 24 Mar 2023 17:28:34 +0100 Subject: [PATCH 5/6] fix(`2.2.7`): set commission during staker creation and set default commission to a more appropriate value --- proto/kyve/stakers/v1beta1/tx.proto | 12 +- .../cli/{tx_stake.go => tx_create_staker.go} | 15 +- x/stakers/keeper/msg_server_create_staker.go | 7 +- .../keeper/msg_server_create_staker_test.go | 13 +- x/stakers/types/keys.go | 2 +- x/stakers/types/message_create_staker.go | 8 ++ x/stakers/types/tx.pb.go | 133 ++++++++++++------ 7 files changed, 133 insertions(+), 57 deletions(-) rename x/stakers/client/cli/{tx_stake.go => tx_create_staker.go} (71%) diff --git a/proto/kyve/stakers/v1beta1/tx.proto b/proto/kyve/stakers/v1beta1/tx.proto index cda550d1..1f4e2b30 100644 --- a/proto/kyve/stakers/v1beta1/tx.proto +++ b/proto/kyve/stakers/v1beta1/tx.proto @@ -25,12 +25,18 @@ service Msg { rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); } -// MsgStakePool defines a SDK message for staking in a pool. +// MsgCreateStaker defines a SDK message for creating a staker message MsgCreateStaker { - // creator ... + // creator is the address of the staker string creator = 1; - // amount ... + // amount is the initial self-stake to create the staker with uint64 amount = 2; + // commission is a number between 0 and 1 specifying the percentage that is deducted from the rewards + // before distributing the rest to the delegators. + string commission = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; } // MsgStakePoolResponse defines the Msg/StakePool response type. diff --git a/x/stakers/client/cli/tx_stake.go b/x/stakers/client/cli/tx_create_staker.go similarity index 71% rename from x/stakers/client/cli/tx_stake.go rename to x/stakers/client/cli/tx_create_staker.go index 310dab85..2b12fadb 100644 --- a/x/stakers/client/cli/tx_stake.go +++ b/x/stakers/client/cli/tx_create_staker.go @@ -5,29 +5,36 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cast" "github.com/spf13/cobra" ) func CmdCreateStaker() *cobra.Command { cmd := &cobra.Command{ - Use: "create-staker [amount]", + Use: "create-staker [amount] [commission]", Short: "Broadcast message create-staker", - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) (err error) { argAmount, err := cast.ToUint64E(args[0]) if err != nil { return err } + argCommission, err := sdk.NewDecFromStr(args[1]) + if err != nil { + return err + } + clientCtx, err := client.GetClientTxContext(cmd) if err != nil { return err } msg := types.MsgCreateStaker{ - Creator: clientCtx.GetFromAddress().String(), - Amount: argAmount, + Creator: clientCtx.GetFromAddress().String(), + Amount: argAmount, + Commission: argCommission, } if err := msg.ValidateBasic(); err != nil { diff --git a/x/stakers/keeper/msg_server_create_staker.go b/x/stakers/keeper/msg_server_create_staker.go index 19599dea..7bd95860 100644 --- a/x/stakers/keeper/msg_server_create_staker.go +++ b/x/stakers/keeper/msg_server_create_staker.go @@ -15,7 +15,10 @@ import ( // Every user can create a staker object with some stake. However, // only if self_delegation + delegation is large enough to join a pool the staker // is able to participate in the protocol -func (k msgServer) CreateStaker(goCtx context.Context, msg *types.MsgCreateStaker) (*types.MsgCreateStakerResponse, error) { +func (k msgServer) CreateStaker( + goCtx context.Context, + msg *types.MsgCreateStaker, +) (*types.MsgCreateStakerResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) // Only create new stakers @@ -26,7 +29,7 @@ func (k msgServer) CreateStaker(goCtx context.Context, msg *types.MsgCreateStake // Create and append new staker to store k.AppendStaker(ctx, types.Staker{ Address: msg.Creator, - Commission: types.DefaultCommission, + Commission: msg.Commission, }) // Perform initial self delegation diff --git a/x/stakers/keeper/msg_server_create_staker_test.go b/x/stakers/keeper/msg_server_create_staker_test.go index c8897310..cc933974 100644 --- a/x/stakers/keeper/msg_server_create_staker_test.go +++ b/x/stakers/keeper/msg_server_create_staker_test.go @@ -2,6 +2,7 @@ package keeper_test import ( delegationtypes "github.com/KYVENetwork/chain/x/delegation/types" + sdk "github.com/cosmos/cosmos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -39,8 +40,9 @@ var _ = Describe("msg_server_create_staker.go", Ordered, func() { It("Create a first new staker and delegate 100 $KYVE", func() { // ACT s.RunTxStakersSuccess(&stakerstypes.MsgCreateStaker{ - Creator: i.STAKER_0, - Amount: 100 * i.KYVE, + Creator: i.STAKER_0, + Amount: 100 * i.KYVE, + Commission: sdk.MustNewDecFromStr("0.2"), }) // ASSERT @@ -56,7 +58,7 @@ var _ = Describe("msg_server_create_staker.go", Ordered, func() { Expect(staker.Address).To(Equal(i.STAKER_0)) Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) Expect(s.App().DelegationKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(100 * i.KYVE)) - Expect(staker.Commission).To(Equal(types.DefaultCommission)) + Expect(staker.Commission).To(Equal(sdk.MustNewDecFromStr("0.2"))) Expect(staker.Moniker).To(BeEmpty()) Expect(staker.Logo).To(BeEmpty()) @@ -68,8 +70,9 @@ var _ = Describe("msg_server_create_staker.go", Ordered, func() { It("Do an additional 50 $KYVE self delegation after staker has already delegated 100 $KYVE", func() { // ARRANGE s.RunTxStakersSuccess(&stakerstypes.MsgCreateStaker{ - Creator: i.STAKER_0, - Amount: 100 * i.KYVE, + Creator: i.STAKER_0, + Amount: 100 * i.KYVE, + Commission: types.DefaultCommission, }) // ACT diff --git a/x/stakers/types/keys.go b/x/stakers/types/keys.go index 0e3c4084..d025544f 100644 --- a/x/stakers/types/keys.go +++ b/x/stakers/types/keys.go @@ -62,7 +62,7 @@ var ( const MaxStakers = 50 -var DefaultCommission = sdk.MustNewDecFromStr("0.9") +var DefaultCommission = sdk.MustNewDecFromStr("0.1") // StakerKey returns the store Key to retrieve a Staker from the index fields func StakerKey(staker string) []byte { diff --git a/x/stakers/types/message_create_staker.go b/x/stakers/types/message_create_staker.go index fed7e615..15bef674 100644 --- a/x/stakers/types/message_create_staker.go +++ b/x/stakers/types/message_create_staker.go @@ -27,5 +27,13 @@ func (msg *MsgCreateStaker) ValidateBasic() error { return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid amount") } + if msg.Commission.IsNil() { + msg.Commission = DefaultCommission + } + + if msg.Commission.IsNegative() || msg.Commission.GT(sdk.OneDec()) { + return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid commission") + } + return nil } diff --git a/x/stakers/types/tx.pb.go b/x/stakers/types/tx.pb.go index 3dede3d2..eb1cd309 100644 --- a/x/stakers/types/tx.pb.go +++ b/x/stakers/types/tx.pb.go @@ -32,10 +32,13 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgStakePool defines a SDK message for staking in a pool. type MsgCreateStaker struct { - // creator ... + // creator is the address of the staker Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - // amount ... + // amount is the initial self-stake to create the staker with Amount uint64 `protobuf:"varint,2,opt,name=amount,proto3" json:"amount,omitempty"` + // commission is a number between 0 and 1 specifying the percentage that is deducted from the rewards + // before distributing the rest to the delegators. + Commission github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=commission,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"commission"` } func (m *MsgCreateStaker) Reset() { *m = MsgCreateStaker{} } @@ -629,46 +632,46 @@ func init() { func init() { proto.RegisterFile("kyve/stakers/v1beta1/tx.proto", fileDescriptor_f52b730e69b9fb06) } var fileDescriptor_f52b730e69b9fb06 = []byte{ - // 613 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcb, 0x6e, 0xd3, 0x4c, - 0x18, 0x8d, 0xff, 0x46, 0xed, 0x9f, 0x8f, 0x8a, 0x8b, 0x09, 0xad, 0xeb, 0xaa, 0x6e, 0xb1, 0x54, - 0x68, 0x11, 0xb1, 0x15, 0x90, 0xd8, 0x37, 0x01, 0x24, 0x2e, 0xae, 0x2a, 0x57, 0x20, 0x2e, 0x8b, - 0x6a, 0x62, 0x8f, 0x1c, 0x93, 0xd8, 0x63, 0x79, 0x26, 0x69, 0xb2, 0xe2, 0x15, 0x78, 0x18, 0x1e, - 0xa2, 0xcb, 0x8a, 0x15, 0x62, 0x51, 0xa1, 0x44, 0xe2, 0x39, 0x90, 0x6f, 0x13, 0x27, 0xcd, 0x4d, - 0xac, 0xe2, 0x6f, 0xbe, 0x33, 0xe7, 0x9c, 0x99, 0x39, 0x33, 0x81, 0x9d, 0x56, 0xbf, 0x8b, 0x75, - 0xca, 0x50, 0x0b, 0x87, 0x54, 0xef, 0x56, 0x1b, 0x98, 0xa1, 0xaa, 0xce, 0x7a, 0x5a, 0x10, 0x12, - 0x46, 0xc4, 0x72, 0xd4, 0xd6, 0xd2, 0xb6, 0x96, 0xb6, 0xe5, 0x2d, 0x8b, 0x50, 0x8f, 0xd0, 0xb3, - 0x18, 0xa3, 0x27, 0x45, 0x32, 0x41, 0x2e, 0x3b, 0xc4, 0x21, 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f6, 0xfe, 0xcc, 0xe9, 0x19, 0x44, 0x3e, 0x5c, - 0x08, 0xe1, 0xcc, 0x9f, 0xa1, 0x34, 0x4a, 0x9f, 0x3a, 0x73, 0x1e, 0xc7, 0xc8, 0x8f, 0x16, 0x63, - 0x38, 0xb9, 0x0d, 0xeb, 0x63, 0xf9, 0xdb, 0x5f, 0xb0, 0xf2, 0x04, 0x36, 0xe7, 0xe8, 0xa7, 0x05, - 0xad, 0xf6, 0xf2, 0x62, 0xa0, 0x08, 0x97, 0x03, 0x45, 0xf8, 0x3d, 0x50, 0x84, 0x6f, 0x43, 0xa5, - 0x70, 0x39, 0x54, 0x0a, 0x3f, 0x87, 0x4a, 0xe1, 0xd3, 0xe3, 0xdc, 0x0b, 0xf2, 0xe6, 0xe3, 0xfb, - 0x17, 0xc7, 0x98, 0x9d, 0x93, 0xb0, 0xa5, 0x5b, 0x4d, 0xe4, 0xfa, 0x7a, 0x8f, 0xff, 0x05, 0xc4, - 0x6f, 0x49, 0x63, 0x35, 0x7e, 0xb7, 0x9f, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x8b, 0x5f, 0x6e, - 0x89, 0x1f, 0x06, 0x00, 0x00, + // 623 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0xcb, 0x6e, 0xd3, 0x40, + 0x14, 0x8d, 0xdb, 0xa8, 0x25, 0x97, 0x8a, 0x87, 0x09, 0xad, 0xeb, 0xaa, 0x6e, 0xb1, 0x54, 0x68, + 0x11, 0xb5, 0x15, 0x90, 0xd8, 0x37, 0x05, 0x24, 0x1e, 0xae, 0x2a, 0x57, 0x20, 0x1e, 0x8b, 0x6a, + 0x62, 0x8f, 0x1c, 0x93, 0xd8, 0x63, 0x79, 0x26, 0x69, 0xb2, 0xe2, 0x17, 0x90, 0xf8, 0x15, 0x3e, + 0xa2, 0xcb, 0x8a, 0x15, 0x62, 0x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, 0xe9, 0x70, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -965,6 +968,16 @@ func (m *MsgCreateStaker) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.Commission.Size() + i -= size + if _, err := m.Commission.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a if m.Amount != 0 { i = encodeVarintTx(dAtA, i, uint64(m.Amount)) i-- @@ -1352,6 +1365,8 @@ func (m *MsgCreateStaker) Size() (n int) { if m.Amount != 0 { n += 1 + sovTx(uint64(m.Amount)) } + l = m.Commission.Size() + n += 1 + l + sovTx(uint64(l)) return n } @@ -1591,6 +1606,40 @@ func (m *MsgCreateStaker) Unmarshal(dAtA []byte) error { break } } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Commission", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Commission.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) From 78dc4fee010d4cd18ea483b45ca3206edfc10059 Mon Sep 17 00:00:00 2001 From: John Letey Date: Mon, 27 Mar 2023 12:57:13 +0200 Subject: [PATCH 6/6] chore: small nits --- proto/kyve/stakers/v1beta1/tx.proto | 10 +++++----- x/stakers/types/message_create_staker.go | 4 ++-- x/stakers/types/tx.pb.go | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/proto/kyve/stakers/v1beta1/tx.proto b/proto/kyve/stakers/v1beta1/tx.proto index 1f4e2b30..d1509d1f 100644 --- a/proto/kyve/stakers/v1beta1/tx.proto +++ b/proto/kyve/stakers/v1beta1/tx.proto @@ -25,14 +25,14 @@ service Msg { rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); } -// MsgCreateStaker defines a SDK message for creating a staker +// MsgCreateStaker defines a SDK message for creating a staker. message MsgCreateStaker { - // creator is the address of the staker + // creator is the address of the staker. string creator = 1; - // amount is the initial self-stake to create the staker with + // amount is the initial self-stake of the staker. uint64 amount = 2; - // commission is a number between 0 and 1 specifying the percentage that is deducted from the rewards - // before distributing the rest to the delegators. + // commission is the percentage that is deducted from rewards before + // distributing the staker's delegators. string commission = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false diff --git a/x/stakers/types/message_create_staker.go b/x/stakers/types/message_create_staker.go index 15bef674..831bee31 100644 --- a/x/stakers/types/message_create_staker.go +++ b/x/stakers/types/message_create_staker.go @@ -3,6 +3,7 @@ package types import ( "cosmossdk.io/errors" "cosmossdk.io/math" + "github.com/KYVENetwork/chain/util" sdk "github.com/cosmos/cosmos-sdk/types" errorsTypes "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -30,8 +31,7 @@ func (msg *MsgCreateStaker) ValidateBasic() error { if msg.Commission.IsNil() { msg.Commission = DefaultCommission } - - if msg.Commission.IsNegative() || msg.Commission.GT(sdk.OneDec()) { + if util.ValidatePercentage(msg.Commission) != nil { return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid commission") } diff --git a/x/stakers/types/tx.pb.go b/x/stakers/types/tx.pb.go index 15622c1c..114d99e5 100644 --- a/x/stakers/types/tx.pb.go +++ b/x/stakers/types/tx.pb.go @@ -30,14 +30,14 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// MsgCreateStaker defines a SDK message for creating a staker +// MsgCreateStaker defines a SDK message for creating a staker. type MsgCreateStaker struct { - // creator is the address of the staker + // creator is the address of the staker. Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - // amount is the initial self-stake to create the staker with + // amount is the initial self-stake of the staker. Amount uint64 `protobuf:"varint,2,opt,name=amount,proto3" json:"amount,omitempty"` - // commission is a number between 0 and 1 specifying the percentage that is deducted from the rewards - // before distributing the rest to the delegators. + // commission is the percentage that is deducted from rewards before + // distributing the staker's delegators. Commission github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=commission,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"commission"` }