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

Introduce ICA Keeper (deduplicating host/controller code) #565

Closed

Conversation

colin-axner
Copy link
Contributor

@colin-axner colin-axner commented Nov 26, 2021

Description

Introduces ICAKeeper to deduplicate code within controller and host. The controller and host modules will be given a prefixed store from the ICAKeeper. Chains not wishing to run controller or host code do not need to create the respective keepers for those modules

This code allows for multiple controller sub modules to be created on the same chain!

closes: #563


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 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.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

These functions within controller/host are wrappers, the actual functionality should be tested by icakeeper.
Furthermore, these functions will be tested by the genesis tests
@codecov-commenter
Copy link

codecov-commenter commented Nov 26, 2021

Codecov Report

Merging #565 (8e0f1a1) into interchain-accounts (009cbec) will decrease coverage by 0.08%.
The diff coverage is 94.01%.

Impacted file tree graph

@@                   Coverage Diff                   @@
##           interchain-accounts     #565      +/-   ##
=======================================================
- Coverage                79.32%   79.23%   -0.09%     
=======================================================
  Files                      139      140       +1     
  Lines                    10460    10443      -17     
=======================================================
- Hits                      8297     8275      -22     
- Misses                    1751     1756       +5     
  Partials                   412      412              
Impacted Files Coverage Δ
modules/apps/27-interchain-accounts/types/keys.go 100.00% <ø> (ø)
.../apps/27-interchain-accounts/host/keeper/keeper.go 72.00% <92.30%> (-13.57%) ⬇️
...27-interchain-accounts/controller/keeper/keeper.go 90.00% <93.75%> (-5.92%) ⬇️
...dules/apps/27-interchain-accounts/keeper/keeper.go 94.31% <94.31%> (ø)

Copy link
Contributor Author

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

I think this is a nice improvement and cuts down on technical debt.

There's one more change necessary to enable support for many ica auth modules (each namespaced). To remove the pointer in the InitGenesis/ExportGenesis logic, we should replace the individual host/controller init/export with a single function at the ica keeper level. The genesis should contain a repeated list of ica submodule genesis, each of which contains the existing fields + the store prefix

My main concern about the store prefix is name collisions (and potentially genesis import/export issues). We might want to have some sort of registration function to ensure there are no name collisions. Thoughts?

@@ -154,70 +138,6 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {
suite.Require().Empty(retrievedAddr)
}

func (suite *KeeperTestSuite) TestGetAllActiveChannels() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed all the GetAll... tests from each controller/host. These have been added to the ica keeper. Testing this functionality at the controller/host level doesn't make sense and it will be tested by the genesis import/export functions

store := ctx.KVStore(k.storeKey)
key := types.KeyActiveChannel(portID)
// GetAllPorts returns all ports to which the interchain accounts controller module is bound. Used in ExportGenesis
func (k Keeper) GetAllPorts(ctx sdk.Context) []string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All duplicate keeper funcs in controller/host are now wrappers

cdc: cdc,
storePrefix: storePrefix,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

prefix used to create a prefixed store from the ICAKeeper

So, one store, but each ica submodule has its own namespace. This is actual quite useful. Now we can create many controller modules (currently require a new keeper for each)

}

// GetAllPorts returns all ports to which a interchain accounts submodule is bound. Used in ExportGenesis
func (k Keeper) GetAllPorts(ctx sdk.Context, storePrefix string) []string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't change any logic in these functions except the first line. Replacing the ctx.KVStore(k.storeKey) with the prefixStore call

@@ -0,0 +1,233 @@
package keeper_test
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test file is copied from controller keeper. Didn't change any logic except calling ICAKeeper directly with icatypes.ControllerModuleName

@colin-axner
Copy link
Contributor Author

After some more reflection, I worry a little too much about introducing reliance on store prefixes not colliding. Chains should be able to register multiple controller modules since they can create multiple IBC controller modules and the keeper functions all use portID for mappings, thus owner addresses could be equivalent across controller modules (assuming we modify the portID to namespace channelID as well).

Thus, the main benefit would be code deduplication. I don't think this trade off is worth it right now given that the SDK is making significant changes to how the stores will work. Once the SDK moves to SMT, we should revisit this discussion. Closing this pr and I will update the issue with my thoughts

@seantking
Copy link
Contributor

Thanks for exploring this regardless. I learned a few things :)

@colin-axner colin-axner deleted the colin/563-ica-code-deduplication branch December 6, 2021 12:20
faddat pushed a commit to notional-labs/ibc-go that referenced this pull request Feb 23, 2022
…erivation

Standardize address derivation
faddat pushed a commit to notional-labs/ibc-go that referenced this pull request Mar 1, 2022
Point to this repo

Thanks for the cleanup @iranzo
CosmosCar pushed a commit to caelus-labs/ibc-go that referenced this pull request Nov 6, 2023
…smos#565)

Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](stretchr/testify@v1.8.0...v1.8.1)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

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

Successfully merging this pull request may close these issues.

3 participants