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

imp: pass client store provider as arg to client modules #6028

Merged
merged 14 commits into from
Jul 15, 2024

Conversation

DimitrisJim
Copy link
Contributor

@DimitrisJim DimitrisJim commented Mar 20, 2024

Description

Opening as draft, parent issue requires discussion.

Upsides:

  • simpler router
  • slightly slimmer lcm interface
  • no dangling nils after init

Downsides:

  • more requirements by light client devs in app.go

closes: #6009


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

Summary by CodeRabbit

  • Refactor
    • Standardized the use of storetypes.StoreKey across various light client modules for simplified initialization.
    • Streamlined the LightClientModule interface by removing the RegisterStoreProvider method.
    • Enhanced setup processes in multiple testing applications by updating the NewSimApp function with additional parameters.

Copy link
Contributor

coderabbitai bot commented Mar 20, 2024

Walkthrough

Walkthrough

The primary focus of the changes is on decentralizing the initialization of the storeProvider to the light client modules, enhancing modularity and simplifying the setup process. This restructuring involves adding storetypes.StoreKey to the NewLightClientModule function, initializing storeProvider within the modules, and removing the RegisterStoreProvider method to streamline the configuration of light client modules.

Changes

Files Change Summary
modules/.../testing/simapp/app.go, modules/light-clients/06-solomachine/light_client_module.go, modules/light-clients/07-tendermint/light_client_module.go, modules/light-clients/08-wasm/light_client_module.go, modules/light-clients/09-localhost/light_client_module.go Added storetypes.StoreKey to NewLightClientModule function and initialized storeProvider. Removed RegisterStoreProvider method.
modules/core/02-client/keeper/keeper.go NewKeeper function initializes router without key parameter.
modules/core/02-client/types/router.go, modules/core/exported/client.go Simplified Router by removing storeProvider and related functionality. Removed RegisterStoreProvider from LightClientModule interface.

Assessment against linked issues

