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: standardise sub keeper usage in core ibc #6081

Merged
merged 6 commits into from
Apr 10, 2024

Conversation

damiannolan
Copy link
Member

@damiannolan damiannolan commented Apr 3, 2024

Description

Use reference types in favour of value types for ibc sub keepers.

closes: #6058


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
    • Updated various functions across modules to use pointer references for improved consistency and efficiency.
    • Modified return types and function parameters to pointers for better memory management.
    • Enhanced test cases to align with the updated pointer reference approach.

Copy link
Contributor

coderabbitai bot commented Apr 3, 2024

Walkthrough

The overarching change involves standardizing the usage of pointers for keepers across various IBC-related modules, ensuring consistency and preventing subtle bugs related to keeper instances. This adjustment facilitates a more reliable and error-free management of keeper references, enhancing the codebase's integrity and functionality.

Changes

File Pattern Change Summary
modules/apps/.../keeper/keeper_test.go Updated type assertions to pointer types for channelkeeper.Keeper.
modules/core/.../genesis.go Modified functions to accept pointers to keeper.Keeper type.
modules/core/.../keeper/keeper.go Changed return type of NewKeeper from Keeper to *Keeper.
modules/core/.../migrations/v7/genesis_test.go Removed dereferencing of suite.chainA.App.GetIBCKeeper().ClientKeeper.

Assessment against linked issues

