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

Deduplicate ICA controller/host keeper code #563

Closed
3 tasks
colin-axner opened this issue Nov 26, 2021 · 3 comments
Closed
3 tasks

Deduplicate ICA controller/host keeper code #563

colin-axner opened this issue Nov 26, 2021 · 3 comments

Comments

@colin-axner
Copy link
Contributor

colin-axner commented Nov 26, 2021

Summary

After splitting host/controller code into 2 submodules (amazing work by @damiannolan), we have some duplicated code. We also have 2 keepers. 2 keepers is nice for dividing storage space so the 2 submodules don't overlap.

Edit: I tried the proposed solution and ran into a couple issues that would require increasing the complexity of the implementation

I propose we combine the keepers into 1 keepers and use 2 key prefixes (host and controller) and allow host/controller to use these prefixed stores. This way we can deduplicate a lot of code (functions like GetAllActiveChannels), we require less code in the app.go file (only 1 keeper needs to be created, no pointer needed), and shared functionality like on-chain parameters can be set at the top level of the ica module.

The controller/host IBC modules will remained split (of course). The ICA keeper would instantiate a controller/host keeper. So in the app.go file, the changes would look something like:

diff --git a/testing/simapp/app.go b/testing/simapp/app.go
index 1955558..702162a 100644
--- a/testing/simapp/app.go
+++ b/testing/simapp/app.go
@@ -352,27 +352,21 @@ func NewSimApp(
        mockModule := ibcmock.NewAppModule(scopedIBCMockKeeper, &app.IBCKeeper.PortKeeper)
        mockIBCModule := ibcmock.NewIBCModule(&ibcmock.MockIBCApp{}, scopedIBCMockKeeper)
 
-       app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
+       app.ICAKeeper = icakeeper.NewKeeper(
                appCodec, keys[icacontrollertypes.StoreKey],
                app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee
                app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
-               app.AccountKeeper, scopedICAControllerKeeper, app.MsgServiceRouter(),
+               app.AccountKeeper, scopedICAKeeper, app.MsgServiceRouter(),
        )
 
-       app.ICAHostKeeper = icahostkeeper.NewKeeper(
-               appCodec, keys[icahosttypes.StoreKey],
-               app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
-               app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(),
-       )
-
-       icaModule := ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper)
+       icaModule := ica.NewAppModule(&app.ICAKeeper.ControllerKeeper, &app.ICAHostKeeper)
 
        // initialize ICA module with mock module as the authentication module on the controller side
        icaAuthModule := ibcmock.NewIBCModule(&ibcmock.MockIBCApp{}, scopedICAMockKeeper)
        app.ICAAuthModule = icaAuthModule
 
-       icaControllerIBCModule := icacontroller.NewIBCModule(app.ICAControllerKeeper, icaAuthModule)
-       icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper)
+       icaControllerIBCModule := icacontroller.NewIBCModule(app.ICAKeeper.ControllerKeeper, icaAuthModule)
+       icaHostIBCModule := icahost.NewIBCModule(app.ICAKeeper.HostKeeper)
 
        // Create static IBC router, add app routes, then set and seal it
        ibcRouter := porttypes.NewRouter()

This works well with #523 since it would allow the params to be set by the ICA keeper, rather than individually in both host/controller. Controller or host can statically be disabled by not registering a IBC route.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged/assigned
@colin-axner colin-axner changed the title Deduplicate ICA controller/host code by creating ICA keeper Deduplicate ICA controller/host keeper code Nov 26, 2021
@colin-axner
Copy link
Contributor Author

colin-axner commented Nov 26, 2021

I tried the above out in #565 by creating a prefixed store for both controller/host based on a top level ICA Keeper. This works great except there is uncertainty in ensuring there are no collisions in store prefixes. The code duplication is fairly minimal and thus the trade off doesn't seem worth it atm. If the SDK could somehow allow you to register prefixed stores, then the changes would be worthwhile

After the SDK releases a stable release (v1.0.0), we could revisit this discussion. However, by this time period, a migration would likely be required to change things

@crodriguezvega
Copy link
Contributor

Thanks for trying, @colin-axner!

@colin-axner
Copy link
Contributor Author

I think we can close this issue for now. The existing solution works fine. There has continued to be a divergence in behaviour between controller/host

faddat pushed a commit to notional-labs/ibc-go that referenced this issue Feb 23, 2022
CosmosCar pushed a commit to caelus-labs/ibc-go that referenced this issue Nov 6, 2023
…osmos#563)

Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.2.0 to 3.3.0.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](golangci/golangci-lint-action@v3.2.0...v3.3.0)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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

No branches or pull requests

2 participants