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(x/genutil)!: remove Address.String() #19926

Merged
merged 3 commits into from
Apr 3, 2024

Conversation

JulianToledano
Copy link
Contributor

@JulianToledano JulianToledano commented Apr 3, 2024

Description

ref:
#13140
#7448


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

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

  • API Changes
    • Significant modifications to API requiring address codec arguments in various methods for improved address handling.
  • Refactor
    • Streamlined code by adjusting function calls and dependencies related to address handling across multiple files.
    • Enhanced address handling logic by converting addresses from bytes to string format before processing.
  • Tests
    • Updated tests to accommodate new address handling methods, ensuring consistency and reliability in address conversions and comparisons.

@JulianToledano JulianToledano requested a review from a team as a code owner April 3, 2024 11:28
@github-actions github-actions bot added C:CLI C:x/genutil genutil module issues labels Apr 3, 2024
Copy link
Contributor

coderabbitai bot commented Apr 3, 2024

Warning

Rate Limit Exceeded

@JulianToledano has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 51 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 2a905a7 and 5f35a02.

Walkthrough

The overarching change involves the introduction of an address codec across various modules in the codebase. This shift necessitates the modification of method signatures to include the address codec as a parameter, removal of global variable reliance, and enhancement of address handling logic. It aligns with efforts to eliminate global usage of bech32 prefixes and improve modularity and safety in address manipulation.

Changes

Files Summary
CHANGELOG.md, simapp/simd/cmd/testnet.go, testutil/network/util.go, x/genutil/client/cli/... Introduced address.Codec in method signatures, removed global bech32 prefix usage, and enhanced address handling.
server, types Removed servertypes.ModuleInitFlags type and modified MsgSimulatorFn to include address.Codec.
x/genutil/gentx.go, x/genutil/gentx_test.go Adjusted address handling by changing parameter types and improving conversion logic.

Possibly related issues

  • EPIC: remove global bech32 #13140: The changes align with the issue's objectives by removing global bech32 prefix usage, introducing address codecs for prefix handling, and deprecating .String() calls on addresses. This suggests a direct effort to address the outlined concerns regarding global usage of bech32 prefixes and the shift towards a more modular approach in handling addresses within the SDK.

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration 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/coderabbit-overrides.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.

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: 2

Review Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 1574814 and 1e24967.
Files selected for processing (14)
  • CHANGELOG.md (1 hunks)
  • simapp/simd/cmd/testnet.go (7 hunks)
  • testutil/network/util.go (1 hunks)
  • x/genutil/client/cli/collect.go (3 hunks)
  • x/genutil/client/cli/commands.go (1 hunks)
  • x/genutil/client/cli/genaccount.go (1 hunks)
  • x/genutil/client/cli/genaccount_test.go (3 hunks)
  • x/genutil/client/cli/gentx.go (1 hunks)
  • x/genutil/collect.go (4 hunks)
  • x/genutil/collect_test.go (1 hunks)
  • x/genutil/genaccounts.go (4 hunks)
  • x/genutil/gentx.go (2 hunks)
  • x/genutil/gentx_test.go (7 hunks)
  • x/genutil/types/genesis_state_test.go (2 hunks)
Additional Context Used
Path-based Instructions (14)
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/collect_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/collect.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.

x/genutil/gentx.go (1)

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

x/genutil/types/genesis_state_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/genaccounts.go (1)

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

x/genutil/collect.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.

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/genutil/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/testnet.go (1)

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

CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Additional comments not posted (21)
x/genutil/client/cli/commands.go (1)

35-35: Ensure that the removal of the validator address codec argument from CollectGenTxsCmd does not impact its functionality or introduce any regressions.

Verification successful

The removal of the validator address codec argument from CollectGenTxsCmd is consistent with its updated function definition and usage within the codebase. There's no indication of impact on functionality or introduction of regressions based on the provided context.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if CollectGenTxsCmd is used elsewhere with the removed argument
rg "CollectGenTxsCmd" --type go

Length of output: 413

x/genutil/collect_test.go (1)

65-65: Confirm that the addition of addresscodec.NewBech32Codec("cosmos") as an argument to genutil.CollectTxs is correctly implemented and aligns with the refactor's objectives.

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

50-50: Verify that the replacement of valAddrCodec with clientCtx.ValidatorAddressCodec and clientCtx.AddressCodec in GenAppStateFromConfig is correctly implemented and aligns with the refactor's objectives.

Verification successful

The replacement of valAddrCodec with clientCtx.ValidatorAddressCodec and clientCtx.AddressCodec in GenAppStateFromConfig is correctly implemented and aligns with the refactor's objectives, as evidenced by its consistent application across the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if GenAppStateFromConfig correctly handles the new arguments
ast-grep --lang go --pattern $'genutil.GenAppStateFromConfig($_, $_, $_, $_, $_, $_, $_, $_, $_)'

