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!: mv AddressCodecs aliases from runtime -> core #19747

Merged
merged 5 commits into from
Mar 14, 2024

Conversation

kocubinski
Copy link
Member

@kocubinski kocubinski commented Mar 14, 2024

Description

Discovered while working simapp v2.

Problem: runtime v1 is not a part of DI root but it defines types used across modules and the SDK. We should probably lint guard this if I understand correctly? In simapp v2 start up:

panic: can't resolve type github.com/cosmos/cosmos-sdk/runtime/runtime.ValidatorAddressCodec for cosmossdk.io/x/staking.ProvideModule (/Users/mattk/src/cosmos-sdk/main/x/staking/depinject.go:57):
	while resolving:
		runtime.ValidatorAddressCodec for cosmossdk.io/x/staking.ProvideModule (/Users/mattk/src/cosmos-sdk/main/x/staking/depinject.go:57)
		types.StakingKeeper for cosmossdk.io/x/distribution.ProvideModule (/Users/mattk/src/cosmos-sdk/main/x/distribution/depinject.go:48)
		types.BankKeeper for cosmossdk.io/x/distribution.ProvideModule (/Users/mattk/src/cosmos-sdk/main/x/distribution/depinject.go:48)
		types.RandomGenesisAccountsFn for cosmossdk.io/x/auth.ProvideModule (/Users/mattk/src/cosmos-sdk/main/x/auth/depinject.go:47)
		appmodule.Environment for cosmossdk.io/x/auth.ProvideModule (/Users/mattk/src/cosmos-sdk/main/x/auth/depinject.go:47)
		types.AccountKeeper for cosmossdk.io/x/distribution.ProvideModule (/Users/mattk/src/cosmos-sdk/main/x/distribution/depinject.go:48)
		types.InterfaceRegistry for cosmossdk.io/runtime/v2.ProvideAppBuilder (/Users/mattk/src/cosmos-sdk/main/runtime/v2/module.go:85)
		*runtime.AppBuilder for cosmossdk.io/runtime/v2.ProvideEnvironment (/Users/mattk/src/cosmos-sdk/main/runtime/v2/module.go:210)
		depinject.ModuleKey for cosmossdk.io/runtime/v2.ProvideEnvironment (/Users/mattk/src/cosmos-sdk/main/runtime/v2/module.go:210)
		appmodule.Environment for cosmossdk.io/x/distribution.ProvideModule (/Users/mattk/src/cosmos-sdk/main/x/distribution/depinject.go:48)
		map[string]appmodule.AppModule for cosmossdk.io/simapp/v2/simdv2/cmd.NewRootCmd (/Users/mattk/src/cosmos-sdk/main/simapp/v2/simdv2/cmd/root_di.go:37)

Proposed solution: Move type definitions to core next to address.Codec.

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
    • Enhanced consistency and reliability by updating address-related functionalities to use the new address package across various modules.
    • Removed unnecessary import statement for runtime and updated function calls for improved performance.

@kocubinski kocubinski requested a review from a team as a code owner March 14, 2024 01:41
Copy link
Contributor

coderabbitai bot commented Mar 14, 2024

Walkthrough

Walkthrough

The changes involve consolidating address-related types from the runtime package to the address package across various files. This migration enhances coherence and maintainability in managing address codecs, impacting tests, client interfaces, core components, and module configurations.

Changes

Files Change Summary
baseapp/utils_test.go
crypto/armor_test.go
crypto/keys/multisig/multisig_test.go
simapp/app_test.go
testutil/network/network.go
x/auth/tx/config/depinject.go
x/genutil/client/cli/collect.go
x/genutil/collect.go
Updated types and references to address.ValidatorAddressCodec and address.ConsensusAddressCodec from runtime.
client/v2/autocli/flag/builder.go
simapp/simd/cmd/root_di.go
simapp/simd/cmd/testnet.go
x/staking/depinject.go
Transitioned address-related codecs from runtime to address package.
core/address/codec.go Introduced type aliases ValidatorAddressCodec and ConsensusAddressCodec as aliases for address.Codec.
runtime/module.go Updated to use address.ValidatorAddressCodec and removed old ValidatorAddressCodec and ConsensusAddressCodec types.

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

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 5424b55 and 04d6e5f.
Files selected for processing (14)
  • baseapp/utils_test.go (2 hunks)
  • client/v2/autocli/flag/builder.go (2 hunks)
  • core/address/codec.go (1 hunks)
  • crypto/armor_test.go (2 hunks)
  • crypto/keys/multisig/multisig_test.go (2 hunks)
  • runtime/module.go (2 hunks)
  • simapp/app_test.go (3 hunks)
  • simapp/simd/cmd/root_di.go (2 hunks)
  • simapp/simd/cmd/testnet.go (4 hunks)
  • testutil/network/network.go (2 hunks)
  • x/auth/tx/config/depinject.go (1 hunks)
  • x/genutil/client/cli/collect.go (2 hunks)
  • x/genutil/collect.go (2 hunks)
  • x/staking/depinject.go (3 hunks)
