Adding Onchain Module Parameters
Adding Onchain Module Parameters
Adding a new onchain module parameter involves multiple steps to ensure the parameter is properly integrated into the system. This guide walks through a generic approach, illustrated by adding a parameter to the proof module.
See https://github.com/pokt-network/poktroll/pull/595 for a real-world example.
The steps below follow the same example where:
Module name:
examplemodNew parameter name:
new_parameterDefault value:
int64(42)
Substitute these example values with your own when following the steps.
At any point, you can run:
```bash go test ./x/examplemod/... ``` to check whether everything is working or to locate outstanding necessary changes. ``` {% endhint %}
{% stepper %}
{% step %}
If the Module Doesn't Already Support a MsgUpdateParam Message
In order to support individual parameter updates, the module MUST have a MsgUpdateParam message. If the module doesn't support this message, add it.
Scaffold the MsgUpdateParam Message
MsgUpdateParam MessageUse ignite to scaffold a new MsgUpdateParam message for the module.
Temporary Workaround Required:
Rename the local go module in go.mod (see related comments there)
go mod tidyignite scaffold ...make proto_regenRestore the original go.mod
go mod tidymake ignite_buildand/or (re)start/build localnet
Update MsgUpdateParam and MsgUpdateParamResponse Fields
MsgUpdateParam and MsgUpdateParamResponse FieldsUpdate the module's tx.proto (e.g. proto/pocket/examplemod/tx.proto) to include comments and protobuf options:
Comment Out AutoCLI
When scaffolding, generated code is added to x/examplemod/module/autocli.go. Since governance parameters aren't updated via pocketd CLI, comment out the generated Tx command lines:
Update the DAO Genesis Authorizations JSON File
Add a grant to tools/scripts/authz/localnet_genesis_authorizations.json with the authorization.msg typeURL for this module's MsgUpdateParam:
Update the NewMsgUpdateParam Constructor and MsgUpdateParam#ValidateBasic()
NewMsgUpdateParam Constructor and MsgUpdateParam#ValidateBasic()Prepare x/examplemod/types/message_update_param.go:
Update the Module's msgServer#UpdateParam() Handler
Prepare x/examplemod/keeper/msg_server_update_param.go to handle updates by type:
Update Module's Params Test Suite ModuleParamConfig
Add MsgUpdateParam & MsgUpdateParamResponse to the module's ModuleParamConfig#ParamsMsg in testutil/integration/suites/param_config.go:
{% endstep %}
{% step %}
Define the Parameter in the Protocol Buffers File
Define the new parameter in the module's params.proto (e.g., proto/pocket/examplemod/params.proto):
{% hint style="warning" %} Be sure to update the gogoproto.jsontag and gogoproto.moretags option values to match the new parameter name! {% endhint %}
{% hint style="info" %} Don't forget to run: {% code title="Regenerate protobuf code" %}
{% endhint %}
{% endstep %}
{% step %}
Update the Default Parameter Values
Go Source Defaults
In x/examplemod/types/params.go, define the key, param name, default, and include it in NewParams and DefaultParams:
Genesis Configuration Parameter Defaults
Add the new parameter to the genesis configuration file (e.g., config.yml):
{% endstep %}
{% step %}
Parameter Validation
Define a Validation Function
Implement a validation function in x/examplemod/types/params.go:
Call it in Params#Validate()
Integrate the validator into Params#Validate():
Add a ParamSetPair to ParamSetPairs()
Include the pair in ParamSetPairs():
{% endstep %}
{% step %}
Add Parameter Case to Switch Statements
MsgUpdateParam#ValidateBasic()
Add the parameter type and name to switch statements in NewMsgUpdateParam() and MsgUpdateParam#ValidateBasic():
msgServer#UpdateParam()
Add the parameter name to the switch in msgServer#UpdateParam() (in x/examplemod/keeper/msg_server_update_param.go):
{% hint style="warning" %} Every error return from msgServer methods (e.g. UpdateParams) SHOULD be encapsulated in a gRPC status error. {% endhint %}
{% endstep %}
{% step %}
Update Unit Tests
Parameter Validation Tests
Add validation tests in x/examplemod/keeper/params_test.go:
Parameter Update Tests
Add cases to x/examplemod/keeper/msg_update_params_test.go for invalid combinations and minimal params:
Add a unit test to exercise individually updating the new parameter in x/examplemod/keeper/msg_server_update_param_test.go:
{% hint style="warning" %} If creating msg_server_update_param_test.go, be sure to:
use the
keeper_testpackage (i.e.package keeper_test).add the testutil keeper import:
testkeeper "github.com/pokt-network/poktroll/testutil/keeper"{% endhint %}
Also update x/examplemod/types/message_update_param_test.go to use the new MsgUpdateParam#AsType fields and include cases covering invalid values:
{% endstep %}
{% step %}
Update the Parameter Integration Tests
Integration tests use ModuleParamConfig in testutil/integration/suites/param_configs.go to dynamically construct and send parameter update messages. When adding parameters, update the module's ModuleParamConfig.
Add a valid param
Update ModuleParamConfig#ValidParams to include a valid non-default value:
Check for as_ on MsgUpdateParam
Ensure an as_<type> field exists on MsgUpdateParam corresponding to the type (e.g., int64) in proto/pocket/examplemod/tx.proto:
Update the module's ModuleParamConfig
Ensure all available as_<type> types for the module are present on ModuleParamConfig#ParamTypes:
{% endstep %}
{% step %}
Update the Makefile and Supporting JSON Files
Update the Makefile
Add a new target in makefiles/params.mk:
{% hint style="warning" %} Reminder to substitute examplemod and new_parameter with your module and param names! {% endhint %}
Create a new JSON File for the Individual Parameter Update
Create e.g. tools/scripts/params/proof_new_parameter_name.json:
Update the JSON File for Updating All Parameters for the Module
Add the new parameter default to the module's MsgUpdateParams JSON file (e.g., proof_all.json):
Was this helpful?
