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

refactor(genutil/cli): remove txConfig from genesis command #20976

Merged
merged 4 commits into from
Jul 18, 2024

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Jul 17, 2024

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...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Refactor

    • Simplified command initialization by removing unnecessary parameters such as txConfig and addressCodec.
    • Updated function signatures and their internal logic to streamline argument handling.
    • Enhanced error handling logic within command setup functions.
  • Bug Fixes

    • Ensured default values are correctly assigned to configuration parameters when not explicitly provided.
  • Tests

    • Adjusted test suite to align with refactored command initialization and parameter handling.

Copy link
Contributor

coderabbitai bot commented Jul 17, 2024

Warning

Rate limit exceeded

@zakir-code has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 22 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between c7a6006 and 5643a13.

Walkthrough

Walkthrough

The changes primarily involve the removal of the txConfig parameter from various functions across multiple files within the simapp and x/genutil directories. The updates simplify function signatures and internalize the retrieval of configuration information, such as addressCodec and txConfig. These modifications streamline code by reducing parameter dependencies and enhancing error handling.

Changes

Files Change Summary
simapp/simd/cmd/commands.go initRootCmd and genesisCommand functions updated to exclude txConfig as a parameter and restructured arguments.
simapp/simd/cmd/root.go NewRootCmd function modified to remove encodingConfig.TxConfig from initRootCmd call.
simapp/simd/cmd/root_di.go NewRootCmd function updated: initRootCmd now only takes rootCmd and moduleManager. Enhanced error handling added.
simapp/v2/simdv2/cmd/commands.go genesisCommand function and rootCmd.AddCommand call modified to exclude txConfig.
x/genutil/client/cli/commands.go Commands function revised to remove txConfig and MigrationMap parameters; updates to CommandsWithCustomMigrationMap accordingly.
x/genutil/client/cli/genaccount.go AddGenesisAccountCmd function updated to internalize addressCodec retrieval from clientCtx.
x/genutil/client/cli/genaccount_test.go Adjustments to reflect removal of addressCodec parameter, use of v instead of viper, and changes in clientCtx initialization.
x/genutil/client/cli/gentx.go GenTxCmd function updated: removed txEncCfg and valAdddressCodec parameters; simplified public key retrieval.
x/genutil/client/cli/gentx_test.go TestGenTxCmd function updated to match changes in GenTxCmd parameters.
x/genutil/client/cli/init.go InitCmd function updated to ensure config.RootDir is set to default if not provided.
x/staking/client/cli/tx.go BuildCreateValidatorMsg function modified to internalize valCodec retrieval from clientCtx.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@zakir-code zakir-code changed the title refactor(genutil/cli): remove txConfig from genesis command refactor(genutil/cli): remove txConfig from genesis command Jul 17, 2024
@zakir-code zakir-code marked this pull request as ready for review July 18, 2024 01:51
@zakir-code zakir-code requested a review from a team as a code owner July 18, 2024 01:51
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: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 49bc189 and c7a6006.

Files selected for processing (11)
  • simapp/simd/cmd/commands.go (3 hunks)
  • simapp/simd/cmd/root.go (1 hunks)
  • simapp/simd/cmd/root_di.go (1 hunks)
  • simapp/v2/simdv2/cmd/commands.go (3 hunks)
  • x/genutil/client/cli/commands.go (2 hunks)
  • x/genutil/client/cli/genaccount.go (3 hunks)
  • x/genutil/client/cli/genaccount_test.go (3 hunks)
  • x/genutil/client/cli/gentx.go (4 hunks)
  • x/genutil/client/cli/gentx_test.go (2 hunks)
  • x/genutil/client/cli/init.go (1 hunks)
  • x/staking/client/cli/tx.go (2 hunks)
Additional context used
Path-based instructions (11)
x/genutil/client/cli/commands.go (1)

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

x/genutil/client/cli/genaccount_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"

x/genutil/client/cli/genaccount.go (1)

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

simapp/simd/cmd/root_di.go (1)

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

x/genutil/client/cli/gentx_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/simd/cmd/root.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.

x/genutil/client/cli/init.go (1)

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

x/genutil/client/cli/gentx.go (1)

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

x/staking/client/cli/tx.go (1)

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

Additional comments not posted (24)
x/genutil/client/cli/commands.go (2)

24-25: Simplified function signature.

The removal of txConfig and MigrationMap parameters simplifies the function signature.


Line range hint 30-44: Simplified function signature and internal calls.

The removal of txConfig and migrationMap parameters simplifies the function signature and internal calls.

x/genutil/client/cli/genaccount_test.go (6)

Line range hint 1-13: Removed unused import.

The removal of addresscodec import is consistent with the changes in the function signatures.


73-73: Updated viper initialization.

The change to use v instead of viper is consistent and improves readability.


