Merge PR #3189: Reset slashing periods on export
* Reset slashing periods on export * Rename old slashing period setter to SetValidatorSlashingPeriod * Update export to reset slashing periods * Fix cons address * Remove old slashing period reset * Add pending log entry * Update slashing period tests
This commit is contained in:
parent
990f3ab4c1
commit
15bd1f668f
|
@ -84,6 +84,8 @@ BUG FIXES
|
||||||
* \#3181 Correctly reset total accum update height and jailed-validator bond height / unbonding height on export-for-zero-height
|
* \#3181 Correctly reset total accum update height and jailed-validator bond height / unbonding height on export-for-zero-height
|
||||||
* [\#3172](https://github.com/cosmos/cosmos-sdk/pull/3172) Fix parsing `gaiad.toml`
|
* [\#3172](https://github.com/cosmos/cosmos-sdk/pull/3172) Fix parsing `gaiad.toml`
|
||||||
when it already exists.
|
when it already exists.
|
||||||
|
* [#3187](https://github.com/cosmos/cosmos-sdk/issues/3187) Fix `gaiad export`
|
||||||
|
by resetting each validator's slashing period.
|
||||||
|
|
||||||
* SDK
|
* SDK
|
||||||
|
|
||||||
|
|
|
@ -128,32 +128,52 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context) {
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
// iterate through validators by power descending, reset bond height, update bond intra-tx counter
|
// Iterate through validators by power descending, reset bond heights, and
|
||||||
|
// update bond intra-tx counters.
|
||||||
store := ctx.KVStore(app.keyStake)
|
store := ctx.KVStore(app.keyStake)
|
||||||
iter := sdk.KVStoreReversePrefixIterator(store, stake.ValidatorsKey)
|
iter := sdk.KVStoreReversePrefixIterator(store, stake.ValidatorsKey)
|
||||||
counter := int16(0)
|
counter := int16(0)
|
||||||
|
|
||||||
|
var valConsAddrs []sdk.ConsAddress
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
addr := sdk.ValAddress(iter.Key()[1:])
|
addr := sdk.ValAddress(iter.Key()[1:])
|
||||||
validator, found := app.stakeKeeper.GetValidator(ctx, addr)
|
validator, found := app.stakeKeeper.GetValidator(ctx, addr)
|
||||||
if !found {
|
if !found {
|
||||||
panic("expected validator, not found")
|
panic("expected validator, not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
validator.BondHeight = 0
|
validator.BondHeight = 0
|
||||||
validator.UnbondingHeight = 0
|
validator.UnbondingHeight = 0
|
||||||
|
valConsAddrs = append(valConsAddrs, validator.ConsAddress())
|
||||||
|
|
||||||
app.stakeKeeper.SetValidator(ctx, validator)
|
app.stakeKeeper.SetValidator(ctx, validator)
|
||||||
counter++
|
counter++
|
||||||
}
|
}
|
||||||
|
|
||||||
iter.Close()
|
iter.Close()
|
||||||
|
|
||||||
/* Handle slashing state. */
|
/* Handle slashing state. */
|
||||||
|
|
||||||
// we have to clear the slashing periods, since they reference heights
|
// remove all existing slashing periods and recreate one for each validator
|
||||||
app.slashingKeeper.DeleteValidatorSlashingPeriods(ctx)
|
app.slashingKeeper.DeleteValidatorSlashingPeriods(ctx)
|
||||||
|
|
||||||
|
for _, valConsAddr := range valConsAddrs {
|
||||||
|
sp := slashing.ValidatorSlashingPeriod{
|
||||||
|
ValidatorAddr: valConsAddr,
|
||||||
|
StartHeight: 0,
|
||||||
|
EndHeight: 0,
|
||||||
|
SlashedSoFar: sdk.ZeroDec(),
|
||||||
|
}
|
||||||
|
app.slashingKeeper.SetValidatorSlashingPeriod(ctx, sp)
|
||||||
|
}
|
||||||
|
|
||||||
// reset start height on signing infos
|
// reset start height on signing infos
|
||||||
app.slashingKeeper.IterateValidatorSigningInfos(ctx, func(addr sdk.ConsAddress, info slashing.ValidatorSigningInfo) (stop bool) {
|
app.slashingKeeper.IterateValidatorSigningInfos(
|
||||||
info.StartHeight = 0
|
ctx,
|
||||||
app.slashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
|
func(addr sdk.ConsAddress, info slashing.ValidatorSigningInfo) (stop bool) {
|
||||||
return false
|
info.StartHeight = 0
|
||||||
})
|
app.slashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState, sdata types.
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, slashingPeriod := range data.SlashingPeriods {
|
for _, slashingPeriod := range data.SlashingPeriods {
|
||||||
keeper.addOrUpdateValidatorSlashingPeriod(ctx, slashingPeriod)
|
keeper.SetValidatorSlashingPeriod(ctx, slashingPeriod)
|
||||||
}
|
}
|
||||||
|
|
||||||
keeper.paramspace.SetParamSet(ctx, &data.Params)
|
keeper.paramspace.SetParamSet(ctx, &data.Params)
|
||||||
|
|
|
@ -28,14 +28,14 @@ func (k Keeper) onValidatorBonded(ctx sdk.Context, address sdk.ConsAddress, _ sd
|
||||||
EndHeight: 0,
|
EndHeight: 0,
|
||||||
SlashedSoFar: sdk.ZeroDec(),
|
SlashedSoFar: sdk.ZeroDec(),
|
||||||
}
|
}
|
||||||
k.addOrUpdateValidatorSlashingPeriod(ctx, slashingPeriod)
|
k.SetValidatorSlashingPeriod(ctx, slashingPeriod)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the slashing period as having ended when a validator begins unbonding
|
// Mark the slashing period as having ended when a validator begins unbonding
|
||||||
func (k Keeper) onValidatorBeginUnbonding(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress) {
|
func (k Keeper) onValidatorBeginUnbonding(ctx sdk.Context, address sdk.ConsAddress, _ sdk.ValAddress) {
|
||||||
slashingPeriod := k.getValidatorSlashingPeriodForHeight(ctx, address, ctx.BlockHeight())
|
slashingPeriod := k.getValidatorSlashingPeriodForHeight(ctx, address, ctx.BlockHeight())
|
||||||
slashingPeriod.EndHeight = ctx.BlockHeight()
|
slashingPeriod.EndHeight = ctx.BlockHeight()
|
||||||
k.addOrUpdateValidatorSlashingPeriod(ctx, slashingPeriod)
|
k.SetValidatorSlashingPeriod(ctx, slashingPeriod)
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a validator is created, add the address-pubkey relation.
|
// When a validator is created, add the address-pubkey relation.
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (k Keeper) capBySlashingPeriod(ctx sdk.Context, address sdk.ConsAddress, fr
|
||||||
|
|
||||||
// Update the slashing period struct
|
// Update the slashing period struct
|
||||||
slashingPeriod.SlashedSoFar = totalToSlash
|
slashingPeriod.SlashedSoFar = totalToSlash
|
||||||
k.addOrUpdateValidatorSlashingPeriod(ctx, slashingPeriod)
|
k.SetValidatorSlashingPeriod(ctx, slashingPeriod)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func (k Keeper) DeleteValidatorSlashingPeriods(ctx sdk.Context) {
|
||||||
// This function sets a validator slashing period for a particular validator,
|
// This function sets a validator slashing period for a particular validator,
|
||||||
// start height, end height, and current slashed-so-far total, or updates
|
// start height, end height, and current slashed-so-far total, or updates
|
||||||
// an existing slashing period for the same validator and start height.
|
// an existing slashing period for the same validator and start height.
|
||||||
func (k Keeper) addOrUpdateValidatorSlashingPeriod(ctx sdk.Context, slashingPeriod ValidatorSlashingPeriod) {
|
func (k Keeper) SetValidatorSlashingPeriod(ctx sdk.Context, slashingPeriod ValidatorSlashingPeriod) {
|
||||||
slashingPeriodValue := ValidatorSlashingPeriodValue{
|
slashingPeriodValue := ValidatorSlashingPeriodValue{
|
||||||
EndHeight: slashingPeriod.EndHeight,
|
EndHeight: slashingPeriod.EndHeight,
|
||||||
SlashedSoFar: slashingPeriod.SlashedSoFar,
|
SlashedSoFar: slashingPeriod.SlashedSoFar,
|
||||||
|
|
|
@ -19,7 +19,7 @@ func TestGetSetValidatorSlashingPeriod(t *testing.T) {
|
||||||
EndHeight: height + 10,
|
EndHeight: height + 10,
|
||||||
SlashedSoFar: sdk.ZeroDec(),
|
SlashedSoFar: sdk.ZeroDec(),
|
||||||
}
|
}
|
||||||
keeper.addOrUpdateValidatorSlashingPeriod(ctx, newPeriod)
|
keeper.SetValidatorSlashingPeriod(ctx, newPeriod)
|
||||||
|
|
||||||
// Get at start height
|
// Get at start height
|
||||||
retrieved := keeper.getValidatorSlashingPeriodForHeight(ctx, addr, height)
|
retrieved := keeper.getValidatorSlashingPeriodForHeight(ctx, addr, height)
|
||||||
|
@ -34,12 +34,12 @@ func TestGetSetValidatorSlashingPeriod(t *testing.T) {
|
||||||
|
|
||||||
// Get after end height (panic)
|
// Get after end height (panic)
|
||||||
newPeriod.EndHeight = int64(4)
|
newPeriod.EndHeight = int64(4)
|
||||||
keeper.addOrUpdateValidatorSlashingPeriod(ctx, newPeriod)
|
keeper.SetValidatorSlashingPeriod(ctx, newPeriod)
|
||||||
require.Panics(t, func() { keeper.capBySlashingPeriod(ctx, addr, sdk.ZeroDec(), height) })
|
require.Panics(t, func() { keeper.capBySlashingPeriod(ctx, addr, sdk.ZeroDec(), height) })
|
||||||
|
|
||||||
// Back to old end height
|
// Back to old end height
|
||||||
newPeriod.EndHeight = height + 10
|
newPeriod.EndHeight = height + 10
|
||||||
keeper.addOrUpdateValidatorSlashingPeriod(ctx, newPeriod)
|
keeper.SetValidatorSlashingPeriod(ctx, newPeriod)
|
||||||
|
|
||||||
// Set a new, later period
|
// Set a new, later period
|
||||||
anotherPeriod := ValidatorSlashingPeriod{
|
anotherPeriod := ValidatorSlashingPeriod{
|
||||||
|
@ -48,7 +48,7 @@ func TestGetSetValidatorSlashingPeriod(t *testing.T) {
|
||||||
EndHeight: height + 11,
|
EndHeight: height + 11,
|
||||||
SlashedSoFar: sdk.ZeroDec(),
|
SlashedSoFar: sdk.ZeroDec(),
|
||||||
}
|
}
|
||||||
keeper.addOrUpdateValidatorSlashingPeriod(ctx, anotherPeriod)
|
keeper.SetValidatorSlashingPeriod(ctx, anotherPeriod)
|
||||||
|
|
||||||
// Old period retrieved for prior height
|
// Old period retrieved for prior height
|
||||||
retrieved = keeper.getValidatorSlashingPeriodForHeight(ctx, addr, height)
|
retrieved = keeper.getValidatorSlashingPeriodForHeight(ctx, addr, height)
|
||||||
|
@ -69,7 +69,7 @@ func TestValidatorSlashingPeriodCap(t *testing.T) {
|
||||||
EndHeight: height + 10,
|
EndHeight: height + 10,
|
||||||
SlashedSoFar: sdk.ZeroDec(),
|
SlashedSoFar: sdk.ZeroDec(),
|
||||||
}
|
}
|
||||||
keeper.addOrUpdateValidatorSlashingPeriod(ctx, newPeriod)
|
keeper.SetValidatorSlashingPeriod(ctx, newPeriod)
|
||||||
half := sdk.NewDec(1).Quo(sdk.NewDec(2))
|
half := sdk.NewDec(1).Quo(sdk.NewDec(2))
|
||||||
|
|
||||||
// First slash should be full
|
// First slash should be full
|
||||||
|
|
Loading…
Reference in New Issue