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/protocol): remove Accounts.String() #19815

Merged
merged 5 commits into from
Mar 21, 2024

Conversation

JulianToledano
Copy link
Contributor

@JulianToledano JulianToledano commented Mar 21, 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

  • Refactor
    • Improved consistency in address handling across various components by standardizing the conversion of addresses to strings.
  • Tests
    • Enhanced testing capabilities through the use of a unified address encoding and decoding approach.
  • Chores
    • Updated simulation and proposal handling to utilize a more robust address conversion method, improving error handling and data integrity.
  • Documentation
    • Clarified the address conversion process for end-users for better understanding.

Copy link
Contributor

coderabbitai bot commented Mar 21, 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 8 minutes and 16 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 f006ee8 and 1186d36.

Walkthrough

The primary focus of the changes is to improve address handling within the protocolpool package by transitioning from direct address string manipulation to utilizing a more structured approach for encoding and decoding addresses. These modifications aim to enhance consistency, error handling, and overall code robustness in address-related operations.

Changes

Files Change Summary
depinject.go, .../keeper/genesis.go Convert addresses to byte slices or strings using specific codec utilities for improved handling.
.../keeper/grpc_query_test.go, .../keeper/keeper_test.go Introduce codectestutil for address encoding and decoding in tests, ensuring consistency.
.../keeper/keeper.go, .../keeper/msg_server.go Modify methods to accept address strings, enhancing address processing within the Keeper struct.
.../simulation/operations.go, .../simulation/proposals.go, .../simulation/proposals_test.go Update address retrieval and comparison methods for improved testing and consistency.

Related issues

  • EPIC: remove global bech32 #13140: The changes in this PR align with the objectives of removing global usage of bech32 prefixes and transitioning towards a more localized and flexible address handling mechanism. By replacing direct bech32 prefix calls with calls to an address codec and deprecating .String() calls on addresses, this PR contributes to addressing the concerns raised in the issue.

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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 3

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 27a231a and 06885ec.
Files selected for processing (10)
  • x/protocolpool/depinject.go (1 hunks)
  • x/protocolpool/keeper/genesis.go (2 hunks)
  • x/protocolpool/keeper/grpc_query_test.go (7 hunks)
  • x/protocolpool/keeper/keeper.go (7 hunks)
  • x/protocolpool/keeper/keeper_test.go (1 hunks)
  • x/protocolpool/keeper/msg_server.go (3 hunks)
  • x/protocolpool/keeper/msg_server_test.go (48 hunks)
  • x/protocolpool/simulation/operations.go (1 hunks)
  • x/protocolpool/simulation/proposals.go (2 hunks)
  • x/protocolpool/simulation/proposals_test.go (2 hunks)
Additional comments: 20
x/protocolpool/simulation/proposals_test.go (1)
  • 32-47: > 📝 NOTE

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

The changes in TestProposalMsgs improve code readability by directly assigning addressCodec and using it for address conversion. This approach is more straightforward and maintains the test's integrity.

x/protocolpool/simulation/proposals.go (1)
  • 37-56: > 📝 NOTE

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

The modifications in SimulateMsgCommunityPoolSpend enhance address handling by using cdc for conversions, which improves consistency and reliability. The error handling and return statements are correctly implemented.

x/protocolpool/keeper/genesis.go (1)
  • 54-65: > 📝 NOTE

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

The changes in ExportGenesis for converting recipient addresses to strings align with the new address handling strategy. The error handling and iteration logic are correctly implemented.

x/protocolpool/simulation/operations.go (1)
  • 75-79: The changes in SimulateMsgFundCommunityPool for converting the funder's address to a string improve error handling and maintain the integrity of the simulation.
x/protocolpool/keeper/grpc_query_test.go (1)
  • 86-100: > 📝 NOTE

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

The use of codectestutil for address encoding and decoding in tests related to budget operations enhances testing capabilities and ensures consistency in address handling.

x/protocolpool/keeper/keeper_test.go (1)
  • 71-80: The introduction of the authority variable in SetupTest aligns with the new address handling strategy. The error handling and use of this variable in the initialization of poolKeeper are correctly implemented.
x/protocolpool/keeper/msg_server.go (3)
  • 34-34: The direct use of msg.RecipientAddress in ClaimBudget simplifies the code and aligns with the new address handling strategy.
  • 167-167: The direct use of msg.RecipientAddress in WithdrawContinuousFund aligns with the new address handling strategy. The error handling and return statements are correctly implemented.
  • 200-200: The direct use of msg.RecipientAddress in CancelContinuousFund simplifies the code and aligns with the new address handling strategy.
