From 2e3c74d395c7736a073204221668942f88706736 Mon Sep 17 00:00:00 2001 From: Hanjun Kim Date: Thu, 30 Jan 2025 21:16:45 +0800 Subject: [PATCH] feat: add max_entries parameter (#244) ## Description This PR adds `max_entries` restaking module parameter to limit the number of unbonding entries per (delegator, delegation target) pair. Closes: MILK-204 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html) - [ ] included the necessary unit and integration [tests](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- app/app.go | 2 + app/upgrades/v9/constants.go | 18 +++++ app/upgrades/v9/upgrades.go | 37 +++++++++ proto/milkyway/restaking/v1/params.proto | 4 + x/liquidvesting/keeper/end_blocker_test.go | 2 + x/liquidvesting/keeper/genesis_test.go | 1 + x/restaking/keeper/alias_functions.go | 36 ++++++++- x/restaking/keeper/genesis_test.go | 4 + x/restaking/keeper/grpc_query_test.go | 4 +- x/restaking/keeper/msg_server_test.go | 6 +- x/restaking/keeper/params.go | 9 +++ .../keeper/restake_restriction_test.go | 3 +- x/restaking/keeper/unbond_test.go | 40 ++++++++++ x/restaking/simulation/utils.go | 2 +- x/restaking/types/errors.go | 1 + x/restaking/types/genesis_test.go | 4 +- x/restaking/types/messages_test.go | 4 +- x/restaking/types/params.go | 15 +++- x/restaking/types/params.pb.go | 80 ++++++++++++++----- x/restaking/types/params_test.go | 15 ++-- 20 files changed, 244 insertions(+), 43 deletions(-) create mode 100644 app/upgrades/v9/constants.go create mode 100644 app/upgrades/v9/upgrades.go create mode 100644 x/restaking/keeper/unbond_test.go diff --git a/app/app.go b/app/app.go index af0c44031..5e44788bf 100644 --- a/app/app.go +++ b/app/app.go @@ -72,6 +72,7 @@ import ( "github.com/milkyway-labs/milkyway/v7/app/keepers" "github.com/milkyway-labs/milkyway/v7/app/upgrades" v6 "github.com/milkyway-labs/milkyway/v7/app/upgrades/v6" + v9 "github.com/milkyway-labs/milkyway/v7/app/upgrades/v9" _ "github.com/milkyway-labs/milkyway/v7/client/docs/statik" liquidvestingtypes "github.com/milkyway-labs/milkyway/v7/x/liquidvesting/types" ) @@ -87,6 +88,7 @@ var ( Upgrades = []upgrades.Upgrade{ v6.Upgrade, + v9.Upgrade, } ) diff --git a/app/upgrades/v9/constants.go b/app/upgrades/v9/constants.go new file mode 100644 index 000000000..cb95539a2 --- /dev/null +++ b/app/upgrades/v9/constants.go @@ -0,0 +1,18 @@ +package v9 + +import ( + storetypes "cosmossdk.io/store/types" + + "github.com/milkyway-labs/milkyway/v7/app/upgrades" +) + +const UpgradeName = "v9" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: storetypes.StoreUpgrades{ + Added: []string{}, + Deleted: []string{}, + }, +} diff --git a/app/upgrades/v9/upgrades.go b/app/upgrades/v9/upgrades.go new file mode 100644 index 000000000..270cf3f8b --- /dev/null +++ b/app/upgrades/v9/upgrades.go @@ -0,0 +1,37 @@ +package v9 + +import ( + "context" + + upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/milkyway-labs/milkyway/v7/app/keepers" + "github.com/milkyway-labs/milkyway/v7/x/restaking/types" +) + +func CreateUpgradeHandler( + mm *module.Manager, + configuration module.Configurator, + keepers *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + vm, err := mm.RunMigrations(ctx, configuration, fromVM) + if err != nil { + return nil, err + } + + // Set the default max entries parameter + params, err := keepers.RestakingKeeper.GetParams(ctx) + if err != nil { + return nil, err + } + params.MaxEntries = types.DefaultMaxEntries + err = keepers.RestakingKeeper.SetParams(ctx, params) + if err != nil { + return nil, err + } + + return vm, nil + } +} diff --git a/proto/milkyway/restaking/v1/params.proto b/proto/milkyway/restaking/v1/params.proto index 9f2561532..fd197cd9c 100644 --- a/proto/milkyway/restaking/v1/params.proto +++ b/proto/milkyway/restaking/v1/params.proto @@ -26,4 +26,8 @@ message Params { (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false ]; + + // MaxEntries represents the maximum number of entries for unbonding + // delegation. + uint32 max_entries = 4; } diff --git a/x/liquidvesting/keeper/end_blocker_test.go b/x/liquidvesting/keeper/end_blocker_test.go index 9d6c193ed..0620995c8 100644 --- a/x/liquidvesting/keeper/end_blocker_test.go +++ b/x/liquidvesting/keeper/end_blocker_test.go @@ -38,6 +38,7 @@ func (suite *KeeperTestSuite) TestKeeper_EndBlocker() { 7*24*time.Hour, nil, restakingtypes.DefaultRestakingCap, + restakingtypes.DefaultMaxEntries, )) suite.Require().NoError(err) @@ -125,6 +126,7 @@ func (suite *KeeperTestSuite) TestKeeper_EndBlocker() { 7*24*time.Hour, nil, restakingtypes.DefaultRestakingCap, + restakingtypes.DefaultMaxEntries, )) suite.Require().NoError(err) diff --git a/x/liquidvesting/keeper/genesis_test.go b/x/liquidvesting/keeper/genesis_test.go index 231557dc2..e87f1dd77 100644 --- a/x/liquidvesting/keeper/genesis_test.go +++ b/x/liquidvesting/keeper/genesis_test.go @@ -70,6 +70,7 @@ func (suite *KeeperTestSuite) TestKeeper_ExportGenesis() { 7*24*time.Hour, nil, restakingtypes.DefaultRestakingCap, + restakingtypes.DefaultMaxEntries, )) suite.Require().NoError(err) diff --git a/x/restaking/keeper/alias_functions.go b/x/restaking/keeper/alias_functions.go index 919277208..c2c21f472 100644 --- a/x/restaking/keeper/alias_functions.go +++ b/x/restaking/keeper/alias_functions.go @@ -650,6 +650,30 @@ func (k *Keeper) getUnbondingDelegationKeyBuilder(ud types.UnbondingDelegation) } } +// HasMaxUnbondingDelegationEntries checks if unbonding delegation has maximum number of entries. +func (k Keeper) HasMaxUnbondingDelegationEntries(ctx context.Context, delegator string, target types.DelegationTarget) (bool, error) { + delType, err := types.GetDelegationTypeFromTarget(target) + if err != nil { + return false, err + } + + ubd, found, err := k.GetUnbondingDelegation(ctx, delegator, delType, target.GetID()) + if err != nil { + return false, err + } + if !found { + // If there's no unbonding delegation, then we know it hasn't reached the max + // entries + return false, nil + } + + maxEntries, err := k.MaxEntries(ctx) + if err != nil { + return false, err + } + return len(ubd.Entries) >= int(maxEntries), nil +} + // SetUnbondingDelegation stores the given unbonding delegation in the store func (k *Keeper) SetUnbondingDelegation(ctx context.Context, ud types.UnbondingDelegation) ([]byte, error) { // Get the key to be used to store the unbonding delegation @@ -720,10 +744,14 @@ func (k *Keeper) RemoveUnbondingDelegation(ctx context.Context, ubd types.Unbond // an unbonding object and inserting it into the unbonding queue which will be // processed during the staking EndBlocker. func (k *Keeper) PerformUndelegation(ctx context.Context, data types.UndelegationData) (time.Time, error) { - // TODO: Probably we should implement this as well - // if k.HasMaxUnbondingDelegationEntries(ctx, delAddr, valAddr) { - // return time.Time{}, types.ErrMaxUnbondingDelegationEntries - // } + // Check if the unbonding delegation has reached the maximum number of entries + haxMaxEntries, err := k.HasMaxUnbondingDelegationEntries(ctx, data.Delegator, data.Target) + if err != nil { + return time.Time{}, err + } + if haxMaxEntries { + return time.Time{}, types.ErrMaxUnbondingDelegationEntries + } // Unbond the tokens returnAmount, err := k.Unbond(ctx, data) diff --git a/x/restaking/keeper/genesis_test.go b/x/restaking/keeper/genesis_test.go index e769b43db..ae761bc95 100644 --- a/x/restaking/keeper/genesis_test.go +++ b/x/restaking/keeper/genesis_test.go @@ -336,6 +336,7 @@ func (suite *KeeperTestSuite) TestKeeper_ExportGenesis() { 30*24*time.Hour, nil, sdkmath.LegacyNewDec(100000), + 100, )) suite.Require().NoError(err) }, @@ -344,6 +345,7 @@ func (suite *KeeperTestSuite) TestKeeper_ExportGenesis() { 30*24*time.Hour, nil, sdkmath.LegacyNewDec(100000), + 100, ), }, }, @@ -658,6 +660,7 @@ func (suite *KeeperTestSuite) TestKeeper_InitGenesis() { 30*24*time.Hour, nil, sdkmath.LegacyNewDec(100000), + 100, ), }, check: func(ctx sdk.Context) { @@ -667,6 +670,7 @@ func (suite *KeeperTestSuite) TestKeeper_InitGenesis() { 30*24*time.Hour, nil, sdkmath.LegacyNewDec(100000), + 100, ), params) }, }, diff --git a/x/restaking/keeper/grpc_query_test.go b/x/restaking/keeper/grpc_query_test.go index a0df5dded..611718b99 100644 --- a/x/restaking/keeper/grpc_query_test.go +++ b/x/restaking/keeper/grpc_query_test.go @@ -3500,13 +3500,13 @@ func (suite *KeeperTestSuite) TestQuerier_Params() { { name: "params are returned properly", store: func(ctx sdk.Context) { - params := types.NewParams(30*24*time.Hour, []string{"uinit", "umilk"}, sdkmath.LegacyNewDec(100000)) + params := types.NewParams(30*24*time.Hour, []string{"uinit", "umilk"}, sdkmath.LegacyNewDec(100000), 5) err := suite.k.SetParams(ctx, params) suite.Require().NoError(err) }, request: types.NewQueryParamsRequest(), shouldErr: false, - expParams: types.NewParams(30*24*time.Hour, []string{"uinit", "umilk"}, sdkmath.LegacyNewDec(100000)), + expParams: types.NewParams(30*24*time.Hour, []string{"uinit", "umilk"}, sdkmath.LegacyNewDec(100000), 5), }, } diff --git a/x/restaking/keeper/msg_server_test.go b/x/restaking/keeper/msg_server_test.go index acd3c48bb..75b1c95d6 100644 --- a/x/restaking/keeper/msg_server_test.go +++ b/x/restaking/keeper/msg_server_test.go @@ -1492,7 +1492,7 @@ func (suite *KeeperTestSuite) TestMsgServer_UndelegatePool() { }, store: func(ctx sdk.Context) { // Set the unbonding time to 1 week - err := suite.k.SetParams(ctx, types.NewParams(7*24*time.Hour, nil, types.DefaultRestakingCap)) + err := suite.k.SetParams(ctx, types.NewParams(7*24*time.Hour, nil, types.DefaultRestakingCap, types.DefaultMaxEntries)) suite.Require().NoError(err) // Create the pool @@ -1809,7 +1809,7 @@ func (suite *KeeperTestSuite) TestMsgServer_UndelegateOperator() { }, store: func(ctx sdk.Context) { // Set the unbonding time to 1 week - err := suite.k.SetParams(ctx, types.NewParams(7*24*time.Hour, nil, types.DefaultRestakingCap)) + err := suite.k.SetParams(ctx, types.NewParams(7*24*time.Hour, nil, types.DefaultRestakingCap, types.DefaultMaxEntries)) suite.Require().NoError(err) // Create the operator @@ -2295,7 +2295,7 @@ func (suite *KeeperTestSuite) TestMsgServer_UndelegateService() { }, store: func(ctx sdk.Context) { // Set the unbonding time to 1 week - err := suite.k.SetParams(ctx, types.NewParams(7*24*time.Hour, nil, types.DefaultRestakingCap)) + err := suite.k.SetParams(ctx, types.NewParams(7*24*time.Hour, nil, types.DefaultRestakingCap, types.DefaultMaxEntries)) suite.Require().NoError(err) // Create the service diff --git a/x/restaking/keeper/params.go b/x/restaking/keeper/params.go index 7bfa90418..7a89ed8ae 100644 --- a/x/restaking/keeper/params.go +++ b/x/restaking/keeper/params.go @@ -63,6 +63,15 @@ func (k *Keeper) RestakingCap(ctx context.Context) (math.LegacyDec, error) { return params.RestakingCap, nil } +// MaxEntries returns the maximum number of simultaneous unbonding delegations. +func (k *Keeper) MaxEntries(ctx context.Context) (uint32, error) { + params, err := k.GetParams(ctx) + if err != nil { + return 0, err + } + return params.MaxEntries, nil +} + // SetParams sets module parameters func (k *Keeper) SetParams(ctx context.Context, params types.Params) error { store := k.storeService.OpenKVStore(ctx) diff --git a/x/restaking/keeper/restake_restriction_test.go b/x/restaking/keeper/restake_restriction_test.go index e6550bace..ef8057392 100644 --- a/x/restaking/keeper/restake_restriction_test.go +++ b/x/restaking/keeper/restake_restriction_test.go @@ -82,6 +82,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateRestakeRestakingCap() { types.DefaultUnbondingTime, nil, sdkmath.LegacyNewDec(5000), + types.DefaultMaxEntries, )) suite.Require().NoError(err) }, @@ -93,7 +94,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateRestakeRestakingCap() { store: func(ctx sdk.Context) { // Set restaking cap err := suite.k.SetParams(ctx, types.NewParams( - types.DefaultUnbondingTime, nil, sdkmath.LegacyNewDec(5000)), + types.DefaultUnbondingTime, nil, sdkmath.LegacyNewDec(5000), types.DefaultMaxEntries), ) suite.Require().NoError(err) }, diff --git a/x/restaking/keeper/unbond_test.go b/x/restaking/keeper/unbond_test.go new file mode 100644 index 000000000..f80ccf399 --- /dev/null +++ b/x/restaking/keeper/unbond_test.go @@ -0,0 +1,40 @@ +package keeper_test + +import ( + "time" + + "github.com/milkyway-labs/milkyway/v7/utils" + "github.com/milkyway-labs/milkyway/v7/x/restaking/keeper" + "github.com/milkyway-labs/milkyway/v7/x/restaking/types" +) + +func (suite *KeeperTestSuite) TestKeeper_MaxUnbondingEntries() { + ctx, _ := suite.ctx.CacheContext() + + params, err := suite.k.GetParams(ctx) + suite.Require().NoError(err) + params.MaxEntries = 2 + err = suite.k.SetParams(ctx, params) + suite.Require().NoError(err) + + delegator := "cosmos167x6ehhple8gwz5ezy9x0464jltvdpzl6qfdt4" + suite.fundAccount(ctx, delegator, utils.MustParseCoins("10000_000000umilk")) + + // First delegate to pool + msgServer := keeper.NewMsgServer(suite.k) + _, err = msgServer.DelegatePool(ctx, types.NewMsgDelegatePool(utils.MustParseCoin("10000_000000umilk"), delegator)) + suite.Require().NoError(err) + + // Unbonding from pool for the first two times should be successful + _, err = msgServer.UndelegatePool(ctx, types.NewMsgUndelegatePool(utils.MustParseCoin("1000_000000umilk"), delegator)) + suite.Require().NoError(err) + // Increase the block height by 1 so that a separate unbonding entry is created + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(5 * time.Second)) + _, err = msgServer.UndelegatePool(ctx, types.NewMsgUndelegatePool(utils.MustParseCoin("1000_000000umilk"), delegator)) + suite.Require().NoError(err) + + // But it should fail for the third time, since it exceeds the max entries + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(5 * time.Second)) + _, err = msgServer.UndelegatePool(ctx, types.NewMsgUndelegatePool(utils.MustParseCoin("1000_000000umilk"), delegator)) + suite.Require().ErrorIs(err, types.ErrMaxUnbondingDelegationEntries) +} diff --git a/x/restaking/simulation/utils.go b/x/restaking/simulation/utils.go index 59584c617..2688c0eb6 100644 --- a/x/restaking/simulation/utils.go +++ b/x/restaking/simulation/utils.go @@ -124,7 +124,7 @@ func RandomUserPreferencesEntries( func RandomParams(r *rand.Rand) types.Params { unbondingDays := time.Duration(r.Intn(7) + 1) - return types.NewParams(time.Hour*24*unbondingDays, nil, simulation.RandomDecAmount(r, math.LegacyNewDec(10000))) + return types.NewParams(time.Hour*24*unbondingDays, nil, simulation.RandomDecAmount(r, math.LegacyNewDec(10000)), uint32(r.Intn(20)+1)) } func RandomUserPreferences(r *rand.Rand, services []servicestypes.Service) types.UserPreferences { diff --git a/x/restaking/types/errors.go b/x/restaking/types/errors.go index 8ea7333bd..eac9c2ba0 100644 --- a/x/restaking/types/errors.go +++ b/x/restaking/types/errors.go @@ -20,4 +20,5 @@ var ( ErrPoolNotSecuringService = errors.Register(ModuleName, 13, "pool not securing the service") ErrDenomNotRestakable = errors.Register(ModuleName, 14, "denom not restakable") ErrRestakingCapExceeded = errors.Register(ModuleName, 15, "restaking cap exceeded") + ErrMaxUnbondingDelegationEntries = errors.Register(ModuleName, 16, "too many unbonding delegation entries for (delegator, delegation target) tuple") ) diff --git a/x/restaking/types/genesis_test.go b/x/restaking/types/genesis_test.go index 593a8c6fe..14e26f90f 100644 --- a/x/restaking/types/genesis_test.go +++ b/x/restaking/types/genesis_test.go @@ -227,7 +227,7 @@ func TestGenesis_Validate(t *testing.T) { nil, nil, nil, - types.NewParams(0, nil, types.DefaultRestakingCap), + types.NewParams(0, nil, types.DefaultRestakingCap, types.DefaultMaxEntries), ), shouldErr: true, }, @@ -323,7 +323,7 @@ func TestGenesis_Validate(t *testing.T) { }), ), }, - types.NewParams(5*24*time.Hour, nil, sdkmath.LegacyNewDec(100000)), + types.NewParams(5*24*time.Hour, nil, sdkmath.LegacyNewDec(100000), types.DefaultMaxEntries), ), shouldErr: false, }, diff --git a/x/restaking/types/messages_test.go b/x/restaking/types/messages_test.go index 069d24384..e8ab10815 100644 --- a/x/restaking/types/messages_test.go +++ b/x/restaking/types/messages_test.go @@ -269,7 +269,7 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) { { name: "invalid params return error", msg: types.NewMsgUpdateParams( - types.NewParams(0, nil, types.DefaultRestakingCap), + types.NewParams(0, nil, types.DefaultRestakingCap, types.DefaultMaxEntries), msgUpdateParams.Authority, ), shouldErr: true, @@ -302,7 +302,7 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) { } func TestMsgUpdateParams_GetSignBytes(t *testing.T) { - expected := `{"type":"milkyway/restaking/MsgUpdateParams","value":{"authority":"cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd","params":{"restaking_cap":"0.000000000000000000","unbonding_time":"259200000000000"}}}` + expected := `{"type":"milkyway/restaking/MsgUpdateParams","value":{"authority":"cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd","params":{"max_entries":7,"restaking_cap":"0.000000000000000000","unbonding_time":"259200000000000"}}}` require.Equal(t, expected, string(msgUpdateParams.GetSignBytes())) } diff --git a/x/restaking/types/params.go b/x/restaking/types/params.go index 809817e76..4b9d2e254 100644 --- a/x/restaking/types/params.go +++ b/x/restaking/types/params.go @@ -10,6 +10,7 @@ import ( const ( DefaultUnbondingTime = 3 * 24 * time.Hour + DefaultMaxEntries = 7 ) var ( @@ -17,17 +18,23 @@ var ( ) // NewParams returns a new Params instance -func NewParams(unbondingTime time.Duration, allowedDenoms []string, restakingCap math.LegacyDec) Params { +func NewParams( + unbondingTime time.Duration, + allowedDenoms []string, + restakingCap math.LegacyDec, + maxEntries uint32, +) Params { return Params{ UnbondingTime: unbondingTime, AllowedDenoms: allowedDenoms, RestakingCap: restakingCap, + MaxEntries: maxEntries, } } // DefaultParams return a Params instance with default values set func DefaultParams() Params { - return NewParams(DefaultUnbondingTime, nil, DefaultRestakingCap) + return NewParams(DefaultUnbondingTime, nil, DefaultRestakingCap, DefaultMaxEntries) } // Validate performs basic validation of params @@ -47,5 +54,9 @@ func (p *Params) Validate() error { return fmt.Errorf("restaking cap cannot be negative: %s", p.RestakingCap) } + if p.MaxEntries == 0 { + return fmt.Errorf("max entries must be positive: %d", p.MaxEntries) + } + return nil } diff --git a/x/restaking/types/params.pb.go b/x/restaking/types/params.pb.go index 8d7e21fdd..b3326514c 100644 --- a/x/restaking/types/params.pb.go +++ b/x/restaking/types/params.pb.go @@ -41,6 +41,9 @@ type Params struct { // inside the chain. If set to 0, it indicates no limit, allowing any amount // of assets to be restaked. RestakingCap cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=restaking_cap,json=restakingCap,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"restaking_cap"` + // MaxEntries represents the maximum number of entries for unbonding + // delegation. + MaxEntries uint32 `protobuf:"varint,4,opt,name=max_entries,json=maxEntries,proto3" json:"max_entries,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -90,6 +93,13 @@ func (m *Params) GetAllowedDenoms() []string { return nil } +func (m *Params) GetMaxEntries() uint32 { + if m != nil { + return m.MaxEntries + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "milkyway.restaking.v1.Params") } @@ -99,27 +109,28 @@ func init() { } var fileDescriptor_342e630197fca2bb = []byte{ - // 307 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x41, 0x4b, 0xc3, 0x30, - 0x00, 0x85, 0x1b, 0x27, 0x83, 0x05, 0xb7, 0x43, 0x51, 0x98, 0x13, 0xb2, 0x31, 0x10, 0x06, 0xb2, - 0x84, 0x21, 0xe8, 0x7d, 0xee, 0xe8, 0x61, 0x0c, 0xf1, 0xe0, 0xa5, 0xa4, 0x69, 0xc8, 0xc2, 0x9a, - 0xa6, 0x2c, 0x59, 0x67, 0xff, 0x85, 0x47, 0x7f, 0xc8, 0x7e, 0xc4, 0x8e, 0xc3, 0x93, 0x78, 0x98, - 0xd2, 0xfe, 0x11, 0xb1, 0xdd, 0x8a, 0xb7, 0xbc, 0x2f, 0x2f, 0x8f, 0x97, 0x07, 0xfb, 0x4a, 0x86, - 0x8b, 0x74, 0x4d, 0x53, 0xb2, 0xe4, 0xc6, 0xd2, 0x85, 0x8c, 0x04, 0x49, 0x46, 0x24, 0xa6, 0x4b, - 0xaa, 0x0c, 0x8e, 0x97, 0xda, 0x6a, 0xf7, 0xe2, 0xe8, 0xc1, 0x95, 0x07, 0x27, 0xa3, 0xce, 0x25, - 0xd3, 0x46, 0x69, 0xe3, 0x15, 0x26, 0x52, 0x8a, 0xf2, 0x45, 0xe7, 0x5c, 0x68, 0xa1, 0x4b, 0xfe, - 0x77, 0x2a, 0x69, 0x7f, 0x03, 0x60, 0x7d, 0x5a, 0x04, 0xbb, 0x37, 0xb0, 0xb5, 0x8a, 0x7c, 0x1d, - 0x05, 0x32, 0x12, 0x9e, 0x95, 0x8a, 0xb7, 0x41, 0x0f, 0x0c, 0x6a, 0xe3, 0xd3, 0xf7, 0xef, 0x2e, - 0x98, 0x35, 0xab, 0xbb, 0x27, 0xa9, 0xb8, 0x7b, 0x0d, 0x5b, 0x34, 0x0c, 0xf5, 0x9a, 0x07, 0x5e, - 0xc0, 0x23, 0xad, 0x4c, 0xfb, 0xa4, 0x57, 0x1b, 0x34, 0x66, 0xcd, 0x03, 0x9d, 0x14, 0xd0, 0x7d, - 0x86, 0xcd, 0xaa, 0x9f, 0xc7, 0x68, 0xdc, 0xae, 0xf5, 0xc0, 0xa0, 0x31, 0x1e, 0x6d, 0xf7, 0x5d, - 0xe7, 0x6b, 0xdf, 0xbd, 0x2a, 0x1b, 0x9a, 0x60, 0x81, 0xa5, 0x26, 0x8a, 0xda, 0x39, 0x7e, 0xe4, - 0x82, 0xb2, 0x74, 0xc2, 0xd9, 0xc7, 0x66, 0x08, 0x0f, 0x1f, 0x98, 0x70, 0x36, 0x3b, 0xab, 0x72, - 0x1e, 0x68, 0x3c, 0x9e, 0x6e, 0x33, 0x04, 0x76, 0x19, 0x02, 0x3f, 0x19, 0x02, 0x6f, 0x39, 0x72, - 0x76, 0x39, 0x72, 0x3e, 0x73, 0xe4, 0xbc, 0xdc, 0x09, 0x69, 0xe7, 0x2b, 0x1f, 0x33, 0xad, 0xc8, - 0x71, 0xa3, 0x61, 0x48, 0x7d, 0x53, 0x29, 0x92, 0xdc, 0x93, 0xd7, 0x7f, 0xd3, 0xda, 0x34, 0xe6, - 0xc6, 0xaf, 0x17, 0x7b, 0xdc, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0x9a, 0x1d, 0x15, 0x80, 0x7d, - 0x01, 0x00, 0x00, + // 330 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x4f, 0x4b, 0xc3, 0x30, + 0x00, 0xc5, 0x1b, 0x37, 0x06, 0x8b, 0x76, 0x87, 0xa2, 0x50, 0x27, 0xb4, 0x65, 0x20, 0x14, 0x64, + 0x0d, 0x43, 0xd0, 0xfb, 0x9c, 0x37, 0x0f, 0xa3, 0x88, 0x07, 0x2f, 0x25, 0x6d, 0x43, 0x17, 0xd6, + 0x34, 0xa5, 0xc9, 0xfe, 0xf4, 0x5b, 0x78, 0xf4, 0x83, 0xf8, 0x21, 0x76, 0x1c, 0x82, 0x20, 0x1e, + 0xa6, 0x6c, 0x5f, 0x44, 0x6c, 0xb6, 0xe2, 0x2d, 0xef, 0x97, 0x97, 0xc7, 0xcb, 0x83, 0x3d, 0x46, + 0xd3, 0x69, 0xb9, 0xc0, 0x25, 0x2a, 0x88, 0x90, 0x78, 0x4a, 0xb3, 0x04, 0xcd, 0x07, 0x28, 0xc7, + 0x05, 0x66, 0xc2, 0xcb, 0x0b, 0x2e, 0xb9, 0x71, 0x76, 0xf0, 0x78, 0xb5, 0xc7, 0x9b, 0x0f, 0xba, + 0xe7, 0x11, 0x17, 0x8c, 0x8b, 0xa0, 0x32, 0x21, 0x25, 0xd4, 0x8b, 0xee, 0x69, 0xc2, 0x13, 0xae, + 0xf8, 0xdf, 0x49, 0xd1, 0xde, 0x07, 0x80, 0xad, 0x71, 0x15, 0x6c, 0x5c, 0xc1, 0xce, 0x2c, 0x0b, + 0x79, 0x16, 0xd3, 0x2c, 0x09, 0x24, 0x65, 0xc4, 0x04, 0x0e, 0x70, 0x1b, 0xc3, 0xe6, 0xeb, 0xb7, + 0x0d, 0x7c, 0xbd, 0xbe, 0x7b, 0xa4, 0x8c, 0x18, 0x97, 0xb0, 0x83, 0xd3, 0x94, 0x2f, 0x48, 0x1c, + 0xc4, 0x24, 0xe3, 0x4c, 0x98, 0x47, 0x4e, 0xc3, 0x6d, 0xfb, 0xfa, 0x9e, 0x8e, 0x2a, 0x68, 0x3c, + 0x41, 0xbd, 0xee, 0x17, 0x44, 0x38, 0x37, 0x1b, 0x0e, 0x70, 0xdb, 0xc3, 0xc1, 0x6a, 0x63, 0x6b, + 0x5f, 0x1b, 0xfb, 0x42, 0x35, 0x14, 0xf1, 0xd4, 0xa3, 0x1c, 0x31, 0x2c, 0x27, 0xde, 0x03, 0x49, + 0x70, 0x54, 0x8e, 0x48, 0xf4, 0xfe, 0xd6, 0x87, 0xfb, 0x0f, 0x8c, 0x48, 0xe4, 0x9f, 0xd4, 0x39, + 0x77, 0x38, 0x37, 0x6c, 0x78, 0xcc, 0xf0, 0x32, 0x20, 0x99, 0x2c, 0x28, 0x11, 0x66, 0xd3, 0x01, + 0xae, 0xee, 0x43, 0x86, 0x97, 0xf7, 0x8a, 0x0c, 0xc7, 0xab, 0xad, 0x05, 0xd6, 0x5b, 0x0b, 0xfc, + 0x6c, 0x2d, 0xf0, 0xb2, 0xb3, 0xb4, 0xf5, 0xce, 0xd2, 0x3e, 0x77, 0x96, 0xf6, 0x7c, 0x93, 0x50, + 0x39, 0x99, 0x85, 0x5e, 0xc4, 0x19, 0x3a, 0x8c, 0xd8, 0x4f, 0x71, 0x28, 0x6a, 0x85, 0xe6, 0xb7, + 0x68, 0xf9, 0x6f, 0x7b, 0x59, 0xe6, 0x44, 0x84, 0xad, 0x6a, 0xb0, 0xeb, 0xdf, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x7f, 0xea, 0x5a, 0x04, 0x9e, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -142,6 +153,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.MaxEntries != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.MaxEntries)) + i-- + dAtA[i] = 0x20 + } { size := m.RestakingCap.Size() i -= size @@ -197,6 +213,9 @@ func (m *Params) Size() (n int) { } l = m.RestakingCap.Size() n += 1 + l + sovParams(uint64(l)) + if m.MaxEntries != 0 { + n += 1 + sovParams(uint64(m.MaxEntries)) + } return n } @@ -320,6 +339,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxEntries", wireType) + } + m.MaxEntries = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxEntries |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/restaking/types/params_test.go b/x/restaking/types/params_test.go index 49013651c..55b8e5939 100644 --- a/x/restaking/types/params_test.go +++ b/x/restaking/types/params_test.go @@ -18,22 +18,27 @@ func TestParams_Validate(t *testing.T) { }{ { name: "invalid unbonding time returns error", - params: types.NewParams(0, nil, types.DefaultRestakingCap), + params: types.NewParams(0, nil, types.DefaultRestakingCap, types.DefaultMaxEntries), shouldErr: true, }, { name: "invalid denom returns error", - params: types.NewParams(5, []string{"1denom"}, types.DefaultRestakingCap), + params: types.NewParams(5, []string{"1denom"}, types.DefaultRestakingCap, types.DefaultMaxEntries), shouldErr: true, }, { name: "empty denom returns error", - params: types.NewParams(5, []string{""}, types.DefaultRestakingCap), + params: types.NewParams(5, []string{""}, types.DefaultRestakingCap, types.DefaultMaxEntries), shouldErr: true, }, { name: "negative restaking cap returns error", - params: types.NewParams(5, nil, math.LegacyNewDec(-1)), + params: types.NewParams(5, nil, math.LegacyNewDec(-1), types.DefaultMaxEntries), + shouldErr: true, + }, + { + name: "zero max entries returns error", + params: types.NewParams(5, nil, types.DefaultRestakingCap, 0), shouldErr: true, }, { @@ -43,7 +48,7 @@ func TestParams_Validate(t *testing.T) { }, { name: "valid params return no error", - params: types.NewParams(5*time.Hour, nil, math.LegacyNewDec(100000)), + params: types.NewParams(5*time.Hour, nil, math.LegacyNewDec(100000), types.DefaultMaxEntries), shouldErr: false, }, }