Skip to content

Commit

Permalink
slash with right params
Browse files Browse the repository at this point in the history
  • Loading branch information
stana-miric committed Nov 26, 2024
1 parent f1e7c6a commit 6d9f644
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
14 changes: 0 additions & 14 deletions testutil/keeper/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
18 changes: 9 additions & 9 deletions x/ccv/provider/keeper/consumer_equivocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions x/ccv/provider/keeper/consumer_equivocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion x/ccv/provider/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 6d9f644

Please sign in to comment.