From 9f017956ac91fa4a21f94fe90d894b2d427b609d Mon Sep 17 00:00:00 2001 From: 0xHansLee Date: Thu, 17 Oct 2024 20:53:13 -0700 Subject: [PATCH] feat(upgrade): add sweep index to init and export genesis --- client/app/upgrades.go | 5 +- client/app/upgrades/v0_10_0/constants.go | 16 ------ client/app/upgrades/v0_10_0/upgrades.go | 64 ----------------------- client/x/evmstaking/keeper/genesis.go | 23 +++++--- client/x/evmstaking/keeper/params.go | 16 +++--- client/x/evmstaking/keeper/params_test.go | 20 +++---- client/x/evmstaking/keeper/withdraw.go | 10 ++-- client/x/evmstaking/types/genesis.go | 23 +++++--- client/x/evmstaking/types/genesis.pb.go | 59 +++++++++------------ client/x/evmstaking/types/genesis.proto | 2 +- client/x/evmstaking/types/genesis_test.go | 2 +- client/x/evmstaking/types/params.go | 18 ++++++- 12 files changed, 100 insertions(+), 158 deletions(-) delete mode 100644 client/app/upgrades/v0_10_0/constants.go delete mode 100644 client/app/upgrades/v0_10_0/upgrades.go diff --git a/client/app/upgrades.go b/client/app/upgrades.go index 9a4c089d..e1bb1088 100644 --- a/client/app/upgrades.go +++ b/client/app/upgrades.go @@ -8,15 +8,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/piplabs/story/client/app/upgrades" - "github.com/piplabs/story/client/app/upgrades/v0_10_0" ) var ( // `Upgrades` defines the upgrade handlers and store loaders for the application. // New upgrades should be added to this slice after they are implemented. - Upgrades = []upgrades.Upgrade{ - v0_10_0.Upgrade, - } + Upgrades = []upgrades.Upgrade{} // Forks are for hard forks that breaks backward compatibility. Forks = []upgrades.Fork{} ) diff --git a/client/app/upgrades/v0_10_0/constants.go b/client/app/upgrades/v0_10_0/constants.go deleted file mode 100644 index 3cb1acd2..00000000 --- a/client/app/upgrades/v0_10_0/constants.go +++ /dev/null @@ -1,16 +0,0 @@ -//nolint:revive,stylecheck // version underscores -package v0_10_0 - -import ( - storetypes "cosmossdk.io/store/types" - - "github.com/piplabs/story/client/app/upgrades" -) - -const UpgradeName = "v0.10.0" - -var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: storetypes.StoreUpgrades{}, -} diff --git a/client/app/upgrades/v0_10_0/upgrades.go b/client/app/upgrades/v0_10_0/upgrades.go deleted file mode 100644 index bc950dbf..00000000 --- a/client/app/upgrades/v0_10_0/upgrades.go +++ /dev/null @@ -1,64 +0,0 @@ -//nolint:revive,stylecheck // version underscores -package v0_10_0 - -import ( - "context" - - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/piplabs/story/client/app/keepers" - "github.com/piplabs/story/lib/errors" - clog "github.com/piplabs/story/lib/log" -) - -const ( - NewMaxSweepPerBlock = 1024 -) - -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - keepers *keepers.Keepers, -) upgradetypes.UpgradeHandler { - return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - clog.Info(ctx, "Starting module migrations...") - - vm, err := mm.RunMigrations(ctx, configurator, vm) - if err != nil { - return vm, errors.Wrap(err, "run migrations") - } - - clog.Info(ctx, "Setting NextValidatorDelegationSweepIndex parameter...") - nextValIndex, err := keepers.EvmStakingKeeper.GetOldValidatorSweepIndex(ctx) - if err != nil { - return vm, errors.Wrap(err, "get old validator sweep index") - } - - nextValDelIndex := uint64(0) - if err := keepers.EvmStakingKeeper.SetValidatorSweepIndex( - ctx, - nextValIndex, - nextValDelIndex, - ); err != nil { - return vm, errors.Wrap(err, "set evmstaking NextValidatorDelegationSweepIndex") - } - - // Update MaxSweepPerBlock - clog.Info(ctx, "Updating MaxSweepPerBlock parameter...") - params, err := keepers.EvmStakingKeeper.GetParams(ctx) - if err != nil { - return vm, errors.Wrap(err, "get evmstaking params") - } - - params.MaxSweepPerBlock = NewMaxSweepPerBlock - if err = keepers.EvmStakingKeeper.SetParams(ctx, params); err != nil { - return vm, errors.Wrap(err, "set evmstaking params") - } - - clog.Info(ctx, "Upgrade v0.10.0 complete") - - return vm, nil - } -} diff --git a/client/x/evmstaking/keeper/genesis.go b/client/x/evmstaking/keeper/genesis.go index f3ae6759..ba43776c 100644 --- a/client/x/evmstaking/keeper/genesis.go +++ b/client/x/evmstaking/keeper/genesis.go @@ -16,10 +16,15 @@ func (k Keeper) InitGenesis(ctx context.Context, gs *types.GenesisState) error { if err := k.ValidateGenesis(gs); err != nil { return err } + if err := k.SetParams(ctx, gs.Params); err != nil { return err } + if err := k.SetValidatorSweepIndex(ctx, gs.ValidatorSweepIndex); err != nil { + return err + } + if err := k.WithdrawalQueue.Initialize(ctx); err != nil { log.Error(ctx, "InitGenesis.evmstaking not initialized", err) return err @@ -71,20 +76,22 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { panic(err) } + validatorSweepIndex, err := k.GetValidatorSweepIndex(ctx) + if err != nil { + panic(err) + } + return &types.GenesisState{ - Params: params, + Params: params, + ValidatorSweepIndex: validatorSweepIndex, } } //nolint:revive // TODO: validate genesis func (k Keeper) ValidateGenesis(gs *types.GenesisState) error { - if err := types.ValidateMaxWithdrawalPerBlock(gs.Params.MaxWithdrawalPerBlock); err != nil { - return err - } - - if err := types.ValidateMaxSweepPerBlock(gs.Params.MaxSweepPerBlock, gs.Params.MaxWithdrawalPerBlock); err != nil { - return err + if err := gs.Params.Validate(); err != nil { + return errors.Wrap(err, "validate genesis state params") } - return types.ValidateMinPartialWithdrawalAmount(gs.Params.MinPartialWithdrawalAmount) + return nil } diff --git a/client/x/evmstaking/keeper/params.go b/client/x/evmstaking/keeper/params.go index f978c836..5eadcccb 100644 --- a/client/x/evmstaking/keeper/params.go +++ b/client/x/evmstaking/keeper/params.go @@ -71,11 +71,11 @@ func (k Keeper) GetParams(ctx context.Context) (params types.Params, err error) return params, nil } -func (k Keeper) SetValidatorSweepIndex(ctx context.Context, nextValIndex uint64, nextValDelIndex uint64) error { +func (k Keeper) SetValidatorSweepIndex(ctx context.Context, validatorSweepIndex types.ValidatorSweepIndex) error { store := k.storeService.OpenKVStore(ctx) bz, err := k.cdc.Marshal(&types.ValidatorSweepIndex{ - NextValIndex: nextValIndex, - NextValDelIndex: nextValDelIndex, + NextValIndex: validatorSweepIndex.NextValIndex, + NextValDelIndex: validatorSweepIndex.NextValDelIndex, }) if err != nil { return errors.Wrap(err, "marshal validator sweep index") @@ -89,24 +89,24 @@ func (k Keeper) SetValidatorSweepIndex(ctx context.Context, nextValIndex uint64, return nil } -func (k Keeper) GetValidatorSweepIndex(ctx context.Context) (nextValIndex uint64, nextValDelIndex uint64, err error) { +func (k Keeper) GetValidatorSweepIndex(ctx context.Context) (types.ValidatorSweepIndex, error) { store := k.storeService.OpenKVStore(ctx) bz, err := store.Get(types.ValidatorSweepIndexKey) if err != nil { - return nextValIndex, nextValDelIndex, errors.Wrap(err, "get validator sweep index") + return types.ValidatorSweepIndex{}, errors.Wrap(err, "get validator sweep index") } if bz == nil { - return nextValIndex, nextValDelIndex, nil + return types.ValidatorSweepIndex{}, nil } var sweepIndex types.ValidatorSweepIndex err = k.cdc.Unmarshal(bz, &sweepIndex) if err != nil { - return nextValIndex, nextValDelIndex, errors.Wrap(err, "unmarshal validator sweep index") + return types.ValidatorSweepIndex{}, errors.Wrap(err, "unmarshal validator sweep index") } - return sweepIndex.NextValIndex, sweepIndex.NextValDelIndex, nil + return sweepIndex, nil } func (k Keeper) GetOldValidatorSweepIndex(ctx context.Context) (nextValIndex uint64, err error) { diff --git a/client/x/evmstaking/keeper/params_test.go b/client/x/evmstaking/keeper/params_test.go index 58446a1a..779d6997 100644 --- a/client/x/evmstaking/keeper/params_test.go +++ b/client/x/evmstaking/keeper/params_test.go @@ -71,31 +71,31 @@ func (s *TestSuite) TestMinPartialWithdrawalAmount() { func (s *TestSuite) TestSetValidatorSweepIndex() { require := s.Require() ctx, keeper := s.Ctx, s.EVMStakingKeeper - existingNextValIndex, existingNextValDelIndex, err := keeper.GetValidatorSweepIndex(ctx) + existingSweepIndex, err := keeper.GetValidatorSweepIndex(ctx) require.NoError(err) // set new sweep index newNextValIndex := uint64(10) newNextValDelIndex := uint64(100) // make sure new value is different from existing value - require.NotEqual(existingNextValIndex, newNextValIndex) - require.NotEqual(existingNextValDelIndex, newNextValDelIndex) - require.NoError(keeper.SetValidatorSweepIndex(ctx, newNextValIndex, newNextValDelIndex)) + require.NotEqual(existingSweepIndex.NextValIndex, newNextValIndex) + require.NotEqual(existingSweepIndex.NextValDelIndex, newNextValDelIndex) + require.NoError(keeper.SetValidatorSweepIndex(ctx, types.NewValidatorSweepIndex(newNextValIndex, newNextValDelIndex))) // check new sweep index is set correctly - nextValIndex, nextValDelIndex, err := keeper.GetValidatorSweepIndex(ctx) + sweepIndex, err := keeper.GetValidatorSweepIndex(ctx) require.NoError(err) - require.Equal(newNextValIndex, nextValIndex) - require.Equal(newNextValDelIndex, nextValDelIndex) + require.Equal(newNextValIndex, sweepIndex.NextValIndex) + require.Equal(newNextValDelIndex, sweepIndex.NextValDelIndex) } func (s *TestSuite) TestGetValidatorSweepIndex() { require := s.Require() ctx, keeper := s.Ctx, s.EVMStakingKeeper - nextValIndex, nextValDelIndex, err := keeper.GetValidatorSweepIndex(ctx) + sweepIndex, err := keeper.GetValidatorSweepIndex(ctx) require.NoError(err) - require.Equal(uint64(0), nextValIndex) - require.Equal(uint64(0), nextValDelIndex) + require.Equal(uint64(0), sweepIndex.NextValIndex) + require.Equal(uint64(0), sweepIndex.NextValDelIndex) } func (s *TestSuite) TestGetOldValidatorSweepIndex() { diff --git a/client/x/evmstaking/keeper/withdraw.go b/client/x/evmstaking/keeper/withdraw.go index fbf960c7..c80791dd 100644 --- a/client/x/evmstaking/keeper/withdraw.go +++ b/client/x/evmstaking/keeper/withdraw.go @@ -89,11 +89,13 @@ func (k Keeper) ProcessRewardWithdrawals(ctx context.Context) error { } func (k Keeper) ExpectedRewardWithdrawals(ctx context.Context) ([]RewardWithdrawal, error) { - nextValIndex, nextValDelIndex, err := k.GetValidatorSweepIndex(ctx) + validatorSweepIndex, err := k.GetValidatorSweepIndex(ctx) if err != nil { return nil, err } + nextValIndex, nextValDelIndex := validatorSweepIndex.NextValIndex, validatorSweepIndex.NextValDelIndex + // Get all validators first, and then do a circular sweep validatorSet, err := (k.stakingKeeper.(*skeeper.Keeper)).GetAllValidators(ctx) if err != nil { @@ -231,11 +233,7 @@ func (k Keeper) ExpectedRewardWithdrawals(ctx context.Context) ([]RewardWithdraw } // Update the validator sweep index. - if err := k.SetValidatorSweepIndex( - ctx, - nextValIndex, - nextValDelIndex, - ); err != nil { + if err := k.SetValidatorSweepIndex(ctx, estypes.NewValidatorSweepIndex(nextValIndex, nextValDelIndex)); err != nil { return nil, err } diff --git a/client/x/evmstaking/types/genesis.go b/client/x/evmstaking/types/genesis.go index 96965cc6..201fffb2 100644 --- a/client/x/evmstaking/types/genesis.go +++ b/client/x/evmstaking/types/genesis.go @@ -3,7 +3,7 @@ package types func NewGenesisState(params Params) *GenesisState { return &GenesisState{ Params: params, - ValidatorSweepIndex: &ValidatorSweepIndex{ + ValidatorSweepIndex: ValidatorSweepIndex{ NextValIndex: 0, NextValDelIndex: 0, }, @@ -13,10 +13,21 @@ func NewGenesisState(params Params) *GenesisState { // DefaultGenesisState returns the default genesis state. func DefaultGenesisState() *GenesisState { return &GenesisState{ - Params: DefaultParams(), - ValidatorSweepIndex: &ValidatorSweepIndex{ - NextValIndex: 0, - NextValDelIndex: 0, - }, + Params: DefaultParams(), + ValidatorSweepIndex: DefaultValidatorSweepIndex(), + } +} + +func NewValidatorSweepIndex(nextValIndex, nextValDelIndex uint64) ValidatorSweepIndex { + return ValidatorSweepIndex{ + NextValIndex: nextValIndex, + NextValDelIndex: nextValDelIndex, + } +} + +func DefaultValidatorSweepIndex() ValidatorSweepIndex { + return ValidatorSweepIndex{ + NextValIndex: 0, + NextValDelIndex: 0, } } diff --git a/client/x/evmstaking/types/genesis.pb.go b/client/x/evmstaking/types/genesis.pb.go index 2700450e..b5a73c79 100644 --- a/client/x/evmstaking/types/genesis.pb.go +++ b/client/x/evmstaking/types/genesis.pb.go @@ -26,7 +26,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type GenesisState struct { Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` // TODO: Add withdrawals collections field as ORM if needed - ValidatorSweepIndex *ValidatorSweepIndex `protobuf:"bytes,2,opt,name=validator_sweep_index,json=validatorSweepIndex,proto3" json:"validator_sweep_index,omitempty"` + ValidatorSweepIndex ValidatorSweepIndex `protobuf:"bytes,2,opt,name=validator_sweep_index,json=validatorSweepIndex,proto3" json:"validator_sweep_index"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -69,11 +69,11 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetValidatorSweepIndex() *ValidatorSweepIndex { +func (m *GenesisState) GetValidatorSweepIndex() ValidatorSweepIndex { if m != nil { return m.ValidatorSweepIndex } - return nil + return ValidatorSweepIndex{} } type ValidatorSweepIndex struct { @@ -138,27 +138,27 @@ func init() { } var fileDescriptor_bf57cf100cbaf4bd = []byte{ - // 309 bytes of a gzipped FileDescriptorProto + // 310 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4f, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0xd1, 0xaf, 0xd0, 0x4f, 0x2d, 0xcb, 0x2d, 0x2e, 0x49, 0xcc, 0xce, 0xcc, 0x4b, 0xd7, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x84, 0x28, 0xd4, 0xab, 0xd0, 0x43, 0x28, 0xd4, 0x03, 0x2b, 0x94, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd2, 0x07, 0xb1, 0x20, 0x1a, 0xa4, 0xd4, 0x70, 0x9b, - 0x5c, 0x90, 0x58, 0x94, 0x98, 0x0b, 0x35, 0x58, 0x69, 0x33, 0x23, 0x17, 0x8f, 0x3b, 0xc4, 0xaa, + 0x5c, 0x90, 0x58, 0x94, 0x98, 0x0b, 0x35, 0x58, 0x69, 0x27, 0x23, 0x17, 0x8f, 0x3b, 0xc4, 0xaa, 0xe0, 0x92, 0xc4, 0x92, 0x54, 0x21, 0x7b, 0x2e, 0x36, 0x88, 0x02, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x45, 0x3d, 0x9c, 0x56, 0xeb, 0x05, 0x80, 0x15, 0x3a, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, - 0x10, 0x04, 0xd5, 0x26, 0x94, 0xc4, 0x25, 0x5a, 0x96, 0x98, 0x93, 0x99, 0x92, 0x58, 0x92, 0x5f, + 0x10, 0x04, 0xd5, 0x26, 0x94, 0xc1, 0x25, 0x5a, 0x96, 0x98, 0x93, 0x99, 0x92, 0x58, 0x92, 0x5f, 0x14, 0x5f, 0x5c, 0x9e, 0x9a, 0x5a, 0x10, 0x9f, 0x99, 0x97, 0x92, 0x5a, 0x21, 0xc1, 0x04, 0x36, - 0x4f, 0x0f, 0x8f, 0x79, 0x61, 0x30, 0x7d, 0xc1, 0x20, 0x6d, 0x9e, 0x20, 0x5d, 0x41, 0xc2, 0x65, - 0x98, 0x82, 0x4a, 0x8b, 0x18, 0xb9, 0x84, 0xb1, 0x28, 0x16, 0xb2, 0xe7, 0xe2, 0xcb, 0x4b, 0xad, - 0x28, 0x89, 0x2f, 0x4b, 0xcc, 0x81, 0x5a, 0x0a, 0xf2, 0x04, 0x8b, 0x93, 0xe4, 0xa7, 0x7b, 0xf2, - 0xa2, 0x95, 0x89, 0xb9, 0x39, 0x56, 0x4a, 0xa8, 0xf2, 0x4a, 0x41, 0x3c, 0x20, 0x81, 0xb0, 0xc4, - 0x1c, 0x88, 0x01, 0x5e, 0x5c, 0x42, 0x70, 0x05, 0x29, 0xa9, 0x39, 0x48, 0x2e, 0x67, 0x71, 0x92, - 0xfd, 0x74, 0x4f, 0x5e, 0x12, 0xcd, 0x10, 0xb8, 0x1a, 0xa5, 0x20, 0x7e, 0xa8, 0x41, 0x2e, 0xa9, - 0x10, 0xb3, 0x9c, 0x8c, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, - 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x12, - 0x67, 0xe4, 0x24, 0xb1, 0x81, 0xa3, 0xc5, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x7b, 0x06, 0x14, - 0x74, 0x1a, 0x02, 0x00, 0x00, + 0x4f, 0x0f, 0x8f, 0x79, 0x61, 0x30, 0x7d, 0xc1, 0x20, 0x6d, 0x9e, 0x20, 0x5d, 0x50, 0xc3, 0x85, + 0xcb, 0x30, 0xa5, 0x94, 0x16, 0x31, 0x72, 0x09, 0x63, 0xd1, 0x22, 0x64, 0xcf, 0xc5, 0x97, 0x97, + 0x5a, 0x51, 0x12, 0x5f, 0x96, 0x98, 0x03, 0xb5, 0x1a, 0xe4, 0x15, 0x16, 0x27, 0xc9, 0x4f, 0xf7, + 0xe4, 0x45, 0x2b, 0x13, 0x73, 0x73, 0xac, 0x94, 0x50, 0xe5, 0x95, 0x82, 0x78, 0x40, 0x02, 0x61, + 0x89, 0x39, 0x10, 0x03, 0xbc, 0xb8, 0x84, 0xe0, 0x0a, 0x52, 0x52, 0x73, 0x90, 0xdc, 0xcf, 0xe2, + 0x24, 0xfb, 0xe9, 0x9e, 0xbc, 0x24, 0x9a, 0x21, 0x70, 0x35, 0x4a, 0x41, 0xfc, 0x50, 0x83, 0x5c, + 0x52, 0x21, 0x66, 0x39, 0x19, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, + 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, + 0x24, 0xce, 0x28, 0x4a, 0x62, 0x03, 0x47, 0x8e, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xe2, 0xc3, + 0x0a, 0x79, 0x20, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -181,18 +181,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.ValidatorSweepIndex != nil { - { - size, err := m.ValidatorSweepIndex.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) + { + size, err := m.ValidatorSweepIndex.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0x12 + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x12 { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -258,10 +256,8 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - if m.ValidatorSweepIndex != nil { - l = m.ValidatorSweepIndex.Size() - n += 1 + l + sovGenesis(uint64(l)) - } + l = m.ValidatorSweepIndex.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -377,9 +373,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.ValidatorSweepIndex == nil { - m.ValidatorSweepIndex = &ValidatorSweepIndex{} - } if err := m.ValidatorSweepIndex.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/client/x/evmstaking/types/genesis.proto b/client/x/evmstaking/types/genesis.proto index 1b094232..76451262 100644 --- a/client/x/evmstaking/types/genesis.proto +++ b/client/x/evmstaking/types/genesis.proto @@ -9,7 +9,7 @@ option go_package = "client/x/evmstaking/types"; message GenesisState { Params params = 1 [(gogoproto.nullable) = false]; // TODO: Add withdrawals collections field as ORM if needed - ValidatorSweepIndex validator_sweep_index = 2; + ValidatorSweepIndex validator_sweep_index = 2 [(gogoproto.nullable) = false]; } message ValidatorSweepIndex { diff --git a/client/x/evmstaking/types/genesis_test.go b/client/x/evmstaking/types/genesis_test.go index 8bb16061..027575d6 100644 --- a/client/x/evmstaking/types/genesis_test.go +++ b/client/x/evmstaking/types/genesis_test.go @@ -8,7 +8,7 @@ import ( "github.com/piplabs/story/client/x/evmstaking/types" ) -var zeroVallidatorSweepIndex = &types.ValidatorSweepIndex{ +var zeroVallidatorSweepIndex = types.ValidatorSweepIndex{ NextValIndex: 0, NextValDelIndex: 0, } diff --git a/client/x/evmstaking/types/params.go b/client/x/evmstaking/types/params.go index 44ed8ee2..c1a189cf 100644 --- a/client/x/evmstaking/types/params.go +++ b/client/x/evmstaking/types/params.go @@ -8,7 +8,7 @@ import ( const ( DefaultMaxWithdrawalPerBlock uint32 = 4 - DefaultMaxSweepPerBlock uint32 = 64 + DefaultMaxSweepPerBlock uint32 = 1024 DefaultMinPartialWithdrawalAmount uint64 = 600_000 @@ -35,6 +35,22 @@ func DefaultParams() Params { ) } +func (p Params) Validate() error { + if err := ValidateMaxWithdrawalPerBlock(p.MaxWithdrawalPerBlock); err != nil { + return err + } + + if err := ValidateMaxSweepPerBlock(p.MaxSweepPerBlock, p.MaxWithdrawalPerBlock); err != nil { + return err + } + + if err := ValidateMinPartialWithdrawalAmount(p.MinPartialWithdrawalAmount); err != nil { + return err + } + + return ValidateSingularityHeight(p.SingularityHeight) +} + func ValidateMaxWithdrawalPerBlock(v uint32) error { if v == 0 { return fmt.Errorf("max withdrawal per block must be positive: %d", v)