-
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
refactor(simapp): Audit simapp #21311
Conversation
WalkthroughWalkthroughThe changes involve refactoring several functions in the Changes
Possibly related issues
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
|
seems like duplicate with #21310 🤯 |
It isn't we actually found different stuff ❤️ |
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, codebase verification and nitpick comments (1)
simapp/app.go (1)
Issues Found: Impact of Removing
consensustypes.ModuleName
The removal of
consensustypes.ModuleName
from theNewSimApp
function may lead to inconsistencies, as it is still used in other parts of the codebase:
simapp/app_config.go
simapp/v2/app_config.go
Please review these files to ensure that all dependencies on
consensustypes.ModuleName
are correctly handled or removed to maintain the application's integrity.Analysis chain
Line range hint
1-1
: Verify the impact of the removal ofconsensustypes.ModuleName
.The removal of
consensustypes.ModuleName
from theNewSimApp
function may affect other parts of the codebase that rely on the consensus module. Ensure that all dependencies on the consensus module are correctly handled or removed.Run the following script to verify the usage of
consensustypes.ModuleName
in the codebase:Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `consensustypes.ModuleName` in the codebase. # Test: Search for the usage of `consensustypes.ModuleName`. Expect: No occurrences. rg --type go 'consensustypes.ModuleName'Length of output: 315
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (1)
simapp/v2/go.sum
is excluded by!**/*.sum
Files selected for processing (16)
- simapp/CHANGELOG.md (1 hunks)
- simapp/app.go (1 hunks)
- simapp/app_config.go (1 hunks)
- simapp/app_di.go (1 hunks)
- simapp/export.go (8 hunks)
- simapp/genesis_account.go (1 hunks)
- simapp/simd/cmd/commands.go (1 hunks)
- simapp/simd/cmd/config.go (1 hunks)
- simapp/simd/cmd/testnet.go (1 hunks)
- simapp/v2/app_config.go (5 hunks)
- simapp/v2/app_di.go (4 hunks)
- simapp/v2/genesis_account.go (1 hunks)
- simapp/v2/genesis_account_test.go (1 hunks)
- simapp/v2/go.mod (3 hunks)
- simapp/v2/simdv2/cmd/commands.go (1 hunks)
- simapp/v2/simdv2/cmd/testnet.go (2 hunks)
Files skipped from review due to trivial changes (6)
- simapp/CHANGELOG.md
- simapp/app_config.go
- simapp/app_di.go
- simapp/simd/cmd/config.go
- simapp/simd/cmd/testnet.go
- simapp/v2/simdv2/cmd/testnet.go
Additional context used
Path-based instructions (9)
simapp/genesis_account.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/v2/genesis_account.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/v2/genesis_account_test.go (2)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Pattern
**/*_test.go
: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"simapp/simd/cmd/commands.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.simapp/v2/app_di.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/export.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/v2/app_config.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.simapp/app.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Learnings (1)
simapp/v2/genesis_account_test.go (1)
Learnt from: testinginprod PR: cosmos/cosmos-sdk#18542 File: x/bank/types/balance.go:64-77 Timestamp: 2023-11-22T14:48:50.376Z Learning: - The `SanitizeGenesisBalances` function in `x/bank/types/balance.go` of the Cosmos SDK should panic when encountering duplicate account addresses in the genesis state. - A test case is required to verify the behavior of `SanitizeGenesisBalances` when duplicates are present.
Additional comments not posted (19)
simapp/genesis_account.go (1)
34-34
: LGTM!The updated error message accurately reflects the validation logic, improving clarity.
The code changes are approved.
simapp/v2/genesis_account.go (1)
34-34
: LGTM!The updated error message accurately reflects the validation logic, improving clarity.
The code changes are approved.
simapp/v2/genesis_account_test.go (1)
1-89
: Well-written test cases!The test function comprehensively covers various scenarios for validating
SimGenesisAccount
, ensuring robust test coverage.The code changes are approved.
simapp/simd/cmd/commands.go (2)
152-152
: LGTM!The change to use
viperAppOpts
instead ofappOpts
is appropriate and ensures the correct configuration is used.The code changes are approved.
158-158
: LGTM!The change to use
viperAppOpts
instead ofappOpts
is appropriate and ensures the correct configuration is used.The code changes are approved.
simapp/v2/simdv2/cmd/commands.go (1)
Line range hint
63-63
: Verify the impact of removed commands.The removal of
server.QueryBlockCmd()
,server.QueryBlocksCmd()
, andserver.QueryBlockResultsCmd()
reduces the available commands for querying block-related information. Ensure that these removals do not negatively impact the user experience or functionality.Run the following script to verify the usage of these commands in the codebase:
simapp/v2/app_di.go (3)
22-22
: LGTM!The addition of the
epochskeeper
package is appropriate for managing epochs within the application's lifecycle.The code changes are approved.
73-73
: LGTM!The addition of the
EpochsKeeper
field to theSimApp
struct is appropriate for managing epochs within the application's lifecycle.The code changes are approved.
182-182
: LGTM!The update to the
NewSimApp
function ensures that theEpochsKeeper
is properly initialized when creating an instance ofSimApp
.The code changes are approved.
simapp/export.go (5)
52-54
: LGTM!The updated comment provides a clearer description of the function's purpose.
The code changes are approved.
69-69
: LGTM!The updated error handling using
panic(err)
enforces stricter error management.The code changes are approved.
82-85
: LGTM!The updated error handling using
panic(err)
enforces stricter error management.The code changes are approved.
99-101
: LGTM!The updated address conversion using
sdk.MustValAddressFromBech32
andsdk.MustAccAddressFromBech32
simplifies the code.The code changes are approved.
238-238
: LGTM!The updated error handling using
panic(err)
enforces stricter error management.The code changes are approved.
simapp/v2/app_config.go (3)
18-18
: LGTM!The import statement for
epochsmodulev1
is necessary to utilize functionalities from the epochs module.The code changes are approved.
49-50
: LGTM!The addition of
epochstypes.ModuleName
ensures that the epochs module is recognized and properly integrated into the application's block processing flow.The code changes are approved.
278-281
: LGTM!The incorporation of
epochstypes.ModuleName
into the module configuration list enhances the application's modular capabilities by integrating the epochs module into its operational structure.The code changes are approved.
simapp/v2/go.mod (2)
24-24
: LGTM!The addition of the
cosmossdk.io/x/epochs
module in therequire
section is necessary to explicitly incorporate the module into the project's dependencies.The code changes are approved.
263-263
: LGTM!The addition of the
cosmossdk.io/x/epochs
module in thereplace
section is necessary to manage the specific version or commit of the module being utilized.The code changes are approved.
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.
lgtm! nice cleanups
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
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (1)
- simapp/v2/app_di.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- simapp/v2/app_di.go
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
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (6)
- simapp/CHANGELOG.md (1 hunks)
- simapp/app.go (1 hunks)
- simapp/app_config.go (1 hunks)
- simapp/app_di.go (1 hunks)
- simapp/simd/cmd/config.go (1 hunks)
- simapp/v2/app_config.go (5 hunks)
Files skipped from review due to trivial changes (3)
- simapp/CHANGELOG.md
- simapp/app_config.go
- simapp/app_di.go
Files skipped from review as they are similar to previous changes (3)
- simapp/app.go
- simapp/simd/cmd/config.go
- simapp/v2/app_config.go
simapp/export.go
Outdated
@@ -80,7 +79,10 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] | |||
if err != nil { | |||
panic(err) | |||
} | |||
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz) | |||
_, err = app.DistrKeeper.WithdrawValidatorCommission(ctx, valBz) |
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.
I don't think we should check the error, it fails tests when a validator has no commission.
Could you revert?
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
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (1)
- simapp/export.go (7 hunks)
Files skipped from review as they are similar to previous changes (1)
- simapp/export.go
@@ -605,7 +605,7 @@ jobs: | |||
simdv2 start & | |||
SIMD_PID=$! | |||
cnt=0 | |||
while ! simdv2 query block --type=height 5; do | |||
while ! simdv2 query comet block --type=height 5; do |
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.
Update a little bit CI and server/v2/cometbft since we using cometbft queries
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
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (1)
simapp/v2/go.sum
is excluded by!**/*.sum
Files selected for processing (5)
- .github/workflows/test.yml (1 hunks)
- server/v2/cometbft/commands.go (1 hunks)
- server/v2/cometbft/config.go (1 hunks)
- server/v2/cometbft/server.go (1 hunks)
- simapp/v2/go.mod (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- simapp/v2/go.mod
Additional context used
Path-based instructions (3)
server/v2/cometbft/config.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.server/v2/cometbft/server.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.server/v2/cometbft/commands.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (3)
server/v2/cometbft/server.go (1)
63-63
: Streamline configuration retrieval inInit
method.The change to use
getAppTomlFromViper
directly simplifies the configuration setup. Ensure that this modification integrates seamlessly with all dependent components of theCometBFTServer
.The modification is approved, but verification is recommended to ensure no regressions in the initialization process.
Run integration tests to confirm that all components dependent on
AppTomlConfig
are functioning correctly.server/v2/cometbft/commands.go (1)
32-33
: Enhance configuration retrieval inrpcClient
.The use of
getAppTomlFromViper
for dynamic configuration retrieval is a positive change, improving flexibility and maintainability. Ensure robust error handling is in place for cases where configuration retrieval fails.The change is approved, but adding comprehensive error handling is recommended to prevent issues during RPC client initialization.
.github/workflows/test.yml (1)
608-608
: Verify the updated command for querying comet blocks.The change from
simdv2 query block --type=height 5
tosimdv2 query comet block --type=height 5
indicates a shift to a more specific block type. Ensure that this new command is supported bysimdv2
and correctly implemented in the context of the intended functionality.
server/v2/cometbft/config.go
Outdated
func getAppTomlFromViper(v *viper.Viper) *AppTomlConfig { | ||
appTomlConfig := DefaultAppTomlConfig() | ||
if err := serverv2.UnmarshalSubConfig(v, ServerName, &appTomlConfig); err != nil { | ||
return DefaultAppTomlConfig() | ||
} | ||
|
||
return appTomlConfig | ||
} |
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.
Review the error handling strategy in getAppTomlFromViper
.
The function correctly handles configuration retrieval with a fallback to the default configuration. However, it would be beneficial to log the error when unmarshalling fails to aid in debugging and ensure that configuration issues are noticeable.
Consider adding error logging before returning the default configuration:
if err := serverv2.UnmarshalSubConfig(v, ServerName, &appTomlConfig); err != nil {
+ log.Errorf("Failed to unmarshal AppTomlConfig: %v", err)
return DefaultAppTomlConfig()
}
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.
func getAppTomlFromViper(v *viper.Viper) *AppTomlConfig { | |
appTomlConfig := DefaultAppTomlConfig() | |
if err := serverv2.UnmarshalSubConfig(v, ServerName, &appTomlConfig); err != nil { | |
return DefaultAppTomlConfig() | |
} | |
return appTomlConfig | |
} | |
func getAppTomlFromViper(v *viper.Viper) *AppTomlConfig { | |
appTomlConfig := DefaultAppTomlConfig() | |
if err := serverv2.UnmarshalSubConfig(v, ServerName, &appTomlConfig); err != nil { | |
log.Errorf("Failed to unmarshal AppTomlConfig: %v", err) | |
return DefaultAppTomlConfig() | |
} | |
return appTomlConfig | |
} |
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
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (2)
- simapp/simd/cmd/testnet.go (1 hunks)
- simapp/v2/simdv2/cmd/testnet.go (2 hunks)
Files skipped from review due to trivial changes (1)
- simapp/v2/simdv2/cmd/testnet.go
Files skipped from review as they are similar to previous changes (1)
- simapp/simd/cmd/testnet.go
server/v2/cometbft/config.go
Outdated
@@ -64,3 +64,12 @@ func getConfigTomlFromViper(v *viper.Viper) *cmtcfg.Config { | |||
|
|||
return conf.SetRoot(rootDir) | |||
} | |||
|
|||
func getAppTomlFromViper(v *viper.Viper) *AppTomlConfig { | |||
appTomlConfig := DefaultAppTomlConfig() |
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.
I think the default should be s.config
and not DefaultAppTomlConfig
} | ||
|
||
// StatusCommand returns the command to return the status of the network. | ||
func (s *CometBFTServer[T]) StatusCommand() *cobra.Command { | ||
func StatusCommand() *cobra.Command { |
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.
comet queries should not relayed on CometBFTServer
anymore.
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
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files selected for processing (3)
- server/v2/cometbft/commands.go (11 hunks)
- server/v2/cometbft/config.go (1 hunks)
- server/v2/cometbft/server.go (1 hunks)
Files skipped from review due to trivial changes (1)
- server/v2/cometbft/config.go
Additional context used
Path-based instructions (2)
server/v2/cometbft/server.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.server/v2/cometbft/commands.go (1)
Pattern
**/*.go
: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.
Additional comments not posted (10)
server/v2/cometbft/server.go (2)
236-241
: LGTM! Improved modularity.The changes enhance modularity by referencing standalone functions instead of instance methods.
The code changes are approved.
241-241
: Verify the new command addition.Ensure that the new command
s.BootstrapStateCmd()
is correctly implemented and integrated.Run the following script to verify the implementation of
BootstrapStateCmd
:Verification successful
BootstrapStateCmd Implementation Verified
The method
BootstrapStateCmd
is implemented inserver/v2/cometbft/commands.go
and is correctly integrated inserver/v2/cometbft/server.go
. The implementation aligns with the expected structure and usage. No issues found.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of `BootstrapStateCmd`. # Test: Search for the function implementation. Expect: Only occurrences of the new signature. rg --type go -A 5 $'func (s *CometBFTServer[T]) BootstrapStateCmd() *cobra.Command'Length of output: 84
Script:
#!/bin/bash # Searching for any occurrence of BootstrapStateCmd in the codebase rg --type go 'BootstrapStateCmd'Length of output: 343
server/v2/cometbft/commands.go (8)
31-55
: LGTM! Improved modularity.The
rpcClient
function has been converted to a standalone function, enhancing modularity by allowing it to operate independently of the server's internal state.The code changes are approved.
Line range hint
59-74
: LGTM! Improved modularity.The
StatusCommand
function has been converted to a standalone function, enhancing modularity by reducing dependencies on the server's state.The code changes are approved.
Line range hint
90-101
: LGTM! Improved modularity.The
ShowNodeIDCmd
function has been converted to a standalone function, enhancing modularity by reducing dependencies on the server's state.The code changes are approved.
Line range hint
108-129
: LGTM! Improved modularity.The
ShowValidatorCmd
function has been converted to a standalone function, enhancing modularity by reducing dependencies on the server's state.The code changes are approved.
Line range hint
142-153
: LGTM! Improved modularity.The
ShowAddressCmd
function has been converted to a standalone function, enhancing modularity by reducing dependencies on the server's state.The code changes are approved.
Line range hint
161-180
: LGTM! Improved modularity.The
VersionCmd
function has been converted to a standalone function, enhancing modularity by reducing dependencies on the server's state.The code changes are approved.
Line range hint
189-221
: LGTM! Improved modularity.The
QueryBlocksCmd
function has been converted to a standalone function, enhancing modularity by reducing dependencies on the server's state.The code changes are approved.
Line range hint
327-347
: LGTM! Improved modularity.The
QueryBlockResultsCmd
function has been converted to a standalone function, enhancing modularity by reducing dependencies on the server's state.The code changes are approved.
server/v2/cometbft/commands.go
Outdated
func (s *CometBFTServer[T]) rpcClient(cmd *cobra.Command) (rpc.CometRPC, error) { | ||
if s.config.AppTomlConfig.Standalone { | ||
func rpcClient(cmd *cobra.Command) (rpc.CometRPC, error) { | ||
v := client.GetViperFromCmd(cmd) |
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.
when doing queries it shouldn't need to read the app.toml actually right, but the client.toml
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.
only for Standalone
check, should we remove? I think FlagNode
is enough
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.
Yeah flag node will get if from client.toml, so that's great. Not sure what a standalone check means for query tbh.
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
Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Files ignored due to path filters (1)
simapp/v2/go.sum
is excluded by!**/*.sum
Files selected for processing (4)
- server/v2/cometbft/commands.go (11 hunks)
- simapp/v2/go.mod (3 hunks)
- simapp/v2/simdv2/cmd/commands.go (1 hunks)
- simapp/v2/simdv2/cmd/testnet.go (2 hunks)
Files skipped from review due to trivial changes (2)
- server/v2/cometbft/commands.go
- simapp/v2/simdv2/cmd/testnet.go
Files skipped from review as they are similar to previous changes (2)
- simapp/v2/go.mod
- simapp/v2/simdv2/cmd/commands.go
should I merge this now? @julienrbrt |
(cherry picked from commit 4096fb8) # Conflicts: # simapp/v2/go.mod # simapp/v2/go.sum
Co-authored-by: Hieu Vu <[email protected]> Co-authored-by: Julien Robert <[email protected]>
Description
Closes: #XXXX
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