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: add common rpc package #2788

Merged
merged 8 commits into from
Aug 29, 2024
Merged

feat: add common rpc package #2788

merged 8 commits into from
Aug 29, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Aug 28, 2024

We currently have logic to create zetacored rpc clients in both e2e and zetaclient/zetacore. We should deduplicate this logic and export it publicly so that we can easily make type safe RPCs in other codebases.

Also add a cometbft client so that it's easier to run e2e tests against anyone who exposes a cometbft/tendermint rpc interface. gRPC is not always exposed publicly.

Closes #2786

External imports degraded by #959. Fixed by #2796

TODO:

  • initial client implementation
  • replace zetaclient/zetacore.clients struct. Update: embed the rpc.Clients struct rather than replacing as it has some other items. rpc.Clients is currently limited to read only operations.
  • replace cmd/zetace2/config.zetaChainClients struct
  • use zetacore_rpc rather than zetacore_grpc if zetacore_grpc is unset in e2e config

Summary by CodeRabbit

  • New Features
    • Introduced a unified Clients interface for easier interaction with various services within the ZetaChain ecosystem.
    • Added support for creating clients using both CometBFT and gRPC transport mechanisms, enhancing flexibility in service communication.

Copy link
Contributor

coderabbitai bot commented Aug 28, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

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.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The changes introduce a new rpc.go file within the ZetaChain ecosystem, defining a package that facilitates interaction with various RPC clients. It establishes a Clients struct encapsulating multiple client interfaces for different services. Additionally, it provides constructor functions for initializing these clients using CometBFT and gRPC transport mechanisms, enhancing the framework's RPC capabilities.

Changes

File Path Change Summary
pkg/rpc/rpc.go Introduced a Clients struct with multiple RPC client interfaces. Added newClients, NewCometBFTClients, and NewGRPCClients functions for client initialization.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RPC
    participant CometBFT
    participant gRPC

    Client->>RPC: Request to initialize Clients
    RPC->>CometBFT: Initialize CometBFT Client
    CometBFT-->>RPC: Return CometBFT Client
    RPC->>gRPC: Initialize gRPC Client
    gRPC-->>RPC: Return gRPC Client
    RPC-->>Client: Return Clients struct
Loading

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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

codecov bot commented Aug 28, 2024

Codecov Report

Attention: Patch coverage is 86.48649% with 15 lines in your changes missing coverage. Please review.

Project coverage is 66.79%. Comparing base (994f1ca) to head (9f11b8e).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
pkg/rpc/clients.go 69.23% 7 Missing and 1 partial ⚠️
pkg/rpc/clients_cosmos.go 66.66% 2 Missing and 2 partials ⚠️
pkg/rpc/clients_crosschain.go 86.95% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2788      +/-   ##
===========================================
- Coverage    66.80%   66.79%   -0.02%     
===========================================
  Files          368      370       +2     
  Lines        20661    20677      +16     
===========================================
+ Hits         13803    13811       +8     
- Misses        6223     6230       +7     
- Partials       635      636       +1     
Files with missing lines Coverage Δ
pkg/rpc/clients_authority.go 60.00% <100.00%> (ø)
pkg/rpc/clients_ethermint.go 42.85% <100.00%> (ø)
pkg/rpc/clients_lightclient.go 72.72% <100.00%> (ø)
pkg/rpc/clients_observer.go 66.99% <100.00%> (ø)
pkg/rpc/clients_tendermint.go 69.23% <100.00%> (ø)
zetaclient/zetacore/client.go 54.95% <100.00%> (-1.93%) ⬇️
zetaclient/zetacore/client_cosmos.go 36.00% <100.00%> (ø)
pkg/rpc/clients_crosschain.go 57.14% <86.95%> (ø)
pkg/rpc/clients_cosmos.go 66.66% <66.66%> (ø)
pkg/rpc/clients.go 69.23% <69.23%> (ø)

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.

Actionable comments posted: 4

Outside diff range, codebase verification and nitpick comments (1)
pkg/rpc/rpc.go (1)

19-28: Add documentation for each field in the Clients struct.

While the struct is well-defined, adding documentation for each field will improve readability and maintainability.

Consider adding comments like this:

// Clients contains RPC client interfaces to interact with zetacored
type Clients struct {
	// AuthorityClient is used to interact with the authority module.
	AuthorityClient authoritytypes.QueryClient
	// CctxClient is used to interact with the crosschain module.
	CctxClient      crosschaintypes.QueryClient
	// FungibleClient is used to interact with the fungible module.
	FungibleClient  fungibletypes.QueryClient
	// AuthClient is used to interact with the auth module.
	AuthClient      authtypes.QueryClient
	// BankClient is used to interact with the bank module.
	BankClient      banktypes.QueryClient
	// ObserverClient is used to interact with the observer module.
	ObserverClient  observertypes.QueryClient
	// LightClient is used to interact with the lightclient module.
	LightClient     lightclienttypes.QueryClient
}
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 26c4fb1 and 8e29b2b.

Files selected for processing (1)
  • pkg/rpc/rpc.go (1 hunks)
Additional context used
Path-based instructions (1)
pkg/rpc/rpc.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

GitHub Check: codecov/patch
pkg/rpc/rpc.go

[warning] 30-39: pkg/rpc/rpc.go#L30-L39
Added lines #L30 - L39 were not covered by tests


[warning] 43-46: pkg/rpc/rpc.go#L43-L46
Added lines #L43 - L46 were not covered by tests


[warning] 48-48: pkg/rpc/rpc.go#L48
Added line #L48 was not covered by tests


[warning] 50-50: pkg/rpc/rpc.go#L50
Added line #L50 was not covered by tests


[warning] 54-57: pkg/rpc/rpc.go#L54-L57
Added lines #L54 - L57 were not covered by tests


[warning] 59-60: pkg/rpc/rpc.go#L59-L60
Added lines #L59 - L60 were not covered by tests

pkg/rpc/rpc.go Outdated Show resolved Hide resolved
pkg/rpc/rpc.go Outdated Show resolved Hide resolved
pkg/rpc/rpc.go Outdated Show resolved Hide resolved
pkg/rpc/rpc.go Outdated Show resolved Hide resolved
Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

I think this is a direction that makes sense

Using grpc was more a shortcut and we should indeed remove it

pkg/rpc/rpc.go Outdated Show resolved Hide resolved
pkg/rpc/rpc.go Outdated Show resolved Hide resolved
pkg/rpc/rpc.go Outdated Show resolved Hide resolved
pkg/rpc/rpc.go Outdated Show resolved Hide resolved
pkg/rpc/rpc.go Outdated Show resolved Hide resolved
pkg/rpc/rpc.go Outdated Show resolved Hide resolved
pkg/rpc/rpc.go Outdated Show resolved Hide resolved
@gartnera gartnera requested a review from lumtis August 29, 2024 19:41
@gartnera gartnera added this pull request to the merge queue Aug 29, 2024
Merged via the queue into develop with commit 91c323d Aug 29, 2024
28 checks passed
@gartnera gartnera deleted the zetacore-rpc-client branch August 29, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow running e2e tests against tendermint/cometbft rpc
3 participants