Skip to content

Commit

Permalink
feat: enable double-signing evidence in Interchain-Security (#11921)
Browse files Browse the repository at this point in the history
* Add a `InfractionType` enum to Slash function arguments

* Remove pubkey condition in HandleEquivocation

* Update docs/core/proto-docs.md

Co-authored-by: billy rennekamp <[email protected]>

* Update proto/cosmos/staking/v1beta1/staking.proto

Co-authored-by: billy rennekamp <[email protected]>

* add a possible solution to the evidence module issue

Co-authored-by: billy rennekamp <[email protected]>
  • Loading branch information
sainoe and okwme committed Nov 16, 2022
1 parent 22515e7 commit add3436
Show file tree
Hide file tree
Showing 17 changed files with 858 additions and 780 deletions.
14 changes: 14 additions & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@
- [Validator](#cosmos.staking.v1beta1.Validator)

- [BondStatus](#cosmos.staking.v1beta1.BondStatus)
- [InfractionType](#cosmos.staking.v1beta1.InfractionType)

- [cosmos/staking/v1beta1/genesis.proto](#cosmos/staking/v1beta1/genesis.proto)
- [GenesisState](#cosmos.staking.v1beta1.GenesisState)
Expand Down Expand Up @@ -6892,6 +6893,19 @@ BondStatus is the status of a validator.
| BOND_STATUS_BONDED | 3 | BONDED defines a validator that is bonded. |



<a name="cosmos.staking.v1beta1.InfractionType"></a>

### InfractionType
InfractionType indicates the infraction type a validator commited.

| Name | Number | Description |
| ---- | ------ | ----------- |
| INFRACTION_TYPE_UNSPECIFIED | 0 | UNSPECIFIED defines an empty infraction type. |
| INFRACTION_TYPE_DOUBLE_SIGN | 1 | DOUBLE_SIGN defines a validator that double-signs a block. |
| INFRACTION_TYPE_DOWNTIME | 2 | DOWNTIME defines a validator that missed signing too many blocks. |


<!-- end enums -->

<!-- end HasExtensions -->
Expand Down
12 changes: 12 additions & 0 deletions proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,15 @@ message Pool {
(gogoproto.moretags) = "yaml:\"bonded_tokens\""
];
}

// InfractionType indicates the infraction type a validator commited.
enum InfractionType {
option (gogoproto.goproto_enum_prefix) = false;

// UNSPECIFIED defines an empty infraction type.
INFRACTION_TYPE_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "InfractionEmpty"];
// DOUBLE_SIGN defines a validator that double-signs a block.
INFRACTION_TYPE_DOUBLE_SIGN = 1 [(gogoproto.enumvalue_customname) = "DoubleSign"];
// DOWNTIME defines a validator that missed signing too many blocks.
INFRACTION_TYPE_DOWNTIME = 2 [(gogoproto.enumvalue_customname) = "Downtime"];
}
14 changes: 7 additions & 7 deletions x/distribution/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) {
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3)

// slash the validator by 50%
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1))
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1), 0)

// retrieve validator
val = app.StakingKeeper.Validator(ctx, valAddrs[0])
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) {
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3)

// slash the validator by 50%
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1))
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1), 0)

// fetch the validator again
val = app.StakingKeeper.Validator(ctx, valAddrs[0])
Expand All @@ -180,7 +180,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) {
app.DistrKeeper.AllocateTokensToValidator(ctx, val, tokens)

// slash the validator by 50% again
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower/2, sdk.NewDecWithPrec(5, 1))
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower/2, sdk.NewDecWithPrec(5, 1), 0)

// fetch the validator again
val = app.StakingKeeper.Validator(ctx, valAddrs[0])
Expand Down Expand Up @@ -400,10 +400,10 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) {
app.DistrKeeper.AllocateTokensToValidator(ctx, val, tokens)

// slash the validator by 50%
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1))
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1), 0)

// slash the validator by 50% again
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower/2, sdk.NewDecWithPrec(5, 1))
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower/2, sdk.NewDecWithPrec(5, 1), 0)

// fetch the validator again
val = app.StakingKeeper.Validator(ctx, valAddrs[0])
Expand Down Expand Up @@ -457,7 +457,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) {

// slash the validator
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3)
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1))
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1), 0)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3)

// second delegation
Expand All @@ -476,7 +476,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) {

// slash the validator again
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3)
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1))
app.StakingKeeper.Slash(ctx, valConsAddr1, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1), 0)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3)

// fetch updated validator
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type StakingKeeper interface {
Validator(sdk.Context, sdk.ValAddress) stakingtypes.ValidatorI // get a particular validator by operator address
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingtypes.ValidatorI // get a particular validator by consensus address

// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec)
// slash the validator and delegators of the validator, specifying offence height, offence power, slash fraction and infraction type
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec, stakingtypes.InfractionType)
Jail(sdk.Context, sdk.ConsAddress) // jail a validator
Unjail(sdk.Context, sdk.ConsAddress) // unjail a validator

