Skip to content

Commit

Permalink
feat(evmstaking): add singularity to evmstaking module
Browse files Browse the repository at this point in the history
  • Loading branch information
0xHansLee committed Oct 16, 2024
1 parent 11f4746 commit 8f05c4b
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 22 deletions.
10 changes: 10 additions & 0 deletions client/x/evmstaking/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions client/x/evmstaking/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
13 changes: 12 additions & 1 deletion client/x/evmstaking/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -28,6 +30,7 @@ func DefaultParams() Params {
DefaultMaxWithdrawalPerBlock,
DefaultMaxSweepPerBlock,
DefaultMinPartialWithdrawalAmount,
DefaultSingularityHeight,
)
}

Expand Down Expand Up @@ -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
}
77 changes: 58 additions & 19 deletions client/x/evmstaking/types/params.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions client/x/evmstaking/types/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
];
}
5 changes: 3 additions & 2 deletions client/x/evmstaking/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand Down

0 comments on commit 8f05c4b

Please sign in to comment.