refactor: revert API breaking change on Slash (#14363)

This commit is contained in:
Julien Robert 2022-12-20 12:12:05 +01:00 committed by GitHub
parent 1441b506c9
commit 419de8de82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 127 additions and 167 deletions

View File

@ -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.
@ -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.

View File

@ -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

View File

@ -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])
@ -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])
@ -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])
@ -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])
@ -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
@ -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

View File

@ -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)
@ -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)
@ -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)
@ -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)
@ -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)
@ -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)
@ -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()
@ -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)
@ -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()
@ -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
@ -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()
@ -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))
}

View File

@ -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,
@ -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

View File

@ -42,20 +42,6 @@ func (m *MockAppModuleBasic) EXPECT() *MockAppModuleBasicMockRecorder {
return m.recorder
}
// DefaultGenesis mocks base method.
func (m *MockAppModuleBasic) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DefaultGenesis", arg0)
ret0, _ := ret[0].(json.RawMessage)
return ret0
}
// DefaultGenesis indicates an expected call of DefaultGenesis.
func (mr *MockAppModuleBasicMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModuleBasic)(nil).DefaultGenesis), arg0)
}
// GetQueryCmd mocks base method.
func (m *MockAppModuleBasic) GetQueryCmd() *cobra.Command {
m.ctrl.T.Helper()
@ -134,20 +120,6 @@ func (mr *MockAppModuleBasicMockRecorder) RegisterLegacyAminoCodec(arg0 interfac
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockAppModuleBasic)(nil).RegisterLegacyAminoCodec), arg0)
}
// ValidateGenesis mocks base method.
func (m *MockAppModuleBasic) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
}
// ValidateGenesis indicates an expected call of ValidateGenesis.
func (mr *MockAppModuleBasicMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModuleBasic)(nil).ValidateGenesis), arg0, arg1, arg2)
}
// MockHasName is a mock of HasName interface.
type MockHasName struct {
ctrl *gomock.Controller
@ -495,20 +467,6 @@ func (m *MockAppModule) EXPECT() *MockAppModuleMockRecorder {
return m.recorder
}
// DefaultGenesis mocks base method.
func (m *MockAppModule) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DefaultGenesis", arg0)
ret0, _ := ret[0].(json.RawMessage)
return ret0
}
// DefaultGenesis indicates an expected call of DefaultGenesis.
func (mr *MockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModule)(nil).DefaultGenesis), arg0)
}
// GetQueryCmd mocks base method.
func (m *MockAppModule) GetQueryCmd() *cobra.Command {
m.ctrl.T.Helper()
@ -587,20 +545,6 @@ func (mr *MockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{})
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockAppModule)(nil).RegisterLegacyAminoCodec), arg0)
}
// ValidateGenesis mocks base method.
func (m *MockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
}
// ValidateGenesis indicates an expected call of ValidateGenesis.
func (mr *MockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2)
}
// MockHasInvariants is a mock of HasInvariants interface.
type MockHasInvariants struct {
ctrl *gomock.Controller
@ -743,20 +687,6 @@ func (mr *MockBeginBlockAppModuleMockRecorder) BeginBlock(arg0, arg1 interface{}
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockBeginBlockAppModule)(nil).BeginBlock), arg0, arg1)
}
// DefaultGenesis mocks base method.
func (m *MockBeginBlockAppModule) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DefaultGenesis", arg0)
ret0, _ := ret[0].(json.RawMessage)
return ret0
}
// DefaultGenesis indicates an expected call of DefaultGenesis.
func (mr *MockBeginBlockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).DefaultGenesis), arg0)
}
// GetQueryCmd mocks base method.
func (m *MockBeginBlockAppModule) GetQueryCmd() *cobra.Command {
m.ctrl.T.Helper()
@ -835,20 +765,6 @@ func (mr *MockBeginBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 int
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0)
}
// ValidateGenesis mocks base method.
func (m *MockBeginBlockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
}
// ValidateGenesis indicates an expected call of ValidateGenesis.
func (mr *MockBeginBlockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2)
}
// MockEndBlockAppModule is a mock of EndBlockAppModule interface.
type MockEndBlockAppModule struct {
ctrl *gomock.Controller
@ -872,20 +788,6 @@ func (m *MockEndBlockAppModule) EXPECT() *MockEndBlockAppModuleMockRecorder {
return m.recorder
}
// DefaultGenesis mocks base method.
func (m *MockEndBlockAppModule) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DefaultGenesis", arg0)
ret0, _ := ret[0].(json.RawMessage)
return ret0
}
// DefaultGenesis indicates an expected call of DefaultGenesis.
func (mr *MockEndBlockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).DefaultGenesis), arg0)
}
// EndBlock mocks base method.
func (m *MockEndBlockAppModule) EndBlock(arg0 types0.Context, arg1 types1.RequestEndBlock) []types1.ValidatorUpdate {
m.ctrl.T.Helper()
@ -977,17 +879,3 @@ func (mr *MockEndBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 inter
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0)
}
// ValidateGenesis mocks base method.
func (m *MockEndBlockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
}
// ValidateGenesis indicates an expected call of ValidateGenesis.
func (mr *MockEndBlockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2)
}

