-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Conversation
📝 WalkthroughWalkthroughThe changes introduce a new Changes
Sequence DiagramsequenceDiagram
participant Module
participant LegacyParams
participant Validator
Module->>LegacyParams: Create ParamSetPair
LegacyParams-->>Module: ParamSetPair instance
Module->>Validator: Validate parameter value
Validator-->>Module: Validation result
The sequence diagram illustrates the basic interaction between a module, legacy parameters, and a validator when creating and validating parameter sets. ✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
@@ -0,0 +1,45 @@ | |||
// Package legacy contains types and interfaces that have support removed, but may need to be exported for legacy |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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
📒 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:
- Adding a return value
- Adding error handling
- Renaming to
SetParamSet
if it's meant to be a setterLet'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:
// NewParamSetPair creates a new ParamSetPair instance. | ||
func NewParamSetPair(key []byte, value interface{}, vfn ValueValidatorFn) ParamSetPair { | ||
return ParamSetPair{key, value, vfn} | ||
} |
There was a problem hiding this comment.
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.
// 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 |
There was a problem hiding this comment.
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.
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
legacy
package with support for parameter validation and migration