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!: decouple client routing from encoding #5806

Merged
merged 92 commits into from
Mar 14, 2024

Conversation

damiannolan
Copy link
Member

@damiannolan damiannolan commented Feb 1, 2024

Description

@colin-axner and I spent the week working through this proof-of-concept to attempt to decouple 02-client routing from encoding. This PR is the initial effort to that story, and feeds into #5084.
Below is a list of items that we would like to see completed before merging this to main of ibc-go, or even taking this PR out draft.

This PR handles the 02-client routing story within ibc-core, however does not address secondary level routing in 08-wasm yet - the final point of the list below is to handle that with "v2 routing". This likely means changes to the Initialize() method of the LightClientModule interface in order to plumb secondary level routing information through.

While discussing the initial design of the new interfaces added within this PR, @colin-axner and I felt it was a good opportunity to also look at the idea of a new api go module, separate to ibc-go. This has not been handled yet but conceptually this means moving interfaces for light client modules as well as ibc applications to a new api module.
The goal with this would be reduce the need for clients and apps to stay in lock-step with ibc-go versioning, essentially closing #2471.

closes: #5565
closes: #5942


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
    • Added new documentation for developers on managing light client instances, implementing the ClientState interface, and documentation on ClientState and ConsensusState.
    • Introduced a Router type in the IBC module for mapping client types to LightClientModule instances.
    • New functionality for managing client stores within the IBC module.
    • Enhanced light client implementations with renaming and new functionalities in solomachine, tendermint, wasm, and localhost packages.
  • Documentation
    • Updated references and links for consistency across developer guides.
  • Tests
    • Modified and added new test cases for improved reliability and coverage.
  • Refactor
    • Code optimizations in test files and keeper functions for direct access and better management of client states and heights.
    • Adjustments in event handling functions to accept new parameters for client types and latest heights.
  • Bug Fixes
    • Fixed type assertions and handling of client states in various test functions across modules.
  • Chores
    • Updated CHANGELOG.md to reflect changes in light client routing and encoding structure.

colin-axner and others added 30 commits January 29, 2024 16:30
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 0d821c5 and ba429b9.
Files selected for processing (1)
  • docs/docs/03-light-clients/01-developer-guide/02-light-client-module.md (3 hunks)
Additional comments: 7
docs/docs/03-light-clients/01-developer-guide/02-light-client-module.md (7)
  • 2-5: The document title and sidebar labels have been updated to reflect the new LightClientModule interface. This change aligns with the PR's objective to decouple client routing from encoding, enhancing clarity and consistency in the documentation.
  • 9-9: The introduction to implementing the LightClientModule interface is clear and concise. It effectively sets the stage for the detailed explanation of the interface's methods that follows.
  • 1-12: > 📝 NOTE

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

The explanation of the Status method and its possible return values is comprehensive and informative. However, the term "misbehaviour" is used, which is British English. While not incorrect, it's important to ensure consistency in spelling conventions throughout the documentation. If the project predominantly uses American English, consider changing to "misbehavior".

Consider standardizing the spelling of "misbehaviour" to "misbehavior" if the rest of the documentation primarily uses American English.

  • 24-24: Renaming GetTimestampAtHeight to TimestampAtHeight simplifies the method name while maintaining clarity about its functionality. This change is a good example of improving readability and conciseness in interface design.
  • 39-39: The link to the "Existence and non-existence proofs section" is a helpful addition, providing readers with a direct reference to further details on membership proofs. Ensuring that such links are up-to-date and accessible is crucial for maintaining the usefulness of the documentation.
  • 44-44: Similar to the previous comment, the link to the "Existence and non-existence proofs section" for non-membership proofs is valuable for readers seeking more information. It's important to regularly verify that these links remain valid and lead to the intended content.
  • 1-12: > 📝 NOTE

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

The explanation of the CheckForMisbehaviour method is clear, but it again uses the term "misbehaviour." As mentioned earlier, consider standardizing the spelling based on the predominant convention used in the project's documentation.

Consider standardizing the spelling of "misbehaviour" to "misbehavior" if the rest of the documentation primarily uses American English.

Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

leaving some more minor comments, don't let these hold you back if you want to merge. Can talk about these async if required.

Will give it a look again in the A.M, again, splendid work all involved 🖖

}

// AddRoute adds LightClientModule for a given module name. It returns the Router
// so AddRoute calls can be linked. It will panic if the Router is sealed.
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't have a concept of sealing the router as far as I can see yea?

Copy link
Contributor

Choose a reason for hiding this comment

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

bumped into it again on main. do we want to seal the router?

Copy link
Contributor

Choose a reason for hiding this comment

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

note that it would not be needed if we do #6010 (and remove GetRouter on client Keeper, it would only have a SetRouter). Sealing would be indirect via keeping it as an inaccessible (after setting) private var.

@@ -31,16 +31,22 @@ import (
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
router *types.Router
Copy link
Contributor

Choose a reason for hiding this comment

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

more food for thought would be having this as a non-reference type and adding a SetRouter to the keeper similar to IBCKeeper's SetRouter. Happy to punt this for another time too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Feel free to open an issue and add needs discussion if you'd like!

@damiannolan
Copy link
Member Author

Woo! Leaving my general approval! 🎉

It was really nice to work alongside @damiannolan on this 🙂

In general I think this is moving in a great direction and removes a big painpoint from the previous design. Given how entangled the client state interface is everywhere, it's hard to swiftly transition the entire codebase to the new design without some cumbersome aspects. It's also too time consuming to redesign the light client modules to elegantly fit the new API. I believe this sets a nice stepping stone for future iterations to slowly move to a more unified, clear, and simple design. I think it'll make it easier to reason about IBC with the routing and encoding decoupled

Some followup actions that come to mind:

  • solidifying the recommended structure for the light client modules
  • ensuring every light client module function has a test
  • ensuring godoc is accurate and informative

There's never been a clear structure for the light client module and I believe now there's a good opportunity to create nice abstractions/layouts, but I think it will require a bit of discussion and reworking. This isn't high priority so it will happen with time, but it's good to begin making suggestions!

Looking forward to seeing this work merged and released with v9! 🚀

Pleasure working with you on this too @colin-axner! ❤️
Thank you for contributing, reviewing, commenting and documenting follow ups today on this PR. Awesome to see approval for it to be merged and have this as a stepping stone towards a cleaner design overall!

I agree that there has never been a clear structure for light client modules, and since IBC v1 all code has generally fallen into package types which isn't an ideal structure/layout as everything is bundled into the one package. But given this, its probably good that no opinionated direction was taken, and gives us a nice opportunity to structure our own light client modules and recommend a desirable approach for third parties too going forward.

Will follow up on comments and issues and get this merged ASAP! 🚀

…e scoped correctly for later usage in misbehaviour test
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 ba429b9 and 0329451.
Files selected for processing (1)
  • e2e/tests/core/02-client/client_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • e2e/tests/core/02-client/client_test.go

Comment on lines +61 to +64
// GetRouter returns the light client module router.
func (k Keeper) GetRouter() *types.Router {
return k.router
}
Copy link
Member Author

Choose a reason for hiding this comment

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

As noted in thread https://github.com/cosmos/ibc-go/pull/5806/files#r1523681992

Refactor: GetRouter() can be changed to ClientModule(clientID string) or Route(clientID string) returning the light client module

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.

a few small comments, overall great work from @damiannolan and @colin-axner!

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.

I will probably do another pass tomorrow morning and then drop my approval.

modules/core/02-client/keeper/client.go Show resolved Hide resolved
modules/core/04-channel/types/expected_keepers.go Outdated Show resolved Hide resolved
modules/core/02-client/types/router.go 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.

Review Status

Actionable comments generated: 6

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 0329451 and 16e141b.
Files selected for processing (26)
  • CHANGELOG.md (1 hunks)
  • docs/docs/03-light-clients/01-developer-guide/01-overview.md (5 hunks)
  • docs/docs/03-light-clients/01-developer-guide/03-client-state.md (1 hunks)
  • docs/docs/03-light-clients/01-developer-guide/04-consensus-state.md (2 hunks)
  • docs/docs/05-migrations/13-v8-to-v9.md (1 hunks)
  • e2e/tests/transfer/localhost_test.go (1 hunks)
  • modules/core/02-client/keeper/grpc_query_test.go (8 hunks)
  • modules/core/02-client/keeper/keeper_test.go (3 hunks)
  • modules/core/02-client/types/router.go (1 hunks)
  • modules/core/keeper/msg_server.go (3 hunks)
  • modules/light-clients/06-solomachine/doc.go (1 hunks)
  • modules/light-clients/06-solomachine/store.go (1 hunks)
  • modules/light-clients/07-tendermint/doc.go (1 hunks)
  • modules/light-clients/07-tendermint/internal/keeper/keeper.go (1 hunks)
  • modules/light-clients/07-tendermint/store.go (1 hunks)
  • modules/light-clients/08-wasm/doc.go (1 hunks)
  • modules/light-clients/08-wasm/keeper/msg_server_test.go (2 hunks)
  • modules/light-clients/08-wasm/types/client_state_test.go (13 hunks)
  • modules/light-clients/08-wasm/types/misbehaviour_handle_test.go (1 hunks)
  • modules/light-clients/08-wasm/types/proposal_handle_test.go (1 hunks)
  • modules/light-clients/08-wasm/types/querier_test.go (3 hunks)
  • modules/light-clients/08-wasm/types/store.go (2 hunks)
  • modules/light-clients/08-wasm/types/update_test.go (4 hunks)
  • modules/light-clients/08-wasm/types/upgrade_test.go (4 hunks)
  • modules/light-clients/09-localhost/doc.go (1 hunks)
  • modules/light-clients/09-localhost/store.go (1 hunks)
Files skipped from review as they are similar to previous changes (16)
  • e2e/tests/transfer/localhost_test.go
  • modules/core/02-client/keeper/grpc_query_test.go
  • modules/core/02-client/keeper/keeper_test.go
  • modules/core/02-client/types/router.go
  • modules/core/keeper/msg_server.go
  • modules/light-clients/06-solomachine/store.go
  • modules/light-clients/07-tendermint/internal/keeper/keeper.go
  • modules/light-clients/07-tendermint/store.go
  • modules/light-clients/08-wasm/types/client_state_test.go
  • modules/light-clients/08-wasm/types/misbehaviour_handle_test.go
  • modules/light-clients/08-wasm/types/proposal_handle_test.go
  • modules/light-clients/08-wasm/types/querier_test.go
  • modules/light-clients/08-wasm/types/store.go
  • modules/light-clients/08-wasm/types/update_test.go
  • modules/light-clients/08-wasm/types/upgrade_test.go
  • modules/light-clients/09-localhost/store.go
Additional comments: 13
modules/light-clients/06-solomachine/doc.go (1)
  • 2-2: The documentation accurately reflects the changes made to the solomachine package, aligning with the Solo Machine light client implementation. It's clear and adheres to Go documentation conventions.
modules/light-clients/07-tendermint/doc.go (1)
  • 2-2: The documentation accurately reflects the changes made to the tendermint package, including the addition of LightClientModule alongside ClientState and ConsensusState. It's clear and adheres to Go documentation conventions.
modules/light-clients/08-wasm/doc.go (1)
  • 2-2: The documentation accurately reflects the changes made to the wasm package, including the addition of LightClientModule alongside ClientState, ConsensusState, and ClientMessage. It's clear and adheres to Go documentation conventions.
docs/docs/03-light-clients/01-developer-guide/03-client-state.md (1)
  • 21-21: The documentation provides a clear explanation of the ClientState interface. Consider using more formal and concise wording to enhance clarity, especially when describing the responsibilities of the light client implementer.
docs/docs/03-light-clients/01-developer-guide/04-consensus-state.md (1)
  • 1-7: > 📝 NOTE

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

The documentation provides a clear explanation of the ConsensusState interface. Consider using more formal and concise wording to enhance clarity, especially when describing the responsibilities of the light client implementer.

docs/docs/05-migrations/13-v8-to-v9.md (1)
  • 58-79: The migration guide from v8 to v9 is clear and detailed, providing valuable information for developers. To improve readability, consider adding spaces between sentences where needed and reviewing the document for any spelling mistakes.
docs/docs/03-light-clients/01-developer-guide/01-overview.md (4)
  • 27-33: > 📝 NOTE

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

The document's metadata (front matter) is correctly formatted, ensuring proper rendering on the website. However, ensure that the slug accurately reflects the document's location and purpose within the site's structure.

  • 30-33: The terms ClientState, ConsensusState, and ClientMessage are correctly introduced and linked to their respective sections. However, ensure that the spelling of "misbehaviour" aligns with the project's preferred English variant (British vs. American English).
  • 41-41: Ensure that the link to the LightClientModule interface is correct and accessible. This is crucial for developers who may want to reference the interface directly.
  • 95-95: The reference to the "Handling update and misbehaviour" section is correctly linked. Ensure that the document exists and is accessible to provide comprehensive guidance on updates and misbehaviour handling.
Verification successful

Given the context and the need to accurately verify the existence and accessibility of the document "05-updates-and-misbehaviour.md" within the local repository, a more suitable approach is required. The initial use of curl was not appropriate for this context. Let's proceed with a revised verification strategy.


The output indicates an error in executing the stat command, which affected the verification process. The conclusion that the file does not exist or is empty may not be accurate due to this error. To clarify the existence and content status of "05-updates-and-misbehaviour.md" without relying on stat, a revised approach is necessary.


The verification process has confirmed that the document "05-updates-and-misbehaviour.md" exists within the repository and is not empty. This supports the review comment regarding the correct linking and accessibility of the document for providing comprehensive guidance on updates and misbehaviour handling.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the existence and accessibility of the linked document.
fd "05-updates-and-misbehaviour.md" --exec curl -o /dev/null --silent --head --fail {}

Length of output: 88



Script:

#!/bin/bash
# Verify the existence of the document and check if it's not empty.
fd "05-updates-and-misbehaviour.md" --exec stat {} \; --exec test -s {} && echo "File exists and is not empty" || echo "File does not exist or is empty"

Length of output: 185



Script:

#!/bin/bash
# Verify the existence of the document and check if it's not empty by counting lines.
fd "05-updates-and-misbehaviour.md" --exec wc -l {} \; | awk '{if ($1 > 0) print "File exists and is not empty"; else print "File does not exist or is empty";}'

Length of output: 192

modules/light-clients/08-wasm/keeper/msg_server_test.go (2)
  • 264-271: > 📝 NOTE

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

The introduction of the ok variable to handle the type assertion result for expClientState is a good practice, ensuring that the type assertion is successful before proceeding. This enhances the robustness of the test by avoiding potential panics due to failed type assertions.

  • 264-271: > 📝 NOTE

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

Ensure that comprehensive test coverage and proper error handling are maintained throughout the test suite. This includes verifying that all possible error paths are tested and that the tests remain consistent with the changes introduced in this PR.

CHANGELOG.md (1)
  • 43-43: The change mentioned here is significant as it impacts the core/02-client and light-clients in the codebase. It's crucial to ensure that this decoupling does not introduce any regressions or unintended behavior changes in the IBC protocol's operation. It would be beneficial to have comprehensive testing around this change to validate its correctness and performance implications.

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 16e141b and c1c70ae.
Files selected for processing (1)
  • e2e/tests/transfer/localhost_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • e2e/tests/transfer/localhost_test.go

Copy link
Member Author

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

I have reviewed files of the PR and am happy to go ahead and merge since CI jobs are passing. I am will go through this PR again and review each of the comments, and open issues for follow up work.

@@ -31,16 +31,22 @@ import (
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
router *types.Router
Copy link
Member Author

Choose a reason for hiding this comment

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

Feel free to open an issue and add needs discussion if you'd like!

Comment on lines +131 to +132
// Deprecated: This function will be removed in a later release of ibc-go.
// NOTE: This function only supports querying latest consensus state of 07-tendermint client state implementations.
Copy link
Member Author

Choose a reason for hiding this comment

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

To be removed in #5991

modules/light-clients/07-tendermint/store.go Show resolved Hide resolved
wasm.NewAppModule(app.WasmClientKeeper),
ibctm.AppModuleBasic{},
solomachine.AppModuleBasic{},
wasm.NewAppModule(app.WasmClientKeeper), // TODO(damian): see if we want to pass the lightclient module here, keeper is used in AppModule.RegisterServices etc
Copy link
Member Author

Choose a reason for hiding this comment

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

will open issue

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 c1c70ae and 696f852.
Files selected for processing (4)
  • modules/core/02-client/keeper/events.go (3 hunks)
  • modules/core/02-client/types/router.go (1 hunks)
  • modules/core/02-client/types/store.go (1 hunks)
  • modules/core/04-channel/types/expected_keepers.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • modules/core/02-client/keeper/events.go
  • modules/core/02-client/types/router.go
  • modules/core/02-client/types/store.go
  • modules/core/04-channel/types/expected_keepers.go

Copy link

sonarcloud bot commented Mar 14, 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 56b8170 into main Mar 14, 2024
83 of 84 checks passed
@damiannolan damiannolan deleted the feat/02-client-router branch March 14, 2024 18:44
@damiannolan
Copy link
Member Author

Merged, feel free to leave post-merge reviews. We can follow up by opening issues and follow up PRs.

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
Status: Done 🥳
Development

Successfully merging this pull request may close these issues.

Update light client developer guide with new 02-client routing PoC for v2 02-client routing
6 participants