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

chore: move initialization logic to light client module method #6037

Merged
merged 8 commits into from
Mar 25, 2024

Conversation

DimitrisJim
Copy link
Contributor

@DimitrisJim DimitrisJim commented Mar 21, 2024

Description

closes: #5974


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
    • Enhanced the Solo Machine light client initialization process by removing obsolete logic.
  • Bug Fixes
    • Ensured accurate comparison of consensus states during client initialization for reliable setup.
  • Tests
    • Updated and added tests to validate new initialization logic and consensus state handling in the Solo Machine light client.

Copy link
Contributor

coderabbitai bot commented Mar 21, 2024

Walkthrough

Walkthrough

The recent changes involve refactoring the Solo Machine light client within the IBC framework. The Initialize function, crucial for setting up the initial consensus state, has been removed from the solomachine package and its logic is now incorporated into the LightClientModule. This adjustment streamlines the initialization process by directly comparing consensus states and setting the client state within the module, enhancing the code's clarity and efficiency.

Changes

File Path Change Summary
.../06-solomachine/client_state.go Removed Initialize function
.../06-solomachine/client_state_test.go Removed TestInitialize function and related package imports
.../06-solomachine/light_client_module.go Added consensus state comparison and setClientState call in Initialize
.../06-solomachine/light_client_module_test.go Added TestInitialize, consensus state initialization tests, and ibctm import

Assessment against linked issues

