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

Allow host_connection_id in version metadata to be empty on ChanOpenInit #5533

Merged
merged 63 commits into from
Mar 12, 2024

Conversation

GNaD13
Copy link
Contributor

@GNaD13 GNaD13 commented Jan 7, 2024

Description

closes: #5437

Commit Message / Changelog Entry

type: commit message

see the guidelines for commit messages. (view raw markdown for examples)


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/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

Summary by CodeRabbit

  • New Features
    • Improved interchain accounts' registration and governance proposal execution process.
  • Refactor
    • Enhanced code readability by refactoring version string setup and handshake logic.
  • Tests
    • Updated and added test cases for ensuring consistency and correctness in version handling and metadata validation.
  • Documentation
    • Clarified comments on host connection identifiers in metadata functions.

@codecov-commenter
Copy link

codecov-commenter commented Jan 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.62%. Comparing base (1c0c756) to head (abcff64).
Report is 72 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5533      +/-   ##
==========================================
+ Coverage   81.59%   81.62%   +0.02%     
==========================================
  Files         199      198       -1     
  Lines       15167    12117    -3050     
==========================================
- Hits        12375     9890    -2485     
+ Misses       2326     1765     -561     
+ Partials      466      462       -4     
Files Coverage Δ
...ps/27-interchain-accounts/host/keeper/handshake.go 88.23% <100.00%> (+0.59%) ⬆️
...ules/apps/27-interchain-accounts/types/metadata.go 81.01% <ø> (+1.21%) ⬆️

... and 170 files with indirect coverage changes

Copy link
Member

@srdtrk srdtrk left a comment

Choose a reason for hiding this comment

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

Thanks for the work @GNaD13. I noted some problems I had with the PR.

Also I'm wondering if we should change the NewDefaultMetadata function in controller's OnChanInit (see here) to not require the counterparty_connection_id?

I could also take over the PR if you think these would be too much work for you @GNaD13 @crodriguezvega

)