75-77: Updated appCodec initialization and introduced encodingConfig.

The introduction of encodingConfig and update to appCodec initialization is consistent with the removal of txConfig parameter.


83-84: Updated context setup to include txConfig.

The update to include txConfig in the context setup is consistent with the changes in the function signatures.


97-97: Updated context setup to use v.

The update to use v instead of viper in the context setup is consistent and improves readability.


100-100: Simplified AddGenesisAccountCmd initialization.

The removal of addresscodec parameter simplifies the function signature and is consistent with the changes in the function signatures.

x/genutil/client/cli/genaccount.go (2)

26-26: Simplified function signature.

The removal of addressCodec parameter simplifies the function signature.


40-40: Simplified internal logic.

The update to retrieve addressCodec from the client context simplifies the function logic and is consistent with the changes in the function signatures.

simapp/simd/cmd/root_di.go (2)

84-84: Simplified function signature.

The removal of clientCtx.TxConfig parameter simplifies the function signature.


Line range hint 86-88: Improved error handling.

The update to handle errors returned by autoCliOpts.EnhanceRootCommand improves error handling and robustness of the function.

x/genutil/client/cli/gentx_test.go (1)

126-126: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to GenTxCmd match the new signature.

Verification successful

All instances of GenTxCmd match the new signature.

The code changes are verified and approved.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `GenTxCmd` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'GenTxCmd'

Length of output: 1774

simapp/simd/cmd/commands.go (2)

Line range hint 17-20:
LGTM! Simplified function signature.

The removal of the txConfig parameter simplifies the function signature.


Line range hint 62-70:
LGTM! Simplified function signature.

The removal of the txConfig parameter simplifies the function signature.

simapp/simd/cmd/root.go (1)

112-112: LGTM! Simplified function call.

The removal of the encodingConfig.TxConfig argument simplifies the function call.

simapp/v2/simdv2/cmd/commands.go (2)

Line range hint 36-39:
LGTM! Simplified function signature.

The removal of the txConfig parameter simplifies the function signature.


Line range hint 145-151:
LGTM! Simplified function signature.

The removal of the txConfig parameter simplifies the function signature.

x/genutil/client/cli/init.go (1)

92-94: Ensure config.RootDir is set correctly.

The change ensures that config.RootDir defaults to clientCtx.HomeDir if it is not set, which is a good practice to avoid null or empty values.

x/genutil/client/cli/gentx.go (3)

30-30: Update function signature to remove unnecessary parameters.

The GenTxCmd function signature has been updated to remove txEncCfg and valAdddressCodec parameters, simplifying the function and reducing dependencies.


141-141: Ensure correct context setup.

The clientCtx is updated with inBuf and addr, which is necessary for subsequent operations.


157-157: Update function call to remove unnecessary parameter.

The call to cli.BuildCreateValidatorMsg has been updated to remove the valAdddressCodec parameter, simplifying the function call.

x/staking/client/cli/tx.go (2)

368-368: Update function signature to remove unnecessary parameter.

The BuildCreateValidatorMsg function signature has been updated to remove the valCodec parameter, simplifying the function and reducing dependencies.


401-402: Retrieve valCodec from clientCtx.

The valCodec is now obtained from clientCtx.TxConfig.SigningContext().ValidatorAddressCodec(), which centralizes the configuration retrieval.

Comment on lines +92 to +94
if config.RootDir == "" {
config.RootDir = clientCtx.HomeDir
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cmd := genutilcli.InitCmd(module.NewManager())

The init command did not read into the root(hoom) directory during unit test TestEmptyMinGasPrices, causing the file to be created in the current directory

@@ -120,6 +120,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

### API Breaking Changes

* (client) [#20976](https://github.com/cosmos/cosmos-sdk/pull/20976) Simplified command initialization by removing unnecessary parameters such as `txConfig` and `addressCodec`.
* Remove parameter `txConfig` from `genutilcli.Commands`,`genutilcli.CommandsWithCustomMigrationMap`,`genutilcli.GenTxCmd`.
* Remove parameter `addressCodec` from `genutilcli.GenTxCmd`,`genutilcli.AddGenesisAccountCmd`,`stakingcli.BuildCreateValidatorMsg`.
Copy link
Member

Choose a reason for hiding this comment

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

Can we check if addressCodec was there in 0.50? I don't think so, and that means we can remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked the latest version 0.50, and it does have addressCodec.

https://github.com/cosmos/cosmos-sdk/blob/v0.50.8/x/genutil/client/cli/commands.go

@julienrbrt julienrbrt added this pull request to the merge queue Jul 18, 2024
Merged via the queue into cosmos:main with commit 2370a50 Jul 18, 2024
68 of 69 checks passed
@zakir-code zakir-code deleted the zakir/genutil-cli branch July 18, 2024 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants