-
Notifications
You must be signed in to change notification settings - Fork 142
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
fix WebSocket serialization #1425
Conversation
Unit test was updated to assert valid encoding of data. Hacky approach to fix the issue is not working. Replacing normal JSON serialization with JSON RPC serialization is required, but there still is an issue.
WalkthroughThe recent update involves enhancing the JSON RPC handling over WebSocket connections in a Go application. A new field has been added to manage the RPC requests more effectively, and there are improvements in the subscription function to better encode and write responses. The changes reflect a focus on more robust and efficient WebSocket communication for RPC services. Changes
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
The last commit might actually fix the issue. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1425 +/- ##
==========================================
+ Coverage 51.56% 51.66% +0.09%
==========================================
Files 48 48
Lines 6469 6484 +15
==========================================
+ Hits 3336 3350 +14
Misses 2789 2789
- Partials 344 345 +1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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
Files selected for processing (4)
- rpc/json/handler.go (1 hunks)
- rpc/json/service.go (2 hunks)
- rpc/json/ws.go (1 hunks)
- rpc/json/ws_test.go (2 hunks)
Additional comments: 5
rpc/json/ws_test.go (2)
12-13: The addition of new imports
cmjson
andjsonrpc
aligns with the PR's objective to switch to JSON RPC serialization. Ensure that these packages are used consistently throughout the codebase for JSON operations.69-73: The unmarshalling logic has been updated to use
jsonrpc.Response
andcmjson.Unmarshal
instead of directly unmarshalling tocmtypes.EventDataNewBlock
. This change is consistent with the PR's goal to use JSON RPC serialization. However, ensure that theEventDataNewBlock
structure is compatible with the new unmarshalling process and that all necessary fields are correctly populated.rpc/json/ws.go (1)
- 16-19: The addition of the
codecReq
field to thewsConn
type is a significant change that likely affects the handling of RPC requests over WebSocket connections. This change should be carefully tested to ensure that it does not introduce any regressions or unexpected behavior, especially since WebSocket connections can be sensitive to changes in serialization and deserialization logic.rpc/json/service.go (2)
4-4: The addition of the
bytes
package is likely used for buffer operations, which is a common requirement when dealing with serialization and deserialization. This change seems appropriate for the task at hand.108-126: The
Subscribe
function has been modified to handle encoding and writing responses differently. It now uses acodecReq
which can be either from thewsConn
or a new JSON RPC codec request. This change is consistent with the PR's goal to use JSON RPC serialization. However, it's crucial to ensure that the subscription logic correctly handles the new serialization format and that the data sent over the WebSocket connection is correctly encoded and decoded.Verification successful
The review comment's concern about ensuring that the subscription logic correctly handles the new serialization format and that the data sent over the WebSocket connection is correctly encoded and decoded is addressed by the
TestWebSockets
function in thews_test.go
file. This test checks the WebSocket functionality, including the subscription logic, and verifies that messages are properly serialized and deserialized using the new JSON RPC serialization format.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the subscription logic correctly handles the new serialization format. rg --type go "func Test.*Subscribe.*" --files-with-matches | xargs -I {} go test {}Length of output: 89
Script:
#!/bin/bash # First, let's find if there are any tests for the Subscribe function. rg --type go "func Test.*Subscribe.*" --files-with-matchesLength of output: 60
Script:
#!/bin/bash # Additionally, let's check if there are any tests related to WebSocket serialization specifically. rg --type go "func Test.*WebSocket.*" --files-with-matchesLength of output: 80
Script:
#!/bin/bash # Let's examine the contents of the ws_test.go file to understand how it tests the WebSocket serialization. cat rpc/json/ws_test.goLength of output: 2474
Unit test was updated to assert valid encoding of data. Hacky approach to fix the issue is not working. Replacing normal JSON serialization with JSON RPC serialization is required, but there still is an issue.
Overview
Draft for visibility. CC: @Manav-Aggarwal
Relates to: #1268
Checklist
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests