-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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(x/gov, x/authz): use cosmossdk.io/core/codec instead of github.com/cosmos/cosmos-sdk/codec #23292
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThis pull request focuses on updating codec imports across multiple modules from Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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
|
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
🔭 Outside diff range comments (1)
x/staking/types/validator.go (1)
Line range hint
18-22
: Fix import ordering according to project guidelines.The imports need to be reordered following the pattern: standard libs, default libs, cosmossdk.io prefix, github.com/cosmos/cosmos-sdk prefix.
"cosmossdk.io/errors" "cosmossdk.io/math" - "cosmossdk.io/core/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "cosmossdk.io/core/codec" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"🧰 Tools
🪛 golangci-lint (1.62.2)
18-18: File is not
gci
-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order(gci)
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
x/staking/migrations/v5/store.go
(1 hunks)x/staking/migrations/v6/store.go
(1 hunks)x/staking/types/validator.go
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- x/staking/migrations/v5/store.go
🧰 Additional context used
📓 Path-based instructions (2)
x/staking/migrations/v6/store.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/staking/types/validator.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
🪛 golangci-lint (1.62.2)
x/staking/migrations/v6/store.go
8-8: File is not gci
-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order
(gci)
x/staking/types/validator.go
18-18: File is not gci
-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order
(gci)
🪛 GitHub Actions: Lint
x/staking/migrations/v6/store.go
[error] 6-8: File is not properly formatted with gci. Import ordering needs to follow: --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order
x/staking/types/validator.go
[error] 14-18: File is not properly formatted with gci. Import ordering needs to follow: --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: tests (00)
- GitHub Check: test-simapp-v2
- GitHub Check: test-system-v2
- GitHub Check: Analyze
- GitHub Check: Summary
🔇 Additional comments (2)
x/staking/migrations/v6/store.go (1)
Line range hint
12-19
: LGTM! Migration logic remains unchanged.The codec interface change is compatible, and the store migration logic is unaffected by the import path update.
Let's verify the codec interface compatibility:
✅ Verification successful
Migration code is safe and unaffected by codec changes
The migration function only performs store deletions and doesn't use the codec parameter, making it immune to any codec interface changes.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that both old and new codec packages expose the same BinaryCodec interface rg -A 5 "type BinaryCodec interface"Length of output: 373
Script:
#!/bin/bash # Find storetypes package and its codec usage rg -A 5 "package storetypes" # Find all BinaryCodec interfaces and their usages ast-grep --pattern 'type BinaryCodec interface { $$$ }'Length of output: 295
🧰 Tools
🪛 golangci-lint (1.62.2)
6-6: File is not
gci
-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order(gci)
8-8: File is not
gci
-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order(gci)
🪛 GitHub Actions: Lint
[error] 6-8: File is not properly formatted with gci. Import ordering needs to follow: --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order
x/staking/types/validator.go (1)
Line range hint
147-147
: LGTM! Removal of panic-prone functions improves safety.The removal of
MustMarshalValidator
andMustUnmarshalValidator
functions is a good change as it:
- Eliminates potential panics in production
- Forces proper error handling
- Simplifies the codebase
Let's verify that no code depends on the removed functions:
✅ Verification successful
Confirmed: MustMarshalValidator and MustUnmarshalValidator functions were safely removed
The verification shows that no code in the codebase depends on the removed panic-prone functions. All validator marshaling operations now properly handle errors.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any remaining usage of the removed functions rg "MustMarshalValidator|MustUnmarshalValidator"Length of output: 50
Script:
#!/bin/bash # Search with broader patterns to catch variations rg -i "marshal.*validator|unmarshal.*validator" -A 2 # Use ast-grep to find any function calls related to validator marshaling ast-grep --pattern 'Must$_Marshal$_($$$)' # Search for any validator-related functions with Must prefix rg "Must.*Validator" # Look for any Marshal/Unmarshal functions in validator files fd validator --exec grep -i "marshal" {} \;Length of output: 70973
🧰 Tools
🪛 golangci-lint (1.62.2)
18-18: File is not
gci
-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order(gci)
x/staking/migrations/v6/store.go
Outdated
@@ -5,7 +5,7 @@ import ( | |||
|
|||
storetypes "cosmossdk.io/store/types" | |||
|
|||
"github.com/cosmos/cosmos-sdk/codec" | |||
"cosmossdk.io/core/codec" |
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
Fix import ordering according to project guidelines.
The imports need to be reordered following the pattern: standard libs, default libs, cosmossdk.io prefix, github.com/cosmos/cosmos-sdk prefix.
import (
"context"
storetypes "cosmossdk.io/store/types"
- "cosmossdk.io/core/codec"
+
+ "cosmossdk.io/core/codec"
)
📝 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.
"cosmossdk.io/core/codec" | |
import ( | |
"context" | |
storetypes "cosmossdk.io/store/types" | |
"cosmossdk.io/core/codec" | |
) |
🧰 Tools
🪛 golangci-lint (1.62.2)
8-8: File is not gci
-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order
(gci)
🪛 GitHub Actions: Lint
[error] 6-8: File is not properly formatted with gci. Import ordering needs to follow: --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order
cc @julienrbrt |
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: 0
🧹 Nitpick comments (2)
x/authz/simulation/decoder.go (1)
21-26
: Consider returning errors instead of panickingWhile the error handling is now explicit, panicking in a decoder function could destabilize simulations. Consider modifying the function signature to return an error instead.
-func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { +func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) (string, error) { - return func(kvA, kvB kv.Pair) string { + return func(kvA, kvB kv.Pair) (string, error) { switch { case bytes.Equal(kvA.Key[:1], keeper.GrantKey): var grantA, grantB authz.Grant if err := cdc.Unmarshal(kvA.Value, &grantA); err != nil { - panic(err) + return "", err } if err := cdc.Unmarshal(kvB.Value, &grantB); err != nil { - panic(err) + return "", err } - return fmt.Sprintf("%v\n%v", grantA, grantB) + return fmt.Sprintf("%v\n%v", grantA, grantB), nilAlso applies to: 30-35
x/gov/module.go (1)
160-164
: Consider returning error instead of panicWhile the current implementation improves error visibility compared to
MustMarshalJSON
, consider returning an error instead of panicking for better error handling. However, since this is called during chain initialization, the current approach is acceptable.-func (am AppModule) DefaultGenesis() json.RawMessage { +func (am AppModule) DefaultGenesis() (json.RawMessage, error) { data, err := am.cdc.MarshalJSON(v1.DefaultGenesisState()) if err != nil { - panic(err) + return nil, fmt.Errorf("failed to marshal default genesis state: %w", err) } - return data + return data, nil }
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
x/authz/migrations/v2/store.go
(1 hunks)x/authz/module/module.go
(2 hunks)x/authz/simulation/decoder.go
(2 hunks)x/gov/migrations/v5/store.go
(1 hunks)x/gov/module.go
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
x/authz/migrations/v2/store.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/gov/module.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/gov/migrations/v5/store.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/authz/simulation/decoder.go (1)
Pattern **/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
x/authz/module/module.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 (4)
- GitHub Check: test-simapp-v2
- GitHub Check: test-system-v2
- GitHub Check: Analyze
- GitHub Check: Summary
🔇 Additional comments (6)
x/authz/simulation/decoder.go (1)
7-7
: Import change looks goodThe codec import has been correctly updated to use the new package path.
x/gov/migrations/v5/store.go (1)
7-7
: Import change looks goodThe codec import has been correctly updated to use the new package path, and the existing error handling is comprehensive.
x/authz/migrations/v2/store.go (1)
7-7
: Import change looks goodThe codec import has been correctly updated to use the new package path, and the existing error handling is comprehensive.
x/authz/module/module.go (2)
13-13
: Import change looks goodThe codec import has been correctly updated to use the new package path.
113-117
: Error handling in DefaultGenesis looks goodThe explicit error handling with panic is acceptable here as DefaultGenesis is a startup function, and failing fast is appropriate when the default genesis state cannot be marshaled.
x/gov/module.go (1)
13-13
: LGTM: Import change aligns with migration objectivesThe transition from
github.com/cosmos/cosmos-sdk/codec
tocosmossdk.io/core/codec
is correctly implemented.
ref: #23253 (comment) |
Description
Partially addresses: #23253
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
Dependency Updates
cosmossdk.io/core/codec
Error Handling Improvements
MustMarshalJSON
with more robust error management techniquesModule Changes
authz
andgov
modulesThe changes primarily focus on improving codec handling and error management across multiple modules with minimal impact on existing functionality.