Expand Down
31 changes: 18 additions & 13 deletions x/evidence/keeper/infraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/x/evidence/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// HandleEquivocationEvidence implements an equivocation evidence handler. Assuming the
Expand All @@ -26,19 +27,6 @@ func (k Keeper) HandleEquivocationEvidence(ctx sdk.Context, evidence *types.Equi
logger := k.Logger(ctx)
consAddr := evidence.GetConsensusAddress()

if _, err := k.slashingKeeper.GetPubkey(ctx, consAddr.Bytes()); err != nil {
// Ignore evidence that cannot be handled.
//
// NOTE: We used to panic with:
// `panic(fmt.Sprintf("Validator consensus-address %v not found", consAddr))`,
// but this couples the expectations of the app to both Tendermint and
// the simulator. Both are expected to provide the full range of
// allowable but none of the disallowed evidence types. Instead of
// getting this coordination right, it is easier to relax the
// constraints and ignore evidence that cannot be handled.
return
}

// calculate the age of the evidence
infractionHeight := evidence.GetHeight()
infractionTime := evidence.GetTime()
Expand Down Expand Up @@ -70,6 +58,22 @@ func (k Keeper) HandleEquivocationEvidence(ctx sdk.Context, evidence *types.Equi
return
}

// ignore the public keys when validators don't have an operator address
if !validator.GetOperator().Empty() {
if _, err := k.slashingKeeper.GetPubkey(ctx, consAddr.Bytes()); err != nil {
// Ignore evidence that cannot be handled.
//
// NOTE: We used to panic with:
// `panic(fmt.Sprintf("Validator consensus-address %v not found", consAddr))`,
// but this couples the expectations of the app to both Tendermint and
// the simulator. Both are expected to provide the full range of
// allowable but none of the disallowed evidence types. Instead of
// getting this coordination right, it is easier to relax the
// constraints and ignore evidence that cannot be handled.
return
}
}

if ok := k.slashingKeeper.HasValidatorSigningInfo(ctx, consAddr); !ok {
panic(fmt.Sprintf("expected signing info for validator %s but not found", consAddr))
}
Expand Down Expand Up @@ -109,6 +113,7 @@ func (k Keeper) HandleEquivocationEvidence(ctx sdk.Context, evidence *types.Equi
consAddr,
k.slashingKeeper.SlashFractionDoubleSign(ctx),
evidence.GetValidatorPower(), distributionHeight,
stakingtypes.DoubleSign,
)

// Jail the validator if not already jailed. This will begin unbonding the
Expand Down
1 change: 1 addition & 0 deletions x/evidence/spec/06_begin_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func (k Keeper) HandleEquivocationEvidence(ctx sdk.Context, evidence *types.Equi
consAddr,
k.slashingKeeper.SlashFractionDoubleSign(ctx),
evidence.GetValidatorPower(), distributionHeight,
stakingtypes.DoubleSign,
)

// Jail the validator if not already jailed. This will begin unbonding the
Expand Down
2 changes: 1 addition & 1 deletion x/evidence/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type (
IsTombstoned(sdk.Context, sdk.ConsAddress) bool
HasValidatorSigningInfo(sdk.Context, sdk.ConsAddress) bool
Tombstone(sdk.Context, sdk.ConsAddress)
Slash(sdk.Context, sdk.ConsAddress, sdk.Dec, int64, int64)
Slash(sdk.Context, sdk.ConsAddress, sdk.Dec, int64, int64, stakingtypes.InfractionType)
SlashFractionDoubleSign(sdk.Context) sdk.Dec
Jail(sdk.Context, sdk.ConsAddress)
JailUntil(sdk.Context, sdk.ConsAddress, time.Time)
Expand Down
3 changes: 2 additions & 1 deletion x/slashing/keeper/infractions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// HandleValidatorSignature handles a validator signature, must be called once per validator per block.
Expand Down Expand Up @@ -95,7 +96,7 @@ func (k Keeper) HandleValidatorSignature(ctx sdk.Context, addr cryptotypes.Addre
sdk.NewAttribute(types.AttributeKeyJailed, consAddr.String()),
),
)
k.sk.Slash(ctx, consAddr, distributionHeight, power, k.SlashFractionDowntime(ctx))
k.sk.Slash(ctx, consAddr, distributionHeight, power, k.SlashFractionDowntime(ctx), stakingtypes.Downtime)
k.sk.Jail(ctx, consAddr)

signInfo.JailedUntil = ctx.BlockHeader().Time.Add(k.DowntimeJailDuration(ctx))
Expand Down
5 changes: 3 additions & 2 deletions x/slashing/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// Keeper of the slashing store
Expand Down Expand Up @@ -64,7 +65,7 @@ func (k Keeper) GetPubkey(ctx sdk.Context, a cryptotypes.Address) (cryptotypes.P

// Slash attempts to slash a validator. The slash is delegated to the staking
// module to make the necessary validator changes.
func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, fraction sdk.Dec, power, distributionHeight int64) {
func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, fraction sdk.Dec, power, distributionHeight int64, infractionType stakingtypes.InfractionType) {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSlash,
Expand All @@ -74,7 +75,7 @@ func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, fraction sdk.De
),
)

