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

02-client routing: implement VerifyUpgradeAndUpdateState in light client modules #5827

Conversation

crodriguezvega
Copy link
Contributor

@crodriguezvega crodriguezvega commented Feb 9, 2024

Description

closes: #XXXX

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.

upgradedClient.GetLatestHeight(), lastHeight)
lightClientModule, found := k.router.GetRoute(clientID)
if !found {
return errorsmod.Wrap(types.ErrRouteNotFound, clientID)
}
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 will want to add this back once LatestHeight is added to the light client module

Copy link
Member

Choose a reason for hiding this comment

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

discussed async, this check must be moved to the light client module, and this functionality should likely only exist in the tendermint client module.

At first glance, we do not have the clientID of the upgradedClientState. However, it should be the same clientID as the clientState (target). However, we need the latest height from the upgradedClientState concrete implementation here - this is the client which the counterparty stores in it upgrade path and we prove against within the tm client module.

@crodriguezvega crodriguezvega marked this pull request as draft February 27, 2024 12:19
},
expPass: true,
},
{
name: "client state not found",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I deleted this test because this is tested in the light client module.

expPass: false,
},
{
name: "unsuccessful upgrade: upgraded height is not greater than current height",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this test to the light client module, but can move it back here in the PR where LatestHeight is added to the light client module and then we can move the check back to 02-client.

Copy link
Member

Choose a reason for hiding this comment

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

#5827 (comment)

I guess it can just be removed entirely now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. At the moment this check is performed in 07-tendermint and 08-wasm light client modules. Based on your comment, is that ok? Any reason why the check should not be done in 08-wasm?

Copy link
Contributor

Choose a reason for hiding this comment

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

we can have these tests in the lcm modules for 07-tendermint and 08-wasm already, i think! is that fine @crodriguezvega?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, correct! The check and the tests are currently in the light client module. Happy to leave it there if that's the right place. :)

@crodriguezvega crodriguezvega marked this pull request as ready for review February 28, 2024 08:57
@crodriguezvega
Copy link
Contributor Author

crodriguezvega commented Feb 28, 2024

I think this is again ready for review after the discussion on Monday. There are a couple of tests that fail because we need to add the right value for the latest height in the create and upgrade client events, but that should be fixed in #5866. cc @damiannolan @colin-axner

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Thanks @crodriguezvega!!

modules/core/keeper/msg_server.go Outdated Show resolved Hide resolved
modules/core/keeper/msg_server.go Outdated Show resolved Hide resolved
modules/light-clients/07-tendermint/light_client_module.go Outdated Show resolved Hide resolved
Copy link
Contributor

coderabbitai bot commented Mar 11, 2024

Important

Auto Review Skipped

Auto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

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.

@damiannolan damiannolan self-assigned this Mar 11, 2024
@damiannolan
Copy link
Member

Resolving conflicts.. 🏃🏻

Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

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

Looks good! I suppose we have to keep the interfaces for users the same way, but would be nice to eventually just pass everything through and unmarshal at the light client module level.

modules/core/keeper/msg_server.go Outdated Show resolved Hide resolved
modules/core/02-client/keeper/client_test.go Outdated Show resolved Hide resolved
upgradedClientProof, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), tmCs.LatestHeight.GetRevisionHeight())
upgradedConsensusStateProof, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), tmCs.LatestHeight.GetRevisionHeight())
upgradedClientProof, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(upgradeHeight.GetRevisionHeight())), tmCs.LatestHeight.GetRevisionHeight())
upgradedConsensusStateProof, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(upgradeHeight.GetRevisionHeight())), tmCs.LatestHeight.GetRevisionHeight())

path.EndpointA.ClientID = "wrongclientid"
Copy link
Contributor

Choose a reason for hiding this comment

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

for some reason it doesnt look like this change is triggering the error code path we would expect, does anyone else see that in the testing code coverage?

Copy link
Member

Choose a reason for hiding this comment

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

can follow up this post merge, maybe? I think all these tests should be using expError and not expPass (bool)

* fix: remove marshalling of anys to bytes for verify upgrade

* test: refactor 02-client tests for verify upgrade

* test: fix tests in 07-tenderint client module

* chore: rm backwards compatability notice and marshalling of anys in core msg server

* test: cleanup happy path assertions in 07-tendermint verify upgrade test

* nit: update inline code commentin test

* doc: update godoc of UpgradeClient handler in core ibc

* lint: make lint-fix
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.

I missed 08-wasm changes needed to aligned with 07-tendermint from my encoding PR.
I'll handle them today and then LGTM! 🙏🏻

modules/core/02-client/keeper/client_test.go Outdated Show resolved Hide resolved
modules/core/02-client/keeper/client_test.go Outdated Show resolved Hide resolved
modules/core/02-client/keeper/client_test.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/light_client_module.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/light_client_module_test.go Outdated Show resolved Hide resolved
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!

upgradedClientProof, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), tmCs.LatestHeight.GetRevisionHeight())
upgradedConsensusStateProof, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), tmCs.LatestHeight.GetRevisionHeight())
upgradedClientProof, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(upgradeHeight.GetRevisionHeight())), tmCs.LatestHeight.GetRevisionHeight())
upgradedConsensusStateProof, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(upgradeHeight.GetRevisionHeight())), tmCs.LatestHeight.GetRevisionHeight())

path.EndpointA.ClientID = "wrongclientid"
Copy link
Member

Choose a reason for hiding this comment

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

can follow up this post merge, maybe? I think all these tests should be using expError and not expPass (bool)

@damiannolan damiannolan merged commit b6d07a5 into feat/02-client-router Mar 12, 2024
30 checks passed
@damiannolan damiannolan deleted the carlos/client-routing-verify-upgrade-update-state branch March 12, 2024 14:47
damiannolan added a commit that referenced this pull request Mar 14, 2024
* refactor: add initial light client module interface

* wip: add boiler plate light client module for tendermint client

* feat: adding initial light client module impl for 06-solomachine

* chore: adding LightClientModule interface assertion for 06-solomachine

* chore: adding initial boiilerplate for 08-wasm mod

* refactor: add boilerplate tendermint light client module

* refactor: add localhost boilerplate code

* imp: add basic 02-client router

* refactor: use light client module for client status

* chore: move solomachine keeper to internal

* chore: adding GetTimestampAtHeight to clientkeeper using 02-client router

* refactor: rm GetTimestampAtHeight from 03-connection and adapt api calls in 04-channel

* chore: wire up solomachine module with clientRouter in app.go

* chore: move commented out test to client keeper - still has todo to uncomment and fix

* chore: add solomachine client module to AppModule constructor and wire up in app.go

* fix: use correct route for client status lookup

* chore: add clientRouter to 08-wasm simapp and wire up

* fix: solo machine unmarshal bug and 02-client keeper tests

* test: fix GetTimestampAtHeight test in clientkeeper

* refactor(solomachine): add getClientState helper and unmarhsal interface

* refactor: align 08-wasm, add GetClientState helper and unmarshal interface

* fix(temp): temporarily add WithStoreKey opt to wasmkeeper to fix failing tests

* fix: wire up callbacks simapp to fix failing tests

* refactor: modify UpdateClient handler to use light client module api

* feat: add ClientStoreProvider interface for isolated prefix stores (#5781)

* refactor: rm internal/keeper from solomachine

* refactor: begin removing stale client state interfaces

* feat: wire up localhost

* fix: tests in 06-solomachine and 07-tendermint

* fix: rest of tests

* refactor: use light client module APIs in 03-connection state verify

* chore: adapt remaining handlers to use light client module api in 03-connection

* fix: locahost verify membership and non membership in light client module

* refactor: remove VerifyMembership and VerifyNonMembership from client state interface

* fix: rm getters for clientID from connection (conflict)

* 02-client routing: fix linter warnings (#5818)

* 02-client routing: fix linter warnings

* fix variable name

* return error

* 02-client routing: pass client ID to get route instead of client type (#5817)

* pass client ID to get route instead of client type

* rename variable

* Update modules/core/02-client/keeper/keeper.go

---------

Co-authored-by: Damian Nolan <[email protected]>

* use localhost client ID

* 02-client routing: function in store provider to return client store (#5824)

* add function to return 02-client module store

* review comment

* 02-client routing: implement `RecoverClient` in light client modules (#5822)

* implement recover client in light client modules

* add tests for wasm light client module recover client function

* missing file

* add tests for tendermint light client module recover client

* add tests for solomachine light client module recover client

* clean up 02-client recover client test cases

* fix test

* fix linter warning

* format client IDs

* fixes from merge of main

* 02-client routing: remove client ID validation (#5897)

* chore: remove client ID validation in light client module functions

* add contract documentation

* Update light_client_module.go

* 02-client routing: add godoc to `LightClientModule` functions (#5900)

* add godoc for light client module functions

* linter

* fix localhost client ID in godoc

* docs: add removal of `ClientState` interface functions to migration docs (#5943)

* docs: add removal of client state functions to migration docs

* test formating

* add comment about tendermint light client module implementation

* Apply suggestions from code review

Co-authored-by: colin axnér <[email protected]>

* mention removal of ZeroCustomFields

* Update docs/docs/05-migrations/13-v8-to-v9.md

Co-authored-by: DimitrisJim <[email protected]>

---------

Co-authored-by: colin axnér <[email protected]>
Co-authored-by: DimitrisJim <[email protected]>

* 02-client routing: remove `GetLatestHeight` from `ClientState` interface and add it to `LightClientModule` (#5866)

* wip: remove GetLatestHeight from ClientState interface and add it to light client module

* chore: add godoc for GetLatestHeight in 02-client keeper

* chore: add args to event emission funcs in 02-client

* chore: add args to usage in 02-client event emissions

* chore: put back logging in upgrade client

* chore: deprecate and refactor 04-channel client utils QueryLatestConsensusState func

* chore: rename lightClientModule to clientModule in core

* chore: undo faulty renames

* fix: godoc for LatestHeight

* chore: add godocs

* chore: readding sequence checking in solomachine RecoverClient

* fix: testing chain helper to use keeper getter for latest height

* chore: fix compilation errors in tests

* fix: import ordering waaah

* imp: adding GetClientLatestHeight to testing endpoint/chain

* test: cleanup test funcs with path.Endpoint.GetClientLatestHeight

* test: cleanup tests in 04-channel to use path.Endpoint.GetClientLatestHeight

* test: cleanup ante_test

* chore: add godocs for light client modules LatestHeight method

* chore: update endpoint.go to use the new GetClientLatestHeight helper fn

* test: usage of path.Endpoint.GetClientLatestHeight in core/keeper and 07-tendermint tests

* test: another one

* chore: rm GetLatestHeight from solomachine ClientState

* test: update QueryConsensusStateProof in testing lib to use test helper

* Update testing/chain.go

* fix typo in variable name

* chore: consolidate two calls to LatestHeight to initialHeight var on createClient

* chore: extract to latestHeight var in VerifyUpgradeAndUpdateState to reduce disk reads

* chore: rm greater than or equal height check in solomachine as already done in 02-client

* chore: address todo on GetLatestHeight in 02-client keeper

---------

Co-authored-by: Damian Nolan <[email protected]>
Co-authored-by: chatton <[email protected]>

* docs: refactor light client developer guide

* imp: cleanup godoc on router type

* 02-client routing: implement `VerifyUpgradeAndUpdateState` in light client modules (#5827)

* wip: implementation and tests for verify upgrade and update state function in light client modules

* add test case

* fix un-marshaling in tendermint light client module

* add tests for verify upgrade and update state of 08-wasm light client module

* fix linter warnings

* check client state post upgrade

* fix: encoding issue: unmarshal to concrete types and not interfaces in 07-tendermint

* fix import

* cast type before calling zero custom fields

* test: marshal concrete types using chain codec for upgrade tests which bypass msg server entrypoint

* chore: remove basic validation of lc types in tm VerifyUpgradeAndUpdateState

* marshal to concrete type in tests

* keep client/consensus state as interface marshalled

* Apply suggestions from code review

Co-authored-by: colin axnér <[email protected]>

* chore: make lint-fix

* chore: rm redundant test, tested in lightclient module

* fix: remove marshalling of anys to bytes for verify upgrade (#5967)

* fix: remove marshalling of anys to bytes for verify upgrade

* test: refactor 02-client tests for verify upgrade

* test: fix tests in 07-tenderint client module

* chore: rm backwards compatability notice and marshalling of anys in core msg server

* test: cleanup happy path assertions in 07-tendermint verify upgrade test

* nit: update inline code commentin test

* doc: update godoc of UpgradeClient handler in core ibc

* lint: make lint-fix

* nit: inline comments in tests last Height -> upgrade height

* fix: address 08-wasm upgrade client and tests

---------

Co-authored-by: Damian Nolan <[email protected]>
Co-authored-by: colin axnér <[email protected]>

* nit: lcm -> l for all light client modules

* remove unnecessary comment

* chore: remove unnecessary todo's

* chore: lint fix docs

* Apply suggestions from code review

* chore: 02-client handler godoc

* Update modules/core/02-client/keeper/client.go

* Update modules/light-clients/06-solomachine/light_client_module_test.go

* remove commented out code in msg server

* chore: update godoc, remove todo's

* chore: remove unnecessary func from localhost + cleanup

* Apply suggestions from code review

* Update docs/docs/03-light-clients/01-developer-guide/01-overview.md

Co-authored-by: DimitrisJim <[email protected]>

* chore: remove todo + deprecation notice

* chore: fix broken link

* chore: godoc for exported client.go file

* chore: test update

* chore: godoc

* chore: update godoc in 06-solomachine light client module

* chore: update 07-tendermint light client module godoc

* chore: update localhost client module godocs

* chore: update 08-wasm light client module godoc

* fix: broken link

* fix(e2e): correctly assign trusted height and latest height vars to be scoped correctly for later usage in misbehaviour test

* address my self-review comments and some of rabbit's comments

* Update e2e/tests/transfer/localhost_test.go

* chore: godocs, rm ClientStore from expected keeper, rename events arg to initialHeight

---------

Co-authored-by: Colin Axnér <[email protected]>
Co-authored-by: Carlos Rodriguez <[email protected]>
Co-authored-by: DimitrisJim <[email protected]>
Co-authored-by: chatton <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
02-client priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants