forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
params.go
80 lines (62 loc) · 2.94 KB
/
params.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package slashing
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// 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) time.Duration {
return time.Duration(k.params.GetInt64WithDefault(ctx, MaxEvidenceAgeKey, defaultMaxEvidenceAge)) * time.Second
}
// 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) time.Duration {
return time.Duration(k.params.GetInt64WithDefault(ctx, DoubleSignUnbondDurationKey, defaultDoubleSignUnbondDuration)) * time.Second
}
// Downtime unbond duration
func (k Keeper) DowntimeUnbondDuration(ctx sdk.Context) time.Duration {
return time.Duration(k.params.GetInt64WithDefault(ctx, DowntimeUnbondDurationKey, defaultDowntimeUnbondDuration)) * time.Second
}
// 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
var (
// defaultMaxEvidenceAge = 60 * 60 * 24 * 7 * 3
// TODO Temporarily set to 2 minutes for testnets.
defaultMaxEvidenceAge int64 = 60 * 2
// TODO Temporarily set to five minutes for testnets
defaultDoubleSignUnbondDuration int64 = 60 * 5
// TODO Temporarily set to 10000 blocks for testnets
defaultSignedBlocksWindow int64 = 10000
// TODO Temporarily set to 10 minutes for testnets
defaultDowntimeUnbondDuration int64 = 60 * 10
defaultMinSignedPerWindow = sdk.NewRat(1, 2)
defaultSlashFractionDoubleSign = sdk.NewRat(1).Quo(sdk.NewRat(20))
defaultSlashFractionDowntime = sdk.NewRat(1).Quo(sdk.NewRat(100))
)