diff --git a/proto/zetachain/zetacore/emissions/params.proto b/proto/zetachain/zetacore/emissions/params.proto index b442130e31..04e8714132 100644 --- a/proto/zetachain/zetacore/emissions/params.proto +++ b/proto/zetachain/zetacore/emissions/params.proto @@ -26,7 +26,7 @@ message Params { reserved 8; } -// Deprecated: Do not use. Use Params. +// Deprecated: Do not use. Use Params Instead message LegacyParams { option (gogoproto.goproto_stringer) = false; string max_bond_factor = 1; diff --git a/typescript/zetachain/zetacore/emissions/params_pb.d.ts b/typescript/zetachain/zetacore/emissions/params_pb.d.ts index cfc9a50bfd..38341d8ab6 100644 --- a/typescript/zetachain/zetacore/emissions/params_pb.d.ts +++ b/typescript/zetachain/zetacore/emissions/params_pb.d.ts @@ -58,7 +58,7 @@ export declare class Params extends Message { } /** - * Deprecated: Do not use. Use Params. + * Deprecated: Do not use. Use Params Instead * * @generated from message zetachain.zetacore.emissions.LegacyParams */ diff --git a/x/emissions/migrations/v4/migrate.go b/x/emissions/migrations/v4/migrate.go index b03a9395b4..b03b6f173b 100644 --- a/x/emissions/migrations/v4/migrate.go +++ b/x/emissions/migrations/v4/migrate.go @@ -16,31 +16,32 @@ type EmissionsKeeper interface { } // MigrateStore migrates the store from v3 to v4 -// The v3 params are copied to the v4 params , and the v4 params are set in the store +// The v3 params are copied to the v4 params, and the v4 params are set in the store +// v4 params removes unused parameters from v3; these values are discarded. // v4 introduces a new parameter, BlockRewardAmount, which is set to the default value func MigrateStore( ctx sdk.Context, emissionsKeeper EmissionsKeeper, ) error { - currentParams, found := GetParamsLegacy(ctx, emissionsKeeper.GetStoreKey(), emissionsKeeper.GetCodec()) + v3Params, found := GetParamsLegacy(ctx, emissionsKeeper.GetStoreKey(), emissionsKeeper.GetCodec()) if !found { return errorsmod.Wrap(types.ErrMigrationFailed, "failed to get legacy params") } - defaultParams := types.NewParams() - if currentParams.ValidatorEmissionPercentage != "" { - defaultParams.ValidatorEmissionPercentage = currentParams.ValidatorEmissionPercentage + v4Params := types.NewParams() + if v3Params.ValidatorEmissionPercentage != "" { + v4Params.ValidatorEmissionPercentage = v3Params.ValidatorEmissionPercentage } - if currentParams.ObserverEmissionPercentage != "" { - defaultParams.ObserverEmissionPercentage = currentParams.ObserverEmissionPercentage + if v3Params.ObserverEmissionPercentage != "" { + v4Params.ObserverEmissionPercentage = v3Params.ObserverEmissionPercentage } - if currentParams.TssSignerEmissionPercentage != "" { - defaultParams.TssSignerEmissionPercentage = currentParams.TssSignerEmissionPercentage + if v3Params.TssSignerEmissionPercentage != "" { + v4Params.TssSignerEmissionPercentage = v3Params.TssSignerEmissionPercentage } - defaultParams.ObserverSlashAmount = currentParams.ObserverSlashAmount - defaultParams.BallotMaturityBlocks = currentParams.BallotMaturityBlocks + v4Params.ObserverSlashAmount = v3Params.ObserverSlashAmount + v4Params.BallotMaturityBlocks = v3Params.BallotMaturityBlocks - err := emissionsKeeper.SetParams(ctx, defaultParams) + err := emissionsKeeper.SetParams(ctx, v4Params) if err != nil { return errorsmod.Wrap(types.ErrMigrationFailed, err.Error()) } diff --git a/x/emissions/migrations/v4/migrate_test.go b/x/emissions/migrations/v4/migrate_test.go index 0020af9626..c5ae05c668 100644 --- a/x/emissions/migrations/v4/migrate_test.go +++ b/x/emissions/migrations/v4/migrate_test.go @@ -62,32 +62,95 @@ func TestMigrateStore(t *testing.T) { require.Equal(t, types.BlockReward, params.BlockRewardAmount) }) - t.Run("should successfully migrate using default values if legacy param is not available", func(t *testing.T) { - //Arrange - k, ctx, _, _ := keepertest.EmissionsKeeper(t) - cdc := k.GetCodec() - emissionsStoreKey := k.GetStoreKey() + t.Run( + "should successfully migrate using default values if legacy param for ValidatorEmissionPercentage is not available", + func(t *testing.T) { + //Arrange + k, ctx, _, _ := keepertest.EmissionsKeeper(t) + cdc := k.GetCodec() + emissionsStoreKey := k.GetStoreKey() - mainnetParams := LegacyMainnetParams() - mainnetParams.ValidatorEmissionPercentage = "" - err := SetLegacyParams(ctx, emissionsStoreKey, cdc, mainnetParams) - require.NoError(t, err) + mainnetParams := LegacyMainnetParams() + mainnetParams.ValidatorEmissionPercentage = "" + err := SetLegacyParams(ctx, emissionsStoreKey, cdc, mainnetParams) + require.NoError(t, err) - //Act - err = v4.MigrateStore(ctx, k) - require.NoError(t, err) + //Act + err = v4.MigrateStore(ctx, k) + require.NoError(t, err) - //Assert - defaultParams := types.DefaultParams() - params, found := k.GetParams(ctx) - require.True(t, found) - require.Equal(t, defaultParams.ValidatorEmissionPercentage, params.ValidatorEmissionPercentage) - require.Equal(t, mainnetParams.ObserverEmissionPercentage, params.ObserverEmissionPercentage) - require.Equal(t, mainnetParams.TssSignerEmissionPercentage, params.TssSignerEmissionPercentage) - require.Equal(t, mainnetParams.ObserverSlashAmount, params.ObserverSlashAmount) - require.Equal(t, mainnetParams.BallotMaturityBlocks, params.BallotMaturityBlocks) - require.Equal(t, types.BlockReward, params.BlockRewardAmount) - }) + //Assert + defaultParams := types.DefaultParams() + params, found := k.GetParams(ctx) + require.True(t, found) + require.Equal(t, defaultParams.ValidatorEmissionPercentage, params.ValidatorEmissionPercentage) + require.Equal(t, mainnetParams.ObserverEmissionPercentage, params.ObserverEmissionPercentage) + require.Equal(t, mainnetParams.TssSignerEmissionPercentage, params.TssSignerEmissionPercentage) + require.Equal(t, mainnetParams.ObserverSlashAmount, params.ObserverSlashAmount) + require.Equal(t, mainnetParams.BallotMaturityBlocks, params.BallotMaturityBlocks) + require.Equal(t, types.BlockReward, params.BlockRewardAmount) + }, + ) + + t.Run( + "should successfully migrate using default values if legacy param for ObserverEmissionPercentage is not available", + func(t *testing.T) { + //Arrange + k, ctx, _, _ := keepertest.EmissionsKeeper(t) + cdc := k.GetCodec() + emissionsStoreKey := k.GetStoreKey() + + mainnetParams := LegacyMainnetParams() + mainnetParams.ObserverEmissionPercentage = "" + err := SetLegacyParams(ctx, emissionsStoreKey, cdc, mainnetParams) + require.NoError(t, err) + + //Act + err = v4.MigrateStore(ctx, k) + require.NoError(t, err) + + //Assert + defaultParams := types.DefaultParams() + params, found := k.GetParams(ctx) + require.True(t, found) + require.Equal(t, mainnetParams.ValidatorEmissionPercentage, params.ValidatorEmissionPercentage) + require.Equal(t, defaultParams.ObserverEmissionPercentage, params.ObserverEmissionPercentage) + require.Equal(t, mainnetParams.TssSignerEmissionPercentage, params.TssSignerEmissionPercentage) + require.Equal(t, mainnetParams.ObserverSlashAmount, params.ObserverSlashAmount) + require.Equal(t, mainnetParams.BallotMaturityBlocks, params.BallotMaturityBlocks) + require.Equal(t, types.BlockReward, params.BlockRewardAmount) + }, + ) + + t.Run( + "should successfully migrate using default values if legacy param for TssSignerEmissionPercentage is not available", + func(t *testing.T) { + //Arrange + k, ctx, _, _ := keepertest.EmissionsKeeper(t) + cdc := k.GetCodec() + emissionsStoreKey := k.GetStoreKey() + + mainnetParams := LegacyMainnetParams() + mainnetParams.TssSignerEmissionPercentage = "" + err := SetLegacyParams(ctx, emissionsStoreKey, cdc, mainnetParams) + require.NoError(t, err) + + //Act + err = v4.MigrateStore(ctx, k) + require.NoError(t, err) + + //Assert + defaultParams := types.DefaultParams() + params, found := k.GetParams(ctx) + require.True(t, found) + require.Equal(t, mainnetParams.ValidatorEmissionPercentage, params.ValidatorEmissionPercentage) + require.Equal(t, mainnetParams.ObserverEmissionPercentage, params.ObserverEmissionPercentage) + require.Equal(t, defaultParams.TssSignerEmissionPercentage, params.TssSignerEmissionPercentage) + require.Equal(t, mainnetParams.ObserverSlashAmount, params.ObserverSlashAmount) + require.Equal(t, mainnetParams.BallotMaturityBlocks, params.BallotMaturityBlocks) + require.Equal(t, types.BlockReward, params.BlockRewardAmount) + }, + ) t.Run("fail to migrate if legacy params are not found", func(t *testing.T) { //Arrange diff --git a/x/emissions/types/keys.go b/x/emissions/types/keys.go index bcf602b6c8..4b8bdd0305 100644 --- a/x/emissions/types/keys.go +++ b/x/emissions/types/keys.go @@ -25,12 +25,8 @@ const ( MemStoreKey = "mem_emissions" WithdrawableEmissionsKey = "WithdrawableEmissions-value-" - SecsInMonth = 30 * 24 * 60 * 60 BlockRewardsInZeta = "210000000" - EmissionScheduledYears = 4 - AvgBlockTime = "5.7" - ParamsKey = "Params-value-" ) @@ -40,14 +36,9 @@ func KeyPrefix(p string) []byte { const ( EmissionsTrackerKey = "EmissionsTracker-value-" - ParamMaxBondFactor = "MaxBondFactor" - ParamMinBondFactor = "MinBondFactor" - ParamAvgBlockTime = "AvgBlockTime" - ParamTargetBondRatio = "TargetBondRation" ParamValidatorEmissionPercentage = "ValidatorEmissionPercentage" ParamObserverEmissionPercentage = "ObserverEmissionPercentage" ParamTssSignerEmissionPercentage = "SignerEmissionPercentage" - ParamDurationFactorConstant = "DurationFactorConstant" ParamObserverSlashAmount = "ObserverSlashAmount" ) diff --git a/x/emissions/types/params.pb.go b/x/emissions/types/params.pb.go index 97fcf693d3..9d135a1066 100644 --- a/x/emissions/types/params.pb.go +++ b/x/emissions/types/params.pb.go @@ -94,7 +94,7 @@ func (m *Params) GetBallotMaturityBlocks() int64 { return 0 } -// Deprecated: Do not use. Use Params. +// Deprecated: Do not use. Use Params Instead type LegacyParams struct { MaxBondFactor string `protobuf:"bytes,1,opt,name=max_bond_factor,json=maxBondFactor,proto3" json:"max_bond_factor,omitempty"` MinBondFactor string `protobuf:"bytes,2,opt,name=min_bond_factor,json=minBondFactor,proto3" json:"min_bond_factor,omitempty"` diff --git a/x/emissions/types/params_test.go b/x/emissions/types/params_test.go index 99e6dd0ff5..6a8e90a98b 100644 --- a/x/emissions/types/params_test.go +++ b/x/emissions/types/params_test.go @@ -20,6 +20,8 @@ func TestNewParams(t *testing.T) { params.ObserverSlashAmount, "ObserverSlashAmount should be set to 100000000000000000", ) + require.Equal(t, int64(100), params.BallotMaturityBlocks, "BallotMaturityBlocks should be set to 100") + require.Equal(t, BlockReward, params.BlockRewardAmount, "BlockRewardAmount should be set to 0") } func TestDefaultParams(t *testing.T) { @@ -63,6 +65,15 @@ func TestValidateBallotMaturityBlocks(t *testing.T) { require.NoError(t, validateBallotMaturityBlocks(int64(100))) } +func TestValidateBlockRewardAmount(t *testing.T) { + require.Error(t, validateBlockRewardsAmount("0.50")) + require.Error(t, validateBlockRewardsAmount("-0.50")) + require.Error(t, validateBlockRewardsAmount(sdkmath.LegacyMustNewDecFromStr("-0.50"))) + require.NoError(t, validateBlockRewardsAmount(sdkmath.LegacyMustNewDecFromStr("0.50"))) + require.NoError(t, validateBlockRewardsAmount(sdkmath.LegacyZeroDec())) + require.NoError(t, validateBlockRewardsAmount(BlockReward)) +} + func TestValidate(t *testing.T) { t.Run("should validate", func(t *testing.T) { params := NewParams()