k.sk.Slash(ctx, consAddr, distributionHeight, power, fraction)
k.sk.Slash(ctx, consAddr, distributionHeight, power, fraction, infractionType)
}

// Jail attempts to jail a validator. The slash is delegated to the staking module
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/spec/04_begin_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ for vote in block.LastCommitInfo.Votes {
// That's fine since this is just used to filter unbonding delegations & redelegations.
distributionHeight := height - sdk.ValidatorUpdateDelay - 1

Slash(vote.Validator.Address, distributionHeight, vote.Validator.Power, SlashFractionDowntime())
Slash(vote.Validator.Address, distributionHeight, vote.Validator.Power, SlashFractionDowntime(), stakingtypes.Downtime)
Jail(vote.Validator.Address)

signInfo.JailedUntil = block.Time.Add(DowntimeJailDuration())
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type StakingKeeper interface {
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingtypes.ValidatorI // get a particular validator by consensus address

// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec)
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec, stakingtypes.InfractionType)
Jail(sdk.Context, sdk.ConsAddress) // jail a validator
Unjail(sdk.Context, sdk.ConsAddress) // unjail a validator

Expand Down
6 changes: 3 additions & 3 deletions x/staking/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestValidatorByPowerIndex(t *testing.T) {

// slash and jail the first validator
consAddr0 := sdk.ConsAddress(PKs[0].Address())
app.StakingKeeper.Slash(ctx, consAddr0, 0, initPower, sdk.NewDecWithPrec(5, 1))
app.StakingKeeper.Slash(ctx, consAddr0, 0, initPower, sdk.NewDecWithPrec(5, 1), 0)
app.StakingKeeper.Jail(ctx, consAddr0)
app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)

Expand Down Expand Up @@ -1110,7 +1110,7 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) {
require.Equal(t, 2, len(updates))

// slash the validator by half
app.StakingKeeper.Slash(ctx, consAddr0, 0, 20, sdk.NewDecWithPrec(5, 1))
app.StakingKeeper.Slash(ctx, consAddr0, 0, 20, sdk.NewDecWithPrec(5, 1), 0)

// unbonding delegation should have been slashed by half
ubd, found := app.StakingKeeper.GetUnbondingDelegation(ctx, del, valA)
Expand All @@ -1135,7 +1135,7 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) {

// slash the validator for an infraction committed after the unbonding and redelegation begin
ctx = ctx.WithBlockHeight(3)
app.StakingKeeper.Slash(ctx, consAddr0, 2, 10, sdk.NewDecWithPrec(5, 1))
app.StakingKeeper.Slash(ctx, consAddr0, 2, 10, sdk.NewDecWithPrec(5, 1), 0)
tstaking.Ctx = ctx

// unbonding delegation should be unchanged
Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
//
// Infraction was committed at the current height or at a past height,
// not at a height in the future
func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec) {
func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec, _ types.InfractionType) {
logger := k.Logger(ctx)

if slashFactor.IsNegative() {
Expand Down
24 changes: 12 additions & 12 deletions x/staking/keeper/slash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestSlashAtFutureHeight(t *testing.T) {

consAddr := sdk.ConsAddress(PKs[0].Address())
fraction := sdk.NewDecWithPrec(5, 1)
require.Panics(t, func() { app.StakingKeeper.Slash(ctx, consAddr, 1, 10, fraction) })
require.Panics(t, func() { app.StakingKeeper.Slash(ctx, consAddr, 1, 10, fraction, 0) })
}

// test slash at a negative height
Expand All @@ -203,7 +203,7 @@ func TestSlashAtNegativeHeight(t *testing.T) {

validator, found := app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found)
app.StakingKeeper.Slash(ctx, consAddr, -2, 10, fraction)
app.StakingKeeper.Slash(ctx, consAddr, -2, 10, fraction, 0)

// read updated state
validator, found = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestSlashValidatorAtCurrentHeight(t *testing.T) {

validator, found := app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found)
app.StakingKeeper.Slash(ctx, consAddr, ctx.BlockHeight(), 10, fraction)
app.StakingKeeper.Slash(ctx, consAddr, ctx.BlockHeight(), 10, fraction, 0)

// read updated state
validator, found = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {

validator, found := app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found)
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, fraction)
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, fraction, 0)

