2019-07-19 06:43:38 -07:00
|
|
|
package keeper
|
2018-05-28 14:24:58 -07:00
|
|
|
|
|
|
|
import (
|
2018-08-12 00:33:48 -07:00
|
|
|
"time"
|
|
|
|
|
2018-05-28 14:24:58 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-07-19 06:43:38 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/internal/types"
|
2018-05-28 14:24:58 -07:00
|
|
|
)
|
|
|
|
|
2018-07-13 17:12:23 -07:00
|
|
|
// SignedBlocksWindow - sliding window for downtime slashing
|
2018-08-31 02:03:43 -07:00
|
|
|
func (k Keeper) SignedBlocksWindow(ctx sdk.Context) (res int64) {
|
2019-06-05 16:26:17 -07:00
|
|
|
k.paramspace.Get(ctx, types.KeySignedBlocksWindow, &res)
|
2018-08-31 02:03:43 -07:00
|
|
|
return
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2019-07-19 06:43:38 -07:00
|
|
|
// MinSignedPerWindow - minimum blocks signed per window
|
2018-07-13 17:12:23 -07:00
|
|
|
func (k Keeper) MinSignedPerWindow(ctx sdk.Context) int64 {
|
2018-08-31 02:03:43 -07:00
|
|
|
var minSignedPerWindow sdk.Dec
|
2019-06-05 16:26:17 -07:00
|
|
|
k.paramspace.Get(ctx, types.KeyMinSignedPerWindow, &minSignedPerWindow)
|
2018-07-13 17:12:23 -07:00
|
|
|
signedBlocksWindow := k.SignedBlocksWindow(ctx)
|
2019-02-05 21:30:48 -08:00
|
|
|
|
|
|
|
// NOTE: RoundInt64 will never panic as minSignedPerWindow is
|
|
|
|
// less than 1.
|
|
|
|
return minSignedPerWindow.MulInt64(signedBlocksWindow).RoundInt64()
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2019-07-19 06:43:38 -07:00
|
|
|
// DowntimeJailDuration - Downtime unbond duration
|
2019-01-10 17:22:49 -08:00
|
|
|
func (k Keeper) DowntimeJailDuration(ctx sdk.Context) (res time.Duration) {
|
2019-06-05 16:26:17 -07:00
|
|
|
k.paramspace.Get(ctx, types.KeyDowntimeJailDuration, &res)
|
2018-08-31 02:03:43 -07:00
|
|
|
return
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2019-07-19 06:43:38 -07:00
|
|
|
// SlashFractionDoubleSign - fraction of power slashed in case of double sign
|
2018-08-31 02:03:43 -07:00
|
|
|
func (k Keeper) SlashFractionDoubleSign(ctx sdk.Context) (res sdk.Dec) {
|
2019-06-05 16:26:17 -07:00
|
|
|
k.paramspace.Get(ctx, types.KeySlashFractionDoubleSign, &res)
|
2018-08-31 02:03:43 -07:00
|
|
|
return
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
|
|
|
|
2019-07-19 06:43:38 -07:00
|
|
|
// SlashFractionDowntime - fraction of power slashed for downtime
|
2018-08-31 02:03:43 -07:00
|
|
|
func (k Keeper) SlashFractionDowntime(ctx sdk.Context) (res sdk.Dec) {
|
2019-06-05 16:26:17 -07:00
|
|
|
k.paramspace.Get(ctx, types.KeySlashFractionDowntime, &res)
|
2018-08-31 02:03:43 -07:00
|
|
|
return
|
2018-07-13 17:12:23 -07:00
|
|
|
}
|
2018-12-14 11:09:39 -08:00
|
|
|
|
|
|
|
// GetParams returns the total set of slashing parameters.
|
2019-06-05 16:26:17 -07:00
|
|
|
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
|
2018-12-14 11:09:39 -08:00
|
|
|
k.paramspace.GetParamSet(ctx, ¶ms)
|
|
|
|
return params
|
|
|
|
}
|
2019-07-19 06:43:38 -07:00
|
|
|
|
|
|
|
// SetParams sets the slashing parameters to the param space.
|
|
|
|
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
|
|
|
k.paramspace.SetParamSet(ctx, ¶ms)
|
|
|
|
}
|