-
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
refactor: remove viper as a direct dependency #21635
Conversation
WalkthroughWalkthroughThe pull request introduces a new Changes
Possibly related PRs
Suggested labels
Recent review detailsConfiguration used: .coderabbit.yml Files selected for processing (2)
Additional context usedPath-based instructions (2)
Additional comments not posted (7)
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: 0
Outside diff range and nitpick comments (3)
core/server/config.go (1)
5-7
: LGTM!The
DynamicConfig
interface provides a clean abstraction for dynamic configuration management and adheres to the Uber Go Style Guide.Consider using a more specific return type for the
Get
method instead ofany
to improve type safety. For example:type DynamicConfig interface { Get(string) (any, bool) GetString(string) string }This would allow the caller to check if the key exists and handle the case accordingly.
runtime/v2/go.mod (1)
Dependencies Still in Use: Reconsider Removal
The following dependencies are still being imported in the codebase, which suggests that their removal from
go.mod
could lead to issues:
github.com/mitchellh/mapstructure
is imported inserver/v2/config.go
.jackfan.us.kg/magiconair/properties
is imported incrypto/keys/secp256k1/secp256k1_cgo_test.go
.Please verify the necessity of these dependencies and consider refactoring the code to remove their usage if they are no longer needed. Alternatively, ensure they remain in
go.mod
if they are still required.Analysis chain
Line range hint
16-27
: Removal of Viper dependency is approved, but verify the impact of removing other dependencies.The removal of the
github.com/spf13/viper
dependency aligns with the PR objective and is approved.However, several other dependencies have also been removed. Please verify that removing these dependencies does not introduce any unintended consequences or break any functionality.
Run the following script to verify the impact of removing the dependencies:
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: # - Verify that the removed dependencies are not imported in the codebase. # - Ensure that the tests pass after removing the dependencies. # Test: Search for the removed dependencies in the codebase. Expect: No results. rg --type go $'github.com/hashicorp/hcl|github.com/magiconair/properties|github.com/mitchellh/mapstructure|github.com/pelletier/go-toml/v2|github.com/sagikazarmark/locafero|github.com/sagikazarmark/slog-shim|github.com/sourcegraph/conc|github.com/spf13/pflag|github.com/subosito/gotenv|go.uber.org/multierr' # Test: Run the tests. Expect: All tests pass. go test ./...Length of output: 2756
Script:
#!/bin/bash # Description: Verify if the other removed dependencies are still being imported in the codebase. # Test: Search for the remaining removed dependencies in the codebase. Expect: No results. rg --type go $'github.com/hashicorp/hcl|github.com/magiconair/properties|github.com/mitchellh/mapstructure|github.com/sagikazarmark/locafero|github.com/sagikazarmark/slog-shim|github.com/sourcegraph/conc|github.com/subosito/gotenv|go.uber.org/multierr'Length of output: 397
tests/integration/genutil/init_test.go (1)
Line range hint
44-97
: Consider adding more test cases.The test function covers the happy path scenario well. However, consider adding more test cases to cover error scenarios and improve the test coverage.
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (5)
go.sum
is excluded by!**/*.sum
runtime/v2/go.sum
is excluded by!**/*.sum
simapp/go.sum
is excluded by!**/*.sum
simapp/v2/go.sum
is excluded by!**/*.sum
x/upgrade/go.sum
is excluded by!**/*.sum
Files selected for processing (24)
- core/server/config.go (1 hunks)
- go.mod (1 hunks)
- runtime/v2/builder.go (6 hunks)
- runtime/v2/go.mod (6 hunks)
- runtime/v2/module.go (4 hunks)
- simapp/go.mod (1 hunks)
- simapp/simd/cmd/testnet_test.go (2 hunks)
- simapp/v2/app_di.go (4 hunks)
- simapp/v2/go.mod (1 hunks)
- simapp/v2/simdv2/cmd/commands.go (4 hunks)
- simapp/v2/simdv2/cmd/root_di.go (1 hunks)
- tests/e2e/genutil/export_test.go (1 hunks)
- tests/go.mod (2 hunks)
- tests/integration/genutil/export_test.go (1 hunks)
- tests/integration/genutil/genaccount_test.go (6 hunks)
- tests/integration/genutil/init_test.go (8 hunks)
- testutil/network/util.go (2 hunks)
- testutil/x/genutil/helper.go (1 hunks)
- x/auth/tx/config/depinject.go (4 hunks)
- x/genutil/v2/cli/commands.go (1 hunks)
- x/genutil/v2/cli/export.go (3 hunks)
- x/genutil/v2/types.go (1 hunks)
- x/upgrade/depinject.go (3 hunks)
- x/upgrade/go.mod (3 hunks)
Files skipped from review due to trivial changes (8)
- simapp/go.mod
- simapp/simd/cmd/testnet_test.go
- simapp/v2/go.mod
- tests/e2e/genutil/export_test.go
- tests/integration/genutil/export_test.go
- tests/integration/genutil/genaccount_test.go
- testutil/x/genutil/helper.go
- x/genutil/v2/cli/commands.go
Additional context used
Path-based instructions (13)
core/server/config.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/genutil/v2/types.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/genutil/v2/cli/export.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/upgrade/depinject.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/v2/simdv2/cmd/root_di.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/v2/simdv2/cmd/commands.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.runtime/v2/module.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.runtime/v2/builder.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.testutil/network/util.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/v2/app_di.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.x/auth/tx/config/depinject.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.tests/integration/genutil/init_test.go (3)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
tests/**/*
: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"tests/go.mod (1)
Pattern
tests/**/*
: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"
Additional comments not posted (39)
x/genutil/v2/types.go (1)
4-4
: Approve the change fromlogger
toctx
, but request more information about the removal ofviper
.
Replacing
logger log.Logger
withctx context.Context
:
- This change is approved as it can enhance the function's ability to handle cancellation signals and deadlines, improving its integration with other components that utilize context.
Removing
viper *viper.Viper
:
- Please provide more information about the reason for removing the
viper
parameter and its impact on the codebase.- Is this change related to a broader refactoring or a shift in how configuration is managed within the application?
Also applies to: 11-11
x/genutil/v2/cli/export.go (3)
Line range hint
24-24
: LGTM!The changes to the
ExportCmd
function signature, which remove thelogger
andviper
parameters, align with the PR objective of eliminating the direct dependency on the Viper library. This simplifies the command's execution flow by reducing dependencies on these variables.
63-63
: LGTM!The modification to the
appExporter
function call, which now passes the command's context directly instead of thelogger
andviper
, aligns with the PR objective of introducing a newDynamicConfig
interface to enhance dynamic configuration management and replace the existing configuration management using theviper
library. This change streamlines the approach to exporting application state by relying solely on the command context and the other parameters.
100-103
: LGTM!The formatting changes to the flag definitions enhance the code's readability and maintainability without affecting functionality. The changes adhere to the Uber Golang style guide.
x/upgrade/depinject.go (4)
10-10
: LGTM!The import statement is correct and aligns with the PR objective of using the new
DynamicConfig
interface from theserverv2
package.
46-47
: LGTM!The changes to the
ModuleInputs
struct are correct and align with the PR objective of transitioning from the oldAppOpts
to the newDynamicConfig
for configuration management. Marking both fields as optional ensures backward compatibility during the transition.
63-69
: LGTM!The changes to the
ProvideModule
function are correct and align with the PR objective of transitioning fromAppOpts
toDynamicConfig
for configuration management. The code correctly prioritizesDynamicConfig
overAppOpts
and retrieves the necessary configuration values.
Line range hint
1-100
: Code style and conformity with the Uber Golang style guide: LGTM!The code follows the Uber Golang style guide, is well-formatted, and readable. No changes are required.
runtime/v2/go.mod (1)
8-8
: LGTM!The change to replace the
cosmossdk.io/core
module with a local path is approved. This change aligns with the PR objective of using a local development version of the module.simapp/v2/simdv2/cmd/root_di.go (1)
85-85
: Verify the removal of the generic type parameterT
from theinitRootCmd
function.The generic type parameter
T
has been removed from theinitRootCmd
function signature and the function call at line 85. This change suggests that theinitRootCmd
function is now constrained to work with a specific transaction type or a default transaction type, potentially limiting its flexibility in handling different transaction types.Please verify if this change aligns with the intended design and functionality of the
initRootCmd
function. Consider the following:
- Is the
initRootCmd
function expected to handle only a specific transaction type or a default transaction type?- Will the removal of the generic type parameter
T
impact the flexibility and extensibility of theinitRootCmd
function in the future?- Are there any downstream dependencies or code that rely on the generic nature of the
initRootCmd
function?If the change is intentional and aligns with the desired behavior, please ensure that the documentation and comments are updated accordingly to reflect the new functionality of the
initRootCmd
function.simapp/v2/simdv2/cmd/commands.go (4)
89-98
: Improved modularity in genesisCommand function.The removal of the
appExport
parameter and retrieval of the function from themoduleManager
within thegenesisCommand
function body is a positive change. It promotes a more encapsulated design where the command construction relies on the module manager's state rather than external parameters.This change improves modularity, reduces coupling, and enhances the overall design of the command structure.
151-167
: Enhanced context management and error handling in appExport function.The update to the
appExport
function signature to include actx context.Context
parameter and the extraction ofviper
andlogger
from the context is a positive change. It signifies a transition to a context-aware approach, allowing the function to access necessary values from the context.Furthermore, the type checking of the extracted values enhances error handling and type safety within the function. It ensures that the function is more robust against incorrect usage and provides informative error messages when the expected types are not met.
Overall, these changes improve context management, error handling, and the overall reliability of the
appExport
function.
4-4
: Appropriate import of "context" package.The import of the
"context"
package aligns with the usage ofcontext.Context
in the updatedappExport
function. It is a necessary addition to support the context-aware approach introduced in the function.
12-12
: Appropriate import of corectx package.The import of the
corectx
package with an alias suggests its usage in the updatedappExport
function. It likely provides additional context-related functionality or constants used in the function, supporting the context-aware approach.runtime/v2/module.go (3)
20-20
: LGTM!The new import statement is necessary to use the
server.DynamicConfig
type.
148-148
: Looks good!The changes to the
AppInputs
struct align with the PR objective to remove the direct dependency on Viper and introduce a new abstraction for dynamic configuration management.
159-160
: LGTM!The changes to the
SetupAppBuilder
function correctly handle the transition from using Viper to the newDynamicConfig
for configuration management. The conditional assignment ensures backward compatibility whenDynamicConfig
is not provided.runtime/v2/builder.go (5)
12-12
: LGTM!The import is necessary to use the
server.DynamicConfig
type in theAppBuilder
struct.
27-28
: LGTM!The changes to the
AppBuilder
struct are part of the refactoring to remove the direct dependency on the Viper library and simplify the management of store options.
123-129
: LGTM!The changes to retrieve the home directory path and create a new database using
server.DynamicConfig
are consistent with the refactoring to remove the direct dependency on the Viper library.
134-142
: LGTM!The change to create
rootstore.FactoryOptions
usinga.storeOptions
simplifies the configuration handling within theAppBuilder
.
Line range hint
205-233
: LGTM!The formatting change improves the readability of the
AppBuilderWithTxValidator
function, and the newAppBuilderWithStoreOptions
function enhances the configurability of theAppBuilder
by allowing store options to be set through a functional option pattern.testutil/network/util.go (1)
183-187
: LGTM!The changes to the configuration setup process in the
collectGenFiles
function look good. Explicitly defining the configuration parameters improves clarity and control over the configuration process.The code segment conforms to the Uber Go Style Guide.
simapp/v2/app_di.go (1)
Line range hint
101-200
: LGTM!The changes to the
NewSimApp
function look good:
The introduction of the
storeOptions
variable and the associated logic to populate it from the Viper configuration enhances the flexibility of the application setup by allowing dynamic configuration of store options.The code adheres to the Uber Go Style Guide and follows idiomatic Go practices.
Error handling is properly implemented when unmarshaling the sub-configuration.
The modifications to the
appBuilder.Build()
call correctly integrate thestoreOptions
into the application builder process.Overall, these changes improve the configurability of the
NewSimApp
function and provide a more flexible application setup.go.mod (1)
188-188
: LGTM! The change enhances local development.The new
replace
directive that maps the module pathcosmossdk.io/core
to the local directory./core
is a good addition. It allows the Go module system to reference the local implementation of thecore
package instead of fetching it from the remote repository.This change indicates a shift towards local development or testing of the
core
package without relying on external sources, which can be beneficial for faster iteration and debugging.x/auth/tx/config/depinject.go (3)
18-18
: LGTM!The import statement is correct and necessary for using the
DynamicConfig
type in theModuleInputs
struct.
69-69
: LGTM!The addition of the optional
DynamicConfig
field is a key change that enables the transition from using Viper to the new dynamic configuration approach. Making it optional allows for backward compatibility.
129-130
: LGTM!The changes reflect the transition from using Viper to the new
DynamicConfig
for retrieving configuration values. The conditional check ensures that the new approach is used only when all the required dependencies (AccountKeeper
,BankKeeper
, andDynamicConfig
) are available, maintaining backward compatibility.x/upgrade/go.mod (2)
162-162
: LGTM!The change to make
github.com/spf13/viper
an indirect dependency aligns with the PR objective of removing the direct dependency on theviper
library.
206-208
: LGTM!The addition of replace directives for
cosmossdk.io/core
,cosmossdk.io/core/testing
, andcosmossdk.io/store
modules to use local paths aligns with the PR objective of improving modularity in the codebase. Using local paths for these modules can facilitate testing and development.tests/integration/genutil/init_test.go (8)
Line range hint
99-132
: LGTM!The code changes are approved.
Line range hint
134-161
: LGTM!The code changes are approved.
Line range hint
163-208
: LGTM!The code changes are approved.
Line range hint
210-242
: LGTM!The code changes are approved.
Line range hint
244-254
: LGTM!The code changes are approved.
Line range hint
256-304
: LGTM!The code changes are approved.
Line range hint
306-340
: LGTM!The code changes are approved.
Line range hint
342-374
: LGTM!The code changes are approved.
tests/go.mod (1)
53-53
: Approved: Direct dependency onjackfan.us.kg/rs/zerolog
is acceptable.The change from an indirect to a direct dependency on the
zerolog
logging library aligns with the project's logging requirements and is acceptable.
* main: docs(client/debug): correct `debug raw-bytes` command example (#21671) build: don't reinstall golangci-lint if already installed (#21662) refactor(server/v2): kill viper from server components (#21663) chore: sync changelog with latest releases (#21658) refactor: remove viper as a direct dependency (#21635) ci: centralized job for rocksdb libaries cache (#21657) fix: remove stray fmt.Println (#21661)
Co-authored-by: Matt Kocubinski <[email protected]> Co-authored-by: Julien Robert <[email protected]>
Description
This fell out as part of the v2 integration test work. It is desirable to interact with config through an abstraction rather than viper specifically.
Specifically, this PR introduces
core/server.DynamicConfig
to interface with runtime config instead of viper, analogous to server v1AppOptions
. This completely removes viper fromruntime/v2/go.mod
, and moves viper to an indirect (from direct) dependency inx/genutil
andx/upgrade
.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
New Features
Bug Fixes
Refactor
Chores