Length of output: 950

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

28-31: Ensure that the use of codectestutil.CodecOptions{}.GetAddressCodec() to obtain an address codec and its subsequent use in converting addresses to strings is correctly implemented and aligns with the refactor's objectives.

Verification successful

The usage of codectestutil.CodecOptions{}.GetAddressCodec() to obtain an address codec and its subsequent application in converting addresses to strings is correctly implemented across the test cases, as evidenced by its consistent application in various files, including x/genutil/client/cli/genaccount_test.go. This aligns with the refactor's objectives.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if the address codec is correctly utilized across the test cases
ast-grep --lang go --pattern $'codectestutil.CodecOptions{}.GetAddressCodec()'

Length of output: 6978

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

77-77: Confirm that the addition of clientCtx.AddressCodec as an argument to genutil.AddGenesisAccount is correctly implemented and aligns with the refactor's objectives.

x/genutil/gentx.go (1)

41-47: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [44-59]

Ensure that the change of the addr parameter type from sdk.Address to string in ValidateAccountInGenesis and its comparison with accAddress are correctly implemented and do not introduce any issues.

Verification successful

The change of the addr parameter type from sdk.Address to string in ValidateAccountInGenesis and its comparison with accAddress using strings.EqualFold are correctly implemented. The verification of the function calls in the codebase confirms that the new parameter type is being correctly handled. No issues introduced by this change were found.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if ValidateAccountInGenesis correctly handles the new parameter type
ast-grep --lang go --pattern $'genutil.ValidateAccountInGenesis($_, $_, $_, $_, $_)'

Length of output: 462

x/genutil/types/genesis_state_test.go (1)

44-53: Verify that the use of valAc.BytesToString to convert validator addresses before creating messages in test functions is correctly implemented and aligns with the refactor's objectives.

x/genutil/genaccounts.go (1)

27-38: Confirm that the addition of the addressCodec parameter to the AddGenesisAccount function and its use in converting account addresses is correctly implemented and aligns with the refactor's objectives.

x/genutil/collect.go (1)

28-28: Ensure the newly added addressCodec parameter is properly documented in the function's comment to explain its purpose and usage.

testutil/network/util.go (1)

153-154: Ensure that the added cfg.ValidatorAddressCodec and cfg.AddressCodec parameters are properly documented in the collectGenFiles function's comment to explain their purpose and usage.

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

125-128: Consider adding a comment above the address conversion logic to explain why the conversion is necessary, enhancing code readability and maintainability.

x/genutil/gentx_test.go (3)

56-56: Ensure the valAc variable is properly documented in the SetupTest method to explain its purpose, especially its role in address conversion.


170-174: Consider adding a comment above the address conversion logic to explain why the conversion is necessary in the context of the test, enhancing code readability.


192-192: In the test case "account without balance in the genesis state", ensure that the address used (addr2Str) aligns with the test's intention. If addr1Str was intended to be used here, correct it accordingly.

Verification successful

The analysis of the test case "account without balance in the genesis state" indicates that the use of addr2Str is intentional and aligns with the test's purpose. The distinction between addr2Str and addr1Str in different test scenarios suggests deliberate usage catering to specific test intentions. Therefore, the original review comment appears to be based on a misunderstanding of the test case's intention.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if addr2Str is intentionally used in this test case or if it should be addr1Str.
echo "Review the test case 'account without balance in the genesis state' to ensure the correct address is used."

Length of output: 228



Script:

#!/bin/bash
# Search for the test case "account without balance in the genesis state" and extract relevant code to understand the use of addr2Str and addr1Str
rg "account without balance in the genesis state" -A 30 x/genutil/gentx_test.go

Length of output: 1126

simapp/simd/cmd/testnet.go (3)

13-18: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-41]

Ensure all removed imports, such as the address package, are no longer referenced in the file. This aligns with the PR's objective to refactor address handling.


302-302: Replace direct address handling with clientCtx.ValidatorAddressCodec for converting addresses, aligning with the PR's objective to improve address representation.

- valStr, err := address.ValidatorAddressCodec.BytesToString(sdk.ValAddress(addr))
+ valStr, err := clientCtx.ValidatorAddressCodec.BytesToString(sdk.ValAddress(addr))

440-440: Ensure the use of clientCtx.ValidatorAddressCodec and clientCtx.AddressCodec in address handling is correctly implemented and aligns with the refactor's objectives.

CHANGELOG.md (4)

112-115: The changes described for x/genutil are clear and accurately reflect the modifications made in the PR. Ensure that all related documentation and examples are updated to reflect these changes.


115-115: The removal of servertypes.ModuleInitFlags and adjustments in server.AddCommands are well-documented. Ensure that any related guides or documentation are updated accordingly.


115-115: The modifications to MsgSimulatorFn in types, including the argument replacement and error handling, are clearly documented. Ensure that all relevant documentation reflects these changes.


115-115: The removal of Accounts.String in types is well-documented. Ensure that any impacted areas of the SDK or documentation are updated to reflect this change.

Comment on lines +145 to +148
valAccAddr, err := addressCodec.BytesToString(valAddr)
if err != nil {
return appGenTxs, persistentPeers, err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Convert the error message to use fmt.Errorf with %w to wrap the original error, enhancing error handling by preserving the original error context.

- return appGenTxs, persistentPeers, err
+ return appGenTxs, persistentPeers, fmt.Errorf("error converting bytes to string: %w", err)

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.

Suggested change
valAccAddr, err := addressCodec.BytesToString(valAddr)
if err != nil {
return appGenTxs, persistentPeers, err
}
valAccAddr, err := addressCodec.BytesToString(valAddr)
if err != nil {
return appGenTxs, persistentPeers, fmt.Errorf("error converting bytes to string: %w", err)
}

Comment on lines +233 to +235
addr, err := addresscodec.NewBech32Codec("cosmos").BytesToString(addr1)
suite.Require().NoError(err)

Copy link
Contributor

Choose a reason for hiding this comment

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

The conversion of addr1 to a string using addresscodec.NewBech32Codec("cosmos").BytesToString(addr1) seems redundant since addr1Str is already available. Consider using addr1Str directly to avoid unnecessary conversions.

- addr, err := addresscodec.NewBech32Codec("cosmos").BytesToString(addr1)
- suite.Require().NoError(err)
+ addr := addr1Str

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.

Suggested change
addr, err := addresscodec.NewBech32Codec("cosmos").BytesToString(addr1)
suite.Require().NoError(err)
addr := addr1Str

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: 2

Review Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 1e24967 and 2a905a7.
Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • simapp/simd/cmd/testnet_test.go (2 hunks)
Additional Context Used
Path-based Instructions (2)
simapp/simd/cmd/testnet_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"

CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Additional comments not posted (3)
simapp/simd/cmd/testnet_test.go (3)

50-50: LGTM! The introduction of cdcOpts for codec options is a clean way to manage codec configurations.


51-51: The modification to include cdcOpts in MakeTestEncodingConfig aligns well with the refactor's goals for improved address handling.


63-65: The updates to the clientCtx setup, including address and validator codecs, are crucial for aligning the test environment with the new address handling mechanism.

CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@testinginprod testinginprod left a comment

Choose a reason for hiding this comment

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

nice cleanup!

@JulianToledano JulianToledano added this pull request to the merge queue Apr 3, 2024
Merged via the queue into main with commit fad30cd Apr 3, 2024
59 of 60 checks passed
@JulianToledano JulianToledano deleted the julian/genutil-accString-removal branch April 3, 2024 20:28
alpe added a commit to alpe/cosmos-sdk that referenced this pull request Apr 8, 2024
* main: (45 commits)
  build(deps): Bump github.com/decred/dcrd/dcrec/secp256k1/v4 from 4.2.0 to 4.3.0 (cosmos#19913)
  build(deps): Bump google.golang.org/grpc from 1.62.1 to 1.63.0 (cosmos#19929)
  test(types/address): add additional unit tests for address.LengthPrefix and a… (cosmos#19964)
  refactor(x/bank)!: remove Address.String() (cosmos#19954)
  build(deps): Bump github.com/prometheus/common from 0.51.1 to 0.52.2 (cosmos#19930)
  fix(x/epochs): Fix init genesis (cosmos#19958)
  feat(core,runtime): transaction service (exec mode) (cosmos#19953)
  fix(x/authz): non utf-8 characters in logs (cosmos#19923)
  build(deps): Bump golang.org/x/crypto from 0.21.0 to 0.22.0 (cosmos#19960)
  chore: fix spelling errors (cosmos#19957)
  fix(x/tx): don't shadow Amino marshalling error messages (cosmos#19955)
  refactor(types): loosen module.AppModule interface (cosmos#19951)
  feat(core): add `TxValidator` interface (cosmos#19950)
  build(deps): Bump cosmossdk.io/store from 1.0.2 to 1.1.0 in /x/epochs (cosmos#19947)
  feat(x/epochs): upstream osmosis epoch module (cosmos#19697)
  build(deps): Bump bufbuild/buf-setup-action from 1.30.0 to 1.30.1 (cosmos#19928)
  refactor(x/genutil)!: remove Address.String() (cosmos#19926)
  docs(x/mint): Fix inconsistency in mint docs  (cosmos#19915)
  build(deps): Bump github.com/regen-network/gocuke from 1.1.0 to 1.1.1 in /orm (cosmos#19920)
  feat: Integrate grpc configuration into client.toml (cosmos#19905)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:CLI C:x/genutil genutil module issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants