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: remove GetLatestHeight from ClientState interface and add it to LightClientModule #5866

Merged
merged 31 commits into from
Mar 11, 2024

Conversation

crodriguezvega
Copy link
Contributor

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.

Copy link
Contributor

coderabbitai bot commented Mar 6, 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
Copy link
Member

damiannolan commented Mar 6, 2024

@chatton and I spent some time working on this PR today, addressing compiler errors and tests. All tests are now passing and we've added a new test helper to Endpoint: endpoint.GetClientLatestHeight

There is still places in which we need to cast: latestHeight := endpoint.GetClientLatestHeight.(clienttypes.Height) and still a couple of more places which can make use of this testing func.

I think the type casting/conversions will naturally resolve themselves when we remove exported.Height and use the concrete type alone when api is introduced. I think this will be ready for review shortly, with a couple of more commits for test cleanup using the new helper.

@colin-axner colin-axner added the priority PRs that need prompt reviews label Mar 7, 2024
@charleenfei charleenfei changed the title 02-client routing: remove GetLatestHeight from ClientState interface and add it to LigthClientModule 02-client routing: remove GetLatestHeight from ClientState interface and add it to LightClientModule Mar 7, 2024
@damiannolan
Copy link
Member

Quality Gate Failed Quality Gate failed for 'ibc-go'

Failed conditions 29.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

I'm trying to understand the duplication meaning. I guess its flagging test files where some boilerplate code is duplicated. E.g. in malleate funcs where we mutate some values. But I think that's fine, I wonder if we can tweek the settings to not complain about this too much, or at least bump the %. It's not nice to see a red x on CI when we had gotten it green! 😢

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.

Going to drop my approval as default on this since I pushed a lot of commits to this PR. I've reviewed all files when working on this and think any concerns can be handled in follow ups as the diff is already quite large - but also fairly digestable considering a lot of changes are basic.

ACK from me for moving this method sooner rather than later! I also think the new test helper provides a lot of value for testing purposes and we can document that in migration notes as a follow up action item!

Comment on lines +138 to +145
// TODO: This code is removed in https://github.com/cosmos/ibc-go/pull/5827
// last height of current counterparty chain must be client's latest height
lastHeight := clientState.GetLatestHeight()
// lastHeight := k.GetLatestHeight(ctx, clientID)

if !upgradedClient.GetLatestHeight().GT(lastHeight) {
return errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "upgraded client height %s must be at greater than current client height %s",
upgradedClient.GetLatestHeight(), lastHeight)
}
// if !upgradedClient.GetLatestHeight().GT(lastHeight) {
// return errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "upgraded client height %s must be at greater than current client height %s",
// upgradedClient.GetLatestHeight(), lastHeight)
// }
Copy link
Member

Choose a reason for hiding this comment

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

Happy to leave this and address in #5827

Copy link
Contributor

Choose a reason for hiding this comment

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

It isn't supposed to be removed 😄 Happy to see it rectified after though

Copy link
Member

Choose a reason for hiding this comment

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

Yup! For sure, just wanted to punt until this PR was merged

@@ -613,6 +611,14 @@ func (chain *TestChain) GetChannelCapability(portID, channelID string) *capabili
return capability
}

// GetClientLatestHeight returns the latest height for the client state with the given client identifier.
// If an invalid client identifier is provided then a zero value height will be returned.
func (chain *TestChain) GetClientLatestHeight(clientID string) exported.Height {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can change this to clienttypes.Height return value when we remove the interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened #5954.

testing/chain.go Outdated Show resolved Hide resolved
@DimitrisJim
Copy link
Contributor

But I think that's fine, I wonder if we can tweek the settings to not complain about this too much, or at least bump the %.

indeed. maybe we can start by ignoring this for test files since duplication there is more acceptable, later on we could tweak it for *.go files if we see it being too whiny about things.

Copy link
Contributor Author

@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 also drop my approval ✅ Thank you very much, @damiannolan and @chatton for the work on this PR.

@@ -127,6 +128,8 @@ func QueryChannelConsensusState(

// QueryLatestConsensusState uses the channel Querier to return the
// latest ConsensusState given the source port ID and source channel ID.
// 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.
func QueryLatestConsensusState(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this function is not exposed as an RPC, probably hermes doesn't use it. And I cannot find any usage of it in the go relayer. So maybe is safe to just delete them?

Copy link
Member

Choose a reason for hiding this comment

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

If there is consensus on this then yes, let's remove it!

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 am fine nuking it. What do you think, @colin-axner?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine with me 👍 pr to main?

Copy link
Contributor

Choose a reason for hiding this comment

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

@crodriguezvega
Copy link
Contributor Author

Quality Gate Failed Quality Gate failed for 'ibc-go'

Failed conditions 29.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

I can tweak this. What value would be good to trigger when really needed and but avoid false positives?

modules/core/02-client/keeper/client.go Outdated Show resolved Hide resolved
modules/core/02-client/keeper/client.go Outdated Show resolved Hide resolved
Comment on lines +138 to +145
// TODO: This code is removed in https://github.com/cosmos/ibc-go/pull/5827
// last height of current counterparty chain must be client's latest height
lastHeight := clientState.GetLatestHeight()
// lastHeight := k.GetLatestHeight(ctx, clientID)

if !upgradedClient.GetLatestHeight().GT(lastHeight) {
return errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "upgraded client height %s must be at greater than current client height %s",
upgradedClient.GetLatestHeight(), lastHeight)
}
// if !upgradedClient.GetLatestHeight().GT(lastHeight) {
// return errorsmod.Wrapf(ibcerrors.ErrInvalidHeight, "upgraded client height %s must be at greater than current client height %s",
// upgradedClient.GetLatestHeight(), lastHeight)
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

It isn't supposed to be removed 😄 Happy to see it rectified after though

@@ -60,7 +60,7 @@ func (suite *KeeperTestSuite) TestSetAndGetClientConnectionPaths() {
}

// create 2 connections: A0 - B0, A1 - B1
func (suite KeeperTestSuite) TestGetAllConnections() { //nolint:govet // this is a test, we are okay with copying locks
func (suite *KeeperTestSuite) TestGetAllConnections() {
Copy link
Contributor

Choose a reason for hiding this comment

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

might be nice to just pull these fixes as a pr to main since they are out of scope and could reduce diffs

Copy link
Member

Choose a reason for hiding this comment

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

Happy to do that! And then rebase the feat branch for 02 router refactor when its merged, think its fine to keep em here tho

@@ -127,6 +128,8 @@ func QueryChannelConsensusState(

// QueryLatestConsensusState uses the channel Querier to return the
// latest ConsensusState given the source port ID and source channel ID.
// 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.
func QueryLatestConsensusState(
Copy link
Contributor

Choose a reason for hiding this comment

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

Fine with me 👍 pr to main?

// If no client is present for the provided client identifier a zero value height is returned.
//
// CONTRACT: clientID is validated in 02-client router, thus clientID is assumed here to be 09-localhost.
func (lcm LightClientModule) LatestHeight(ctx sdk.Context, clientID string) exported.Height {
Copy link
Contributor

@colin-axner colin-axner Mar 11, 2024

Choose a reason for hiding this comment

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

needs a test (followup against main is fine)

Copy link
Member

Choose a reason for hiding this comment

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

Let's address in localhost PR :)

modules/core/02-client/keeper/keeper.go Outdated Show resolved Hide resolved
Comment on lines -28 to -30
// if !sdk.IsAlphaNumeric(module) {
// panic(errors.New("route expressions can only contain alphanumeric characters"))
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

do we still want some of formatting check?

Copy link
Member

Choose a reason for hiding this comment

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

Let's take this discussion to the feat branch PR maybe. Will take a look at it closer there :)

// prevent accidental sends with clients that cannot be updated
if status := k.clientKeeper.GetClientStatus(ctx, connectionEnd.ClientId); status != exported.Active {
return 0, errorsmod.Wrapf(clienttypes.ErrClientNotActive, "cannot send packet using client (%s) with status %s", connectionEnd.ClientId, status)
}

latestHeight := clientState.GetLatestHeight()
latestHeight := k.clientKeeper.GetLatestHeight(ctx, connectionEnd.ClientId)
Copy link
Contributor

Choose a reason for hiding this comment

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

probably should do a latestHeight.IsZero check here, otherwise the timeout height is disregarded:

// heightElapsed returns true if the timeout height is non empty
// and the timeout height is greater than or equal to the relative height.
func (t Timeout) heightElapsed(height clienttypes.Height) bool {
    return !t.Height.IsZero() && height.GTE(t.Height)
}

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I follow this one, this latestHeight var is pased to timeout.Elapsed which performs the check you've just showed.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, if the latest height is zero, then heightElapsed can never return true as the latest height will never be greater than the timeout height

Copy link
Member

Choose a reason for hiding this comment

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

Cool, so check latestHeight.IsZero and return error before creating the timeout?

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.

Excellent work y'all 💪 Big thanks to @damiannolan and @chatton for muscling through this one!! Happy to see this merged, left a note on anything that stood out to me, but they can be tackled in later pr's as necessary

Feels like things are moving in a nice direction 🙂

@damiannolan
Copy link
Member

Excellent work y'all 💪 Big thanks to @damiannolan and @chatton for muscling through this one!! Happy to see this merged, left a note on anything that stood out to me, but they can be tackled in later pr's as necessary

Feels like things are moving in a nice direction 🙂

Awesome! ❤️ I'll address some of the smaller points in a commit before merge! Happy to handle the others later :)

@damiannolan damiannolan merged commit 501a846 into feat/02-client-router Mar 11, 2024
75 of 76 checks passed
@damiannolan damiannolan deleted the carlos/move-latest-height branch March 11, 2024 15:43
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
priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants