diff --git a/client/app/upgrades.go b/client/app/upgrades.go index e1bb1088..9a4c089d 100644 --- a/client/app/upgrades.go +++ b/client/app/upgrades.go @@ -8,12 +8,15 @@ 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{} + Upgrades = []upgrades.Upgrade{ + v0_10_0.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 new file mode 100644 index 00000000..3cb1acd2 --- /dev/null +++ b/client/app/upgrades/v0_10_0/constants.go @@ -0,0 +1,16 @@ +//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 new file mode 100644 index 00000000..bc950dbf --- /dev/null +++ b/client/app/upgrades/v0_10_0/upgrades.go @@ -0,0 +1,64 @@ +//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/params.go b/client/x/evmstaking/keeper/params.go index a500fed5..f978c836 100644 --- a/client/x/evmstaking/keeper/params.go +++ b/client/x/evmstaking/keeper/params.go @@ -3,8 +3,6 @@ package keeper import ( "context" - "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/piplabs/story/client/x/evmstaking/types" @@ -73,36 +71,60 @@ func (k Keeper) GetParams(ctx context.Context) (params types.Params, err error) return params, nil } -func (k Keeper) SetNextValidatorSweepIndex(ctx context.Context, nextValIndex sdk.IntProto) error { +func (k Keeper) SetValidatorSweepIndex(ctx context.Context, nextValIndex uint64, nextValDelIndex uint64) error { store := k.storeService.OpenKVStore(ctx) - bz, err := k.cdc.Marshal(&nextValIndex) + bz, err := k.cdc.Marshal(&types.ValidatorSweepIndex{ + NextValIndex: nextValIndex, + NextValDelIndex: nextValDelIndex, + }) if err != nil { - return errors.Wrap(err, "marshal next validator sweep index") + return errors.Wrap(err, "marshal validator sweep index") } - err = store.Set(types.NextValidatorSweepIndexKey, bz) + err = store.Set(types.ValidatorSweepIndexKey, bz) if err != nil { - return errors.Wrap(err, "set next validator sweep index") + return errors.Wrap(err, "set validator sweep index") } return nil } -func (k Keeper) GetNextValidatorSweepIndex(ctx context.Context) (nextValIndex sdk.IntProto, err error) { +func (k Keeper) GetValidatorSweepIndex(ctx context.Context) (nextValIndex uint64, nextValDelIndex uint64, err 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") + } + + if bz == nil { + return nextValIndex, nextValDelIndex, 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 sweepIndex.NextValIndex, sweepIndex.NextValDelIndex, nil +} + +func (k Keeper) GetOldValidatorSweepIndex(ctx context.Context) (nextValIndex uint64, err error) { store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.NextValidatorSweepIndexKey) + bz, err := store.Get(types.ValidatorSweepIndexKey) if err != nil { return nextValIndex, errors.Wrap(err, "get next validator sweep index") } if bz == nil { - return sdk.IntProto{Int: math.NewInt(0)}, nil + return nextValIndex, nil } - err = k.cdc.Unmarshal(bz, &nextValIndex) + var nextValIndexProto sdk.IntProto + err = k.cdc.Unmarshal(bz, &nextValIndexProto) if err != nil { return nextValIndex, errors.Wrap(err, "unmarshal next validator sweep index") } - return nextValIndex, nil + return nextValIndexProto.Int.Uint64(), nil } diff --git a/client/x/evmstaking/keeper/withdraw.go b/client/x/evmstaking/keeper/withdraw.go index 87f28f51..22f2cf81 100644 --- a/client/x/evmstaking/keeper/withdraw.go +++ b/client/x/evmstaking/keeper/withdraw.go @@ -3,8 +3,6 @@ package keeper import ( "context" - "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" dtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" skeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" @@ -20,19 +18,18 @@ import ( ) func (k Keeper) ExpectedPartialWithdrawals(ctx context.Context) ([]estypes.Withdrawal, error) { - // TODO: user more fine-grained cursor with next delegator sweep index. - nextValSweepIndex, err := k.GetNextValidatorSweepIndex(ctx) + nextValIndex, nextValDelIndex, err := k.GetValidatorSweepIndex(ctx) if err != nil { return nil, err } - nextValIndex := nextValSweepIndex.Int.Int64() + // Get all validators first, and then do a circular sweep validatorSet, err := (k.stakingKeeper.(*skeeper.Keeper)).GetAllValidators(ctx) if err != nil { return nil, errors.Wrap(err, "get all validators") } - if nextValIndex >= int64(len(validatorSet)) { + if nextValIndex >= uint64(len(validatorSet)) { // TODO: TBD log.Warn( ctx, "NextValidatorIndex exceeds the validator set size", @@ -41,6 +38,7 @@ func (k Keeper) ExpectedPartialWithdrawals(ctx context.Context) ([]estypes.Withd "next_validator_index", nextValIndex, ) nextValIndex = 0 + nextValDelIndex = 0 } // Iterate all validators from `nextValidatorIndex` to find out eligible partial withdrawals. @@ -48,30 +46,26 @@ func (k Keeper) ExpectedPartialWithdrawals(ctx context.Context) ([]estypes.Withd swept uint32 withdrawals []estypes.Withdrawal ) + // Get sweep limit per block. sweepBound, err := k.MaxSweepPerBlock(ctx) if err != nil { return nil, err } + // Get minimal partial withdrawal amount. minPartialWithdrawalAmount, err := k.MinPartialWithdrawalAmount(ctx) if err != nil { return nil, err } - log.Debug( - ctx, "partial withdrawal params", - "min_partial_withdraw_amount", minPartialWithdrawalAmount, - "max_sweep_per_block", sweepBound, - ) + // Sweep and get eligible partial withdrawals. for range validatorSet { - if swept > sweepBound { - break - } - if validatorSet[nextValIndex].IsJailed() { // nextValIndex should be updated, even if the validator is jailed, to progress to the sweep. - nextValIndex = (nextValIndex + 1) % int64(len(validatorSet)) + nextValIndex = (nextValIndex + 1) % uint64(len(validatorSet)) + nextValDelIndex = 0 + continue } @@ -82,86 +76,100 @@ func (k Keeper) ExpectedPartialWithdrawals(ctx context.Context) ([]estypes.Withd } valAddr := sdk.ValAddress(valBz) valAccAddr := sdk.AccAddress(valAddr) + // Get validator commissions. valCommission, err := k.distributionKeeper.GetValidatorAccumulatedCommission(ctx, valAddr) if err != nil { return nil, err } - log.Debug( - ctx, "Get validator commission", - "val_addr", valAddr.String(), - "commission_amount", valCommission.Commission.String(), - ) + // Get all delegators of the validator. delegators, err := (k.stakingKeeper.(*skeeper.Keeper)).GetValidatorDelegations(ctx, valAddr) if err != nil { return nil, errors.Wrap(err, "get validator delegations") } - swept += uint32(len(delegators)) - log.Debug( - ctx, "Get all delegators of validator", - "val_addr", valAddr.String(), - "delegator_amount", len(delegators), - ) - // Get delegator rewards. - for i := range delegators { + + if nextValDelIndex >= uint64(len(delegators)) { + nextValIndex = (nextValIndex + 1) % uint64(len(validatorSet)) + nextValDelIndex = 0 + + continue + } + + nextDelegators := delegators[nextValDelIndex:] + var shouldStopPrematurely bool + + // Check if the sweep should stop prematurely as the current delegator loop exceeds the sweep bound while sweeping. + remainingSweep := sweepBound - swept + if uint32(len(nextDelegators)) > remainingSweep { + nextDelegators = nextDelegators[:remainingSweep] + shouldStopPrematurely = true + } + + // Iterate on the validator's delegator rewards in the range [nextValDelIndex, len(delegators)]. + for i := range nextDelegators { // Get end current period and calculate rewards. endingPeriod, err := k.distributionKeeper.IncrementValidatorPeriod(ctx, validatorSet[nextValIndex]) if err != nil { return nil, err } - delRewards, err := k.distributionKeeper.CalculateDelegationRewards(ctx, validatorSet[nextValIndex], delegators[i], endingPeriod) + + delRewards, err := k.distributionKeeper.CalculateDelegationRewards(ctx, validatorSet[nextValIndex], nextDelegators[i], endingPeriod) if err != nil { return nil, err } - if delegators[i].DelegatorAddress == valAccAddr.String() { + + if nextDelegators[i].DelegatorAddress == valAccAddr.String() { delRewards = delRewards.Add(valCommission.Commission...) } delRewardsTruncated, _ := delRewards.TruncateDecimal() bondDenomAmount := delRewardsTruncated.AmountOf(sdk.DefaultBondDenom).Uint64() - log.Debug( - ctx, "Calculate delegator rewards", - "val_addr", valAddr.String(), - "del_addr", delegators[i].DelegatorAddress, - "rewards_amount", bondDenomAmount, - "ending_period", endingPeriod, - ) - if bondDenomAmount >= minPartialWithdrawalAmount { - delEvmAddr, err := k.DelegatorMap.Get(ctx, delegators[i].DelegatorAddress) + delEvmAddr, err := k.DelegatorMap.Get(ctx, nextDelegators[i].DelegatorAddress) if err != nil { return nil, errors.Wrap(err, "map delegator pubkey to evm address") } + withdrawals = append(withdrawals, estypes.NewWithdrawal( uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()), - delegators[i].DelegatorAddress, + nextDelegators[i].DelegatorAddress, valAddr.String(), delEvmAddr, bondDenomAmount, )) - - log.Debug( - ctx, "Found an eligible partial withdrawal", - "val_addr", valAddr.String(), - "del_addr", delegators[i].DelegatorAddress, - "del_evm_addr", delEvmAddr, - "rewards_amount", bondDenomAmount, - ) } + + nextValDelIndex++ + } + + // If the validator's delegation loop was stopped prematurely, we break from the validator sweep loop. + if shouldStopPrematurely { + break } - nextValIndex = (nextValIndex + 1) % int64(len(validatorSet)) + + // Here, we have looped through all delegators of the validator (since we did not prematurely stop in the loop above). + // Thus, we signal to progress to the next validator by resetting the nextValDelIndex and circularly incrementing the nextValIndex + nextValIndex = (nextValIndex + 1) % uint64(len(validatorSet)) + nextValDelIndex = 0 + + // Increase the total swept amount. + swept += uint32(len(nextDelegators)) } - // Update the nextValidatorSweepIndex. - if err := k.SetNextValidatorSweepIndex( + + // Update the validator sweep index. + if err := k.SetValidatorSweepIndex( ctx, - sdk.IntProto{Int: math.NewInt(nextValIndex)}, + nextValIndex, + nextValDelIndex, ); err != nil { return nil, err } + log.Debug( ctx, "Finish validator sweep for partial withdrawals", "next_validator_index", nextValIndex, + "next_validator_delegation_index", nextValDelIndex, "partial_withdrawals", len(withdrawals), ) diff --git a/client/x/evmstaking/keeper/withdraw_test.go b/client/x/evmstaking/keeper/withdraw_test.go index 0762a9eb..3e669f8e 100644 --- a/client/x/evmstaking/keeper/withdraw_test.go +++ b/client/x/evmstaking/keeper/withdraw_test.go @@ -67,9 +67,9 @@ func (s *TestSuite) TestExpectedPartialWithdrawals() { }, }, { - name: "pass: next val sweep index is out of bounds, so it should be reset to 0 which is the index of the first validator", + name: "pass: val sweep index is out of bounds, so it should be reset to 0 which is the index of the first validator", preRun: func(_ sdk.Context) { - require.NoError(keeper.SetNextValidatorSweepIndex(ctx, sdk.IntProto{Int: sdkmath.NewInt(100)})) + require.NoError(keeper.SetValidatorSweepIndex(ctx, uint64(100), uint64(0))) distrKeeper.EXPECT().GetValidatorAccumulatedCommission(gomock.Any(), gomock.Any()).Return(dtypes.ValidatorAccumulatedCommission{}, nil) distrKeeper.EXPECT().IncrementValidatorPeriod(gomock.Any(), gomock.Any()).Return(uint64(0), nil) distrKeeper.EXPECT().CalculateDelegationRewards(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(delRewards, nil) diff --git a/client/x/evmstaking/module/module.go b/client/x/evmstaking/module/module.go index 699f9fa3..2f38081e 100644 --- a/client/x/evmstaking/module/module.go +++ b/client/x/evmstaking/module/module.go @@ -30,9 +30,6 @@ var ( _ appmodule.AppModule = AppModule{} ) -// ConsensusVersion defines the current module consensus version. -const ConsensusVersion = 1 - // ---------------------------------------------------------------------------- // AppModuleBasic // ---------------------------------------------------------------------------- @@ -106,7 +103,7 @@ func (AppModule) IsOnePerModuleType() {} func (AppModule) IsAppModule() {} // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } +func (AppModule) ConsensusVersion() uint64 { return 1 } // DefaultGenesis returns default genesis state as raw bytes for the module. func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { @@ -114,11 +111,6 @@ func (AppModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { } // RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries. -// -// func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { -// types.RegisterQueryServer(registrar, am.keeper) -// return nil -// } func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterQueryServer(cfg.QueryServer(), am.keeper) types.RegisterMsgServiceServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) diff --git a/client/x/evmstaking/types/genesis.go b/client/x/evmstaking/types/genesis.go index 6f230796..96965cc6 100644 --- a/client/x/evmstaking/types/genesis.go +++ b/client/x/evmstaking/types/genesis.go @@ -3,6 +3,10 @@ package types func NewGenesisState(params Params) *GenesisState { return &GenesisState{ Params: params, + ValidatorSweepIndex: &ValidatorSweepIndex{ + NextValIndex: 0, + NextValDelIndex: 0, + }, } } @@ -10,5 +14,9 @@ func NewGenesisState(params Params) *GenesisState { func DefaultGenesisState() *GenesisState { return &GenesisState{ Params: DefaultParams(), + ValidatorSweepIndex: &ValidatorSweepIndex{ + NextValIndex: 0, + NextValDelIndex: 0, + }, } } diff --git a/client/x/evmstaking/types/genesis.pb.go b/client/x/evmstaking/types/genesis.pb.go index 6105a7a6..2700450e 100644 --- a/client/x/evmstaking/types/genesis.pb.go +++ b/client/x/evmstaking/types/genesis.pb.go @@ -25,6 +25,8 @@ 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"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -67,8 +69,68 @@ func (m *GenesisState) GetParams() Params { return Params{} } +func (m *GenesisState) GetValidatorSweepIndex() *ValidatorSweepIndex { + if m != nil { + return m.ValidatorSweepIndex + } + return nil +} + +type ValidatorSweepIndex struct { + NextValIndex uint64 `protobuf:"varint,1,opt,name=next_val_index,json=nextValIndex,proto3" json:"next_val_index,omitempty" yaml:"next_val_index"` + NextValDelIndex uint64 `protobuf:"varint,2,opt,name=next_val_del_index,json=nextValDelIndex,proto3" json:"next_val_del_index,omitempty" yaml:"next_val_del_index"` +} + +func (m *ValidatorSweepIndex) Reset() { *m = ValidatorSweepIndex{} } +func (m *ValidatorSweepIndex) String() string { return proto.CompactTextString(m) } +func (*ValidatorSweepIndex) ProtoMessage() {} +func (*ValidatorSweepIndex) Descriptor() ([]byte, []int) { + return fileDescriptor_bf57cf100cbaf4bd, []int{1} +} +func (m *ValidatorSweepIndex) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorSweepIndex) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorSweepIndex.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorSweepIndex) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorSweepIndex.Merge(m, src) +} +func (m *ValidatorSweepIndex) XXX_Size() int { + return m.Size() +} +func (m *ValidatorSweepIndex) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorSweepIndex.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorSweepIndex proto.InternalMessageInfo + +func (m *ValidatorSweepIndex) GetNextValIndex() uint64 { + if m != nil { + return m.NextValIndex + } + return 0 +} + +func (m *ValidatorSweepIndex) GetNextValDelIndex() uint64 { + if m != nil { + return m.NextValDelIndex + } + return 0 +} + func init() { proto.RegisterType((*GenesisState)(nil), "client.x.evmstaking.types.GenesisState") + proto.RegisterType((*ValidatorSweepIndex)(nil), "client.x.evmstaking.types.ValidatorSweepIndex") } func init() { @@ -76,19 +138,27 @@ func init() { } var fileDescriptor_bf57cf100cbaf4bd = []byte{ - // 181 bytes of a gzipped FileDescriptorProto + // 309 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, 0xc9, 0x9f, 0x8b, 0xc7, 0x1d, 0x62, 0x53, 0x70, - 0x49, 0x62, 0x49, 0xaa, 0x90, 0x3d, 0x17, 0x1b, 0x44, 0x5e, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, - 0x48, 0x51, 0x0f, 0xa7, 0xcd, 0x7a, 0x01, 0x60, 0x85, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, - 0x41, 0xb5, 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, - 0x4e, 0x27, 0x25, 0xb1, 0x81, 0x1d, 0x63, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x1d, 0x1e, 0x57, - 0x0f, 0x10, 0x01, 0x00, 0x00, + 0x5c, 0x90, 0x58, 0x94, 0x98, 0x0b, 0x35, 0x58, 0x69, 0x33, 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, + 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, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -111,6 +181,18 @@ 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)) + } + i-- + dAtA[i] = 0x12 + } { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -124,6 +206,39 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ValidatorSweepIndex) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorSweepIndex) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorSweepIndex) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.NextValDelIndex != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.NextValDelIndex)) + i-- + dAtA[i] = 0x10 + } + if m.NextValIndex != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.NextValIndex)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { offset -= sovGenesis(v) base := offset @@ -143,6 +258,25 @@ 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)) + } + return n +} + +func (m *ValidatorSweepIndex) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.NextValIndex != 0 { + n += 1 + sovGenesis(uint64(m.NextValIndex)) + } + if m.NextValDelIndex != 0 { + n += 1 + sovGenesis(uint64(m.NextValDelIndex)) + } return n } @@ -214,6 +348,130 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorSweepIndex", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + 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 + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorSweepIndex) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorSweepIndex: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorSweepIndex: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NextValIndex", wireType) + } + m.NextValIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NextValIndex |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NextValDelIndex", wireType) + } + m.NextValDelIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.NextValDelIndex |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/client/x/evmstaking/types/genesis.proto b/client/x/evmstaking/types/genesis.proto index 6a7433de..1b094232 100644 --- a/client/x/evmstaking/types/genesis.proto +++ b/client/x/evmstaking/types/genesis.proto @@ -9,4 +9,18 @@ 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; +} + +message ValidatorSweepIndex { + uint64 next_val_index = 1 [ + // TODO: use custom Int type, need to resolve issue in auto-generated pb.go + // (cosmos_proto.scalar) = "cosmos.Int", + // (gogoproto.customtype) = "cosmossdk.io/math.Int", + // (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"next_val_index\"" + ]; + uint64 next_val_del_index = 2 [ + (gogoproto.moretags) = "yaml:\"next_val_del_index\"" + ]; } \ No newline at end of file diff --git a/client/x/evmstaking/types/keys.go b/client/x/evmstaking/types/keys.go index f453a6d2..8ae47e53 100644 --- a/client/x/evmstaking/types/keys.go +++ b/client/x/evmstaking/types/keys.go @@ -15,8 +15,8 @@ const ( // KVStore keys. var ( - ParamsKey = collections.NewPrefix(0) - WithdrawalQueueKey = collections.NewPrefix(1) - DelegatorMapKey = collections.NewPrefix(2) - NextValidatorSweepIndexKey = collections.NewPrefix(3) + ParamsKey = collections.NewPrefix(0) + WithdrawalQueueKey = collections.NewPrefix(1) + DelegatorMapKey = collections.NewPrefix(2) + ValidatorSweepIndexKey = collections.NewPrefix(3) ) diff --git a/lib/buildinfo/buildinfo.go b/lib/buildinfo/buildinfo.go index bf5984ef..88d348c1 100644 --- a/lib/buildinfo/buildinfo.go +++ b/lib/buildinfo/buildinfo.go @@ -14,8 +14,8 @@ import ( const ( VersionMajor = 0 // Major version component of the current release - VersionMinor = 9 // Minor version component of the current release - VersionPatch = 12 // Patch version component of the current release + VersionMinor = 10 // Minor version component of the current release + VersionPatch = 0 // Patch version component of the current release VersionMeta = "unstable" // Version metadata to append to the version string )