cosmos-sdk/x/staking/keeper/params.go
mergify[bot] af357c8d30
chore(x/staking): audit changes (backport #16795) (#16815)
Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
2023-07-03 08:04:12 +00:00

85 lines
2.4 KiB
Go

package keeper
import (
"context"
"time"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
// UnbondingTime - The time duration for unbonding
func (k Keeper) UnbondingTime(ctx context.Context) (time.Duration, error) {
params, err := k.GetParams(ctx)
return params.UnbondingTime, err
}
// MaxValidators - Maximum number of validators
func (k Keeper) MaxValidators(ctx context.Context) (uint32, error) {
params, err := k.GetParams(ctx)
return params.MaxValidators, err
}
// MaxEntries - Maximum number of simultaneous unbonding
// delegations or redelegations (per pair/trio)
func (k Keeper) MaxEntries(ctx context.Context) (uint32, error) {
params, err := k.GetParams(ctx)
return params.MaxEntries, err
}
// HistoricalEntries = number of historical info entries
// to persist in store
func (k Keeper) HistoricalEntries(ctx context.Context) (uint32, error) {
params, err := k.GetParams(ctx)
return params.HistoricalEntries, err
}
// BondDenom - Bondable coin denomination
func (k Keeper) BondDenom(ctx context.Context) (string, error) {
params, err := k.GetParams(ctx)
return params.BondDenom, err
}
// PowerReduction - is the amount of staking tokens required for 1 unit of consensus-engine power.
// Currently, this returns a global variable that the app developer can tweak.
// TODO: we might turn this into an on-chain param:
// https://github.com/cosmos/cosmos-sdk/issues/8365
func (k Keeper) PowerReduction(ctx context.Context) math.Int {
return sdk.DefaultPowerReduction
}
// MinCommissionRate - Minimum validator commission rate
func (k Keeper) MinCommissionRate(ctx context.Context) (math.LegacyDec, error) {
params, err := k.GetParams(ctx)
return params.MinCommissionRate, err
}
// SetParams sets the x/staking 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(&params)
if err != nil {
return err
}
return store.Set(types.ParamsKey, bz)
}
// GetParams gets the x/staking 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, &params)
return params, err
}