-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
params.go
75 lines (62 loc) · 2.15 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
package keeper
import (
"context"
"time"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
)
// SignedBlocksWindow - sliding window for downtime slashing
func (k Keeper) SignedBlocksWindow(ctx context.Context) (int64, error) {
params, err := k.GetParams(ctx)
return params.SignedBlocksWindow, err
}
// MinSignedPerWindow - minimum blocks signed per window
func (k Keeper) MinSignedPerWindow(ctx context.Context) (int64, error) {
params, err := k.GetParams(ctx)
if err != nil {
return 0, err
}
signedBlocksWindow := params.SignedBlocksWindow
minSignedPerWindow := params.MinSignedPerWindow
// NOTE: RoundInt64 will never panic as minSignedPerWindow is
// less than 1.
return minSignedPerWindow.MulInt64(signedBlocksWindow).RoundInt64(), nil
}
// DowntimeJailDuration - Downtime unbond duration
func (k Keeper) DowntimeJailDuration(ctx context.Context) (time.Duration, error) {
params, err := k.GetParams(ctx)
return params.DowntimeJailDuration, err
}
// SlashFractionDoubleSign - fraction of power slashed in case of double sign
func (k Keeper) SlashFractionDoubleSign(ctx context.Context) (sdkmath.LegacyDec, error) {
params, err := k.GetParams(ctx)
return params.SlashFractionDoubleSign, err
}
// SlashFractionDowntime - fraction of power slashed for downtime
func (k Keeper) SlashFractionDowntime(ctx context.Context) (sdkmath.LegacyDec, error) {
params, err := k.GetParams(ctx)
return params.SlashFractionDowntime, err
}
// GetParams returns the current x/slashing module parameters.
func (k Keeper) GetParams(ctx context.Context) (params types.Params, err error) {
store := k.storeService.OpenKVStore(ctx)
bz, err := store.Get(types.ParamsKey)
if err != nil {
return params, err
}
if bz == nil {
return params, nil
}
err = k.cdc.Unmarshal(bz, ¶ms)
return params, err
}
// SetParams sets the x/slashing module parameters.
// CONTRACT: This method performs no validation of the parameters.
func (k Keeper) SetParams(ctx context.Context, params types.Params) error {
store := k.storeService.OpenKVStore(ctx)
bz, err := k.cdc.Marshal(¶ms)
if err != nil {
return err
}
return store.Set(types.ParamsKey, bz)
}