Objective Addressed Explanation
Standardize sub-keeper usage within the ibc keeper (#6058)
Remove ics4Wrapper Field from Keepers and Adjust ICS4 Wrapper Implementation (#3371) The changes do not mention modifications related to ics4Wrapper or its implementation adjustments.
Restructuring ICS4Wrapper Reference (#4427) The provided changes do not cover the restructuring of ICS4Wrapper references as described.

Possibly related issues

Poem

In the realm of code, where keepers dwell,
A rabbit hopped, casting a spell.
With a flick and a hop, pointers aligned,
Bugs scampered away, no errors to find.

🌟🐇📚
Through fields of code, the rabbit danced,
In its wake, improved code, enhanced.
A tale of change, so deftly spun,
Under the bright, gleaming code sun.


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.

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

@damiannolan damiannolan marked this pull request as ready for review April 8, 2024 13:48
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: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 50d2a08 and 41a6f7f.
Files selected for processing (19)
  • modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go (1 hunks)
  • modules/apps/27-interchain-accounts/host/keeper/keeper_test.go (1 hunks)
  • modules/apps/29-fee/keeper/keeper_test.go (2 hunks)
  • modules/apps/callbacks/ibc_middleware_test.go (1 hunks)
  • modules/apps/transfer/keeper/keeper_test.go (1 hunks)
  • modules/core/02-client/genesis.go (2 hunks)
  • modules/core/02-client/keeper/keeper.go (1 hunks)
  • modules/core/02-client/migrations/v7/genesis_test.go (2 hunks)
  • modules/core/02-client/types/genesis_test.go (1 hunks)
  • modules/core/03-connection/genesis.go (2 hunks)
  • modules/core/03-connection/keeper/keeper.go (1 hunks)
  • modules/core/03-connection/keeper/migrations.go (1 hunks)
  • modules/core/04-channel/genesis.go (2 hunks)
  • modules/core/04-channel/keeper/keeper.go (1 hunks)
  • modules/core/04-channel/keeper/migrations.go (1 hunks)
  • modules/core/05-port/keeper/keeper.go (1 hunks)
  • modules/core/genesis.go (1 hunks)
  • modules/core/keeper/keeper.go (2 hunks)
  • modules/core/migrations/v7/genesis_test.go (2 hunks)
Additional Context Used
Learnings (3)
modules/core/genesis.go (1)
User: likhita-809"
PR: cosmos/cosmos-sdk#18471
File: x/protocolpool/keeper/genesis.go:12-51
Timestamp: 2023-11-22T12:32:39.368Z
Learning: - The user `likhita-809` has confirmed the changes suggested in the previous interaction.
- The file in question is `x/protocolpool/keeper/genesis.go` from a Cosmos SDK module.
- The changes involve optimizing the `InitGenesis` function by removing redundant code and ensuring proper handling of start times for budget proposals.
modules/core/02-client/genesis.go (1)
User: likhita-809"
PR: cosmos/cosmos-sdk#18471
File: x/protocolpool/keeper/genesis.go:12-51
Timestamp: 2023-11-22T12:32:39.368Z
Learning: - The user `likhita-809` has confirmed the changes suggested in the previous interaction.
- The file in question is `x/protocolpool/keeper/genesis.go` from a Cosmos SDK module.
- The changes involve optimizing the `InitGenesis` function by removing redundant code and ensuring proper handling of start times for budget proposals.
modules/core/02-client/migrations/v7/genesis_test.go (1)
User: likhita-809"
PR: cosmos/cosmos-sdk#18471
File: x/protocolpool/keeper/genesis.go:12-51
Timestamp: 2023-11-22T12:32:39.368Z
Learning: - The user `likhita-809` has confirmed the changes suggested in the previous interaction.
- The file in question is `x/protocolpool/keeper/genesis.go` from a Cosmos SDK module.
- The changes involve optimizing the `InitGenesis` function by removing redundant code and ensuring proper handling of start times for budget proposals.
Additional comments not posted (30)
modules/core/04-channel/keeper/migrations.go (2)

11-11: Change to pointer type for keeper field in Migrator struct aligns with PR objectives to standardize sub-keeper usage.


15-15: Adjustment in NewMigrator function parameter to use a pointer type is consistent with the refactor goal.

modules/core/genesis.go (2)

16-16: Passing Keeper instances by reference in InitGenesis function aligns with the refactor's goal for consistent keeper usage.


24-24: Using pointers for Keeper instances in ExportGenesis function is consistent with the refactor's objective.

modules/core/03-connection/keeper/migrations.go (2)

12-12: Change to pointer type for keeper field in Migrator struct aligns with PR objectives to standardize sub-keeper usage.


16-16: Adjustment in NewMigrator function parameter to use a pointer type is consistent with the refactor goal.

modules/core/03-connection/genesis.go (2)

12-12: Using pointers for Keeper instances in InitGenesis function is consistent with the refactor's objective for consistent keeper usage.


27-27: Passing Keeper instances by reference in ExportGenesis function aligns with the refactor's goal.

modules/core/04-channel/genesis.go (2)

14-14: Using pointers for Keeper instances in InitGenesis function is consistent with the refactor's objective for consistent keeper usage.


45-45: Passing Keeper instances by reference in ExportGenesis function aligns with the refactor's goal.

modules/core/05-port/keeper/keeper.go (1)

24-25: Change in NewKeeper function's return type to a pointer aligns with PR objectives to standardize sub-keeper usage.

modules/core/02-client/genesis.go (2)

16-16: Using pointers for Keeper instances in InitGenesis function is consistent with the refactor's objective for consistent keeper usage.


64-64: Passing Keeper instances by reference in ExportGenesis function aligns with the refactor's goal.

modules/core/keeper/keeper.go (2)

32-33: Changing ConnectionKeeper and ChannelKeeper fields to pointers aligns with PR objectives to standardize sub-keeper usage.


63-65: Adjustments in NewKeeper functions for connectionkeeper and channelkeeper to use actual values are consistent with the refactor goal.

modules/core/02-client/migrations/v7/genesis_test.go (2)

36-36: Ensure the ClientKeeper is correctly handled as a pointer throughout the codebase.


111-111: Confirm that the transition to using pointers for ClientKeeper does not affect the expected genesis state.

modules/core/migrations/v7/genesis_test.go (2)

64-64: Ensure the ClientKeeper is correctly handled as a pointer throughout the codebase.


138-138: Confirm that the transition to using pointers for ClientKeeper does not affect the expected genesis state.

modules/core/03-connection/keeper/keeper.go (1)

32-33: The change to return a pointer from NewKeeper aligns with the refactor to use reference types for sub-keepers. Ensure all usages of NewKeeper are updated accordingly.

modules/apps/transfer/keeper/keeper_test.go (2)

344-344: The update to the type assertion in TestWithICS4Wrapper to expect a pointer type aligns with the refactor to use reference types for sub-keepers.


351-351: Confirm that the WithICS4Wrapper method correctly handles the transition to using pointers for the ChannelKeeper.

modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go (1)

364-364: The update to the type assertion in TestWithICS4Wrapper to expect a pointer type aligns with the refactor to use reference types for sub-keepers.

modules/apps/29-fee/keeper/keeper_test.go (2)

309-309: Ensure correct type assertion for channelkeeper.Keeper.


320-320: Ensure correct type assertion for channelkeeper.Keeper.

modules/apps/27-interchain-accounts/host/keeper/keeper_test.go (2)

414-414: Ensure correct type assertion for channelkeeper.Keeper.


421-421: Ensure correct type assertion for channelkeeper.Keeper.

modules/core/02-client/types/genesis_test.go (1)

35-35: Ensure correct usage of ClientKeeper in ExportGenesis function call.

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

36-41: Switching NewKeeper to return a pointer to Keeper aligns with the goal of standardizing sub-keeper usage by ensuring consistent references. This change is crucial for eliminating subtle bugs related to keeper instance management.

modules/core/04-channel/keeper/keeper.go (1)

46-47: Switching NewKeeper to return a pointer to Keeper aligns with the goal of standardizing sub-keeper usage by ensuring consistent references. This change is crucial for eliminating subtle bugs related to keeper instance management.

@@ -89,7 +89,7 @@ func (s *CallbacksTestSuite) TestWithICS4Wrapper() {
cbsMiddleware.WithICS4Wrapper(s.chainA.App.GetIBCKeeper().ChannelKeeper)
ics4Wrapper := cbsMiddleware.GetICS4Wrapper()

s.Require().IsType(channelkeeper.Keeper{}, ics4Wrapper)
s.Require().IsType(&channelkeeper.Keeper{}, ics4Wrapper)
Copy link
Contributor

Choose a reason for hiding this comment

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

Update type assertion to expect a pointer to channelkeeper.Keeper.

- s.Require().IsType(&channelkeeper.Keeper{}, ics4Wrapper)
+ s.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)

This change aligns with the PR's objective to standardize the usage of reference types for sub-keepers, ensuring consistency across the IBC module.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
s.Require().IsType(&channelkeeper.Keeper{}, ics4Wrapper)
s.Require().IsType((*channelkeeper.Keeper)(nil), ics4Wrapper)

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Thanks, @damiannolan!

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.

Love the change! I think it will make things less error prone. I think we should go one step further, and make sure that only the pointer types implement the functions in the expected_keepers.go files.

To make it actually not compile without the pointers being passed. will let you decide if you think that is overkill or not

@crodriguezvega crodriguezvega added the priority PRs that need prompt reviews label Apr 9, 2024
Copy link

sonarcloud bot commented Apr 10, 2024

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

Issues
5 New issues
0 Accepted issues

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

See analysis details on SonarCloud

@damiannolan damiannolan merged commit d89cb08 into main Apr 10, 2024
86 checks passed
@damiannolan damiannolan deleted the damian/6058-standardise-sub-keeper-usage branch April 10, 2024 12:17
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.

Standardize sub-keeper usage within the ibc keeper
4 participants