Skip to content

Params definition for PSE module with excluded addresses#11

Merged
TxCorpi0x merged 8 commits into
masterfrom
mehdi/pse-excluded-addresses
Nov 4, 2025
Merged

Params definition for PSE module with excluded addresses#11
TxCorpi0x merged 8 commits into
masterfrom
mehdi/pse-excluded-addresses

Conversation

@TxCorpi0x

@TxCorpi0x TxCorpi0x commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

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

  • Introduced a new Params structure in params.proto to hold module parameters, specifically the excluded_addresses list, and updated all relevant proto files and documentation to use this structure.
  • Replaced the generic MsgUpdateParams with MsgUpdateExcludedAddresses, a governance message specifically for modifying the list of excluded addresses, and updated all references, handlers, and documentation accordingly.

Keeper and Service Implementation

  • Added full keeper support for parameter storage and manipulation, including GetParams, SetParams, and UpdateExcludedAddresses methods, and wired these into the module’s gRPC query and message servers.

Genesis and State Management

  • Updated genesis handling to initialize and export the new Params structure, ensuring excluded addresses are properly persisted across chain restarts.

Testing and Validation

  • Added comprehensive unit tests for parameter get/set and excluded address update logic, including authority checks and edge cases.

Error Handling

  • Introduced a new ErrInvalidAuthority error for improved governance security and feedback.

Reviewers checklist:

  • Try to write more meaningful comments with clear actions to be taken.
  • Nit-picking should be unblocking. Focus on core issues.

Authors checklist

  • Provide a concise and meaningful description
  • Review the code yourself first, before making the PR.
  • Annotate your PR in places that require explanation.
  • Think and try to split the PR to smaller PR if it is big.

This change is Reviewable

@TxCorpi0x TxCorpi0x requested a review from a team as a code owner October 31, 2025 14:10
@TxCorpi0x TxCorpi0x requested a review from miladz68 October 31, 2025 14:10
@TxCorpi0x TxCorpi0x changed the title Params definition for PSE module with exluded addresses Params definition for PSE module with excluded addresses Oct 31, 2025
@ysv ysv self-requested a review October 31, 2025 15:30

@ysv ysv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

  1. addressesToAdd contains duplicate ?
  2. what if address is included in both ToAdd & ToRemove

@TxCorpi0x TxCorpi0x left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Append a list of addresses in the blockchain startup
  2. 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

  1. addressesToAdd contains duplicate ?
  2. 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 miladz68 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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:

  1. Append a list of addresses in the blockchain startup
  2. 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.

Copilot AI review requested due to automatic review settings November 3, 2025 15:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Params protobuf message containing an excluded_addresses field
  • Replaces MsgUpdateParams with MsgUpdateExcludedAddresses to 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.

Comment thread proto/tx/pse/v1/params.proto Outdated
// 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 [

Copilot AI Nov 3, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
repeated string excluded_addresses = 2 [
repeated string excluded_addresses = 1 [

Copilot uses AI. Check for mistakes.
Comment thread x/pse/keeper/params.go Outdated
Comment on lines +47 to +48
params.ExcludedAddresses = lo.Filter(params.ExcludedAddresses, func(addr string, _ int) bool {
return !slices.Contains(addressesToRemove, addr)

Copilot AI Nov 3, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread x/pse/keeper/params.go Outdated
Comment on lines +52 to +53
toActuallyAdd := lo.Filter(addressesToAdd, func(addr string, _ int) bool {
return !slices.Contains(params.ExcludedAddresses, addr)

Copilot AI Nov 3, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@TxCorpi0x TxCorpi0x left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot AI commented Nov 3, 2025

Copy link
Copy Markdown

@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 ysv requested a review from miladz68 November 3, 2025 16:13

@ysv ysv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 ?

Comment thread x/pse/keeper/params.go Outdated
Comment on lines +47 to +48
params.ExcludedAddresses = lo.Filter(params.ExcludedAddresses, func(addr string, _ int) bool {
return !slices.Contains(addressesToRemove, addr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

Comment thread x/pse/keeper/params.go Outdated
Comment on lines +52 to +53
toActuallyAdd := lo.Filter(addressesToAdd, func(addr string, _ int) bool {
return !slices.Contains(params.ExcludedAddresses, addr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

@TxCorpi0x TxCorpi0x force-pushed the mehdi/pse-excluded-addresses branch from 8942b2e to 31fa48a Compare November 3, 2025 16:57

@TxCorpi0x TxCorpi0x left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 24 of 25 files reviewed, 3 unresolved discussions (waiting on @miladz68 and @ysv)

Comment thread x/pse/keeper/params.go Outdated
Comment on lines +47 to +48
params.ExcludedAddresses = lo.Filter(params.ExcludedAddresses, func(addr string, _ int) bool {
return !slices.Contains(addressesToRemove, addr)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread x/pse/keeper/params.go Outdated
Comment on lines +52 to +53
toActuallyAdd := lo.Filter(addressesToAdd, func(addr string, _ int) bool {
return !slices.Contains(params.ExcludedAddresses, addr)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@miladz68 miladz68 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 ysv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ysv reviewed 1 of 1 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @TxCorpi0x)

@TxCorpi0x TxCorpi0x merged commit 6a32745 into master Nov 4, 2025
9 checks passed
@ysv ysv deleted the mehdi/pse-excluded-addresses branch December 19, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants