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

Change signature of NewKeeper to directly accept a ConsensusHost #6084

Conversation

chatton
Copy link
Contributor

@chatton chatton commented Apr 3, 2024

Description

closes: #6082


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 the initialization logic for certain components to use a ConsensusHost implementation instead of a StakingKeeper. This change aims to enhance clarity and functionality in the system's consensus mechanism.

Copy link
Contributor

coderabbitai bot commented Apr 3, 2024

Walkthrough

The recent update focuses on enhancing the initialization logic of the IBC keeper by replacing the stakingKeeper argument with a consensusHost in the NewKeeper function. This change streamlines the keeper's dependencies, aligning with the broader goal of refining the IBC module's architecture for improved clarity and functionality across various components.

Changes

File Path Change Summary
modules/core/02-client/keeper/keeper.go Replaced stakingKeeper with consensusHost in NewKeeper function.
modules/core/keeper/keeper.go Updated NewKeeper function to use consensusHost instead of stakingKeeper.
modules/core/keeper/keeper_test.go Adjusted tests for NewKeeper to use ConsensusHost instead of StakingKeeper.
.../callbacks/testing/simapp/app.go
.../light-clients/08-wasm/testing/simapp/app.go
testing/simapp/app.go
Modified IBCKeeper initialization to use NewConsensusHost as a parameter in NewSimApp.

Assessment against linked issues

