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

feat(core,runtime): add address codecs in environment #21905

Closed
wants to merge 2 commits into from

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Sep 25, 2024

Description

Proposal to add address codec in environment as discussed on Slack.
DNM until agreement.


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

    • Introduced new address codec fields in the environment structure to enhance address handling capabilities.
    • Added functionality to set address codecs when creating an environment.
  • Bug Fixes

    • Implemented a mechanism to prevent uninitialized access to address codecs, ensuring stability.
  • Chores

    • Updated module paths in the go.mod files for local development and testing.

@julienrbrt julienrbrt requested review from a team and hieuvubk as code owners September 25, 2024 11:00
Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request primarily focus on enhancing the Environment struct within the Cosmos SDK by introducing new fields for address handling and encoding. This includes the addition of AddressCodec, ValidatorAddressCodec, and ConsensusAddressCodec. Additionally, updates to the go.mod files for both the main module and simapp reflect local path replacements for the cosmossdk.io/core module, facilitating local development. The ProvideEnvironment function in the runtime modules is also modified to incorporate these new address codec parameters.

Changes

File Change Summary
core/appmodule/v2/environment.go Added fields AddressCodec, ValidatorAddressCodec, and ConsensusAddressCodec to the Environment struct for address handling and encoding.
go.mod Introduced replacement directives for cosmossdk.io/core to point to local paths in both the main module and simapp, enabling local development.
runtime/environment.go Updated NewEnvironment to initialize new codec fields and added EnvWithAddressCodecs function. Introduced failingAddressCodec type with methods for string and byte conversion.
runtime/module.go Modified ProvideEnvironment function to include new address codec parameters for environment setup.
runtime/v2/module.go Updated ProvideEnvironment function to add address codec parameters in the appmodulev2.Environment struct, enhancing its functionality for address encoding.
simapp/go.mod Added replacement directive for cosmossdk.io/core to point to a local path, facilitating local testing and development.
tests/go.mod Included a replacement directive for cosmossdk.io/core to redirect to a local path, allowing for local development and testing.

Possibly related PRs

Suggested labels

C:x/params, C:x/accounts, C:x/evidence, C:x/consensus, C:x/staking, C:x/upgrade, C:core/testing, C:server/v2

Suggested reviewers

  • hieuvubk
  • aaronc
  • lucaslopezf
  • akhilkumarpilli
  • testinginprod
  • facundomedica

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2110ca2 and af7776f.

📒 Files selected for processing (1)
  • runtime/environment.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • runtime/environment.go

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

@julienrbrt your pull request is missing a changelog!

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

🧹 Outside diff range and nitpick comments (5)
core/appmodule/v2/environment.go (2)

31-33: LGTM: New address codec fields are well-structured and align with PR objectives.

The new fields AddressCodec, ValidatorAddressCodec, and ConsensusAddressCodec are correctly added to the Environment struct. They align with the PR objectives to introduce address codecs into the environment. The field names are clear, follow Go naming conventions, and use appropriate types from the address package.

Consider adding a brief comment above these new fields to explain their purpose and usage within the Environment struct. This would enhance the documentation and make it easier for other developers to understand the role of these address codecs.


Potential Inconsistencies Detected with the New Address Codec Fields

The introduction of AddressCodec, ValidatorAddressCodec, and ConsensusAddressCodec in Environment has widespread implications across the codebase. Numerous functions and modules interact with the Environment struct and may require updates to handle these new codec fields appropriately. It's essential to review and modify each affected area to ensure consistency and prevent potential runtime issues.

  • Modules and Functions to Review:
    • Slashing Keeper
    • Group Keeper
    • Bank Keeper
    • Authz Keeper
    • Distribution Keeper
    • Mint Keeper
    • Consensus Keeper
    • And many others as indicated by the shell script output.
🔗 Analysis chain

Line range hint 1-33: Overall changes align well with PR objectives and maintain code quality.

The modifications to environment.go successfully introduce address codecs into the Environment struct as intended. The changes are minimal, focused, and well-integrated into the existing code structure. They comply with the Uber Go Style Guide and maintain the overall code quality.

These additions enhance the struct's capability to manage different types of address encodings, which aligns perfectly with the PR objectives discussed in the Slack conversation.

To ensure these changes don't introduce any breaking changes or inconsistencies, please run the following verification script:

This script will help identify any potential areas in the codebase that might need to be updated to accommodate these new fields.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any references to the new address codec fields in other files

# Test: Search for references to the new fields
echo "Checking for references to new address codec fields:"
rg --type go -i '(AddressCodec|ValidatorAddressCodec|ConsensusAddressCodec)'

# Test: Check if there are any existing methods or functions that might need to be updated
echo "Checking for potential methods or functions that might need updates:"
rg --type go -i 'func.*Environment'

Length of output: 231229

runtime/v2/module.go (1)

182-184: LGTM: Address codec parameters and fields added correctly.

The new address codec parameters and fields have been added correctly to the ProvideEnvironment function and the appmodulev2.Environment struct. The changes are consistent with the PR objectives and maintain backward compatibility.

Consider adding a brief comment above the ProvideEnvironment function to explain the purpose of the new address codec parameters and how they enhance the environment's functionality.

Also applies to: 224-226

runtime/module.go (1)

258-260: LGTM: Address codec parameters added correctly.

The new parameters addressCodec, valAddressCodec, and consAddressCodec have been added to the ProvideEnvironment function, and they are correctly used in the EnvWithAddressCodecs call. This change implements a more modular approach to address handling within the application environment.

Consider adding a brief comment above the ProvideEnvironment function to explain the purpose of these new address codec parameters and how they enhance the environment configuration.

Also applies to: 282-282

runtime/environment.go (1)

149-150: Simplify error message formatting

You can simplify the error message formatting by including the space within the format string rather than concatenating it to the prefix.

Apply this diff to adjust the error messages:

 func (f failingAddressCodec) StringToBytes(text string) ([]byte, error) {
-	return nil, fmt.Errorf("%saddress codec not set", f.prefix+" ")
+	return nil, fmt.Errorf("%s address codec not set", f.prefix)
 }

 func (f failingAddressCodec) BytesToString(bz []byte) (string, error) {
-	return "", fmt.Errorf("%saddress codec not set", f.prefix+" ")
+	return "", fmt.Errorf("%s address codec not set", f.prefix)
 }

Also applies to: 153-154

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d54f6fa and 2110ca2.

🔇 Files ignored due to path filters (3)
  • go.sum is excluded by !**/*.sum
  • simapp/go.sum is excluded by !**/*.sum
  • tests/go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • core/appmodule/v2/environment.go (2 hunks)
  • go.mod (1 hunks)
  • runtime/environment.go (4 hunks)
  • runtime/module.go (3 hunks)
  • runtime/v2/module.go (3 hunks)
  • simapp/go.mod (1 hunks)
  • tests/go.mod (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
core/appmodule/v2/environment.go (1)

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

runtime/environment.go (1)

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

runtime/module.go (1)

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

runtime/v2/module.go (1)

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

tests/go.mod (1)

Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

🔇 Additional comments not posted (9)
core/appmodule/v2/environment.go (1)

4-4: LGTM: Import statement is correct and necessary.

The new import for the address package is correctly placed and necessary for the new address codec fields. It follows the Uber Go Style Guide for import formatting.

runtime/v2/module.go (2)

17-17: LGTM: New import added correctly.

The new import for the address package is correctly placed and follows the Uber Go Style Guide for import grouping and ordering.


182-184: Verify the impact of address codec changes on the codebase.

The changes to ProvideEnvironment function and appmodulev2.Environment struct are well-implemented. However, it's important to ensure that these changes don't break existing functionality or require updates in other parts of the codebase.

Please run the following script to check for any potential issues:

This script will help identify areas of the codebase that might need updates or verification due to the new address codec changes.

Also applies to: 224-226

runtime/module.go (3)

15-15: LGTM: New import added correctly.

The new import "cosmossdk.io/core/address" is correctly added and placed in alphabetical order within the import block. This import is necessary for the new address codec parameters in the ProvideEnvironment function.


258-260: Summary of changes: Address codecs added to environment configuration.

The changes to ProvideEnvironment function enhance the modularity of address handling in the application environment. The new address codec parameters allow for more flexible and type-safe address management. These changes align with the PR objectives of introducing address codecs into the environment.

Key points:

  1. New address codec parameters added correctly.
  2. EnvWithAddressCodecs used to incorporate the new parameters.
  3. Import statement added for the new address package.

Next steps:

  1. Verify and update all callers of ProvideEnvironment in the codebase.
  2. Consider adding brief documentation for the new parameters.
  3. Ensure that these changes are thoroughly tested, especially in integration scenarios.

Also applies to: 282-282


258-260: Verify impact on other parts of the codebase.

The changes to ProvideEnvironment function signature will require updates in other parts of the codebase where this function is called. Please ensure that all callers of this function are updated to provide the new address codec parameters.

Run the following script to identify potential places that need to be updated:

✅ Verification successful

Run the following corrected script to identify potential callers of ProvideEnvironment and related wire definitions:


Verification Successful: No additional updates needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find potential callers of ProvideEnvironment that might need updating

# Search for function calls to ProvideEnvironment
echo "Potential callers of ProvideEnvironment:"
rg --type go "ProvideEnvironment\s*\(" -g '!runtime/module.go'

# Search for wire definitions that might need updating
echo "\nPotential wire definitions that might need updating:"
rg --type go "provide.*environment"i -g '!runtime/module.go'

Length of output: 337


Script:

#!/bin/bash
# Description: Find potential callers of ProvideEnvironment that might need updating

# Search for function calls to ProvideEnvironment excluding runtime/module.go
echo "Potential callers of ProvideEnvironment:"
rg --type go "ProvideEnvironment\s*\(" -g '!runtime/module.go'

# Search for wire definitions that might need updating
echo "\nPotential wire definitions that might need updating:"
rg --type go "provide.*environment" -i -g '!runtime/module.go'

Length of output: 1240

go.mod (1)

187-187: LGTM: New replacement directive for cosmossdk.io/core added.

The addition of cosmossdk.io/core => ./core is consistent with other local replacements in this file. This change allows the project to use a local version of the core module, which is likely necessary for implementing the address codecs mentioned in the PR objectives.

To ensure this change doesn't introduce any unintended consequences, please run the following verification script:

tests/go.mod (1)

240-240: LGTM: New replacement directive for cosmossdk.io/core added.

The addition of cosmossdk.io/core => ../core is consistent with other local replacements in this file. This change allows the tests to use the local version of the core module, which is necessary for testing the new address codecs functionality mentioned in the PR objectives.

simapp/go.mod (1)

246-246: LGTM: Local development setup for core module

The addition of the replacement directive for cosmossdk.io/core is consistent with other local development setups in this file. This change allows for easier testing and development of the core module locally.

To ensure this change doesn't introduce any issues, please verify:

  1. The ../core directory exists and contains the expected core module code.
  2. Any changes made to the core module are reflected when building or testing the simapp.

You can use the following script to verify the setup:

runtime/environment.go Show resolved Hide resolved
runtime/environment.go Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@julienrbrt
Copy link
Member Author

@julienrbrt your pull request is missing a changelog!

Will do if accepted.

@julienrbrt
Copy link
Member Author

Not accepted to not leak val address and cons address in environment.

@julienrbrt julienrbrt closed this Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants