Params definition for PSE module with excluded addresses#11
Conversation
ysv
left a comment
There was a problem hiding this comment.
@ysv reviewed 23 of 23 files at r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @miladz68)
proto/tx/pse/v1/params.proto line 12 at r1 (raw file):
message Params { // excluded_addresses is a list of addresses excluded from PSE distribution. // This list includes module accounts and other addresses that should not receive PSE rewards.
good point about module accounts.
Should we exclude them by default (independently on this list) or add them to this list ?
Code quote:
// This list includes module accounts and other addresses that should not receive PSE rewards.x/pse/keeper/params.go line 34 at r1 (raw file):
ctx context.Context, authority string, addressesToAdd, addressesToRemove []string,
what if
- addressesToAdd contains duplicate ?
- what if address is included in both ToAdd & ToRemove
TxCorpi0x
left a comment
There was a problem hiding this comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @miladz68 and @ysv)
proto/tx/pse/v1/params.proto line 12 at r1 (raw file):
Previously, ysv (Yaroslav Savchuk) wrote…
good point about module accounts.
Should we exclude them by default (independently on this list) or add them to this list ?
We have two ways:
- Append a list of addresses in the blockchain startup
- Include the addresses in the list in the upgrade handlers
x/pse/keeper/params.go line 34 at r1 (raw file):
Previously, ysv (Yaroslav Savchuk) wrote…
what if
- addressesToAdd contains duplicate ?
- what if address is included in both ToAdd & ToRemove
Two layers of validation in ValidateBasic and Params validation prevents all of wrong data scenarios, there are also tests in types and keeper packages.
miladz68
left a comment
There was a problem hiding this comment.
@miladz68 reviewed 23 of 23 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @ysv)
proto/tx/pse/v1/params.proto line 12 at r1 (raw file):
Previously, TxCorpi0x wrote…
We have two ways:
- Append a list of addresses in the blockchain startup
- Include the addresses in the list in the upgrade handlers
I don't think module accounts should be part of this param field. they should be dynamically appended on demand.
x/pse/module.go line 111 at r1 (raw file):
// InitGenesis performs genesis initialization for the module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
you should add genesis test.
There was a problem hiding this comment.
Pull Request Overview
This PR implements a governance-controlled parameter system for the PSE module, specifically to manage a list of excluded addresses. The main changes replace a generic MsgUpdateParams with a more specific MsgUpdateExcludedAddresses message that allows governance to add and remove addresses from an exclusion list.
- Introduces a new
Paramsprotobuf message containing anexcluded_addressesfield - Replaces
MsgUpdateParamswithMsgUpdateExcludedAddressesto handle incremental updates - Implements keeper methods for parameter management and genesis state handling
Reviewed Changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| x/pse/types/tx.pb.go | Generated code for renamed message with new address list fields |
| x/pse/types/query.pb.go | Generated code adding Params field to query response |
| x/pse/types/params_test.go | New test file validating parameter logic and address validation |
| x/pse/types/params.pb.go | New generated file for Params message |
| x/pse/types/params.go | Implements validation logic for excluded addresses |
| x/pse/types/msg.go | Updated message validation with duplicate and conflict checks |
| x/pse/types/key.go | Adds ParamsKey and shifts existing key prefixes |
| x/pse/types/genesis.pb.go | Generated code adding Params to genesis state |
| x/pse/types/genesis.go | Updates genesis handling to include params |
| x/pse/types/errors.go | Adds new error types for authority and genesis handling |
| x/pse/module.go | Implements InitGenesis and ExportGenesis with error handling |
| x/pse/keeper/params_test.go | Tests for keeper parameter operations |
| x/pse/keeper/params.go | Keeper methods for params management |
| x/pse/keeper/msg_server.go | Message server implementation for excluded addresses |
| x/pse/keeper/keeper.go | Adds Params collection to keeper |
| x/pse/keeper/grpc.go | Implements params query handler |
| x/pse/keeper/genesis_test.go | Tests for genesis import/export |
| x/pse/keeper/genesis.go | Genesis initialization and export logic |
| x/deterministicgas/spec/README.md | Updates message reference in documentation |
| x/deterministicgas/config.go | Updates message reference in config |
| proto files | Proto definitions for new params structure |
| docs/api.md | Updated API documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // excluded_addresses is a list of addresses excluded from PSE distribution. | ||
| // This list includes account addresses that should not receive PSE rewards. | ||
| // Can be modified via governance proposals. | ||
| repeated string excluded_addresses = 2 [ |
There was a problem hiding this comment.
The field number is 2, but there is no field 1 in the Params message. This creates a gap in field numbering which could indicate a removed field or an unintentional skip. Field numbers should typically be sequential starting from 1 unless there's a specific reason for the gap. Consider using field number 1 unless field 1 was previously used and removed for backwards compatibility reasons.
| repeated string excluded_addresses = 2 [ | |
| repeated string excluded_addresses = 1 [ |
| params.ExcludedAddresses = lo.Filter(params.ExcludedAddresses, func(addr string, _ int) bool { | ||
| return !slices.Contains(addressesToRemove, addr) |
There was a problem hiding this comment.
The nested loop created by filtering with slices.Contains results in O(n*m) complexity where n is the number of existing addresses and m is the number of addresses to remove. For better performance with larger lists, convert addressesToRemove to a map for O(1) lookups, reducing overall complexity to O(n).
| params.ExcludedAddresses = lo.Filter(params.ExcludedAddresses, func(addr string, _ int) bool { | |
| return !slices.Contains(addressesToRemove, addr) | |
| addressesToRemoveSet := make(map[string]struct{}, len(addressesToRemove)) | |
| for _, addr := range addressesToRemove { | |
| addressesToRemoveSet[addr] = struct{}{} | |
| } | |
| params.ExcludedAddresses = lo.Filter(params.ExcludedAddresses, func(addr string, _ int) bool { | |
| _, found := addressesToRemoveSet[addr] | |
| return !found |
| toActuallyAdd := lo.Filter(addressesToAdd, func(addr string, _ int) bool { | ||
| return !slices.Contains(params.ExcludedAddresses, addr) |
There was a problem hiding this comment.
Similar performance issue with O(n*m) complexity from nested slices.Contains calls. Convert params.ExcludedAddresses to a map for O(1) lookups to improve performance when adding multiple addresses to a large existing list.
| toActuallyAdd := lo.Filter(addressesToAdd, func(addr string, _ int) bool { | |
| return !slices.Contains(params.ExcludedAddresses, addr) | |
| excludedAddrMap := make(map[string]struct{}, len(params.ExcludedAddresses)) | |
| for _, addr := range params.ExcludedAddresses { | |
| excludedAddrMap[addr] = struct{}{} | |
| } | |
| toActuallyAdd := lo.Filter(addressesToAdd, func(addr string, _ int) bool { | |
| _, exists := excludedAddrMap[addr] | |
| return !exists |
TxCorpi0x
left a comment
There was a problem hiding this comment.
Reviewable status: 18 of 25 files reviewed, 6 unresolved discussions (waiting on @copilot, @miladz68, and @ysv)
proto/tx/pse/v1/params.proto line 12 at r1 (raw file):
Previously, miladz68 (milad) wrote…
I don't think module accounts should be part of this param field. they should be dynamically appended on demand.
Removed from the comment.
x/pse/module.go line 111 at r1 (raw file):
Previously, miladz68 (milad) wrote…
you should add genesis test.
Done
|
@TxCorpi0x I've opened a new pull request, #12, to work on those changes. Once the pull request is ready, I'll request review from you. |
ysv
left a comment
There was a problem hiding this comment.
@ysv reviewed 3 of 7 files at r2, 2 of 2 files at r3, 2 of 2 files at r4, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @miladz68 and @TxCorpi0x)
proto/tx/pse/v1/params.proto line 12 at r1 (raw file):
Previously, TxCorpi0x wrote…
Removed from the comment.
so does it mean that we exclude module accounts inside code by default independently on this list ?
@miladz68 do you want to add this details to a task ?
| params.ExcludedAddresses = lo.Filter(params.ExcludedAddresses, func(addr string, _ int) bool { | ||
| return !slices.Contains(addressesToRemove, addr) |
| toActuallyAdd := lo.Filter(addressesToAdd, func(addr string, _ int) bool { | ||
| return !slices.Contains(params.ExcludedAddresses, addr) |
8942b2e to
31fa48a
Compare
TxCorpi0x
left a comment
There was a problem hiding this comment.
Reviewable status: 24 of 25 files reviewed, 3 unresolved discussions (waiting on @miladz68 and @ysv)
| params.ExcludedAddresses = lo.Filter(params.ExcludedAddresses, func(addr string, _ int) bool { | ||
| return !slices.Contains(addressesToRemove, addr) |
| toActuallyAdd := lo.Filter(addressesToAdd, func(addr string, _ int) bool { | ||
| return !slices.Contains(params.ExcludedAddresses, addr) |
miladz68
left a comment
There was a problem hiding this comment.
@miladz68 reviewed 3 of 7 files at r2, 2 of 2 files at r3, 2 of 2 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @TxCorpi0x and @ysv)
proto/tx/pse/v1/params.proto line 12 at r1 (raw file):
Previously, ysv (Yaroslav Savchuk) wrote…
so does it mean that we exclude module accounts inside code by default independently on this list ?
@miladz68 do you want to add this details to a task ?
I will add a task to double check it and make sure we do not forget it.
ysv
left a comment
There was a problem hiding this comment.
@ysv reviewed 1 of 1 files at r5, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @TxCorpi0x)
Description
This pull request introduces a new parameter management system for the PSE module, focusing on a more robust and flexible way to manage excluded addresses via governance. The changes replace the previous generic parameter update mechanism with a dedicated structure and message for updating excluded addresses, and implement full support for storing, querying, and updating these parameters. Comprehensive tests and documentation updates are included.
Parameter Management and Governance
Paramsstructure inparams.prototo hold module parameters, specifically theexcluded_addresseslist, and updated all relevant proto files and documentation to use this structure.MsgUpdateParamswithMsgUpdateExcludedAddresses, a governance message specifically for modifying the list of excluded addresses, and updated all references, handlers, and documentation accordingly.Keeper and Service Implementation
GetParams,SetParams, andUpdateExcludedAddressesmethods, and wired these into the module’s gRPC query and message servers.Genesis and State Management
Paramsstructure, ensuring excluded addresses are properly persisted across chain restarts.Testing and Validation
Error Handling
ErrInvalidAuthorityerror for improved governance security and feedback.Reviewers checklist:
Authors checklist
This change is