// end block
applyValidatorSetUpdates(t, ctx, app.StakingKeeper, 1)
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {

// slash validator again
ctx = ctx.WithBlockHeight(13)
app.StakingKeeper.Slash(ctx, consAddr, 9, 10, fraction)
app.StakingKeeper.Slash(ctx, consAddr, 9, 10, fraction, 0)

ubd, found = app.StakingKeeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
require.True(t, found)
Expand All @@ -330,7 +330,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// on the unbonding delegation, but it will slash stake bonded since the infraction
// this may not be the desirable behaviour, ref https://github.com/cosmos/cosmos-sdk/issues/1440
ctx = ctx.WithBlockHeight(13)
app.StakingKeeper.Slash(ctx, consAddr, 9, 10, fraction)
app.StakingKeeper.Slash(ctx, consAddr, 9, 10, fraction, 0)

ubd, found = app.StakingKeeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
require.True(t, found)
Expand All @@ -356,7 +356,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// on the unbonding delegation, but it will slash stake bonded since the infraction
// this may not be the desirable behaviour, ref https://github.com/cosmos/cosmos-sdk/issues/1440
ctx = ctx.WithBlockHeight(13)
app.StakingKeeper.Slash(ctx, consAddr, 9, 10, fraction)
app.StakingKeeper.Slash(ctx, consAddr, 9, 10, fraction, 0)

ubd, found = app.StakingKeeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
require.True(t, found)
Expand Down Expand Up @@ -414,7 +414,7 @@ func TestSlashWithRedelegation(t *testing.T) {
validator, found := app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found)

require.NotPanics(t, func() { app.StakingKeeper.Slash(ctx, consAddr, 10, 10, fraction) })
require.NotPanics(t, func() { app.StakingKeeper.Slash(ctx, consAddr, 10, 10, fraction, 0) })
burnAmount := app.StakingKeeper.TokensFromConsensusPower(ctx, 10).ToDec().Mul(fraction).TruncateInt()

bondedPool = app.StakingKeeper.GetBondedPool(ctx)
Expand Down Expand Up @@ -445,7 +445,7 @@ func TestSlashWithRedelegation(t *testing.T) {
validator, found = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found)

require.NotPanics(t, func() { app.StakingKeeper.Slash(ctx, consAddr, 10, 10, sdk.OneDec()) })
require.NotPanics(t, func() { app.StakingKeeper.Slash(ctx, consAddr, 10, 10, sdk.OneDec(), 0) })
burnAmount = app.StakingKeeper.TokensFromConsensusPower(ctx, 7)

// read updated pool
Expand Down Expand Up @@ -479,7 +479,7 @@ func TestSlashWithRedelegation(t *testing.T) {
validator, found = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found)

require.NotPanics(t, func() { app.StakingKeeper.Slash(ctx, consAddr, 10, 10, sdk.OneDec()) })
require.NotPanics(t, func() { app.StakingKeeper.Slash(ctx, consAddr, 10, 10, sdk.OneDec(), 0) })

burnAmount = app.StakingKeeper.TokensFromConsensusPower(ctx, 10).ToDec().Mul(sdk.OneDec()).TruncateInt()
burnAmount = burnAmount.Sub(sdk.OneDec().MulInt(rdTokens).TruncateInt())
Expand Down Expand Up @@ -512,7 +512,7 @@ func TestSlashWithRedelegation(t *testing.T) {
validator, _ = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
require.Equal(t, validator.GetStatus(), types.Unbonding)

require.NotPanics(t, func() { app.StakingKeeper.Slash(ctx, consAddr, 10, 10, sdk.OneDec()) })
require.NotPanics(t, func() { app.StakingKeeper.Slash(ctx, consAddr, 10, 10, sdk.OneDec(), 0) })

// read updated pool
bondedPool = app.StakingKeeper.GetBondedPool(ctx)
Expand Down Expand Up @@ -578,7 +578,7 @@ func TestSlashBoth(t *testing.T) {
validator, found := app.StakingKeeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(PKs[0]))
require.True(t, found)
consAddr0 := sdk.ConsAddress(PKs[0].Address())
app.StakingKeeper.Slash(ctx, consAddr0, 10, 10, fraction)
app.StakingKeeper.Slash(ctx, consAddr0, 10, 10, fraction, 0)

burnedNotBondedAmount := fraction.MulInt(ubdATokens).TruncateInt()
burnedBondAmount := app.StakingKeeper.TokensFromConsensusPower(ctx, 10).ToDec().Mul(fraction).TruncateInt()
Expand Down
Loading

0 comments on commit add3436

Please sign in to comment.