From 6d9f644eed3fa887ecb3ad88f515d45f67e57649 Mon Sep 17 00:00:00 2001 From: stana-ethernal Date: Tue, 26 Nov 2024 12:25:27 +0100 Subject: [PATCH] slash with right params --- testutil/keeper/expectations.go | 14 -------------- x/ccv/provider/keeper/consumer_equivocation.go | 18 +++++++++--------- .../keeper/consumer_equivocation_test.go | 4 ++-- x/ccv/provider/keeper/relay.go | 4 +++- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/testutil/keeper/expectations.go b/testutil/keeper/expectations.go index 984fca6859..d5bf6ac9ea 100644 --- a/testutil/keeper/expectations.go +++ b/testutil/keeper/expectations.go @@ -103,20 +103,6 @@ func GetMocksForHandleSlashPacket(ctx sdk.Context, mocks MockedKeepers, mocks.MockSlashingKeeper.EXPECT().IsTombstoned(ctx, expectedProviderValConsAddr.ToSdkConsAddr()).Return(false).Times(1), - // called in slash fn - mocks.MockStakingKeeper.EXPECT().GetValidatorByConsAddr( - ctx, expectedProviderValConsAddr.ToSdkConsAddr()).Return( - valToReturn, nil, - ).Times(1), - mocks.MockSlashingKeeper.EXPECT().IsTombstoned(ctx, - expectedProviderValConsAddr.ToSdkConsAddr()).Return(false).Times(1), - mocks.MockStakingKeeper.EXPECT().GetUnbondingDelegationsFromValidator(ctx, - valAddr).Return([]stakingtypes.UnbondingDelegation{}, nil).Times(1), - mocks.MockStakingKeeper.EXPECT().GetRedelegationsFromSrcValidator(ctx, - valAddr).Return([]stakingtypes.Redelegation{}, nil).Times(1), - mocks.MockStakingKeeper.EXPECT().GetLastValidatorPower(ctx, - valAddr).Return(int64(100), nil).Times(1), - mocks.MockStakingKeeper.EXPECT().PowerReduction(ctx).Return(sdk.DefaultPowerReduction).Times(1), mocks.MockStakingKeeper.EXPECT().SlashWithInfractionReason(ctx, expectedProviderValConsAddr.ToSdkConsAddr(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(math.NewInt(0), nil).Times(1), } diff --git a/x/ccv/provider/keeper/consumer_equivocation.go b/x/ccv/provider/keeper/consumer_equivocation.go index 27f23b0ceb..439dc80bce 100644 --- a/x/ccv/provider/keeper/consumer_equivocation.go +++ b/x/ccv/provider/keeper/consumer_equivocation.go @@ -80,7 +80,7 @@ func (k Keeper) HandleConsumerDoubleVoting( return err } - if err = k.SlashValidator(ctx, providerAddr, infractionParams.DoubleSign, stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN, evidence.VoteA.Height); err != nil { + if err = k.SlashValidator(ctx, providerAddr, infractionParams.DoubleSign); err != nil { return err } if err = k.JailAndTombstoneValidator(ctx, providerAddr, infractionParams.DoubleSign); err != nil { @@ -203,7 +203,7 @@ func (k Keeper) HandleConsumerMisbehaviour(ctx sdk.Context, consumerId string, m consumerId, types.NewConsumerConsAddress(sdk.ConsAddress(v.Address.Bytes())), ) - err := k.SlashValidator(ctx, providerAddr, infractionParams.DoubleSign, stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN, 0) + err := k.SlashValidator(ctx, providerAddr, infractionParams.DoubleSign) if err != nil { logger.Error("failed to slash validator: %s", err) continue @@ -492,12 +492,7 @@ func (k Keeper) ComputePowerToSlash(ctx sdk.Context, validator stakingtypes.Vali } // SlashValidator slashes validator with given provider Address -func (k Keeper) SlashValidator( - ctx sdk.Context, - providerAddr types.ProviderConsAddress, - slashingParams *types.SlashJailParameters, - slashingReason stakingtypes.Infraction, - infractionHeight int64) error { +func (k Keeper) SlashValidator(ctx sdk.Context, providerAddr types.ProviderConsAddress, slashingParams *types.SlashJailParameters) error { validator, err := k.stakingKeeper.GetValidatorByConsAddr(ctx, providerAddr.ToSdkConsAddr()) if err != nil && errors.Is(err, stakingtypes.ErrNoValidatorFound) { return errorsmod.Wrapf(slashingtypes.ErrNoValidatorForAddress, "provider consensus address: %s", providerAddr.String()) @@ -534,7 +529,12 @@ func (k Keeper) SlashValidator( powerReduction := k.stakingKeeper.PowerReduction(ctx) totalPower := k.ComputePowerToSlash(ctx, validator, undelegations, redelegations, lastPower, powerReduction) - _, err = k.stakingKeeper.SlashWithInfractionReason(ctx, providerAddr.ToSdkConsAddr(), infractionHeight, totalPower, slashingParams.SlashFraction, slashingReason) + consAdrr, err := validator.GetConsAddr() + if err != nil { + return err + } + + _, err = k.stakingKeeper.SlashWithInfractionReason(ctx, consAdrr, 0, totalPower, slashingParams.SlashFraction, stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN) return err } diff --git a/x/ccv/provider/keeper/consumer_equivocation_test.go b/x/ccv/provider/keeper/consumer_equivocation_test.go index f9c2b35a0f..1e740a4aae 100644 --- a/x/ccv/provider/keeper/consumer_equivocation_test.go +++ b/x/ccv/provider/keeper/consumer_equivocation_test.go @@ -739,7 +739,7 @@ func TestSlashValidator(t *testing.T) { } gomock.InOrder(expectedCalls...) - keeper.SlashValidator(ctx, providerAddr, getTestInfractionParameters().DoubleSign, stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN, 0) + keeper.SlashValidator(ctx, providerAddr, getTestInfractionParameters().DoubleSign) } // TestSlashValidatorDoesNotSlashIfValidatorIsUnbonded asserts that `SlashValidator` does not call @@ -766,7 +766,7 @@ func TestSlashValidatorDoesNotSlashIfValidatorIsUnbonded(t *testing.T) { } gomock.InOrder(expectedCalls...) - keeper.SlashValidator(ctx, providerAddr, getTestInfractionParameters().DoubleSign, stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN, 0) + keeper.SlashValidator(ctx, providerAddr, getTestInfractionParameters().DoubleSign) } func TestEquivocationEvidenceMinHeightCRUD(t *testing.T) { diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index 5c76ec30cf..790bf8b10b 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -485,7 +485,9 @@ func (k Keeper) HandleSlashPacket(ctx sdk.Context, consumerId string, data ccv.S } // slash validator - if err = k.SlashValidator(ctx, providerConsAddr, infractionParams.Downtime, stakingtypes.Infraction_INFRACTION_DOWNTIME, int64(infractionHeight)); err != nil { + _, err = k.stakingKeeper.SlashWithInfractionReason(ctx, providerConsAddr.ToSdkConsAddr(), int64(infractionHeight), + data.Validator.Power, infractionParams.Downtime.SlashFraction, stakingtypes.Infraction_INFRACTION_DOWNTIME) + if err != nil { k.Logger(ctx).Error("failed to slash vaidator", providerConsAddr.ToSdkConsAddr().String(), "err", err.Error()) return }