cosmos-sdk/x/params
Marko 38c7c948f5
style: various linting fixes (#15675)
## Description

fix various linting issues

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

* [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
* [ ] added `!` to the type prefix if API or client breaking change
* [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
* [ ] provided a link to the relevant issue or specification
* [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules)
* [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
* [ ] added a changelog entry to `CHANGELOG.md`
* [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
* [ ] updated the relevant documentation or specification
* [ ] reviewed "Files changed" and left comments if necessary
* [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

* [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
* [ ] confirmed `!` in the type prefix if API or client breaking change
* [ ] confirmed all author checklist items have been addressed 
* [ ] reviewed state machine logic
* [ ] reviewed API design and naming
* [ ] reviewed documentation is accurate
* [ ] reviewed tests and test coverage
* [ ] manually tested (if applicable)
2023-04-03 17:00:44 +00:00
..
client test: rename e2e tests (#13913) 2022-12-15 10:55:01 +01:00
keeper style: make lint-fix everything (#15631) 2023-03-30 17:27:39 +00:00
simulation style: various linting fixes (#15675) 2023-04-03 17:00:44 +00:00
testutil refactor: remove unnecessary depinject usage (#15529) 2023-03-23 16:18:41 +00:00
types style: various linting fixes (#15675) 2023-04-03 17:00:44 +00:00
doc.go x/params docs general audit & cleanup (#8295) 2021-01-15 13:30:17 +00:00
module.go style: more linting (#15618) 2023-03-30 13:00:18 +00:00
proposal_handler_test.go style: more linting (#15616) 2023-03-30 12:05:50 +00:00
proposal_handler.go refactor: fix lint issues + gofumpt (#15062) 2023-02-19 10:31:49 +00:00
README.md docs: fix toc links (#13770) 2022-11-04 15:35:22 +00:00

sidebar_position
1

x/params

Note: The Params module has been depreacted in favour of each module housing its own parameters.

Abstract

Package params provides a globally available parameter store.

There are two main types, Keeper and Subspace. Subspace is an isolated namespace for a paramstore, where keys are prefixed by preconfigured spacename. Keeper has a permission to access all existing spaces.

Subspace can be used by the individual keepers, which need a private parameter store that the other keepers cannot modify. The params Keeper can be used to add a route to x/gov router in order to modify any parameter in case a proposal passes.

The following contents explains how to use params module for master and user modules.

Contents

Keeper

In the app initialization stage, subspaces can be allocated for other modules' keeper using Keeper.Subspace and are stored in Keeper.spaces. Then, those modules can have a reference to their specific parameter store through Keeper.GetSubspace.

Example:

type ExampleKeeper struct {
	paramSpace paramtypes.Subspace
}

func (k ExampleKeeper) SetParams(ctx sdk.Context, params types.Params) {
	k.paramSpace.SetParamSet(ctx, &params)
}

Subspace

Subspace is a prefixed subspace of the parameter store. Each module which uses the parameter store will take a Subspace to isolate permission to access.

Key

Parameter keys are human readable alphanumeric strings. A parameter for the key "ExampleParameter" is stored under []byte("SubspaceName" + "/" + "ExampleParameter"), where "SubspaceName" is the name of the subspace.

Subkeys are secondary parameter keys those are used along with a primary parameter key. Subkeys can be used for grouping or dynamic parameter key generation during runtime.

KeyTable

All of the parameter keys that will be used should be registered at the compile time. KeyTable is essentially a map[string]attribute, where the string is a parameter key.

Currently, attribute consists of a reflect.Type, which indicates the parameter type to check that provided key and value are compatible and registered, as well as a function ValueValidatorFn to validate values.

Only primary keys have to be registered on the KeyTable. Subkeys inherit the attribute of the primary key.

ParamSet

Modules often define parameters as a proto message. The generated struct can implement ParamSet interface to be used with the following methods:

  • KeyTable.RegisterParamSet(): registers all parameters in the struct
  • Subspace.{Get, Set}ParamSet(): Get to & Set from the struct

The implementor should be a pointer in order to use GetParamSet().