View File

@ -30,7 +30,7 @@ func TestBasicManager(t *testing.T) {
wantDefaultGenesis := map[string]json.RawMessage{"mockAppModuleBasic1": json.RawMessage(``)}
mockAppModuleBasic1 := mock.NewMockAppModuleBasic(mockCtrl)
mockAppModuleBasic1 := mock.NewMockAppModuleWithAllExtensions(mockCtrl)
mockAppModuleBasic1.EXPECT().Name().AnyTimes().Return("mockAppModuleBasic1")
mockAppModuleBasic1.EXPECT().DefaultGenesis(gomock.Eq(cdc)).Times(1).Return(json.RawMessage(``))

View File

@ -120,7 +120,7 @@ func (k Keeper) HandleEquivocationEvidence(ctx sdk.Context, evidence *types.Equi
// to/by Tendermint. This value is validator.Tokens as sent to Tendermint via
// ABCI, and now received as evidence. The fraction is passed in to separately
// to slash unbonding and rebonding delegations.
k.slashingKeeper.Slash(
k.slashingKeeper.SlashWithInfractionReason(
ctx,
consAddr,
k.slashingKeeper.SlashFractionDoubleSign(ctx),

View File

@ -157,15 +157,15 @@ func (mr *MockSlashingKeeperMockRecorder) JailUntil(arg0, arg1, arg2 interface{}
}
// Slash mocks base method.
func (m *MockSlashingKeeper) Slash(arg0 types0.Context, arg1 types0.ConsAddress, arg2 types0.Dec, arg3, arg4 int64, arg5 types2.Infraction) {
func (m *MockSlashingKeeper) Slash(arg0 types0.Context, arg1 types0.ConsAddress, arg2 types0.Dec, arg3, arg4 int64) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Slash", arg0, arg1, arg2, arg3, arg4, arg5)
m.ctrl.Call(m, "Slash", arg0, arg1, arg2, arg3, arg4)
}
// Slash indicates an expected call of Slash.
func (mr *MockSlashingKeeperMockRecorder) Slash(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
func (mr *MockSlashingKeeperMockRecorder) Slash(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Slash", reflect.TypeOf((*MockSlashingKeeper)(nil).Slash), arg0, arg1, arg2, arg3, arg4, arg5)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Slash", reflect.TypeOf((*MockSlashingKeeper)(nil).Slash), arg0, arg1, arg2, arg3, arg4)
}
// SlashFractionDoubleSign mocks base method.
@ -182,6 +182,18 @@ func (mr *MockSlashingKeeperMockRecorder) SlashFractionDoubleSign(arg0 interface
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SlashFractionDoubleSign", reflect.TypeOf((*MockSlashingKeeper)(nil).SlashFractionDoubleSign), arg0)
}
// SlashWithInfractionReason mocks base method.
func (m *MockSlashingKeeper) SlashWithInfractionReason(arg0 types0.Context, arg1 types0.ConsAddress, arg2 types0.Dec, arg3, arg4 int64, arg5 types2.Infraction) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SlashWithInfractionReason", arg0, arg1, arg2, arg3, arg4, arg5)
}
// SlashWithInfractionReason indicates an expected call of SlashWithInfractionReason.
func (mr *MockSlashingKeeperMockRecorder) SlashWithInfractionReason(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SlashWithInfractionReason", reflect.TypeOf((*MockSlashingKeeper)(nil).SlashWithInfractionReason), arg0, arg1, arg2, arg3, arg4, arg5)
}
// Tombstone mocks base method.
func (m *MockSlashingKeeper) Tombstone(arg0 types0.Context, arg1 types0.ConsAddress) {
m.ctrl.T.Helper()

View File

@ -25,7 +25,8 @@ 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, stakingtypes.Infraction)
Slash(sdk.Context, sdk.ConsAddress, sdk.Dec, int64, int64)
SlashWithInfractionReason(sdk.Context, sdk.ConsAddress, sdk.Dec, int64, int64, stakingtypes.Infraction)
SlashFractionDoubleSign(sdk.Context) sdk.Dec
Jail(sdk.Context, sdk.ConsAddress)
JailUntil(sdk.Context, sdk.ConsAddress, time.Time)

View File

@ -284,7 +284,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(), stakingtypes.Downtime)
SlashWithInfractionReason(vote.Validator.Address, distributionHeight, vote.Validator.Power, SlashFractionDowntime(), stakingtypes.Downtime)
Jail(vote.Validator.Address)
signInfo.JailedUntil = block.Time.Add(DowntimeJailDuration())

View File

@ -90,7 +90,7 @@ func (k Keeper) HandleValidatorSignature(ctx sdk.Context, addr cryptotypes.Addre
// That's fine since this is just used to filter unbonding delegations & redelegations.
distributionHeight := height - sdk.ValidatorUpdateDelay - 1
coinsBurned := k.sk.Slash(ctx, consAddr, distributionHeight, power, k.SlashFractionDowntime(ctx), stakingtypes.Infraction_INFRACTION_DOWNTIME)
coinsBurned := k.sk.SlashWithInfractionReason(ctx, consAddr, distributionHeight, power, k.SlashFractionDowntime(ctx), stakingtypes.Infraction_INFRACTION_DOWNTIME)
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSlash,

View File

@ -70,9 +70,15 @@ 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, infraction stakingtypes.Infraction) {
coinsBurned := k.sk.Slash(ctx, consAddr, distributionHeight, power, fraction, infraction)
// module to make the necessary validator changes. It specifies no intraction reason.
func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, fraction sdk.Dec, power, distributionHeight int64) {
k.SlashWithInfractionReason(ctx, consAddr, fraction, power, distributionHeight, stakingtypes.Infraction_INFRACTION_UNSPECIFIED)
}
// SlashWithInfractionReason attempts to slash a validator. The slash is delegated to the staking
// module to make the necessary validator changes. It specifies an intraction reason.
func (k Keeper) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, fraction sdk.Dec, power, distributionHeight int64, infraction stakingtypes.Infraction) {
coinsBurned := k.sk.SlashWithInfractionReason(ctx, consAddr, distributionHeight, power, fraction, infraction)
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSlash,

View File

@ -19,7 +19,7 @@ import (
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtestutil "github.com/cosmos/cosmos-sdk/x/slashing/testutil"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
var consAddr = sdk.ConsAddress(sdk.AccAddress([]byte("addr1_______________")))
@ -76,12 +76,12 @@ func (s *KeeperTestSuite) TestPubkey() {
}
func (s *KeeperTestSuite) TestJailAndSlash() {
s.stakingKeeper.EXPECT().Slash(s.ctx,
s.stakingKeeper.EXPECT().SlashWithInfractionReason(s.ctx,
consAddr,
s.ctx.BlockHeight(),
sdk.TokensToConsensusPower(sdk.NewInt(1), sdk.DefaultPowerReduction),
s.slashingKeeper.SlashFractionDoubleSign(s.ctx),
types.Infraction_INFRACTION_DOUBLE_SIGN,
stakingtypes.Infraction_INFRACTION_UNSPECIFIED,
).Return(sdk.NewInt(0))
s.slashingKeeper.Slash(
@ -90,7 +90,28 @@ func (s *KeeperTestSuite) TestJailAndSlash() {
s.slashingKeeper.SlashFractionDoubleSign(s.ctx),
sdk.TokensToConsensusPower(sdk.NewInt(1), sdk.DefaultPowerReduction),
s.ctx.BlockHeight(),
types.Infraction_INFRACTION_DOUBLE_SIGN,
)
s.stakingKeeper.EXPECT().Jail(s.ctx, consAddr).Return()
s.slashingKeeper.Jail(s.ctx, consAddr)
}
func (s *KeeperTestSuite) TestJailAndSlashWithInfractionReason() {
s.stakingKeeper.EXPECT().SlashWithInfractionReason(s.ctx,
consAddr,
s.ctx.BlockHeight(),
sdk.TokensToConsensusPower(sdk.NewInt(1), sdk.DefaultPowerReduction),
s.slashingKeeper.SlashFractionDoubleSign(s.ctx),
stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN,
).Return(sdk.NewInt(0))
s.slashingKeeper.SlashWithInfractionReason(
s.ctx,
consAddr,
s.slashingKeeper.SlashFractionDoubleSign(s.ctx),
sdk.TokensToConsensusPower(sdk.NewInt(1), sdk.DefaultPowerReduction),
s.ctx.BlockHeight(),
stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN,
)
s.stakingKeeper.EXPECT().Jail(s.ctx, consAddr).Return()

View File

@ -334,17 +334,31 @@ func (mr *MockStakingKeeperMockRecorder) MaxValidators(arg0 interface{}) *gomock
}
// Slash mocks base method.
func (m *MockStakingKeeper) Slash(arg0 types.Context, arg1 types.ConsAddress, arg2, arg3 int64, arg4 types.Dec, arg5 types2.Infraction) math.Int {
func (m *MockStakingKeeper) Slash(arg0 types.Context, arg1 types.ConsAddress, arg2, arg3 int64, arg4 types.Dec) math.Int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Slash", arg0, arg1, arg2, arg3, arg4, arg5)
ret := m.ctrl.Call(m, "Slash", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].(math.Int)
return ret0
}
// Slash indicates an expected call of Slash.
func (mr *MockStakingKeeperMockRecorder) Slash(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
func (mr *MockStakingKeeperMockRecorder) Slash(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Slash", reflect.TypeOf((*MockStakingKeeper)(nil).Slash), arg0, arg1, arg2, arg3, arg4, arg5)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Slash", reflect.TypeOf((*MockStakingKeeper)(nil).Slash), arg0, arg1, arg2, arg3, arg4)
}
// SlashWithInfractionReason mocks base method.
func (m *MockStakingKeeper) SlashWithInfractionReason(arg0 types.Context, arg1 types.ConsAddress, arg2, arg3 int64, arg4 types.Dec, arg5 types2.Infraction) math.Int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SlashWithInfractionReason", arg0, arg1, arg2, arg3, arg4, arg5)
ret0, _ := ret[0].(math.Int)
return ret0
}
// SlashWithInfractionReason indicates an expected call of SlashWithInfractionReason.
func (mr *MockStakingKeeperMockRecorder) SlashWithInfractionReason(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SlashWithInfractionReason", reflect.TypeOf((*MockStakingKeeper)(nil).SlashWithInfractionReason), arg0, arg1, arg2, arg3, arg4, arg5)
}
// Unjail mocks base method.

View File

@ -41,7 +41,8 @@ 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, stakingtypes.Infraction) math.Int
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec) math.Int
SlashWithInfractionReason(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec, stakingtypes.Infraction) math.Int
Jail(sdk.Context, sdk.ConsAddress) // jail a validator
Unjail(sdk.Context, sdk.ConsAddress) // unjail a validator

View File

@ -30,10 +30,7 @@ import (
//
// Infraction was committed at the current height or at a past height,
// not at a height in the future
// ---
//
// Slash implementation doesn't require the infraction (types.Infraction) to work but the IS one does. It is here to have IS satisfy the Slash signature.
func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec, _ types.Infraction) math.Int {
func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec) math.Int {
logger := k.Logger(ctx)
if slashFactor.IsNegative() {
@ -159,6 +156,11 @@ func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeigh
return tokensToBurn
}
// SlashWithInfractionReason implementation doesn't require the infraction (types.Infraction) to work but is required by Interchain Security.
func (k Keeper) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeight int64, power int64, slashFactor sdk.Dec, _ types.Infraction) math.Int {
return k.Slash(ctx, consAddr, infractionHeight, power, slashFactor)
}
// jail a validator
func (k Keeper) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) {
validator := k.mustGetValidatorByConsAddr(ctx, consAddr)

View File

@ -46,5 +46,5 @@ func (s *KeeperTestSuite) TestSlashAtFutureHeight() {
require.NoError(err)
fraction := sdk.NewDecWithPrec(5, 1)
require.Panics(func() { keeper.Slash(ctx, consAddr, 1, 10, fraction, 0) })
require.Panics(func() { keeper.Slash(ctx, consAddr, 1, 10, fraction) })
}

View File

@ -403,17 +403,31 @@ func (mr *MockValidatorSetMockRecorder) MaxValidators(arg0 interface{}) *gomock.
}
// Slash mocks base method.
func (m *MockValidatorSet) Slash(arg0 types.Context, arg1 types.ConsAddress, arg2, arg3 int64, arg4 types.Dec, arg5 types1.Infraction) math.Int {
func (m *MockValidatorSet) Slash(arg0 types.Context, arg1 types.ConsAddress, arg2, arg3 int64, arg4 types.Dec) math.Int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Slash", arg0, arg1, arg2, arg3, arg4, arg5)
ret := m.ctrl.Call(m, "Slash", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].(math.Int)
return ret0
}
// Slash indicates an expected call of Slash.
func (mr *MockValidatorSetMockRecorder) Slash(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
func (mr *MockValidatorSetMockRecorder) Slash(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Slash", reflect.TypeOf((*MockValidatorSet)(nil).Slash), arg0, arg1, arg2, arg3, arg4, arg5)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Slash", reflect.TypeOf((*MockValidatorSet)(nil).Slash), arg0, arg1, arg2, arg3, arg4)
}
// SlashWithInfractionReason mocks base method.
func (m *MockValidatorSet) SlashWithInfractionReason(arg0 types.Context, arg1 types.ConsAddress, arg2, arg3 int64, arg4 types.Dec, arg5 types1.Infraction) math.Int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SlashWithInfractionReason", arg0, arg1, arg2, arg3, arg4, arg5)
ret0, _ := ret[0].(math.Int)
return ret0
}
// SlashWithInfractionReason indicates an expected call of SlashWithInfractionReason.
func (mr *MockValidatorSetMockRecorder) SlashWithInfractionReason(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SlashWithInfractionReason", reflect.TypeOf((*MockValidatorSet)(nil).SlashWithInfractionReason), arg0, arg1, arg2, arg3, arg4, arg5)
}
// StakingTokenSupply mocks base method.

View File

@ -61,7 +61,8 @@ type ValidatorSet interface {
StakingTokenSupply(sdk.Context) math.Int // total staking token supply
// 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, Infraction) math.Int
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec) math.Int
SlashWithInfractionReason(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec, Infraction) math.Int
Jail(sdk.Context, sdk.ConsAddress) // jail a validator
Unjail(sdk.Context, sdk.ConsAddress) // unjail a validator