github.com/cosmos/cosmos-sdk@v0.50.10/x/slashing/keeper/params.go (about) 1 package keeper 2 3 import ( 4 "context" 5 "time" 6 7 sdkmath "cosmossdk.io/math" 8 9 "github.com/cosmos/cosmos-sdk/x/slashing/types" 10 ) 11 12 // SignedBlocksWindow - sliding window for downtime slashing 13 func (k Keeper) SignedBlocksWindow(ctx context.Context) (int64, error) { 14 params, err := k.GetParams(ctx) 15 return params.SignedBlocksWindow, err 16 } 17 18 // MinSignedPerWindow - minimum blocks signed per window 19 func (k Keeper) MinSignedPerWindow(ctx context.Context) (int64, error) { 20 params, err := k.GetParams(ctx) 21 if err != nil { 22 return 0, err 23 } 24 25 signedBlocksWindow := params.SignedBlocksWindow 26 minSignedPerWindow := params.MinSignedPerWindow 27 28 // NOTE: RoundInt64 will never panic as minSignedPerWindow is 29 // less than 1. 30 return minSignedPerWindow.MulInt64(signedBlocksWindow).RoundInt64(), nil 31 } 32 33 // DowntimeJailDuration - Downtime unbond duration 34 func (k Keeper) DowntimeJailDuration(ctx context.Context) (time.Duration, error) { 35 params, err := k.GetParams(ctx) 36 return params.DowntimeJailDuration, err 37 } 38 39 // SlashFractionDoubleSign - fraction of power slashed in case of double sign 40 func (k Keeper) SlashFractionDoubleSign(ctx context.Context) (sdkmath.LegacyDec, error) { 41 params, err := k.GetParams(ctx) 42 return params.SlashFractionDoubleSign, err 43 } 44 45 // SlashFractionDowntime - fraction of power slashed for downtime 46 func (k Keeper) SlashFractionDowntime(ctx context.Context) (sdkmath.LegacyDec, error) { 47 params, err := k.GetParams(ctx) 48 return params.SlashFractionDowntime, err 49 } 50 51 // GetParams returns the current x/slashing module parameters. 52 func (k Keeper) GetParams(ctx context.Context) (params types.Params, err error) { 53 store := k.storeService.OpenKVStore(ctx) 54 bz, err := store.Get(types.ParamsKey) 55 if err != nil { 56 return params, err 57 } 58 if bz == nil { 59 return params, nil 60 } 61 62 err = k.cdc.Unmarshal(bz, ¶ms) 63 return params, err 64 } 65 66 // SetParams sets the x/slashing module parameters. 67 // CONTRACT: This method performs no validation of the parameters. 68 func (k Keeper) SetParams(ctx context.Context, params types.Params) error { 69 store := k.storeService.OpenKVStore(ctx) 70 bz, err := k.cdc.Marshal(¶ms) 71 if err != nil { 72 return err 73 } 74 return store.Set(types.ParamsKey, bz) 75 }