Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: revert API breaking change on Slash #14363

Merged
merged 7 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* (x/slashing, x/staking) [#14363](https://github.com/cosmos/cosmos-sdk/pull/14363) Add the infraction a validator commited type as an argument to a `SlashWithInfractionReason` keeper method.
* (x/evidence) [#13740](https://github.com/cosmos/cosmos-sdk/pull/13740) Add new proto field `hash` of type `string` to `QueryEvidenceRequest` which helps to decode the hash properly while using query API.
* (core) [#13306](https://github.com/cosmos/cosmos-sdk/pull/13306) Add a `FormatCoins` function to in `core/coins` to format sdk Coins following the Value Renderers spec.
* (math) [#13306](https://github.com/cosmos/cosmos-sdk/pull/13306) Add `FormatInt` and `FormatDec` functiosn in `math` to format integers and decimals following the Value Renderers spec.
Expand Down Expand Up @@ -135,7 +136,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/auth) [#13877](https://github.com/cosmos/cosmos-sdk/pull/13877) Rename `AccountKeeper`'s `GetNextAccountNumber` to `NextAccountNumber`.
* (x/evidence) [#13740](https://github.com/cosmos/cosmos-sdk/pull/13740) The `NewQueryEvidenceRequest` function now takes `hash` as a HEX encoded `string`.
* (server) [#13485](https://github.com/cosmos/cosmos-sdk/pull/13485) The `Application` service now requires the `RegisterNodeService` method to be implemented.
* (x/slashing, x/staking) [#13122](https://github.com/cosmos/cosmos-sdk/pull/13122) Add the infraction a validator commited type as an argument to the `Slash` keeper method.
* [#13437](https://github.com/cosmos/cosmos-sdk/pull/13437) Add a list of modules to export argument in `ExportAppStateAndValidators`.
* (x/slashing) [#13427](https://github.com/cosmos/cosmos-sdk/pull/13427) Move `x/slashing/testslashing` to `x/slashing/testutil` for consistency with other modules.
* (x/staking) [#13427](https://github.com/cosmos/cosmos-sdk/pull/13427) Move `x/staking/teststaking` to `x/staking/testutil` for consistency with other modules.
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/SPEC_MODULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ specifications for modules. The following list is nonbinding and all sections ar

### Notation for key-value mapping

Within `state.md` the following notation `->` should be used to describe key to
Within `## State` the following notation `->` should be used to describe key to
value mapping:

```text
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/distribution/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) {
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3)

// slash the validator by 50%
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1), stakingtypes.Infraction_INFRACTION_UNSPECIFIED)
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1))

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

// slash the validator by 50%
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1), stakingtypes.Infraction_INFRACTION_UNSPECIFIED)
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1))

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

// slash the validator by 50% again
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower/2, sdk.NewDecWithPrec(5, 1), stakingtypes.Infraction_INFRACTION_UNSPECIFIED)
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower/2, sdk.NewDecWithPrec(5, 1))

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

// slash the validator by 50%
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1), stakingtypes.Infraction_INFRACTION_UNSPECIFIED)
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1))

// slash the validator by 50% again
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower/2, sdk.NewDecWithPrec(5, 1), stakingtypes.Infraction_INFRACTION_UNSPECIFIED)
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower/2, sdk.NewDecWithPrec(5, 1))

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

// slash the validator
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3)
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1), stakingtypes.Infraction_INFRACTION_UNSPECIFIED)
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1))
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3)

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

// slash the validator again
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3)
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1), stakingtypes.Infraction_INFRACTION_UNSPECIFIED)
stakingKeeper.Slash(ctx, valConsAddr0, ctx.BlockHeight(), valPower, sdk.NewDecWithPrec(5, 1))
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 3)

// fetch updated validator
Expand Down
26 changes: 13 additions & 13 deletions tests/integration/staking/keeper/slash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,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, types.Infraction_INFRACTION_UNSPECIFIED)
app.StakingKeeper.Slash(ctx, consAddr, -2, 10, fraction)

// read updated state
validator, found = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
Expand Down Expand Up @@ -203,7 +203,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, types.Infraction_INFRACTION_UNSPECIFIED)
app.StakingKeeper.Slash(ctx, consAddr, ctx.BlockHeight(), 10, fraction)

// read updated state
validator, found = app.StakingKeeper.GetValidatorByConsAddr(ctx, consAddr)
Expand Down Expand Up @@ -243,7 +243,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, types.Infraction_INFRACTION_UNSPECIFIED)
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, fraction)

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

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

ubd, found = app.StakingKeeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
require.True(t, found)
Expand All @@ -299,7 +299,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, types.Infraction_INFRACTION_UNSPECIFIED)
app.StakingKeeper.Slash(ctx, consAddr, 9, 10, fraction)

ubd, found = app.StakingKeeper.GetUnbondingDelegation(ctx, addrDels[0], addrVals[0])
require.True(t, found)
Expand All @@ -325,7 +325,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, types.Infraction_INFRACTION_UNSPECIFIED)
app.StakingKeeper.Slash(ctx, consAddr, 9, 10, fraction)

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

require.NotPanics(t, func() {
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, fraction, types.Infraction_INFRACTION_UNSPECIFIED)
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, fraction)
})
burnAmount := sdk.NewDecFromInt(app.StakingKeeper.TokensFromConsensusPower(ctx, 10)).Mul(fraction).TruncateInt()

Expand Down Expand Up @@ -416,7 +416,7 @@ func TestSlashWithRedelegation(t *testing.T) {
require.True(t, found)

require.NotPanics(t, func() {
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, math.LegacyOneDec(), types.Infraction_INFRACTION_UNSPECIFIED)
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, math.LegacyOneDec())
})
burnAmount = app.StakingKeeper.TokensFromConsensusPower(ctx, 7)

Expand Down Expand Up @@ -452,7 +452,7 @@ func TestSlashWithRedelegation(t *testing.T) {
require.True(t, found)

require.NotPanics(t, func() {
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, math.LegacyOneDec(), types.Infraction_INFRACTION_UNSPECIFIED)
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, math.LegacyOneDec())
})

burnAmount = sdk.NewDecFromInt(app.StakingKeeper.TokensFromConsensusPower(ctx, 10)).Mul(math.LegacyOneDec()).TruncateInt()
Expand Down Expand Up @@ -487,7 +487,7 @@ func TestSlashWithRedelegation(t *testing.T) {
require.Equal(t, validator.GetStatus(), types.Unbonding)

require.NotPanics(t, func() {
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, math.LegacyOneDec(), types.Infraction_INFRACTION_UNSPECIFIED)
app.StakingKeeper.Slash(ctx, consAddr, 10, 10, math.LegacyOneDec())
})

// read updated pool
Expand Down Expand Up @@ -552,7 +552,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, types.Infraction_INFRACTION_UNSPECIFIED)
app.StakingKeeper.Slash(ctx, consAddr0, 10, 10, fraction)

burnedNotBondedAmount := fraction.MulInt(ubdATokens).TruncateInt()
burnedBondAmount := sdk.NewDecFromInt(app.StakingKeeper.TokensFromConsensusPower(ctx, 10)).Mul(fraction).TruncateInt()
Expand Down Expand Up @@ -583,11 +583,11 @@ func TestSlashAmount(t *testing.T) {
app, ctx, _, _ := bootstrapSlashTest(t, 10)
consAddr := sdk.ConsAddress(PKs[0].Address())
fraction := sdk.NewDecWithPrec(5, 1)
burnedCoins := app.StakingKeeper.Slash(ctx, consAddr, ctx.BlockHeight(), 10, fraction, types.Infraction_INFRACTION_UNSPECIFIED)
burnedCoins := app.StakingKeeper.Slash(ctx, consAddr, ctx.BlockHeight(), 10, fraction)
require.True(t, burnedCoins.GT(math.ZeroInt()))

// test the case where the validator was not found, which should return no coins
_, addrVals := generateAddresses(app, ctx, 100)
noBurned := app.StakingKeeper.Slash(ctx, sdk.ConsAddress(addrVals[0]), ctx.BlockHeight(), 10, fraction, types.Infraction_INFRACTION_UNSPECIFIED)
noBurned := app.StakingKeeper.Slash(ctx, sdk.ConsAddress(addrVals[0]), ctx.BlockHeight(), 10, fraction)
require.True(t, sdk.NewInt(0).Equal(noBurned))
}
4 changes: 2 additions & 2 deletions tests/integration/staking/keeper/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
app.StakingKeeper.DeleteValidatorByPowerIndex(ctx, nextCliffVal)
shares := app.StakingKeeper.TokensFromConsensusPower(ctx, 21)
nextCliffVal, _ = nextCliffVal.RemoveDelShares(sdk.NewDecFromInt(shares))
nextCliffVal = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, nextCliffVal, true)
_ = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, nextCliffVal, true)

expectedValStatus := map[int]types.BondStatus{
9: types.Bonded, 8: types.Bonded, 7: types.Bonded, 5: types.Bonded, 4: types.Bonded,
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestSlashToZeroPowerRemoved(t *testing.T) {
require.Equal(t, valTokens, validator.Tokens, "\nvalidator %v\npool %v", validator, valTokens)

// slash the validator by 100%
app.StakingKeeper.Slash(ctx, sdk.ConsAddress(PKs[0].Address()), 0, 100, math.LegacyOneDec(), types.Infraction_INFRACTION_UNSPECIFIED)
app.StakingKeeper.Slash(ctx, sdk.ConsAddress(PKs[0].Address()), 0, 100, math.LegacyOneDec())
// apply TM updates
applyValidatorSetUpdates(t, ctx, app.StakingKeeper, -1)
// validator should be unbonding
Expand Down
112 changes: 0 additions & 112 deletions testutil/mock/types_module_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading