Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add basic types for legacy params #23543

Closed
wants to merge 2 commits into from
Closed

Conversation

aljo242
Copy link
Collaborator

@aljo242 aljo242 commented Jan 28, 2025

Add a package in types/legacy where we can add some legacy interfaces that apps may want to use.

In this case, x/params has been removed, but apps may still want to have an exported interface for old migration logic.

Summary by CodeRabbit

  • New Features
    • Introduced a new legacy package with support for parameter validation and migration
    • Added interfaces and types for managing module parameters
    • Created utility functions for parameter set handling and validation

@aljo242 aljo242 added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Jan 28, 2025
@aljo242 aljo242 requested a review from a team as a code owner January 28, 2025 20:04
Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new legacy package in the types directory, focusing on parameter management and migration support. The package defines several key types and interfaces to facilitate parameter validation, including a ValueValidatorFn for validating parameter values, a ParamSetPair for associating parameter keys with values and validation functions, and interfaces like ParamSet and Subspace to standardize parameter handling during migration processes.

Changes

File Change Summary
types/legacy/params.go - Added ValueValidatorFn type for parameter validation
- Introduced ParamSetPair struct with key, value, and validator
- Created NewParamSetPair function for pair creation
- Defined ParamSetPairs slice type
- Added ParamSet interface for parameter set retrieval
- Defined Subspace interface for parameter management

Sequence Diagram

sequenceDiagram
    participant Module
    participant LegacyParams
    participant Validator

    Module->>LegacyParams: Create ParamSetPair
    LegacyParams-->>Module: ParamSetPair instance
    Module->>Validator: Validate parameter value
    Validator-->>Module: Validation result
Loading

The sequence diagram illustrates the basic interaction between a module, legacy parameters, and a validator when creating and validating parameter sets.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -0,0 +1,45 @@
// Package legacy contains types and interfaces that have support removed, but may need to be exported for legacy
Copy link
Member

@julienrbrt julienrbrt Jan 28, 2025

Choose a reason for hiding this comment

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

While x/params is indeed removed from main, its tag remains and is still importable. When do you foresee the need for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This ties the types to the actual sdk import as opposed to some other package. At some point there will be a drift between the version of SDK used in an old tag and what a user is using

Copy link
Member

Choose a reason for hiding this comment

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

Are you going to update x/params to use those then? Otherwise it will be moot.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
types/legacy/params.go (2)

12-22: Add documentation for ValueValidatorFn behavior.

The ValueValidatorFn type would benefit from documentation explaining:

  • Expected validation behavior
  • Return error conditions
  • Common use cases

29-30: Enhance type documentation.

The current comment "Slice of KeyFieldPair" could be more descriptive. Consider documenting:

  • The purpose of grouping ParamSetPairs
  • Common usage patterns
  • Any slice-specific behaviors
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2027bf and d0aad66.

📒 Files selected for processing (1)
  • types/legacy/params.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
types/legacy/params.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: tests (01)
  • GitHub Check: tests (00)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-system-v2
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: test-integration
  • GitHub Check: build (arm64)
  • GitHub Check: Analyze
  • GitHub Check: build (amd64)
  • GitHub Check: golangci-lint
  • GitHub Check: Summary
🔇 Additional comments (4)
types/legacy/params.go (4)

1-7: Well-documented package purpose and clean imports!

The package documentation clearly explains its purpose for legacy support and migration, following Go conventions.


32-35: Clean interface definition!

The ParamSet interface is well-documented and follows Go interface design best practices.


37-45: Review GetParamSet method signature.

The GetParamSet method appears to be missing a return value or error handling. For a getter method, consider:

  1. Adding a return value
  2. Adding error handling
  3. Renaming to SetParamSet if it's meant to be a setter

Let's check the original implementation this interface is based on:


17-21: Consider adding field tags for serialization.

The ParamSetPair struct might need serialization support for persistence or network communication. Consider adding appropriate tags (e.g., json, yaml) to the fields.

Let's check if other similar structs in the codebase use serialization tags:

Comment on lines +24 to +27
// NewParamSetPair creates a new ParamSetPair instance.
func NewParamSetPair(key []byte, value interface{}, vfn ValueValidatorFn) ParamSetPair {
return ParamSetPair{key, value, vfn}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add input validation to constructor.

The NewParamSetPair function should validate its inputs:

  • Ensure key is not nil/empty
  • Validate value is not nil
  • Verify vfn is not nil

Here's a suggested implementation:

 func NewParamSetPair(key []byte, value interface{}, vfn ValueValidatorFn) ParamSetPair {
+    if len(key) == 0 {
+        panic("parameter key cannot be empty")
+    }
+    if value == nil {
+        panic("parameter value cannot be nil")
+    }
+    if vfn == nil {
+        panic("validator function cannot be nil")
+    }
     return ParamSetPair{key, value, vfn}
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// NewParamSetPair creates a new ParamSetPair instance.
func NewParamSetPair(key []byte, value interface{}, vfn ValueValidatorFn) ParamSetPair {
return ParamSetPair{key, value, vfn}
}
// NewParamSetPair creates a new ParamSetPair instance.
func NewParamSetPair(key []byte, value interface{}, vfn ValueValidatorFn) ParamSetPair {
if len(key) == 0 {
panic("parameter key cannot be empty")
}
if value == nil {
panic("parameter value cannot be nil")
}
if vfn == nil {
panic("validator function cannot be nil")
}
return ParamSetPair{key, value, vfn}
}


// ParamSet defines an interface for structs containing parameters for a module
type ParamSet interface {
ParamSetPairs() ParamSetPairs
Copy link
Member

Choose a reason for hiding this comment

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

because of the type redefinition of this interface, you won't be able to just swap for this. x/params would need to be updated to use this, or it needs to be using structural typing instead.

@aljo242 aljo242 closed this Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants