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

da: add jsonrpc proxy #54

Merged
merged 9 commits into from
Mar 18, 2024
Merged

da: add jsonrpc proxy #54

merged 9 commits into from
Mar 18, 2024

Conversation

tuxcanfly
Copy link
Contributor

@tuxcanfly tuxcanfly commented Mar 5, 2024

Overview

This PR adds a jsonrpc proxy.

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

Summary by CodeRabbit

  • New Features

    • Introduced a gRPC proxy client for the Data Availability (DA) interface, enabling various operations such as retrieving blobs, creating commitments, and submitting data.
    • Added a gRPC server implementation for the DA interface to serve requests and manage services.
  • Refactor

    • Renamed the package in proxy/grpc/proxy_test.go for consistency and clarity.
  • Tests

    • Implemented test suites for the gRPC proxy functionality, covering server-client communication and data operations.

@tuxcanfly tuxcanfly requested a review from distractedm1nd March 5, 2024 22:50
Copy link

coderabbitai bot commented Mar 5, 2024

Walkthrough

The recent changes involve a significant overhaul of the proxy package to enhance the Data Availability (DA) service. The updates include restructuring the client functionality to dynamically create a DA backend based on the provided URI and token, supporting various schemes like grpc, http, and https. Additionally, the introduction of gRPC and JSON-RPC clients and servers expands the communication protocols available for DA operations.

Changes

Files Change Summary
proxy/client.go Restructured to dynamically create DA backends based on URI and token, supporting multiple schemes.
proxy/grpc/client.go Introduced gRPC proxy client for DA interface with various functions for interacting with the DA service.
proxy/grpc/proxy_test.go, proxy/grpc/server.go, proxy/grpc/util.go Renamed packages and updated import paths for gRPC functionality.
proxy/jsonrpc/client.go Introduced JSON-RPC client for interacting with the DA service, managing connections and authorization tokens.
proxy/jsonrpc/proxy_test.go Added a test suite for testing JSON-RPC functionality against a test server.
proxy/jsonrpc/server.go Introduced a JSON-RPC server struct for serving the DA interface, providing server management methods.

🐇✨
In the realm of code, where data streams flow,
A rabbit hopped, with updates in tow.
From gRPC to JSON, a leap so bold,
A tale of interfaces, gracefully told.
🌟📡🐾

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.

Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 70.65868% with 49 lines in your changes are missing coverage. Please review.

Project coverage is 75.54%. Comparing base (da59f58) to head (6bb1c53).

Files Patch % Lines
proxy/grpc/client.go 71.42% 19 Missing and 5 partials ⚠️
proxy/jsonrpc/server.go 67.44% 10 Missing and 4 partials ⚠️
proxy/jsonrpc/client.go 72.50% 10 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #54      +/-   ##
==========================================
- Coverage   78.01%   75.54%   -2.47%     
==========================================
  Files           3        5       +2     
  Lines         191      274      +83     
==========================================
+ Hits          149      207      +58     
- Misses         32       52      +20     
- Partials       10       15       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tuxcanfly tuxcanfly changed the title da: switch protocol from grpc to jsonrpc da: add jsonrpc proxy Mar 8, 2024
@tuxcanfly tuxcanfly marked this pull request as ready for review March 13, 2024 12:25
Copy link

@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: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between da59f58 and 9f38d3f.
Files ignored due to path filters (2)
  • go.mod is excluded by: !**/*.mod
  • go.sum is excluded by: !**/*.sum
Files selected for processing (4)
  • proxy-grpc/proxy_test.go (1 hunks)
  • proxy-jsonrpc/client.go (1 hunks)
  • proxy-jsonrpc/proxy_test.go (1 hunks)
  • proxy-jsonrpc/server.go (1 hunks)
Check Runs (4)
test / Run Unit Tests completed (1)
lint / golangci-lint completed (1)
lint / yamllint completed (1)
lint / markdown-lint completed (1)
Additional comments: 2
proxy-grpc/proxy_test.go (2)
  • 11-11: The renaming of the imported package to github.com/rollkit/go-da/proxy-grpc aligns with the PR's objective to distinguish between different proxy implementations. Ensure that this renaming is consistently applied across all relevant files in the project.
  • 8-14: > 📝 NOTE

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

The usage of the renamed package proxy-grpc within the test function appears to be correct and consistent with the PR's objectives. Ensure that the interface provided by proxy-grpc remains compatible with the existing test code.

Copy link
Contributor

@MSevey MSevey left a comment

Choose a reason for hiding this comment

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

Some minor updates.
Also I'd recommend a common top level proxy directory with jsonrpc and grpc subfolders so that it is easy to pull out any common code in the future, vs the to separate top level directories.

Copy link

@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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9f38d3f and b3d104c.
Files selected for processing (3)
  • proxy-jsonrpc/proxy_test.go (1 hunks)
  • proxy-jsonrpc/server.go (1 hunks)
  • proxy/client.go (1 hunks)
Check Runs (1)
codecov/patch failure (15)
  • proxy-jsonrpc/server.go: 55-57: Added lines #L55 - L57 were not covered by tests
  • proxy-jsonrpc/server.go: 60-61: Added lines #L60 - L61 were not covered by tests
  • proxy-jsonrpc/server.go: 75-77: Added lines #L75 - L77 were not covered by tests
  • proxy-jsonrpc/server.go: 80-81: Added lines #L80 - L81 were not covered by tests
Files skipped from review as they are similar to previous changes (1)
  • proxy-jsonrpc/proxy_test.go
Additional comments: 2
proxy-jsonrpc/server.go (2)
  • 49-67: The implementation of the Start method correctly handles concurrent calls, ensuring that the server can only be started once. The logging for an already started server is a good practice. However, consider the following improvements:
  1. Error Handling: When net.Listen fails, the error is returned immediately. It might be beneficial to log this error for easier debugging.
  2. Testing Coverage: The static analysis hints at missing test coverage for this method. Ensure that tests cover the concurrent behavior and error scenarios to maintain reliability.
+ log.Error("failed to listen on address", "address", s.srv.Addr, "error", err)
  • 69-85: The Stop method's implementation and the added documentation for handling concurrent calls are commendable. Similar to the Start method, consider logging the error from srv.Shutdown for better traceability. Additionally, ensure that tests cover the concurrent behavior and error scenarios for this method as well.
+ log.Error("failed to shutdown server", "error", err)

@tuxcanfly tuxcanfly requested a review from MSevey March 14, 2024 20:17
Copy link

@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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b3d104c and 766d5ec.
Files selected for processing (8)
  • proxy/client.go (1 hunks)
  • proxy/grpc/client.go (1 hunks)
  • proxy/grpc/proxy_test.go (2 hunks)
  • proxy/grpc/server.go (1 hunks)
  • proxy/grpc/util.go (1 hunks)
  • proxy/jsonrpc/client.go (1 hunks)
  • proxy/jsonrpc/proxy_test.go (1 hunks)
  • proxy/jsonrpc/server.go (1 hunks)