Additional comments: 22
core/address/codec.go (1)
  • 12-16: LGTM! The addition of ValidatorAddressCodec and ConsensusAddressCodec type aliases is clear and follows the naming conventions appropriately.
x/genutil/client/cli/collect.go (2)
  • 7-7: The update of the import path for ValidatorAddressCodec from runtime to address is correctly implemented.
  • 21-21: The usage of address.ValidatorAddressCodec in the CollectGenTxsCmd function signature is appropriate and follows the refactor's objective.
x/staking/depinject.go (2)
  • 7-7: The update of the import path for ValidatorAddressCodec and ConsensusAddressCodec from runtime to address is correctly implemented.
  • 41-42: The usage of address.ValidatorAddressCodec and address.ConsensusAddressCodec in the ModuleInputs struct is appropriate and follows the refactor's objective.
simapp/simd/cmd/root_di.go (1)
  • 105-106: The usage of address.ValidatorAddressCodec and address.ConsensusAddressCodec in the ProvideClientContext function is appropriate and aligns with the refactor's goals.
x/genutil/collect.go (2)
  • 28-28: The update to use address.ValidatorAddressCodec in the GenAppStateFromConfig function is correctly implemented.
  • 71-71: The update to use address.ValidatorAddressCodec in the CollectTxs function is correctly implemented.
x/auth/tx/config/depinject.go (1)
  • 45-45: The update to use address.ValidatorAddressCodec in the ModuleInputs struct is correctly implemented.
crypto/armor_test.go (1)
  • 86-87: The update to use address.ValidatorAddressCodec and address.ConsensusAddressCodec in the test setup is correctly implemented.
runtime/module.go (3)
  • 145-145: The ProvideInterfaceRegistry function now correctly uses address.ValidatorAddressCodec as part of its parameters, aligning with the PR's objective to refactor type usage for better architectural integrity. This change ensures that the core types are defined within the core package, which is part of the Dependency Injection (DI) root.
  • 254-256: The introduction of factory functions for AddressCodec, ValidatorAddressCodec, and ConsensusAddressCodec in the AddressCodecInputs struct is a significant improvement. It allows for more flexible and decoupled code, facilitating easier testing and future modifications. This change aligns with best practices in software design, promoting modularity and maintainability.
  • 261-261: The ProvideAddressCodec function's implementation to dynamically provide address.Codec, address.ValidatorAddressCodec, and address.ConsensusAddressCodec based on the provided inputs is a robust solution. It ensures that the application can adapt to different configurations and requirements without hardcoding dependencies. This approach enhances the flexibility and scalability of the codebase.
baseapp/utils_test.go (1)
  • 49-50: The changes updating validatorAddressCodec and consensusAddressCodec from the runtime package to the address package are correctly implemented and align with the PR's objectives.
simapp/app_test.go (1)
  • 315-316: The updates replacing references to runtime.ValidatorAddressCodec and runtime.ConsensusAddressCodec with address.ValidatorAddressCodec and address.ConsensusAddressCodec are correctly implemented and align with the PR's objectives.

Also applies to: 342-343

crypto/keys/multisig/multisig_test.go (1)
  • 365-366: The update of references from runtime.ValidatorAddressCodec and runtime.ConsensusAddressCodec to address.ValidatorAddressCodec and address.ConsensusAddressCodec respectively in the TestDisplay function aligns with the PR's objective to refactor and move these type aliases to the core/address package. This change is crucial for resolving dependency issues and improving architectural design within the Cosmos SDK. The usage of these new references in tests ensures that the refactor is consistently applied across the codebase, including test cases, which is a good practice for maintaining code integrity and reliability.