Objective Addressed Explanation
Move solo machine client state Initialize logic into client module implementation (#5974)
Decouple encoding from routing for enhanced flexibility (#5845) The changes do not address encoding or routing issues directly.
Provide 06-solomachine with its own go.mod file to reduce dependencies (#4213) The PR does not involve modifications to module dependencies or go.mod files.
Enhance 08-wasm module for better handling of light clients (#5084) Changes are specific to the Solo Machine light client and do not impact the 08-wasm module.
Implement conditional clients for improved dependency management in IBC (#5112) The updates do not include conditional client functionality or dependency management enhancements.

Related issues

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.

@DimitrisJim
Copy link
Contributor Author

also looking for opinions on #5974 (comment)

@@ -67,19 +65,6 @@ func (cs ClientState) Validate() error {
return cs.ConsensusState.ValidateBasic()
}

// Initialize checks that the initial consensus state is equal to the latest consensus state of the initial client and
// sets the client state in the provided client store.
func (cs ClientState) Initialize(_ sdk.Context, cdc codec.BinaryCodec, clientStore storetypes.KVStore, consState exported.ConsensusState) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changelog?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it doesn't hurt. Also, even though the migration docs already mention that the interface function has been removed, maybe it's worth adding a separate section in the migration docs to document that this function has also been removed from the concrete type.

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

Commits Files that changed from the base of the PR and between ee4549b and 617e241.
Files selected for processing (4)
  • modules/light-clients/06-solomachine/client_state.go (2 hunks)
  • modules/light-clients/06-solomachine/client_state_test.go (2 hunks)
  • modules/light-clients/06-solomachine/light_client_module.go (2 hunks)
  • modules/light-clients/06-solomachine/light_client_module_test.go (2 hunks)
Additional comments: 11
modules/light-clients/06-solomachine/light_client_module_test.go (2)
  • 8-8: The addition of the ibctm package import is noted. Ensure that this import is utilized within the test cases, particularly for creating instances of ibctm.ConsensusState used in the test scenarios.
  • 17-77: The TestInitialize function tests various scenarios for initializing the solo machine client state with different consensus states. Here are some observations and suggestions:
  1. The use of table-driven tests is a good practice for covering multiple scenarios efficiently.
  2. The test setup and execution logic are clear and well-structured.
  3. The use of reflect.DeepEqual for comparing expected and actual consensus states in the test cases would enhance the robustness of the tests.

Consider adding a test case to cover the scenario where the initialization succeeds but with a warning or minor issue that doesn't block the client state's initialization. This could help ensure the resilience of the initialization logic under less-than-ideal conditions.

Overall, the test function is well-implemented and follows good testing practices.

modules/light-clients/06-solomachine/client_state.go (1)
  • 1-1: The removal of the Initialize function from client_state.go is in line with the PR's objective to refactor the initialization logic into the LightClientModule. Ensure that all references to the Initialize function have been updated or removed accordingly across the codebase to prevent any broken dependencies or compilation errors.
modules/light-clients/06-solomachine/light_client_module.go (1)
  • 61-69: The Initialize function correctly implements the logic to compare clientState.ConsensusState with consensusState using reflect.DeepEqual. This is a critical check to ensure that the consensus state matches the client state during the initialization phase. Here are some observations and suggestions:
  1. The use of reflect.DeepEqual for deep comparison is appropriate in this context, as it ensures that the two consensus states are identical in all respects.
  2. Ensure that the error message provided when the consensus states do not match is clear and informative, helping developers understand the nature of the mismatch.
  3. Consider adding logging or metrics around this initialization process to aid in debugging and monitoring the initialization of solo machine clients in production environments.

Overall, the implementation of the Initialize function aligns with the PR's objectives and follows best practices for ensuring the integrity of the initialization process.

modules/light-clients/06-solomachine/client_state_test.go (7)
  • 8-15: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The removal of imports ibctm and host suggests that dependencies on these packages were eliminated due to the refactor. Ensure that this change does not leave unused variables or functions that were specifically tied to these imports.

  • 8-15: > 📝 NOTE

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

The TestStatus function correctly tests the client state's status both when active and when frozen. This test remains relevant and well-implemented.

  • 8-15: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [24-70]

The TestClientStateValidateBasic function provides comprehensive coverage of the basic validation scenarios for the solo machine client state. It's well-structured and adheres to best practices for testing.

  • 90-95: > 📝 NOTE

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

The TestVerifyMembership function thoroughly tests the verification of membership across a variety of scenarios. This is crucial for ensuring the integrity and correctness of the solo machine client state.

  • 8-15: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [289-308]

The TestSignBytesMarshalling function correctly tests the marshalling behavior of sign bytes, ensuring that nil and empty array data are treated equivalently. This is an important aspect of the serialization logic.

  • 8-15: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [310-409]

The TestVerifyNonMembership function provides comprehensive testing for the verification of non-membership across various scenarios. This ensures the solo machine client state accurately recognizes non-existent memberships.

  • 8-15: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [411-441]

The TestGetTimestampAtHeight function tests the retrieval of timestamps at specific heights, a fundamental aspect of the solo machine client state's functionality. It's well-implemented and relevant.

@@ -1,6 +1,8 @@
package solomachine

import (
"reflect"

Check notice

Code scanning / CodeQL

Sensitive package import Note

Certain system packages contain functions which may be a possible source of non-determinism
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.yml

Commits Files that changed from the base of the PR and between 617e241 and 3ec58b2.
Files selected for processing (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go

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.

Looks perfectly fine to me. I would still add a note in the migration docs.

@DimitrisJim
Copy link
Contributor Author

Will add changelog before merge. After merge will also make similar changes for other small functions in solomachine and we can leave that PR open until discussed!

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

Commits Files that changed from the base of the PR and between 3ec58b2 and 033ff17.
Files selected for processing (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go

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.

Changes look good to me, happy to merge this with or without the changelog (can happen in a follow up)

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.

LGTM

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

Commits Files that changed from the base of the PR and between 033ff17 and 4ec0e97.
Files selected for processing (1)
  • docs/docs/05-migrations/13-v8-to-v9.md (1 hunks)
Additional comments: 9
docs/docs/05-migrations/13-v8-to-v9.md (9)
  • 80-89: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [10-10]

Near line 10, there's a possible spelling mistake found in the context "...tions for migrating to a new version of ibc-go. There are four sections based on the...". However, upon review, this appears to be a false positive, as "ibc-go" is correctly spelled and relevant in this context.

  • 80-89: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [19-19]

The note about "ibc-go supports golang semantic versioning" is crucial for users to understand the importance of updating imports on major version releases. This is correctly placed and well-worded for clarity.

  • 80-89: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [29-30]

In the section detailing API removals for IBC Apps, it's mentioned that various interfaces and their functions have been removed, urging users to use concrete types instead. This change is significant and well-documented, providing clear guidance for users on how to adapt their applications.

  • 80-89: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [41-42]

The deprecation notice for certain testing package functions and the introduction of new functions is an important change that's well-highlighted. It's crucial for developers to transition to the new functions to ensure compatibility with future versions.

  • 80-89: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [46-46]

The replacement of mock.PV with cmttypes.MockPV is a specific change that could impact testing setups. The documentation provides a direct link to the new type, which is helpful for developers looking to make the necessary adjustments.

  • 80-89: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [58-62]

The removal of various functions from the ClientState interface, including Initialize, Status, GetLatestHeight, etc., is a major change for IBC Light Clients. The documentation clearly outlines these removals and suggests that light client developers implement the LightClientModule interface instead. This guidance is crucial for maintaining functionality and compatibility with ibc-go v9.

  • 85-85: The specific change regarding the Initialize function in 06-solomachine being moved to the LightClientModule interface is well-documented. This change is part of the broader effort to streamline the initialization process and enhance maintainability.
  • 89-89: The removal of the IterateConsensusMetadata function in 07-tendermint is noted without additional context. Given the nature of migration documentation, it would be beneficial to briefly explain the reason behind this removal or its impact, if significant.

Consider providing a brief explanation or context for the removal of the IterateConsensusMetadata function to help users understand its impact on their implementations.

  • 80-89: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [93-94]

The changes in 08-wasm, including the removal of the ExportMetadataMsg struct and the ZeroCustomFields interface function, are significant for developers working with wasm light clients. The documentation clearly states these removals, which is essential for developers to update their contracts accordingly.

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

Commits Files that changed from the base of the PR and between 4ec0e97 and e33c37d.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments: 1
CHANGELOG.md (1)
  • 45-45: The summary provided in the CHANGELOG.md accurately reflects the changes made in the codebase regarding the Initialize function's relocation. The description is clear and concise.

Copy link

sonarcloud bot commented Mar 25, 2024

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

Issues
0 New issues
0 Accepted issues

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

See analysis details on SonarCloud

@DimitrisJim DimitrisJim merged commit d18a661 into main Mar 25, 2024
74 of 75 checks passed
@DimitrisJim DimitrisJim deleted the jim/issue5974-move-solomachine-initialize branch March 25, 2024 16:49
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.

Move solo machine client state initialize logic into client module implementation
4 participants