Check Runs (1)
codecov/patch failure (15)
  • proxy/grpc/client.go: 28-29: Added lines #L28 - L29 were not covered by tests
  • proxy/grpc/client.go: 36-37: Added lines #L36 - L37 were not covered by tests
  • proxy/grpc/client.go: 41-47: Added lines #L41 - L47 were not covered by tests
  • proxy/grpc/client.go: 72-73: Added lines #L72 - L73 were not covered by tests
  • proxy/grpc/client.go: 86-87: Added lines #L86 - L87 were not covered by tests
  • proxy/grpc/client.go: 101-102: Added lines #L101 - L102 were not covered by tests
  • proxy/grpc/client.go: 117-118: Added lines #L117 - L118 were not covered by tests
  • proxy/jsonrpc/client.go: 34-35: Added lines #L34 - L35 were not covered by tests
  • proxy/jsonrpc/client.go: 85-88: Added lines #L85 - L88 were not covered by tests
  • proxy/jsonrpc/client.go: 92-93: Added lines #L92 - L93 were not covered by tests
  • proxy/jsonrpc/client.go: 109-110: Added lines #L109 - L110 were not covered by tests
  • proxy/jsonrpc/server.go: 55-57: Added lines #L55 - L57 were not covered by tests
  • proxy/jsonrpc/server.go: 60-61: Added lines #L60 - L61 were not covered by tests
  • proxy/jsonrpc/server.go: 75-77: Added lines #L75 - L77 were not covered by tests
  • proxy/jsonrpc/server.go: 80-81: Added lines #L80 - L81 were not covered by tests
Files skipped from review due to trivial changes (3)
  • proxy/grpc/proxy_test.go
  • proxy/grpc/server.go
  • proxy/grpc/util.go
Additional comments: 2
proxy/jsonrpc/proxy_test.go (1)
  • 22-39: The test suite for the JSONRPC service is a good start. Consider the following improvements:
  1. Mocking External Services: If the JSONRPC service relies on external services, use mocking to ensure tests are not flaky and can run in isolation.
  2. Error Paths: Include tests for error paths to ensure robust error handling.

Consider using a mocking framework to simulate external dependencies and add tests for error scenarios.

proxy/jsonrpc/server.go (1)
  • 49-66: The server start logic is well-implemented, but consider the following:
  1. Error Handling: Improve error messages for better clarity, especially when the server is already started.
  2. Concurrency: Ensure that concurrent calls to Start do not lead to race conditions or unexpected behavior.
- log.Warn("cannot start server: already started")
+ log.Warn("Server start attempted but it's already running.")

Ensure that the started atomic.Bool effectively prevents race conditions in concurrent Start calls.

MSevey
MSevey previously approved these changes Mar 15, 2024
Copy link
Contributor

@MSevey MSevey left a comment

Choose a reason for hiding this comment

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

lgtm, minor question but it can just be resolved if it is the only blocker.

@gupadhyaya
Copy link
Member

looks good, just a minor comment. @tuxcanfly

Copy link

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

Commits Files that changed from the base of the PR and between 766d5ec and 6bb1c53.
Files selected for processing (1)
  • proxy/jsonrpc/server.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • proxy/jsonrpc/server.go

@MSevey MSevey added this pull request to the merge queue Mar 18, 2024
Merged via the queue into main with commit 02a78bb Mar 18, 2024
12 of 14 checks passed
@MSevey MSevey deleted the tux/jsonrpc branch March 18, 2024 14:56
github-merge-queue bot pushed a commit to rollkit/rollkit that referenced this pull request Mar 18, 2024
## Overview

This PR adds jsonrpc da client.

Depends on rollkit/go-da#54

## Checklist

- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [x] Required CI checks are passing
- [x] Visual proof for any user facing features like CLI or
documentation updates
- [x] Linked issues closed with keywords


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added a new flag for specifying a data availability layer (DA) auth
token.
- Introduced support for connecting via gRPC or JSON-RPC transports with
configuration options including DA address, auth token, and namespace.
- **Bug Fixes**
- Updated default DA address format and protocol to ensure consistency
and correct connection handling.
- **Refactor**
- Simplified DA client initialization with default timeout values and
new client creation methods.
- Renamed and restructured timeout constants and fields within the
`DAClient` struct.
- Replaced direct gRPC server setup with simplified proxy server
initialization for both gRPC and JSONRPC.
- Updated references and variable names across various tests to align
with new addressing and namespace configurations.
- **Chores**
- Removed unused imports across multiple files to clean up the codebase.
- **Documentation**
- Updated documentation to reflect new DA connection options and
configurations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants