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(schema)!: move bech32 address prefixes to a higher level #21026

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Jul 22, 2024

Description

This is a small refactor of address handling in schema which does not require modules to specify bech32 address prefixes. I see this as preferable because it moves handling of bech32 rendering to a higher level. Ideally, modules should not need to care how addresses are rendered for clients and should not need to know about bech32 prefixes or whether the standardized address encoding is even bech32. With this design, indexers would receive an address codec instance and use that for all modules and objects in an app when indexing.

One thing that remains to be decided with this new approach is how to handle other types of addresses such as validator addresses.


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

  • New Features

    • The representation of account address types has been updated to reflect a broader scope, allowing for better usability.
  • Bug Fixes

    • Removed validation logic related to the AddressPrefix, simplifying the validation process for various field types.
  • Documentation

    • Enhanced comments and documentation to clarify the expected handling of address types, improving code clarity and maintainability.

Copy link
Contributor

coderabbitai bot commented Jul 22, 2024

Walkthrough

Walkthrough

The recent changes streamline the codebase by removing the AddressPrefix field from the Field struct and renaming Bech32AddressKind to AddressKind. This refactor simplifies validation logic and enhances clarity in handling address types. Test cases related to the removed field have also been deleted, ensuring consistency with the updated structure. Overall, these modifications improve maintainability and usability across the schema's handling of address-related functionalities.

Changes

File Change Summary
schema/field.go Removed AddressPrefix field from Field struct; eliminated related validation logic in the Validate method, simplifying the structure and its validation focus.
schema/field_test.go Removed test cases validating AddressPrefix for Bech32AddressKind, reflecting changes in validation logic and focusing on remaining field types.
schema/kind.go Renamed Bech32AddressKind to AddressKind; updated related comments, String(), and ValidateValueType() methods for consistency and clarity regarding address types.
schema/kind_test.go Updated test cases to reference AddressKind instead of Bech32AddressKind, maintaining validation logic while aligning with the new naming convention.

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.

// AddressKind represents an account address and must be of type []byte. Addresses usually have a
// human-readable rendering, such as bech32, and tooling should provide a way for apps to define a
// string encoder for friendly user-facing display.
AddressKind
Copy link
Member Author

Choose a reason for hiding this comment

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

Most user facing addresses are simply account addresses, but in staking we do have validator addresses exposed to users. Two approaches to handling this are:

  1. add a separate ValidatorAddressKind - this would mirror x/tx which supports only account and validator address
  2. allow some open ended list of address types as Field options - this could be useful if we expect apps will expose other address types because validator and account addresses in queries

Copy link
Member Author

Choose a reason for hiding this comment

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

Anyone have an opinion here? Kind of leaning towards 1. I don't think it's great practice to proliferate lots of bech32 prefixes in one app. They're all account addresses in the end

@aaronc aaronc marked this pull request as ready for review July 22, 2024 16:28
@aaronc aaronc requested a review from a team as a code owner July 22, 2024 16:28
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 ba7e6be and f8da7dd.

Files selected for processing (4)
  • schema/field.go (2 hunks)
  • schema/field_test.go (1 hunks)
  • schema/kind.go (4 hunks)
  • schema/kind_test.go (2 hunks)
Additional context used
Path-based instructions (4)
schema/field.go (1)

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

schema/field_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"

schema/kind_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"

schema/kind.go (1)

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

Additional comments not posted (11)
schema/field.go (2)

Line range hint 14-35:
LGTM! Simplified validation logic.

The removal of the AddressPrefix field and its associated validation logic simplifies the Validate method. The remaining validation logic appears correct and complete.


Line range hint 37-55:
LGTM! Comprehensive value validation.

The ValidateValue method correctly handles null values, validates the value type, and performs additional validation for enum types. The logic appears correct and complete.

schema/field_test.go (2)

Line range hint 7-48:
LGTM! Removed obsolete test cases.

The removal of test cases related to the AddressPrefix field is consistent with the changes in the Field struct. The remaining test cases cover all other validation scenarios.


Line range hint 50-114:
LGTM! Comprehensive value validation tests.

The test cases in TestField_ValidateValue cover all validation scenarios for the ValidateValue method. The logic appears correct and complete.

schema/kind_test.go (3)

Line range hint 7-26:
LGTM! Comprehensive kind validation tests.

The test cases in TestKind_Validate cover all validation scenarios for the Validate method. The logic appears correct and complete.


Line range hint 28-96:
LGTM! Updated kind validation tests.

The test cases for Bech32AddressKind have been correctly updated to AddressKind. The remaining test cases cover all validation scenarios for the ValidateValueType method.


Line range hint 198-220:
LGTM! Updated kind string tests.

The test cases for Bech32AddressKind have been correctly updated to AddressKind. The remaining test cases cover all scenarios for the String method.

schema/kind.go (4)

75-78: LGTM! The renaming improves clarity.

The renaming of Bech32AddressKind to AddressKind and the updated comments enhance the readability and flexibility of the code.


153-153: LGTM! The update ensures consistency.

The change from Bech32AddressKind to AddressKind in the String() method ensures consistency with the renamed constant.


257-257: LGTM! The update ensures consistency.

The change from Bech32AddressKind to AddressKind in the ValidateValueType method ensures consistency with the renamed constant.


324-324: LGTM! The comment update ensures accuracy.

The updated comment in the KindForGoValue function accurately reflects the renaming of Bech32AddressKind to AddressKind.

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.

lgtm

Copy link
Contributor

@lucaslopezf lucaslopezf left a comment

Choose a reason for hiding this comment

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

lgtm

@tac0turtle tac0turtle added this pull request to the merge queue Jul 23, 2024
Merged via the queue into main with commit 2c236af Jul 23, 2024
76 checks passed
@tac0turtle tac0turtle deleted the aaronc/schema-refactor-address branch July 23, 2024 14:39
alpe added a commit that referenced this pull request Jul 23, 2024
* main:
  refactor(schema)!: move bech32 address prefixes to a higher level (#21026)
  chore(core): sync changelog (#21025)
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.

6 participants