2018-05-28 14:24:58 -07:00
|
|
|
package slashing
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2018-07-13 17:12:23 -07:00
|
|
|
// nolint
|
|
|
|
const (
|
|
|
|
MaxEvidenceAgeKey = "slashing/MaxEvidenceAge"
|
|
|
|
SignedBlocksWindowKey = "slashing/SignedBlocksWindow"
|
|
|
|
MinSignedPerWindowKey = "slashing/MinSignedPerWindow"
|
|
|
|
DoubleSignUnbondDurationKey = "slashing/DoubleSignUnbondDuration"
|
|
|
|
DowntimeUnbondDurationKey = "slashing/DowntimeUnbondDuration"
|
|
|
|
SlashFractionDoubleSignKey = "slashing/SlashFractionDoubleSign"
|
|
|
|
SlashFractionDowntimeKey = "slashing/SlashFractionDowntime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MaxEvidenceAge - Max age for evidence - 21 days (3 weeks)
|
|
|
|
// MaxEvidenceAge = 60 * 60 * 24 * 7 * 3
|
|
|
|
func (k Keeper) MaxEvidenceAge(ctx sdk.Context) int64 {
|
|
|
|
return k.params.GetInt64WithDefault(ctx, MaxEvidenceAgeKey, defaultMaxEvidenceAge)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SignedBlocksWindow - sliding window for downtime slashing
|
|
|
|
func (k Keeper) SignedBlocksWindow(ctx sdk.Context) int64 {
|
|
|
|
return k.params.GetInt64WithDefault(ctx, SignedBlocksWindowKey, defaultSignedBlocksWindow)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Downtime slashing thershold - default 50%
|
|
|
|
func (k Keeper) MinSignedPerWindow(ctx sdk.Context) int64 {
|
|
|
|
minSignedPerWindow := k.params.GetRatWithDefault(ctx, MinSignedPerWindowKey, defaultMinSignedPerWindow)
|
|
|
|
signedBlocksWindow := k.SignedBlocksWindow(ctx)
|
|
|
|
return sdk.NewRat(signedBlocksWindow).Mul(minSignedPerWindow).RoundInt64()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Double-sign unbond duration
|
|
|
|
func (k Keeper) DoubleSignUnbondDuration(ctx sdk.Context) int64 {
|
|
|
|
return k.params.GetInt64WithDefault(ctx, DoubleSignUnbondDurationKey, defaultDoubleSignUnbondDuration)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Downtime unbond duration
|
|
|
|
func (k Keeper) DowntimeUnbondDuration(ctx sdk.Context) int64 {
|
|
|
|
return k.params.GetInt64WithDefault(ctx, DowntimeUnbondDurationKey, defaultDowntimeUnbondDuration)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SlashFractionDoubleSign - currently default 5%
|
|
|
|
func (k Keeper) SlashFractionDoubleSign(ctx sdk.Context) sdk.Rat {
|
|
|
|
return k.params.GetRatWithDefault(ctx, SlashFractionDoubleSignKey, defaultSlashFractionDoubleSign)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SlashFractionDowntime - currently default 1%
|
|
|
|
func (k Keeper) SlashFractionDowntime(ctx sdk.Context) sdk.Rat {
|
|
|
|
return k.params.GetRatWithDefault(ctx, SlashFractionDowntimeKey, defaultSlashFractionDowntime)
|
|
|
|
}
|
|
|
|
|
|
|
|
// declared as var because of keeper_test.go
|
|
|
|
// TODO: make it const or parameter of NewKeeper
|
|
|
|
|
2018-06-29 20:34:55 -07:00
|
|
|
var (
|
2018-07-13 17:12:23 -07:00
|
|
|
// defaultMaxEvidenceAge = 60 * 60 * 24 * 7 * 3
|
2018-05-28 14:24:58 -07:00
|
|
|
// TODO Temporarily set to 2 minutes for testnets.
|
2018-07-13 17:12:23 -07:00
|
|
|
defaultMaxEvidenceAge int64 = 60 * 2
|
2018-05-28 14:24:58 -07:00
|
|
|
|
2018-07-13 17:12:23 -07:00
|
|
|
// TODO Temporarily set to five minutes for testnets
|
|
|
|
defaultDoubleSignUnbondDuration int64 = 60 * 5
|
2018-05-28 14:24:58 -07:00
|
|
|
|
2018-07-13 17:12:23 -07:00
|
|
|
// TODO Temporarily set to 100 blocks for testnets
|
|
|
|
defaultSignedBlocksWindow int64 = 100
|
2018-05-28 14:24:58 -07:00
|
|
|
|
2018-07-13 17:12:23 -07:00
|
|
|
// TODO Temporarily set to 10 minutes for testnets
|
|
|
|
defaultDowntimeUnbondDuration int64 = 60 * 10
|
2018-06-29 20:34:55 -07:00
|
|
|
|
2018-07-17 13:59:06 -07:00
|
|
|
defaultMinSignedPerWindow = sdk.NewRat(1, 2)
|
2018-05-28 14:24:58 -07:00
|
|
|
|
2018-07-13 17:12:23 -07:00
|
|
|
defaultSlashFractionDoubleSign = sdk.NewRat(1).Quo(sdk.NewRat(20))
|
2018-05-28 14:24:58 -07:00
|
|
|
|
2018-07-13 17:12:23 -07:00
|
|
|
defaultSlashFractionDowntime = sdk.NewRat(1).Quo(sdk.NewRat(100))
|
2018-05-28 14:24:58 -07:00
|
|
|
)
|