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

feat: allow module safe queries in ICA (backport #5785) #6065

Merged
merged 14 commits into from
Apr 11, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Mar 27, 2024

Description

closes: #5784

Commit Message / Changelog Entry

feat: allow module safe queries in ICA

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


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

Summary by CodeRabbit

  • New Features

    • Implemented a mechanism for whitelisting safe queries to enhance module query safety.
    • Added a new message structure for defining query requests by interchain accounts.
    • Introduced an RPC handler for safe queries with payload and response message definitions.
  • Tests

    • Expanded test coverage to validate module query safety and successful execution of specific queries.
    • Introduced test functions to ensure the correct functioning of query safelisting and transaction handling.
  • Documentation

    • Updated the codec setup function to include interface registration for improved transaction handling.

This is an automatic backport of pull request #5785 done by [Mergify](https://mergify.com).

* imp: initial modification of tx.proto

* imp: ran 'make proto-all'

* fix: compiler errors

* imp: added query router interface

* imp: added queryRouter to icahost keeper

* imp: improved proto definitions

* imp: ran 'make proto-all'

* imp: added sdk.Msg helpers

* feat: basic implementation

* style: improved field names

* imp: ran 'make proto-all'

* fix: compiler errors

* imp: ran gofumpt

* feat: tests passing

* feat: tests improved

* test: removed unneeded code

* imp: improved 'IsModuleSafe' function

* imp: added IsModuleQuerySafe to msg_server

* imp: added more test cases

* fix: callbacks compiler

* fix: non determinancy issues

* fix: added query msg to codec

* imp: whitelist logic added

* e2e: new test added

* fix: new test

* fix: test

* fix: e2e

* fix: e2e

* imp(e2e): added the QueryTxsByEvents function

* fix: e2e

* e2e: lint fix

* fix: e2e

* e2e: debug

* fix: e2e

* test: debug helpers

* debug

* test: added codec_test case

* imp: additional test case

* imp: added important unit test

* r4r

* e2e: debug

* imp: added logs

* fix: e2e

* fix: e2e

* fix: e2e

* imp: added height to proto response

* imp: ran 'make proto-all'

* imp: added height

* e2e: updated e2e to test height

* imp: review suggestions

* e2e: remove unneeded log

* refactor: refactored 'ExtractValueFromEvents'

* e2e: review item

* imp: review item

* nit: review item

* docs: added godocs

* test: unit test for mqsWhitelist added

* imp: added logging

* style: rename to allow list

* add changelog

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
(cherry picked from commit eecfa5c)

# Conflicts:
#	CHANGELOG.md
#	e2e/testsuite/codec.go
#	e2e/testsuite/tx.go
#	modules/apps/27-interchain-accounts/host/types/msgs.go
#	modules/light-clients/08-wasm/testing/simapp/app.go
Copy link
Contributor Author

mergify bot commented Mar 27, 2024

Cherry-pick of eecfa5c has failed:

On branch mergify/bp/release/v8.2.x/pr-5785
Your branch is up to date with 'origin/release/v8.2.x'.

You are currently cherry-picking commit eecfa5c0.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   e2e/tests/interchain_accounts/query_test.go
	modified:   modules/apps/27-interchain-accounts/host/keeper/export_test.go
	modified:   modules/apps/27-interchain-accounts/host/keeper/keeper.go
	modified:   modules/apps/27-interchain-accounts/host/keeper/keeper_test.go
	modified:   modules/apps/27-interchain-accounts/host/keeper/msg_server.go
	modified:   modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go
	modified:   modules/apps/27-interchain-accounts/host/keeper/relay_test.go
	modified:   modules/apps/27-interchain-accounts/host/types/codec.go
	modified:   modules/apps/27-interchain-accounts/host/types/codec_test.go
	modified:   modules/apps/27-interchain-accounts/host/types/host.pb.go
	modified:   modules/apps/27-interchain-accounts/host/types/tx.pb.go
	modified:   modules/apps/27-interchain-accounts/types/router.go
	modified:   modules/apps/callbacks/testing/simapp/app.go
	modified:   proto/ibc/applications/interchain_accounts/host/v1/host.proto
	modified:   proto/ibc/applications/interchain_accounts/host/v1/tx.proto
	modified:   testing/simapp/app.go

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	both modified:   CHANGELOG.md
	deleted by us:   e2e/testsuite/codec.go
	deleted by us:   e2e/testsuite/tx.go
	both modified:   modules/apps/27-interchain-accounts/host/types/msgs.go
	deleted by us:   modules/light-clients/08-wasm/testing/simapp/app.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Copy link
Contributor

coderabbitai bot commented Mar 27, 2024

Important

Auto Review Skipped

Bot user detected.

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 testing code 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 testing code 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 testing code.
    • @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.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@crodriguezvega crodriguezvega self-assigned this Mar 27, 2024
@crodriguezvega crodriguezvega added the priority PRs that need prompt reviews label Mar 27, 2024
@crodriguezvega
Copy link
Contributor

It might be easier to review the individual commits on this PR, since that's the diff with respect to the original PR.

@crodriguezvega crodriguezvega marked this pull request as draft March 28, 2024 19:28
@crodriguezvega crodriguezvega removed the priority PRs that need prompt reviews label Mar 28, 2024
@crodriguezvega crodriguezvega changed the base branch from release/v8.2.x to release/v8.3.x April 8, 2024 07:56
@crodriguezvega crodriguezvega marked this pull request as ready for review April 8, 2024 07:57
@crodriguezvega crodriguezvega marked this pull request as draft April 8, 2024 08:19
@crodriguezvega
Copy link
Contributor

Needs #6105

@crodriguezvega crodriguezvega marked this pull request as ready for review April 8, 2024 12:30
@crodriguezvega crodriguezvega added the priority PRs that need prompt reviews label Apr 8, 2024
@srdtrk
Copy link
Member

srdtrk commented Apr 8, 2024

Is there any way to have panic on chain startup if queryRouter is not set?

@damiannolan
Copy link
Member

Is there any way to have panic on chain startup if queryRouter is not set?

good question, and consideration! Normally we do it in NewKeeper on main, right? but since this is adding it in a non-api breaking way we use WithQueryRouter.

This does seem like a feature a lot of users would like to pick up and it would be unfortunate to start nodes with somebody missing this (it would lead to panic on nil pointer) on the host chain when msgs are delivered - we could potentially add a panic in hostkeeper/msg_server.go in the NewMsgServerImpl() func: https://github.com/cosmos/ibc-go/pull/6065/files#diff-13a052f2a68bb6a94ffe300852c0b625ff0340a3c524f68ddb6a1256f7b55f4bL22-L24

This would panic in RegisterServices() of the module which would bubble up to app.go - ModuleManager.RegisterServices()

@DimitrisJim
Copy link
Contributor

we could potentially add a panic in hostkeeper/msg_server.go in the NewMsgServerImpl() func

another candidate seems to be NewAppModule but going through RegisterServices seems best since its already guarded by an if checking if host keeper is set.

@crodriguezvega
Copy link
Contributor

Is there any way to have panic on chain startup if queryRouter is not set?

good question, and consideration! Normally we do it in NewKeeper on main, right? but since this is adding it in a non-api breaking way we use WithQueryRouter.

This does seem like a feature a lot of users would like to pick up and it would be unfortunate to start nodes with somebody missing this (it would lead to panic on nil pointer) on the host chain when msgs are delivered - we could potentially add a panic in hostkeeper/msg_server.go in the NewMsgServerImpl() func: https://github.com/cosmos/ibc-go/pull/6065/files#diff-13a052f2a68bb6a94ffe300852c0b625ff0340a3c524f68ddb6a1256f7b55f4bL22-L24

This would panic in RegisterServices() of the module which would bubble up to app.go - ModuleManager.RegisterServices()

@damiannolan @srdtrk like this?

If we want to enforce that a query router is set, is it enough to document this in the release notes or do we need to add a migration doc for v7.5 and document it there as well?

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.

Thanks @crodriguezvega! 🚀

Comment on lines 26 to 31
func NewMsgServerImpl(keeper *Keeper) types.MsgServer {
if keeper.queryRouter == nil {
panic("query router must not be nil")
}
return &msgServer{Keeper: keeper}
}
Copy link
Member

Choose a reason for hiding this comment

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

ACK this change looks good to me! As long as we put something into the release notes which document that users should use app.HostKeeper.WithQueryRouter in app.go, otherwise nodes won't start!

@crodriguezvega crodriguezvega merged commit 759897b into release/v8.3.x Apr 11, 2024
19 checks passed
@crodriguezvega crodriguezvega deleted the mergify/bp/release/v8.2.x/pr-5785 branch April 11, 2024 11:29
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.

4 participants