diff --git a/client/x/evmstaking/keeper/abci.go b/client/x/evmstaking/keeper/abci.go index 0617a284..6779eb08 100644 --- a/client/x/evmstaking/keeper/abci.go +++ b/client/x/evmstaking/keeper/abci.go @@ -20,9 +20,19 @@ func (k *Keeper) EndBlock(ctx context.Context) (abci.ValidatorUpdates, error) { log.Debug(ctx, "EndBlock.evmstaking") defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + params, err := k.GetParams(ctx) + if err != nil { + return nil, err + } + sdkCtx := sdk.UnwrapSDKContext(ctx) blockHeight := sdkCtx.BlockHeader().Height + if blockHeight < int64(params.SingularityHeight) { + log.Debug(ctx, "In singularity period") + return nil, nil + } + valUpdates, unbondedEntries, err := k.stakingKeeper.EndBlockerWithUnbondedEntries(ctx) if err != nil { return nil, err diff --git a/client/x/evmstaking/types/genesis_test.go b/client/x/evmstaking/types/genesis_test.go index 093f0d94..8bb16061 100644 --- a/client/x/evmstaking/types/genesis_test.go +++ b/client/x/evmstaking/types/genesis_test.go @@ -34,12 +34,14 @@ func TestNewGenesisState(t *testing.T) { 10, 20, 30, + 30, ), expectedGenesisState: &types.GenesisState{ Params: types.NewParams( 10, 20, 30, + 30, ), ValidatorSweepIndex: zeroVallidatorSweepIndex, }, diff --git a/client/x/evmstaking/types/params.go b/client/x/evmstaking/types/params.go index bdefd22c..33719f5e 100644 --- a/client/x/evmstaking/types/params.go +++ b/client/x/evmstaking/types/params.go @@ -11,14 +11,16 @@ const ( DefaultMaxSweepPerBlock uint32 = 64 DefaultMinPartialWithdrawalAmount uint64 = 600_000 + DefaultSingularityHeight uint64 = 725760 // 42 days with assuming 5 seconds block time ) // NewParams creates a new Params instance. -func NewParams(maxWithdrawalPerBlock uint32, maxSweepPerBlock uint32, minPartialWithdrawalAmount uint64) Params { +func NewParams(maxWithdrawalPerBlock uint32, maxSweepPerBlock uint32, minPartialWithdrawalAmount, singularityHeight uint64) Params { return Params{ MaxWithdrawalPerBlock: maxWithdrawalPerBlock, MaxSweepPerBlock: maxSweepPerBlock, MinPartialWithdrawalAmount: minPartialWithdrawalAmount, + SingularityHeight: singularityHeight, } } @@ -28,6 +30,7 @@ func DefaultParams() Params { DefaultMaxWithdrawalPerBlock, DefaultMaxSweepPerBlock, DefaultMinPartialWithdrawalAmount, + DefaultSingularityHeight, ) } @@ -58,3 +61,11 @@ func ValidateMinPartialWithdrawalAmount(v uint64) error { return nil } + +func ValidateSingularityHeight(v uint64) error { + if v == 0 { + return fmt.Errorf("singularity height must be positive: %d", v) + } + + return nil +} diff --git a/client/x/evmstaking/types/params.pb.go b/client/x/evmstaking/types/params.pb.go index 0a5473bb..ca798f66 100644 --- a/client/x/evmstaking/types/params.pb.go +++ b/client/x/evmstaking/types/params.pb.go @@ -28,6 +28,8 @@ type Params struct { MaxWithdrawalPerBlock uint32 `protobuf:"varint,1,opt,name=max_withdrawal_per_block,json=maxWithdrawalPerBlock,proto3" json:"max_withdrawal_per_block,omitempty" yaml:"max_withdrawal_per_block"` MaxSweepPerBlock uint32 `protobuf:"varint,2,opt,name=max_sweep_per_block,json=maxSweepPerBlock,proto3" json:"max_sweep_per_block,omitempty" yaml:"max_sweep_per_block"` MinPartialWithdrawalAmount uint64 `protobuf:"varint,3,opt,name=min_partial_withdrawal_amount,json=minPartialWithdrawalAmount,proto3" json:"min_partial_withdrawal_amount,omitempty" yaml:"min_partial_withdrawal_amount"` + // the block height until singularity is activated + SingularityHeight uint64 `protobuf:"varint,4,opt,name=singularity_height,json=singularityHeight,proto3" json:"singularity_height,omitempty" yaml:"singularity_height"` } func (m *Params) Reset() { *m = Params{} } @@ -84,6 +86,13 @@ func (m *Params) GetMinPartialWithdrawalAmount() uint64 { return 0 } +func (m *Params) GetSingularityHeight() uint64 { + if m != nil { + return m.SingularityHeight + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "client.x.evmstaking.types.Params") } @@ -93,25 +102,28 @@ func init() { } var fileDescriptor_dddf03d6f1b350f8 = []byte{ - // 288 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4b, 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, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, - 0x2f, 0xc9, 0x17, 0x92, 0x84, 0xa8, 0xd3, 0xab, 0xd0, 0x43, 0xa8, 0xd3, 0x03, 0xab, 0x93, 0x12, - 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd2, 0x07, 0xb1, 0x20, 0x1a, 0x94, 0x16, 0x31, 0x71, 0xb1, - 0x05, 0x80, 0x4d, 0x10, 0x8a, 0xe1, 0x92, 0xc8, 0x4d, 0xac, 0x88, 0x2f, 0xcf, 0x2c, 0xc9, 0x48, - 0x29, 0x4a, 0x2c, 0x4f, 0xcc, 0x89, 0x2f, 0x48, 0x2d, 0x8a, 0x4f, 0xca, 0xc9, 0x4f, 0xce, 0x96, - 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x75, 0x52, 0xfe, 0x74, 0x4f, 0x5e, 0xbe, 0x32, 0x31, 0x37, 0xc7, - 0x4a, 0x09, 0x97, 0x4a, 0xa5, 0x20, 0xd1, 0xdc, 0xc4, 0x8a, 0x70, 0xb8, 0x4c, 0x40, 0x6a, 0x91, - 0x13, 0x48, 0x5c, 0xc8, 0x97, 0x4b, 0x18, 0xa4, 0xa7, 0xb8, 0x3c, 0x35, 0xb5, 0x00, 0xc9, 0x60, - 0x26, 0xb0, 0xc1, 0x72, 0x9f, 0xee, 0xc9, 0x4b, 0x21, 0x0c, 0x46, 0x53, 0xa4, 0x14, 0x24, 0x90, - 0x9b, 0x58, 0x11, 0x0c, 0x12, 0x84, 0x1b, 0x97, 0xcd, 0x25, 0x9b, 0x9b, 0x99, 0x17, 0x5f, 0x90, - 0x58, 0x54, 0x92, 0x99, 0x98, 0x83, 0xec, 0x94, 0xc4, 0xdc, 0xfc, 0xd2, 0xbc, 0x12, 0x09, 0x66, - 0x05, 0x46, 0x0d, 0x16, 0x27, 0x8d, 0x4f, 0xf7, 0xe4, 0x55, 0xa0, 0x06, 0xe3, 0x53, 0xae, 0x14, - 0x24, 0x95, 0x9b, 0x99, 0x17, 0x00, 0x91, 0x46, 0xb8, 0xde, 0x11, 0x2c, 0xe9, 0x64, 0x7c, 0xe2, - 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, - 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x92, 0x38, 0xe3, 0x25, 0x89, 0x0d, 0x1c, - 0xc0, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe8, 0x45, 0xda, 0xba, 0xbb, 0x01, 0x00, 0x00, + // 328 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0xcd, 0x4a, 0xf3, 0x40, + 0x14, 0x86, 0x9b, 0x7e, 0xa5, 0x8b, 0xc0, 0x07, 0x1a, 0x15, 0xd2, 0x42, 0x27, 0x25, 0x8a, 0x74, + 0x95, 0x2c, 0xba, 0x73, 0x67, 0x56, 0x2e, 0x14, 0x4a, 0x5c, 0x08, 0x22, 0x84, 0xd3, 0x3a, 0xa4, + 0x43, 0xe7, 0x8f, 0xc9, 0xd4, 0xa6, 0x77, 0xe1, 0x65, 0xb9, 0xec, 0xd2, 0x55, 0x90, 0xf6, 0x06, + 0x24, 0x57, 0x20, 0x99, 0x48, 0x5b, 0x94, 0xba, 0x1b, 0x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0x39, 0x05, 0x45, 0xf4, 0x32, 0x99, 0x62, 0x92, 0x4e, 0xb5, 0xdb, 0x32, 0x13, 0x7a, 0x65, 0xe1, + 0x75, 0xea, 0x09, 0xbf, 0x19, 0x3f, 0x3e, 0xde, 0x0b, 0x6f, 0x4c, 0x16, 0x0d, 0xdf, 0xd6, 0xc8, + 0x5a, 0xad, 0x91, 0xf5, 0xb1, 0x46, 0xd6, 0xeb, 0x06, 0x35, 0x56, 0x1b, 0xd4, 0x78, 0xdf, 0xa0, + 0xc6, 0x63, 0xe7, 0xe0, 0x95, 0xc7, 0x6d, 0x73, 0xae, 0xe1, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x78, 0x93, 0xa8, 0x7a, 0x09, 0x02, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -134,6 +146,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.SingularityHeight != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.SingularityHeight)) + i-- + dAtA[i] = 0x20 + } if m.MinPartialWithdrawalAmount != 0 { i = encodeVarintParams(dAtA, i, uint64(m.MinPartialWithdrawalAmount)) i-- @@ -178,6 +195,9 @@ func (m *Params) Size() (n int) { if m.MinPartialWithdrawalAmount != 0 { n += 1 + sovParams(uint64(m.MinPartialWithdrawalAmount)) } + if m.SingularityHeight != 0 { + n += 1 + sovParams(uint64(m.SingularityHeight)) + } return n } @@ -273,6 +293,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SingularityHeight", wireType) + } + m.SingularityHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SingularityHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/client/x/evmstaking/types/params.proto b/client/x/evmstaking/types/params.proto index 38cf6443..e92f77d7 100644 --- a/client/x/evmstaking/types/params.proto +++ b/client/x/evmstaking/types/params.proto @@ -16,4 +16,8 @@ message Params { uint64 min_partial_withdrawal_amount = 3 [ (gogoproto.moretags) = "yaml:\"min_partial_withdrawal_amount\"" ]; + // the block height until singularity is activated + uint64 singularity_height = 4 [ + (gogoproto.moretags) = "yaml:\"singularity_height\"" + ]; } \ No newline at end of file diff --git a/client/x/evmstaking/types/params_test.go b/client/x/evmstaking/types/params_test.go index 5c7019eb..5318fa40 100644 --- a/client/x/evmstaking/types/params_test.go +++ b/client/x/evmstaking/types/params_test.go @@ -20,8 +20,8 @@ func (suite *ParamsTestSuite) SetupTest() { func (suite *ParamsTestSuite) TestNewParams() { require := suite.Require() - maxWithdrawalPerBlock, maxSweepPerBlock, minPartialWithdrawalAmount := uint32(1), uint32(2), uint64(3) - params := types.NewParams(maxWithdrawalPerBlock, maxSweepPerBlock, minPartialWithdrawalAmount) + maxWithdrawalPerBlock, maxSweepPerBlock, minPartialWithdrawalAmount, singularityHeight := uint32(1), uint32(2), uint64(3), uint64(10) + params := types.NewParams(maxWithdrawalPerBlock, maxSweepPerBlock, minPartialWithdrawalAmount, singularityHeight) // check values are set correctly require.Equal(maxWithdrawalPerBlock, params.MaxWithdrawalPerBlock) require.Equal(maxSweepPerBlock, params.MaxSweepPerBlock) @@ -35,6 +35,7 @@ func (suite *ParamsTestSuite) TestDefaultParams() { require.Equal(types.DefaultMaxWithdrawalPerBlock, params.MaxWithdrawalPerBlock) require.Equal(types.DefaultMaxSweepPerBlock, params.MaxSweepPerBlock) require.Equal(types.DefaultMinPartialWithdrawalAmount, params.MinPartialWithdrawalAmount) + require.Equal(types.DefaultSingularityHeight, params.SingularityHeight) } func (suite *ParamsTestSuite) TestValidateMaxWithdrawalPerBlock() {