testCases := []struct {
name string
malleate func()
assert func()
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't add an assert function since you can just check the host_connection_id after every successful handshake anyway.

Copy link
Member

Choose a reason for hiding this comment

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

I see that you removed assert but I don't think you are testing that the output version inside the expPass case. Could you please check that the host_connection_id is correct?

@@ -169,6 +169,9 @@ func validateConnectionParams(metadata Metadata, controllerConnectionID, hostCon
}

if metadata.HostConnectionId != hostConnectionID {
if metadata.HostConnectionId == "" {
return nil
Copy link
Member

@srdtrk srdtrk Jan 8, 2024

Choose a reason for hiding this comment

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

This is not how we should do it imo. It is possible that we want to add other checks after this in the future. So, the only nil returned should be at the end of the function, not inside this if statement

Copy link
Contributor Author

@GNaD13 GNaD13 Jan 8, 2024

Choose a reason for hiding this comment

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

The reason I added an if statement here to check whether metadata.HostConnectionId is empty or not because I think we still need to keep check and return an error if
metadata.HostConnectionId != hostConnectionID and metadata.HostConnectionId not empty when the controller chain received an OnChanOpenAck package. So that it could check for the handshake. Should we remove this check?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to be a bit carefully with the validation of metadata.HostConnectionId because it will be valid to be empty in ChanOpenInit but it should not be empty anymore in ChanOpenAck, right?

Copy link
Member

Choose a reason for hiding this comment

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

I'd make the following suggestion @GNaD13 :

  1. Revert your changes to validateConnectionParams.
  2. In ChanOpenTry, before sending the metadata to validation, override metadata.HostConnectionId to be connectionHops[0] regardless of whether or not it is filled.
  3. Send to validation after step 2.

Note that this is okay because the host is allowed to propose a new version string in ChanOpenTry. Does this sound good @crodriguezvega?

Copy link
Contributor Author

@GNaD13 GNaD13 Jan 9, 2024

Choose a reason for hiding this comment

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

If so, I think we will also remove the validation in ChanOpenInit and leave the controller chain validation for ChanOpenAck

Copy link
Member

Choose a reason for hiding this comment

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

We can perform the validation if the user provided the version string, but not if we are using the default

@crodriguezvega
Copy link
Contributor

Also I'm wondering if we should change the NewDefaultMetadata function in controller's OnChanInit (see here) to not require the counterparty_connection_id?

That sounds fine to me, but that change would be API breaking. Do you think it's ok for users to wait until the v9 to release this? Otherwise we could add a new function NewDefaultMetadataWithoutHostConnection (or something like that) only with the controller connection ID.

I could also take over the PR if you think these would be too much work for you @GNaD13 @crodriguezvega

That's also fine by me. Is it ok for you if we continue from here, @GNaD13? Thank you very much for opening the PR!

@GNaD13
Copy link
Contributor Author

GNaD13 commented Jan 9, 2024

I could also take over the PR if you think these would be too much work for you @GNaD13 @crodriguezvega

That's also fine by me. Is it ok for you if we continue from here, @GNaD13? Thank you very much for opening the PR!

Yeah, that's also fine to me. It will be great if we could work together

@crodriguezvega
Copy link
Contributor

Yeah, that's also fine to me. It will be great if we could work together

Agree! Maybe then @srdtrk can comment the changes that would be needed and we can all together continue from there. :)

@srdtrk
Copy link
Member

srdtrk commented Jan 9, 2024

@crodriguezvega I think we can break API in this PR to main. We can worry about the API if we backport (we might not backport). So I'd say, we should break NewDefaultMetadata. Sounds good, then I'll continue to give suggestions under my review.

{
"success: empty host connection ID",
func() {
path.EndpointB.ConnectionID = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this test case actually testing?

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 is for my old code. I removed it. Thank you sir

Copy link
Contributor

coderabbitai bot commented Mar 7, 2024

Walkthrough

The changes focus on enhancing the interchain accounts functionality in the ibc-go framework, particularly refining version metadata handling and improving flexibility with host_connection_id. These updates aim to improve code readability, consistency in version string setup, and allow for an empty host_connection_id during channel opening to streamline negotiation processes.

Changes

Files Change Summary
e2e/tests/.../base_test.go, e2e/tests/.../gov_test.go Added newlines for readability and clarity in test functions.
modules/apps/.../controller/ibc_middleware_test.go, modules/apps/.../controller/migrations/v6/migrations_test.go, modules/apps/.../types/metadata.go Utilized icatypes.NewDefaultMetadataString for version string setup, enhancing code readability and consistency.
modules/apps/.../controller/keeper/handshake.go, modules/apps/.../controller/keeper/handshake_test.go, modules/apps/.../host/keeper/handshake.go Adjusted handling of host_connection_id, allowing it to be empty during ChanOpenInit and set during version negotiation; improved test cases for consistency and clarity.

Assessment against linked issues

Objective Addressed Explanation
Allow host_connection_id to be empty on ChanOpenInit (#5437)
icahost fills in host_connection_id during version negotiation (#5437)

Poem

In the realm of chains where data flows,
A rabbit hopped, tweaking the codes.
🌌 Across the cosmos, connections wide,
🛠 With tweaks and turns, it did provide.

"Let version strings be clear and bright,
And host_connection_id take flight.
🚀 For interchain accounts, a smoother ride,"
Whispered the rabbit, with pride inside.

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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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 UI

Commits Files that changed from the base of the PR and between e20b6f8 and e23cf85.
Files selected for processing (9)
  • e2e/tests/interchain_accounts/base_test.go (2 hunks)
  • e2e/tests/interchain_accounts/gov_test.go (1 hunks)
  • modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go (3 hunks)
  • modules/apps/27-interchain-accounts/controller/keeper/handshake.go (1 hunks)
  • modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go (4 hunks)
  • modules/apps/27-interchain-accounts/controller/migrations/v6/migrations_test.go (2 hunks)
  • modules/apps/27-interchain-accounts/host/keeper/handshake.go (1 hunks)
  • modules/apps/27-interchain-accounts/host/keeper/handshake_test.go (9 hunks)
  • modules/apps/27-interchain-accounts/types/metadata.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • e2e/tests/interchain_accounts/base_test.go
  • modules/apps/27-interchain-accounts/controller/keeper/handshake.go
Additional comments: 14
e2e/tests/interchain_accounts/gov_test.go (1)
  • 58-58: The addition of a newline character is a minor stylistic change that improves readability. This change is approved as it does not impact the functionality or correctness of the code.
modules/apps/27-interchain-accounts/types/metadata.go (2)
  • 36-36: The clarification added to the comment regarding the host connection identifier's ability to be an empty string improves the understanding of the NewDefaultMetadata function's functionality. This change is approved as it enhances clarity.
  • 50-50: The clarification added to the comment regarding the host connection identifier's ability to be an empty string improves the understanding of the NewDefaultMetadataString function's functionality. This change is approved as it enhances clarity.
modules/apps/27-interchain-accounts/host/keeper/handshake.go (1)
  • 42-44: The addition of setting the HostConnectionId to the first connection hop if not set by the controller before validating the host metadata aligns with the PR's objectives and ensures correct host metadata validation. This change is approved as it is necessary for the functionality and correctness of the code.
modules/apps/27-interchain-accounts/controller/migrations/v6/migrations_test.go (2)
  • 31-32: The assignment of a new version using icatypes.NewDefaultMetadataString for testing purposes is logically sound and aligns with the changes introduced in the PR. This ensures that the tests accurately reflect the intended behavior of the updated metadata handling.
  • 43-44: Using the newly assigned version for setting ChannelConfig.Version for both EndpointA and EndpointB is appropriate for testing the migration process with the updated metadata functionality. This change is approved as it correctly implements the intended testing functionality.
modules/apps/27-interchain-accounts/host/keeper/handshake_test.go (2)
  • 73-74: The modifications in TestOnChanOpenTry introduce several test cases to validate the handling of empty host_connection_id and ensure metadata consistency. Here are some observations and recommendations:
  • Empty host_connection_id Handling (Lines 100-107): This test case effectively checks the scenario where host_connection_id is intentionally left empty, aligning with the PR's objectives. It's crucial to ensure that other parts of the system gracefully handle this scenario without unintended side effects.

  • Metadata Consistency Checks: Several test cases have been added or modified to test various failure scenarios, such as invalid metadata, unsupported encoding formats, and incorrect connection IDs. These are essential for maintaining robustness in the face of potentially malformed or malicious inputs.

  • Use of suite.Require().NoError(err) (Multiple Instances): The consistent use of suite.Require().NoError(err) for error handling in test cases is good practice, ensuring that tests fail fast upon encountering an unexpected error.

  • Dynamic Test Case Structure (Lines 314-351): The dynamic structure used for defining test cases, where each case is defined with a name, a malleate function to mutate test data, and an expected pass/fail outcome, enhances readability and maintainability. This pattern is especially useful for testing a wide range of scenarios with varying setup requirements.

Overall, these changes are well-aligned with the PR's objectives and contribute to the robustness and flexibility of the ibc-go framework's testing suite. It's recommended to continue this pattern of thorough and scenario-specific testing for future changes.

Also applies to: 94-96, 100-107, 145-146, 170-171, 271-272, 314-351

  • 591-591: The addition of handling the host_connection_id within the TestOnChanUpgradeTry test case (Line 591) is a critical update that aligns with the PR's objectives. By explicitly setting the host_connection_id to the connection ID of path.EndpointB, this change ensures that the test accurately reflects the intended behavior of allowing host_connection_id to be optionally empty and filled during version negotiation.

It's commendable that the test case also considers various failure scenarios, such as invalid port IDs, unsupported metadata encoding formats, and changes to the interchain account address. These comprehensive tests are crucial for ensuring the robustness of the ibc-go framework's upgrade mechanism.

One minor suggestion for improvement is to ensure that all possible edge cases related to the host_connection_id handling are covered in the test scenarios. This includes scenarios where the host_connection_id might be incorrectly filled or left empty when it should not be. Adding such test cases, if not already present, would further strengthen the framework's resilience to potential issues.

Overall, the changes to TestOnChanUpgradeTry are well-thought-out and contribute significantly to the testing coverage of the new functionality introduced by the PR.

modules/apps/27-interchain-accounts/controller/keeper/handshake_test.go (4)
  • 19-23: The introduction of the expectedVersion variable is a good practice for making tests more dynamic and adaptable to changes. This approach allows for easier maintenance and readability of test cases, especially when dealing with version strings that might change based on the test scenario.
  • 58-58: The assignment of expectedVersion using icatypes.NewDefaultMetadataString within the test case "success: empty channel version returns default metadata JSON string" is a crucial change. It ensures that the test accurately reflects the behavior of the system when the channel version is empty, aligning with the PR's objective to handle host_connection_id more flexibly. This change is correctly implemented and directly addresses the issue at hand.
  • 280-281: Setting the expectedVersion to the marshaled JSON string of metadata at the beginning of the test setup is a good practice. It establishes a baseline expectation for the version string that will be used in most test cases, ensuring consistency and reducing redundancy in test code. This setup is well thought out and contributes to the clarity and maintainability of the test suite.
  • 303-303: The assertion that checks if the expectedVersion matches the actual version returned by OnChanOpenInit is a critical part of validating the correctness of the implementation. This assertion directly tests the functionality introduced in the PR, ensuring that the version negotiation behaves as expected. The use of suite.Require().Equal for this assertion is appropriate and follows best practices for writing effective and meaningful tests.
modules/apps/27-interchain-accounts/controller/ibc_middleware_test.go (2)
  • 34-34: The change to TestVersion using icatypes.NewDefaultMetadataString is a significant improvement in terms of code readability and maintainability. By utilizing the NewDefaultMetadataString function, the test setup becomes more aligned with the actual implementation logic, ensuring that the tests are more representative of real-world scenarios. This change also reduces the potential for errors in manually marshaling JSON strings for test version metadata.
  • 241-241: The assertion suite.Require().Equal(TestVersion, version) within the TestOnChanOpenInit test case correctly validates that the version returned by the OnChanOpenInit callback matches the expected TestVersion. This ensures that the version negotiation process adheres to the expected behavior, particularly in the context of the changes made to handle host_connection_id more flexibly. It's crucial for maintaining the integrity of the version negotiation process in the IBC middleware.

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 UI

Commits Files that changed from the base of the PR and between e23cf85 and 5b5b609.
Files selected for processing (1)
  • modules/apps/27-interchain-accounts/host/keeper/handshake_test.go (9 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/apps/27-interchain-accounts/host/keeper/handshake_test.go

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 UI

Commits Files that changed from the base of the PR and between 5b5b609 and 883d795.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Files not reviewed due to errors (1)
  • (no review received)

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.

Thank you, @GNaD13. The changes look good to me now.

@crodriguezvega crodriguezvega merged commit 1ebede6 into cosmos:main Mar 12, 2024
71 of 72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Allow host_connection_id in version metadata to be empty on ChanOpenInit
5 participants