client/v2/autocli/flag/builder.go (1)
  • 56-57: The update of ValidatorAddressCodec and ConsensusAddressCodec fields in the Builder struct from the runtime package to the address package is consistent with the PR's objective to refactor and improve the architectural integrity of the Cosmos SDK. By ensuring that core types are defined within the core package, which is part of the Dependency Injection (DI) root, this change contributes to resolving dependency issues and enhancing the SDK's design. It's important to verify that all references to these codecs throughout the SDK have been updated accordingly to avoid any potential issues with unresolved types.
simapp/simd/cmd/testnet.go (3)
  • 11-11: The addition of the import statement "cosmossdk.io/core/address" is correctly placed and follows Go conventions for organizing imports. Grouping standard library imports separately from third-party packages is a good practice.
  • 212-212: The update to the function signature of initTestnetFiles to use address.ValidatorAddressCodec instead of runtime.ValidatorAddressCodec correctly reflects the architectural change. This ensures that the dependency on core types is properly managed within the DI root.
  • 420-420: Similarly, the update to the function signature of collectGenFiles to use address.ValidatorAddressCodec aligns with the architectural improvements aimed at resolving dependency issues and enhancing the SDK's design. This change is consistent and necessary for the refactor.
testutil/network/network.go (2)
  • 132-133: The update of ValidatorAddressCodec and ConsensusAddressCodec types from the runtime package to the address package in the Config struct aligns with the PR's objective to improve architectural integrity by ensuring core types are defined within the core package. This change is crucial for resolving dependency issues and facilitating smoother development processes.
  • 188-189: The use of ValidatorAddressCodec and ConsensusAddressCodec from the address package in the DefaultConfigWithAppConfig function is consistent with the changes made in the Config struct. This ensures that the new types are properly integrated and used throughout the file, contributing to the overall goal of the refactor.

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 04d6e5f and 038fcd3.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments: 1
CHANGELOG.md (1)
  • 153-153: The changelog entry for PR refactor!: mv AddressCodecs aliases from runtime -> core #19747 accurately notes the movement of ValidatorAddressCodec and ConsensusAddressCodec from runtime to core. However, it could be enhanced by specifying the exact new location (core/address) and briefly mentioning the motivation behind this change, such as resolving dependency issues and enhancing the architectural design of the Cosmos SDK. This additional information would provide more context and clarity to the readers.

Copy link
Member

@julienrbrt julienrbrt 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

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

just one question, otherwise lgtm
and also linting imports should be fixed

@@ -25,7 +25,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/xsalsa20symmetric"
"github.com/cosmos/cosmos-sdk/runtime"
_ "github.com/cosmos/cosmos-sdk/runtime"
Copy link
Contributor

Choose a reason for hiding this comment

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

dumb question, why do we still blank import runtime ? is it because of depinject ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, this test uses depinject to initialize, so without runtime imported the Provider funcs are absent.

To be honest it seems a bit not golang, I'd like to see a composition root where Providers are defined rather than importing packages for side effects.

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 038fcd3 and 0782026.
Files selected for processing (2)
  • crypto/armor_test.go (2 hunks)
  • crypto/keys/multisig/multisig_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • crypto/armor_test.go
  • crypto/keys/multisig/multisig_test.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 0782026 and a3a294d.
Files selected for processing (4)
  • simapp/simd/cmd/testnet.go (4 hunks)
  • x/genutil/client/cli/collect.go (2 hunks)
  • x/genutil/collect.go (2 hunks)
  • x/staking/depinject.go (3 hunks)
Files skipped from review as they are similar to previous changes (4)
  • simapp/simd/cmd/testnet.go
  • x/genutil/client/cli/collect.go
  • x/genutil/collect.go
  • x/staking/depinject.go

@kocubinski kocubinski added this pull request to the merge queue Mar 14, 2024
Merged via the queue into main with commit c807aae Mar 14, 2024
62 of 63 checks passed
@kocubinski kocubinski deleted the kocubinski/rf-address-codec branch March 14, 2024 14:24
kocubinski added a commit that referenced this pull request Mar 14, 2024
Co-authored-by: Marko <marbar3778@yahoo.com>
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.

4 participants