Objective Addressed Explanation
Move initialization of storeProvider to light client modules (#6009)
Decouple encoding and routing; Address interface functions and state handling issues (#5845) The changes focus on storeProvider initialization and do not address encoding, routing, or interface adjustments directly.
Enhance flexibility and maintainability of 08-wasm module (#5084) The PR does not specifically address wasm module restructuring or the introduction of a client_type field.
Implement conditional client functionality and dependency management (#5112) The modifications are unrelated to conditional clients or their specific dependency management needs.
Enhance modularity and reduce dependencies by providing 06-solomachine with its own go.mod file (#4213) Changes are centered on storeProvider and do not include modularization or dependency reduction efforts for 06-solomachine.
Move client state testing to light client module entry points (#6001) While the changes align with enhancing light client module autonomy, it's unclear if they directly facilitate the movement of client state testing to module entry points.

Possibly related issues


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

@DimitrisJim
Copy link
Contributor Author

DimitrisJim commented Mar 25, 2024

dunno why I kept this in draft, opening for review. Can ignore linting issue will fix tomorrow.

edit: whoops, seems the rebase messed with me, I'll fix em up.

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 5514d56 and 2bb2f38.
Files selected for processing (10)
  • modules/apps/callbacks/testing/simapp/app.go (1 hunks)
  • modules/core/02-client/keeper/keeper.go (1 hunks)
  • modules/core/02-client/types/router.go (2 hunks)
  • modules/core/exported/client.go (1 hunks)
  • modules/light-clients/06-solomachine/light_client_module.go (2 hunks)
  • modules/light-clients/07-tendermint/light_client_module.go (2 hunks)
  • modules/light-clients/08-wasm/light_client_module.go (2 hunks)
  • modules/light-clients/08-wasm/testing/simapp/app.go (1 hunks)
  • modules/light-clients/09-localhost/light_client_module.go (1 hunks)
  • testing/simapp/app.go (1 hunks)
Additional comments: 19
modules/core/02-client/types/router.go (3)
  • 11-11: The removal of the storeProvider field from the Router struct simplifies the router's structure, aligning with the PR's objectives to streamline the initialization process for light client modules. This change should reduce complexity and potential sources of errors related to uninitialized variables.
  • 15-17: The NewRouter function has been correctly updated to reflect the removal of the storeProvider. It now initializes the Router struct without requiring a StoreKey parameter, which simplifies the router initialization process.
  • 22-22: The AddRoute method's documentation and implementation have been appropriately updated to remove references to the storeProvider. This change is consistent with the PR's goal of simplifying the router's structure by directly passing keys to light client modules during their initialization.
modules/light-clients/09-localhost/light_client_module.go (1)
  • 27-29: The NewLightClientModule function has been correctly updated to initialize the storeProvider field directly using the storetypes.StoreKey parameter. This change aligns with the PR's objectives to streamline the initialization process for light client modules and eliminate uninitialized variables post-initialization.
modules/core/exported/client.go (1)
  • 54-59: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The removal of the RegisterStoreProvider method from the LightClientModule interface simplifies the interface and aligns with the PR's objectives to streamline the initialization process for light client modules. This change should make the interface more straightforward and reduce the burden on light client developers.

modules/light-clients/06-solomachine/light_client_module.go (2)
  • 5-5: The addition of the storetypes import is necessary for the changes made to the NewLightClientModule function, allowing the use of storetypes.StoreKey in the function signature. This change is consistent with the PR's objectives to directly pass keys to light client modules during their initialization.
  • 23-26: The NewLightClientModule function has been correctly updated to include a key storetypes.StoreKey parameter and initialize the storeProvider field directly. This change aligns with the PR's objectives to streamline the initialization process for light client modules and eliminate uninitialized variables post-initialization.
modules/light-clients/07-tendermint/light_client_module.go (2)
  • 5-5: The addition of the storetypes import is necessary for the changes made to the NewLightClientModule function, allowing the use of storetypes.StoreKey in the function signature. This change is consistent with the PR's objectives to directly pass keys to light client modules during their initialization.
  • 25-28: The NewLightClientModule function has been correctly updated to include a key storetypes.StoreKey parameter and initialize the storeProvider field directly. This change aligns with the PR's objectives to streamline the initialization process for light client modules and eliminate uninitialized variables post-initialization.
modules/light-clients/08-wasm/light_client_module.go (2)
  • 6-6: The addition of the storetypes import is necessary for the changes made to the NewLightClientModule function, allowing the use of storetypes.StoreKey in the function signature. This change is consistent with the PR's objectives to directly pass keys to light client modules during their initialization.
  • 25-28: The NewLightClientModule function has been correctly updated to include a key storetypes.StoreKey parameter and initialize the storeProvider field directly. This change aligns with the PR's objectives to streamline the initialization process for light client modules and eliminate uninitialized variables post-initialization.
modules/core/02-client/keeper/keeper.go (1)
  • 42-42: The NewKeeper function has been modified to initialize the router without passing the key parameter. This change aligns with the PR's objective to simplify the router's complexity by directly passing keys to light client modules during their initialization. However, it's crucial to ensure that all references and usages of the router throughout the codebase are updated to reflect this new initialization pattern. Additionally, consider adding comments to explain the rationale behind this change for future maintainability.

Ensure that all usages of the router and light client modules are consistent with this new initialization approach.

testing/simapp/app.go (2)
  • 566-566: The initialization of the tmLightClientModule now includes passing keys[ibcexported.StoreKey] directly. This change aligns with the PR objectives and simplifies the initialization process by ensuring that the light client module has direct access to its required store key. Ensure that the keys map is correctly populated with ibcexported.StoreKey before this point in the code.
  • 569-569: Similarly, the smLightClientModule initialization now directly receives keys[ibcexported.StoreKey]. This modification is consistent with the PR's goal of streamlining the initialization process for light client modules. As with the previous comment, verify that the keys map contains the ibcexported.StoreKey at this stage.
modules/apps/callbacks/testing/simapp/app.go (2)
  • 574-574: The addition of keys[ibcexported.StoreKey] as a parameter to the ibctm.NewLightClientModule function aligns with the PR's objective to pass keys directly to light client modules during their initialization. This change simplifies the initialization process and eliminates the need for uninitialized variables post-initialization.
  • 577-577: Similarly, the addition of keys[ibcexported.StoreKey] as a parameter to the solomachine.NewLightClientModule function is consistent with the PR's objectives and enhances the initialization process for the solomachine light client module.
modules/light-clients/08-wasm/testing/simapp/app.go (3)
  • 608-608: The initialization of the Tendermint light client module (tmLightClientModule) now includes passing keys[ibcexported.StoreKey] directly. This change aligns with the PR objectives and simplifies the initialization process by directly providing necessary keys.
  • 611-611: The initialization of the Solo Machine light client module (smLightClientModule) has been updated to include keys[ibcexported.StoreKey] as a parameter. This modification is consistent with the PR's goal of streamlining the initialization process for light client modules.
  • 614-614: The initialization of the Wasm light client module (wasmLightClientModule) now passes keys[ibcexported.StoreKey] directly to the NewLightClientModule function. This change is in line with the PR's objectives to simplify the router's complexity and improve the initialization process.

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 Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 2bb2f38 and caeee91.
Files selected for processing (7)
  • modules/apps/callbacks/testing/simapp/app.go (1 hunks)
  • modules/core/02-client/keeper/keeper.go (1 hunks)
  • modules/core/02-client/types/router_test.go (2 hunks)
  • modules/light-clients/06-solomachine/light_client_module.go (2 hunks)
  • modules/light-clients/08-wasm/light_client_module.go (2 hunks)
  • modules/light-clients/08-wasm/testing/simapp/app.go (1 hunks)
  • testing/simapp/app.go (1 hunks)
Additional Context Used
Path-based Instructions (7)
modules/core/02-client/types/router_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"

modules/light-clients/06-solomachine/light_client_module.go (1)

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

modules/light-clients/08-wasm/light_client_module.go (1)

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

modules/core/02-client/keeper/keeper.go (1)

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

testing/simapp/app.go (1)

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

modules/apps/callbacks/testing/simapp/app.go (1)

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

modules/light-clients/08-wasm/testing/simapp/app.go (1)

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

Additional comments not posted (14)
modules/core/02-client/types/router_test.go (2)

62-63: The modifications to the NewLightClientModule and NewRouter function calls in the test align with the PR objectives and correctly reflect the changes made to these functions.


128-129: The adjustments to the NewLightClientModule and NewRouter function calls in this test are consistent with the PR's objectives, accurately reflecting the changes made to these functions.

modules/light-clients/06-solomachine/light_client_module.go (2)

25-28: The addition of the key parameter to the NewLightClientModule function and its use to initialize the storeProvider field align with the PR objectives, simplifying the initialization process for the light client module.


25-28: The removal of the RegisterStoreProvider method is justified by the direct initialization of the storeProvider within the NewLightClientModule function, streamlining the initialization process.

modules/light-clients/08-wasm/light_client_module.go (2)

25-28: The addition of the key parameter to the NewLightClientModule function and its use to initialize the storeProvider field align with the PR objectives, simplifying the initialization process for the light client module.


25-28: The removal of the RegisterStoreProvider method is justified by the direct initialization of the storeProvider within the NewLightClientModule function, streamlining the initialization process.

modules/core/02-client/keeper/keeper.go (1)

37-37: The modification to the NewKeeper function, creating a router without passing the key parameter to types.NewRouter(), aligns with the PR objectives and correctly reflects the changes made to simplify the router's structure.

testing/simapp/app.go (2)

566-566: This change correctly initializes the Tendermint light client module with the necessary store key, aligning with the PR's objectives.


569-569: This change correctly initializes the Solo Machine light client module with the necessary store key, aligning with the PR's objectives.

modules/apps/callbacks/testing/simapp/app.go (2)

574-574: Ensure the keys[ibcexported.StoreKey] parameter is correctly passed and utilized within the ibctm.NewLightClientModule function.

Verification successful

The NewLightClientModule function within the ibctm module correctly utilizes the passed StoreKey parameter. This is evident from the function definition and its usage:

func NewLightClientModule(key storetypes.StoreKey, cdc codec.BinaryCodec, authority string) LightClientModule {
    return LightClientModule{
        keeper:        keeper.NewKeeper(cdc, authority),
        storeProvider: clienttypes.NewStoreProvider(key),
    }
}

The StoreKey parameter is used to initialize a storeProvider via clienttypes.NewStoreProvider(key), indicating that the parameter is correctly passed and utilized within the function.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the `NewLightClientModule` function within the `ibctm` module correctly utilizes the passed `StoreKey`.
ast-grep --lang go --pattern $'func NewLightClientModule($_, $_, $_) $_ { $$$ }' --include '*/ibctm/*.go'

Length of output: 309



Script:

#!/bin/bash
# Verify that the `NewLightClientModule` function within the `ibctm` module correctly utilizes the passed `StoreKey`.
ast-grep --lang go --pattern $'func NewLightClientModule($_, $_, $_) $_ { $$$ }'

Length of output: 712


577-577: Ensure the keys[ibcexported.StoreKey] parameter is correctly passed and utilized within the solomachine.NewLightClientModule function.

Verification successful

The verification process confirms that the keys[ibcexported.StoreKey] parameter is correctly passed and utilized within the solomachine.NewLightClientModule function. The parameter is used to initialize the storeProvider field of the LightClientModule instance, indicating proper utilization within the function.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the `NewLightClientModule` function within the `solomachine` module correctly utilizes the passed `StoreKey`.
ast-grep --lang go --pattern $'func NewLightClientModule($_, $_) $_ { $$$ }' --include '*/solomachine/*.go'

Length of output: 311



Script:

#!/bin/bash
# Verify that the `NewLightClientModule` function within the `solomachine` module correctly utilizes the passed `StoreKey`.
ast-grep --lang go --pattern $'func NewLightClientModule($_, $_) $_ { $$$ }'

Length of output: 1886

modules/light-clients/08-wasm/testing/simapp/app.go (3)

609-609: Ensure the keys[ibcexported.StoreKey] parameter is correctly passed and utilized within the NewLightClientModule function of the Tendermint light client module.


612-612: Ensure the keys[ibcexported.StoreKey] parameter is correctly passed and utilized within the NewLightClientModule function of the Solo Machine light client module.


615-615: Ensure the keys[ibcexported.StoreKey] parameter is correctly passed and utilized within the NewLightClientModule function of the Wasm light client module.

Copy link
Contributor

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

In general I agree with removing the weird injection thing, but I think we should pass the interface type as an arg instead of the key directly

modules/light-clients/07-tendermint/light_client_module.go Outdated Show resolved Hide resolved
Copy link

Quality Gate Passed Quality Gate passed for 'ibc-go'

Issues
7 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

Quality Gate Passed Quality Gate passed for 'ibc-go'

Issues
8 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link
Contributor

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Leaving some comments for context

@@ -40,8 +33,6 @@ func (rtr *Router) AddRoute(clientType string, module exported.LightClientModule
}

rtr.routes[clientType] = module

module.RegisterStoreProvider(rtr.storeProvider)
Copy link
Contributor

Choose a reason for hiding this comment

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

For context: this was the main thing we wanted to remove with this PR!

// RegisterStoreProvider is called by core IBC when a LightClientModule is added to the router.
// It allows the LightClientModule to set a ClientStoreProvider which supplies isolated prefix client stores
// to IBC light client instances.
RegisterStoreProvider(storeProvider ClientStoreProvider)
Copy link
Contributor

Choose a reason for hiding this comment

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

And this!

testing/simapp/app.go Outdated Show resolved Hide resolved
@damiannolan damiannolan added the priority PRs that need prompt reviews label Jul 15, 2024
Copy link
Contributor Author

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

can't leave review so LGTMing verbally! Thanks for follow up @damiannolan!

Copy link

Copy link
Contributor

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Thanks @DimitrisJim

@damiannolan damiannolan changed the title Pass keys to light client modules during initialization. imp: pass client store provider as arg to client modules Jul 15, 2024
Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

LGTM thank you @damiannolan / @DimitrisJim 🥇

@DimitrisJim DimitrisJim added this pull request to the merge queue Jul 15, 2024
Merged via the queue into main with commit 52d73f2 Jul 15, 2024
71 of 72 checks passed
@DimitrisJim DimitrisJim deleted the jim/issue6009-init-provider-in-lcm branch July 15, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move initialization of storeProvider to light client modules
4 participants