Skip to content

Commit

Permalink
feat(params): combine singularity height into one (#291)
Browse files Browse the repository at this point in the history
Combined all three singularity height param into one of staking keeper
param.

issue: none
  • Loading branch information
0xHansLee authored Oct 23, 2024
1 parent c7573a2 commit 4f8db70
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 188 deletions.
4 changes: 0 additions & 4 deletions client/x/evmengine/testutil/expected_keepers_mocks.go

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

7 changes: 3 additions & 4 deletions client/x/evmstaking/keeper/singularity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import (
)

func (k *Keeper) IsSingularity(ctx context.Context) (bool, error) {
params, err := k.GetParams(ctx)
singularityHeight, err := k.stakingKeeper.GetSingularityHeight(ctx)
if err != nil {
return false, err
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
blockHeight := sdkCtx.BlockHeader().Height
blockHeight := sdk.UnwrapSDKContext(ctx).BlockHeight()

if blockHeight < int64(params.SingularityHeight) {
if blockHeight < int64(singularityHeight) {
return true, nil
}

Expand Down
20 changes: 15 additions & 5 deletions client/x/evmstaking/testutil/expected_keepers_mocks.go

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

2 changes: 2 additions & 0 deletions client/x/evmstaking/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type StakingKeeper interface {
GetPeriodInfo(ctx context.Context, periodType int32) (stakingtypes.Period, error)
GetLockedTokenType(ctx context.Context) (int32, error)
GetTokenTypeInfo(ctx context.Context, tokenType int32) (stakingtypes.TokenTypeInfo, error)

GetSingularityHeight(ctx context.Context) (uint64, error)
}

// SlashingKeeper defines the expected interface for the slashing module.
Expand Down
2 changes: 0 additions & 2 deletions client/x/evmstaking/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ func TestNewGenesisState(t *testing.T) {
10,
20,
30,
30,
),
expectedGenesisState: &types.GenesisState{
Params: types.NewParams(
10,
20,
30,
30,
),
ValidatorSweepIndex: zeroVallidatorSweepIndex,
},
Expand Down
20 changes: 2 additions & 18 deletions client/x/evmstaking/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ const (
DefaultMaxSweepPerBlock uint32 = 1024

DefaultMinPartialWithdrawalAmount uint64 = 600_000

DefaultSingularityHeight uint64 = 1209600 // 42 days with 3 seconds block time
)

// NewParams creates a new Params instance.
func NewParams(maxWithdrawalPerBlock uint32, maxSweepPerBlock uint32, minPartialWithdrawalAmount, singularityHeight uint64) Params {
func NewParams(maxWithdrawalPerBlock uint32, maxSweepPerBlock uint32, minPartialWithdrawalAmount uint64) Params {
return Params{
MaxWithdrawalPerBlock: maxWithdrawalPerBlock,
MaxSweepPerBlock: maxSweepPerBlock,
MinPartialWithdrawalAmount: minPartialWithdrawalAmount,
SingularityHeight: singularityHeight,
}
}

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

Expand All @@ -44,11 +40,7 @@ func (p Params) Validate() error {
return err
}

if err := ValidateMinPartialWithdrawalAmount(p.MinPartialWithdrawalAmount); err != nil {
return err
}

return ValidateSingularityHeight(p.SingularityHeight)
return ValidateMinPartialWithdrawalAmount(p.MinPartialWithdrawalAmount)
}

func ValidateMaxWithdrawalPerBlock(v uint32) error {
Expand Down Expand Up @@ -78,11 +70,3 @@ 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
}
86 changes: 24 additions & 62 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.

6 changes: 1 addition & 5 deletions client/x/evmstaking/types/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ 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\""
];
string ubi_withdraw_address = 5 [
string ubi_withdraw_address = 4 [
(gogoproto.moretags) = "yaml:\"ubi_withdraw_address\""
];
}
5 changes: 2 additions & 3 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, singularityHeight := uint32(1), uint32(2), uint64(3), uint64(10)
params := types.NewParams(maxWithdrawalPerBlock, maxSweepPerBlock, minPartialWithdrawalAmount, singularityHeight)
maxWithdrawalPerBlock, maxSweepPerBlock, minPartialWithdrawalAmount := uint32(1), uint32(2), uint64(3)
params := types.NewParams(maxWithdrawalPerBlock, maxSweepPerBlock, minPartialWithdrawalAmount)
// check values are set correctly
require.Equal(maxWithdrawalPerBlock, params.MaxWithdrawalPerBlock)
require.Equal(maxSweepPerBlock, params.MaxSweepPerBlock)
Expand All @@ -35,7 +35,6 @@ 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
9 changes: 7 additions & 2 deletions client/x/mint/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ import (
func (k Keeper) BeginBlocker(ctx context.Context, ic types.InflationCalculationFn) error {
defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker)

params, err := k.Params.Get(ctx)
singularityHeight, err := k.stakingKeeper.GetSingularityHeight(ctx)
if err != nil {
return err
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
if sdkCtx.BlockHeight() < int64(params.SingularityHeight) {
if sdkCtx.BlockHeight() < int64(singularityHeight) {
log.Debug(ctx, "Skip minting during singularity")
return nil
}

params, err := k.GetParams(ctx)
if err != nil {
return err
}

// mint coins, update supply
mintedCoinAmt := ic(ctx, params, math.LegacyNewDec(0)) // NOTE: bondedRatio is not used in current implementation.
mintedCoin := sdk.NewCoin(params.MintDenom, mintedCoinAmt.TruncateInt())
Expand Down
1 change: 0 additions & 1 deletion client/x/mint/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func (s *GenesisTestSuite) TestImportExportGenesis() {
"testDenom",
math.LegacyNewDec(24625000000000000.000000000000000000),
uint64(60*60*8766/5),
10,
)

s.keeper.InitGenesis(s.sdkCtx, s.accountKeeper, genesisState)
Expand Down
Loading

0 comments on commit 4f8db70

Please sign in to comment.