From 6875c4f4b429f2a4ac06bc30f53101b912929f3a Mon Sep 17 00:00:00 2001 From: mpoke Date: Tue, 28 Nov 2023 15:05:01 +0100 Subject: [PATCH] add LSM changes to slashing module --- .../slashing/keeper/keeper_test.go | 62 ------------------- x/slashing/keeper/hooks.go | 4 ++ x/slashing/keeper/unjail.go | 9 --- x/slashing/simulation/operations_test.go | 6 +- 4 files changed, 8 insertions(+), 73 deletions(-) diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index 7678c981195f..a438f68a41c7 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -76,68 +76,6 @@ func (s *KeeperTestSuite) SetupTest() { s.msgServer = slashingkeeper.NewMsgServerImpl(s.slashingKeeper) } -func (s *KeeperTestSuite) TestUnJailNotBonded() { - ctx := s.ctx - - p := s.stakingKeeper.GetParams(ctx) - p.MaxValidators = 5 - s.stakingKeeper.SetParams(ctx, p) - - addrDels := simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 6, s.stakingKeeper.TokensFromConsensusPower(ctx, 200)) - valAddrs := simtestutil.ConvertAddrsToValAddrs(addrDels) - pks := simtestutil.CreateTestPubKeys(6) - tstaking := stakingtestutil.NewHelper(s.T(), ctx, s.stakingKeeper) - - // create max (5) validators all with the same power - for i := uint32(0); i < p.MaxValidators; i++ { - addr, val := valAddrs[i], pks[i] - tstaking.CreateValidatorWithValPower(addr, val, 100, true) - } - - staking.EndBlocker(ctx, s.stakingKeeper) - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) - - // create a 6th validator with less power than the cliff validator (won't be bonded) - addr, val := valAddrs[5], pks[5] - amt := s.stakingKeeper.TokensFromConsensusPower(ctx, 50) - msg := tstaking.CreateValidatorMsg(addr, val, amt) - msg.MinSelfDelegation = amt - res, err := tstaking.CreateValidatorWithMsg(sdk.WrapSDKContext(ctx), msg) - s.Require().NoError(err) - s.Require().NotNil(res) - - staking.EndBlocker(ctx, s.stakingKeeper) - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) - - tstaking.CheckValidator(addr, stakingtypes.Unbonded, false) - - // unbond below minimum self-delegation - s.Require().Equal(p.BondDenom, tstaking.Denom) - tstaking.Undelegate(sdk.AccAddress(addr), addr, s.stakingKeeper.TokensFromConsensusPower(ctx, 1), true) - - staking.EndBlocker(ctx, s.stakingKeeper) - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) - - // verify that validator is jailed - tstaking.CheckValidator(addr, -1, true) - - // verify we cannot unjail (yet) - s.Require().Error(s.slashingKeeper.Unjail(ctx, addr)) - - staking.EndBlocker(ctx, s.stakingKeeper) - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) - // bond to meet minimum self-delegation - tstaking.DelegateWithPower(sdk.AccAddress(addr), addr, 1) - - staking.EndBlocker(ctx, s.stakingKeeper) - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) - - // verify we can immediately unjail - s.Require().NoError(s.slashingKeeper.Unjail(ctx, addr)) - - tstaking.CheckValidator(addr, -1, false) -} - // Test a new validator entering the validator set // Ensure that SigningInfo.StartHeight is set correctly // and that they are not immediately jailed diff --git a/x/slashing/keeper/hooks.go b/x/slashing/keeper/hooks.go index bdb2f38c1439..a6942023e722 100644 --- a/x/slashing/keeper/hooks.go +++ b/x/slashing/keeper/hooks.go @@ -90,3 +90,7 @@ func (h Hooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ sdk.Dec func (h Hooks) AfterUnbondingInitiated(_ sdk.Context, _ uint64) error { return nil } + +func (h Hooks) BeforeTokenizeShareRecordRemoved(_ sdk.Context, _ uint64) error { + return nil +} diff --git a/x/slashing/keeper/unjail.go b/x/slashing/keeper/unjail.go index 23a9121e5472..f417bdc546f4 100644 --- a/x/slashing/keeper/unjail.go +++ b/x/slashing/keeper/unjail.go @@ -2,7 +2,6 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/slashing/types" ) @@ -20,14 +19,6 @@ func (k Keeper) Unjail(ctx sdk.Context, validatorAddr sdk.ValAddress) error { return types.ErrMissingSelfDelegation } - tokens := validator.TokensFromShares(selfDel.GetShares()).TruncateInt() - minSelfBond := validator.GetMinSelfDelegation() - if tokens.LT(minSelfBond) { - return sdkerrors.Wrapf( - types.ErrSelfDelegationTooLowToUnjail, "%s less than %s", tokens, minSelfBond, - ) - } - // cannot be unjailed if not jailed if !validator.IsJailed() { return types.ErrValidatorNotJailed diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 991ac17f0b3c..2582116f4826 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -150,7 +150,8 @@ func (suite *SimTestSuite) TestSimulateMsgUnjail() { suite.Require().NoError(err) // setup validator0 by consensus address - suite.stakingKeeper.SetValidatorByConsAddr(ctx, validator0) + err = suite.stakingKeeper.SetValidatorByConsAddr(ctx, validator0) + suite.Require().NoError(err) val0ConsAddress, err := validator0.GetConsAddr() suite.Require().NoError(err) info := types.NewValidatorSigningInfo(val0ConsAddress, int64(4), int64(3), @@ -178,7 +179,8 @@ func (suite *SimTestSuite) TestSimulateMsgUnjail() { suite.Require().NoError(err) var msg types.MsgUnjail - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(types.TypeMsgUnjail, msg.Type())