x/protocolpool/keeper/keeper.go (6)
  • 116-120: The conversion from recipientAddr string to bytes using k.authKeeper.AddressCodec().StringToBytes(recipientAddr) is correctly implemented. However, consider adding more detailed error handling or logging to provide insights into why an address might be invalid.
  • 125-127: The error messages returned in the withdrawContinuousFund function are clear and informative. However, consider using sdkerrors.Wrapf for consistency with Cosmos SDK error handling practices.
  • 130-130: The check for fund expiry using cf.Expiry.Before(k.environment.HeaderService.GetHeaderInfo(ctx).Time) is a good practice. It ensures that funds cannot be withdrawn after they have expired.
  • 265-268: The conversion from bytes to string using k.authKeeper.AddressCodec().BytesToString(key) within the iterateAndUpdateFundsDistribution function is correctly implemented. However, consider adding error handling for the case where the conversion fails, to ensure the function exits early and cleanly.
  • 318-320: In the claimFunds function, the approach of getting claimable funds and then distributing them from the community pool is logically sound. However, ensure that the error handling is consistent and provides enough context for debugging.
  • 334-338: The getClaimableFunds function correctly checks for the existence of a budget for the recipient and handles the case where no budget is found. Consider enhancing the error message to include more details about why the budget might not exist.
x/protocolpool/keeper/msg_server_test.go (5)
  • 11-11: The addition of codectestutil from github.com/cosmos/cosmos-sdk/codec/testutil is a positive change, as it standardizes the way addresses are handled in tests, improving consistency and maintainability.
  • 28-29: Using codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(recipientAddr) for converting byte slice addresses to string format is a good practice for handling addresses in a consistent manner across tests. This approach enhances readability and ensures that address handling aligns with the SDK's standards.
  • 348-357: The repeated conversion of different recipient addresses to string format using codectestutil.CodecOptions{}.GetAddressCodec() is correctly implemented. However, consider refactoring this repetitive code into a helper function within the test suite to improve code maintainability and reduce duplication.

Consider creating a helper function within the test suite for address conversion to string format to reduce code duplication and improve maintainability.

  • 598-601: The conversion of recipient addresses to string format right before making a call to suite.msgServer.WithdrawContinuousFund is correctly implemented. This ensures that the test aligns with the updated method signatures that expect string addresses. Good attention to detail in ensuring consistency across the test suite.
  • 901-905: The conversion of recipient addresses to string format in the TestCancelContinuousFund test case is correctly implemented, ensuring that the test aligns with the updated method signatures. This consistency in handling addresses as strings is crucial for maintaining the integrity of the test suite.

x/protocolpool/keeper/keeper.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/keeper.go Show resolved Hide resolved
x/protocolpool/depinject.go Outdated Show resolved Hide resolved
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

lgtm

x/protocolpool/keeper/keeper.go Outdated Show resolved Hide resolved
@@ -322,11 +331,11 @@ func (k Keeper) claimFunds(ctx context.Context, recipient sdk.AccAddress) (amoun
return amount, nil
}

func (k Keeper) getClaimableFunds(ctx context.Context, recipient sdk.AccAddress) (amount sdk.Coin, err error) {
func (k Keeper) getClaimableFunds(ctx context.Context, recipient sdk.AccAddress, recipientAddr string) (amount sdk.Coin, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is called from claimFunds, which just converted the string address to sdk.AccAddress. If both are not passed, we just have to convert it again.
I'm not against it, but I don't know how performance can be affected.

Copy link
Contributor

Choose a reason for hiding this comment

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

As it doesn't involve complex operations and inconsistencies, I think we could just call it twice to maintain consistency with other functions

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 06885ec and 5e1a582.
Files selected for processing (3)
  • x/protocolpool/depinject.go (1 hunks)
  • x/protocolpool/keeper/keeper.go (7 hunks)
  • x/protocolpool/keeper/msg_server.go (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/protocolpool/depinject.go
  • x/protocolpool/keeper/keeper.go
  • x/protocolpool/keeper/msg_server.go

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 5e1a582 and f006ee8.
Files selected for processing (1)
  • x/protocolpool/keeper/keeper.go (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/protocolpool/keeper/keeper.go

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

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

one final comment, otherwise lgtm

}

return withdrawnAmount, nil
}

func (k Keeper) withdrawRecipientFunds(ctx context.Context, recipient sdk.AccAddress) (sdk.Coin, error) {
func (k Keeper) withdrawRecipientFunds(ctx context.Context, recipient sdk.AccAddress, recipientAddr string) (sdk.Coin, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, maintain consistency

@JulianToledano JulianToledano added this pull request to the merge queue Mar 21, 2024
Merged via the queue into main with commit 9933a44 Mar 21, 2024
59 of 60 checks passed
@JulianToledano JulianToledano deleted the julian/protocol-accString-removal branch March 21, 2024 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants