From 7fb0ffcd46c3140e1099b2b8bd20f20e0aaef7f3 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 2 Feb 2024 14:46:44 -0500 Subject: [PATCH] add observe slashed amounts to genesis export --- x/emissions/keeper/params_test.go | 13 +++++++++++++ x/emissions/types/keys.go | 1 + x/emissions/types/params.go | 14 +++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/x/emissions/keeper/params_test.go b/x/emissions/keeper/params_test.go index a2d6063360..b278bbab9f 100644 --- a/x/emissions/keeper/params_test.go +++ b/x/emissions/keeper/params_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + sdkmath "cosmossdk.io/math" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" @@ -26,6 +27,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "00.25", TssSignerEmissionPercentage: "00.25", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "", }, @@ -54,6 +56,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "00.25", TssSignerEmissionPercentage: "00.25", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "min bond factor cannot be lower that 0.75", }, @@ -68,6 +71,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "00.25", TssSignerEmissionPercentage: "00.25", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "invalid block time", }, @@ -82,6 +86,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "00.25", TssSignerEmissionPercentage: "00.25", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "block time cannot be less than or equal to 0", }, @@ -96,6 +101,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "00.25", TssSignerEmissionPercentage: "00.25", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "target bond ratio cannot be more than 100 percent", }, @@ -110,6 +116,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "00.25", TssSignerEmissionPercentage: "00.25", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "target bond ratio cannot be less than 0 percent", }, @@ -124,6 +131,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "00.25", TssSignerEmissionPercentage: "00.25", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "validator emission percentage cannot be more than 100 percent", }, @@ -138,6 +146,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "00.25", TssSignerEmissionPercentage: "00.25", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "validator emission percentage cannot be less than 0 percent", }, @@ -152,6 +161,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "-00.25", TssSignerEmissionPercentage: "00.25", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "observer emission percentage cannot be less than 0 percent", }, @@ -166,6 +176,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "150.25", TssSignerEmissionPercentage: "00.25", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "observer emission percentage cannot be more than 100 percent", }, @@ -180,6 +191,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "00.25", TssSignerEmissionPercentage: "102.22", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "tss emission percentage cannot be more than 100 percent", }, @@ -194,6 +206,7 @@ func TestKeeper_GetParams(t *testing.T) { ObserverEmissionPercentage: "00.25", TssSignerEmissionPercentage: "-102.22", DurationFactorConstant: "0.001877876953694702", + ObserverSlashAmount: sdkmath.NewInt(100000000000000000), }, isPanic: "tss emission percentage cannot be less than 0 percent", }, diff --git a/x/emissions/types/keys.go b/x/emissions/types/keys.go index 4be2d268b4..9f1fa705fc 100644 --- a/x/emissions/types/keys.go +++ b/x/emissions/types/keys.go @@ -45,6 +45,7 @@ const ( ParamObserverEmissionPercentage = "ObserverEmissionPercentage" ParamTssSignerEmissionPercentage = "SignerEmissionPercentage" ParamDurationFactorConstant = "DurationFactorConstant" + ParamObserverSlashAmount = "ObserverSlashAmount" ) var ( diff --git a/x/emissions/types/params.go b/x/emissions/types/params.go index 5a5cbab58c..aa896f77e8 100644 --- a/x/emissions/types/params.go +++ b/x/emissions/types/params.go @@ -54,6 +54,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { paramtypes.NewParamSetPair(KeyPrefix(ParamObserverEmissionPercentage), &p.ObserverEmissionPercentage, validateObserverEmissionPercentage), paramtypes.NewParamSetPair(KeyPrefix(ParamTssSignerEmissionPercentage), &p.TssSignerEmissionPercentage, validateTssEmissonPercentage), paramtypes.NewParamSetPair(KeyPrefix(ParamDurationFactorConstant), &p.DurationFactorConstant, validateDurationFactorConstant), + paramtypes.NewParamSetPair(KeyPrefix(ParamObserverSlashAmount), &p.ObserverSlashAmount, validateObserverSlashAmount), } } @@ -71,6 +72,16 @@ func (p Params) String() string { return string(out) } +func validateObserverSlashAmount(i interface{}) error { + v, ok := i.(sdkmath.Int) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + if v.LT(sdk.ZeroInt()) { + return fmt.Errorf("slash amount cannot be less than 0") + } + return nil +} func validateDurationFactorConstant(i interface{}) error { _, ok := i.(string) if !ok { @@ -96,9 +107,6 @@ func validateMinBondFactor(i interface{}) error { if !ok { return fmt.Errorf("invalid parameter type: %T", i) } - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } decMaxBond := sdk.MustNewDecFromStr(v) if decMaxBond.LT(sdk.MustNewDecFromStr("0.75")) { return fmt.Errorf("min bond factor cannot be lower that 0.75")