Objective Addressed Explanation
Pass ConsensusHost as arg to core ibc NewKeeper func (#6082)
Standardize sub-keeper usage within the ibc keeper (#6058) The changes focus on replacing stakingKeeper with consensusHost, which aligns with standardization efforts, but it's unclear if all sub-keeper usage has been standardized.
Remove ics4Wrapper Field from Keepers and Modify IBCMiddleware Structure (#3371, #4427) The provided changes do not address the restructuring of ics4Wrapper references or IBCMiddleware adjustments.

Possibly related issues

  • Issue Standardize sub-keeper usage within the ibc keeper #6058: The effort to standardize sub-keeper usage within the ibc keeper could be indirectly supported by this PR, as it involves a significant change in keeper initialization that could pave the way for further standardization efforts. However, the PR does not explicitly address all aspects of sub-keeper standardization as mentioned in the issue.

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

Copy link
Member

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

ACK, think there's a compiler error in test file. We can also remove the expected keeper in 02-client/types for staking keeper. Otherwise LGTM!

modules/core/keeper/keeper_test.go Outdated Show resolved Hide resolved
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: 2

Review Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 50d2a08 and f1d2a0a.
Files selected for processing (7)
  • CHANGELOG.md (1 hunks)
  • modules/apps/callbacks/testing/simapp/app.go (1 hunks)
  • modules/core/02-client/keeper/keeper.go (2 hunks)
  • modules/core/keeper/keeper.go (2 hunks)
  • modules/core/keeper/keeper_test.go (6 hunks)
  • modules/light-clients/08-wasm/testing/simapp/app.go (1 hunks)
  • testing/simapp/app.go (1 hunks)
Files not reviewed due to errors (1)
  • (no review received)
Additional Context Used
GitHub Check Runs (2)
tests (03) failure (5)

modules/core/keeper/keeper_test.go: [failure] 20-20:
ibctm redeclared in this block


modules/core/keeper/keeper_test.go: [failure] 8-8:
other declaration of ibctm


modules/core/keeper/keeper_test.go: [failure] 20-20:
"github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" imported as ibctm and not used

lint failure (6)

modules/core/keeper/keeper_test.go: [failure] 20-20:
ibctm redeclared in this block


modules/core/keeper/keeper_test.go: [failure] 8-8:
other declaration of ibctm


modules/core/keeper/keeper_test.go: [failure] 20-20:
"github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" imported as ibctm and not used (typecheck)

Path-based Instructions (7)
modules/core/keeper/keeper.go (1)

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

modules/core/keeper/keeper_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/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.

CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Additional comments not posted (5)
modules/core/keeper/keeper.go (1)

40-53: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [43-63]

The changes to the NewKeeper function, including the introduction of the consensusHost parameter and the updated error messages, are correctly implemented and align with the PR objectives.

modules/core/keeper/keeper_test.go (1)

74-84: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [66-136]

The updates to the TestNewKeeper function's test cases correctly reflect the changes from StakingKeeper to ConsensusHost.

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

33-39: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [36-45]

The changes to the NewKeeper function, including the introduction of the consensusHost parameter and its assignment in the Keeper struct, are correctly implemented and align with the PR objectives.

testing/simapp/app.go (1)

411-411: Ensure that the broader impact of changing the NewKeeper function's signature to accept a ConsensusHost directly instead of a StakingKeeper is verified across the IBC module and related components.

Verification successful

Given the absence of results from the initial verification scripts, it's possible that the search patterns used were too specific or that the scope of the search did not capture the relevant occurrences. To ensure a thorough verification, I recommend generating new verification scripts with adjusted search patterns or expanding the search scope. If the scripts still return no results, it might be necessary to request manual verification from the user or conclude based on the best available evidence.


The verification process has confirmed that the NewConsensusHost function is properly defined and utilized within the IBC module and related components. Additionally, there are no unintended references to the old StakingKeeper parameter within the IBC module's initialization. The references to StakingKeeper found in the search are part of other modules' initialization processes and are intended. Therefore, the changes to the NewKeeper function's signature to accept a ConsensusHost directly instead of a StakingKeeper have been verified across the IBC module and related components without issues.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the NewConsensusHost function is properly defined and used elsewhere in the IBC module.
ast-grep --lang go --pattern $'NewConsensusHost($_)'
# Ensure no unintended references to the old StakingKeeper parameter remain in the IBC module initialization.
ast-grep --lang go --pattern $'NewKeeper($$$, $_.StakingKeeper, $$$)'

Length of output: 124



Script:

#!/bin/bash
# Broaden the search for NewConsensusHost to ensure it's properly defined and used within the IBC module or related components.
rg 'NewConsensusHost' --type go
# Broaden the search to ensure no unintended references to the old StakingKeeper parameter remain in the IBC module initialization or related components.
rg 'NewKeeper' --type go | grep 'StakingKeeper'

Length of output: 3425

CHANGELOG.md (1)

46-46: Ensure the CHANGELOG entry for the NewKeeper function change in core/02-client includes details about the motivation and impact of the change.

@@ -407,7 +407,7 @@ func NewSimApp(
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String())

app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the NewConsensusHost function properly handles the StakingKeeper argument and any potential errors.

- ibctm.NewConsensusHost(app.StakingKeeper)
+ consensusHost, err := ibctm.NewConsensusHost(app.StakingKeeper)
+ if err != nil {
+     panic(fmt.Errorf("failed to create NewConsensusHost: %w", err))
+ }

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
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), consensusHost, err := ibctm.NewConsensusHost(app.StakingKeeper)
if err != nil {
panic(fmt.Errorf("failed to create NewConsensusHost: %w", err))
}, app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),

Comment on lines 8 to 20
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

testifysuite "github.com/stretchr/testify/suite"

upgradekeeper "cosmossdk.io/x/upgrade/keeper"

stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the duplicate import of "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" as ibctm.

-	ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

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
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
testifysuite "github.com/stretchr/testify/suite"
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
testifysuite "github.com/stretchr/testify/suite"
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

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 f1d2a0a and be61348.
Files selected for processing (2)
  • modules/core/keeper/keeper_test.go (6 hunks)
  • modules/light-clients/07-tendermint/consensus_host.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/core/keeper/keeper_test.go
Additional Context Used
Path-based Instructions (1)
modules/light-clients/07-tendermint/consensus_host.go (1)

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

Additional comments not posted (1)
modules/light-clients/07-tendermint/consensus_host.go (1)

37-39: The addition of a nil check for stakingKeeper in NewConsensusHost is a good practice to ensure that essential dependencies are not nil.

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.

Nice. :)

Copy link
Contributor

@charleenfei charleenfei left a comment

Choose a reason for hiding this comment

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

thank you @chatton!

Copy link

sonarcloud bot commented Apr 5, 2024

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

Issues
1 New issue
0 Accepted issues

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

See analysis details on SonarCloud

@crodriguezvega crodriguezvega merged commit 9f6fca8 into main Apr 5, 2024
88 checks passed
@crodriguezvega crodriguezvega deleted the cian/issue#6082-pass-consensushost-as-arg-to-core-ibc-newkeeper-func branch April 5, 2024 10:55
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.

Pass ConsensusHost as arg to core ibc NewKeeper func
4 participants