rpc/lib/client & server: try to conform to JSON-RPC 2.0 spec#3858
rpc/lib/client & server: try to conform to JSON-RPC 2.0 spec#3858
Conversation
in conformance with JSON-RPC spec
Codecov Report
@@ Coverage Diff @@
## master #3858 +/- ##
=========================================
Coverage ? 65.92%
=========================================
Files ? 240
Lines ? 20297
Branches ? 0
=========================================
Hits ? 13381
Misses ? 5861
Partials ? 1055
|
this will require a lot of work. probably not worth it |
| cdc: cdc, | ||
| Upgrader: websocket.Upgrader{ | ||
| CheckOrigin: func(r *http.Request) bool { | ||
| // TODO ??? |
There was a problem hiding this comment.
The default behaviour would be relevant to browser-based clients, afaik. I suppose having a pass-through is a workaround for allowing for more complex security schemes, shifting the burden of AuthN/AuthZ outside the Tendermint RPC.
I can't think of other uses right now that would warrant a TODO though. The real backstory of this TODO shall remain shrouded in mystery 👻
There was a problem hiding this comment.
Gold! Saved this comment for future generations 😄
see commit body for the reason
it will be closed automatically
also, use t.Rate in tm-bench indexer when calculating ID
I do believe this is worth it, to bring us within the spec and what the wider community is using and used to. Do you think we could have it for 0.33? we can branch off from this branch then make the PR to be merged into this PR as it has already been reviewed? |
|
Impossible to merge master (too many conflicts). Will have to redo every step. |
https://www.jsonrpc.org/specification
What is done in this PR:
JSONRPCClient: validate that Response.ID matches Request.ID
I wanted to do the same for the WSClient, but since we're sending events as responses, not notifications, checking IDs would require storing them in memory indefinitely (and we won't be able to remove them upon client unsubscribing because ID is different then).
Request.ID is now optional. Notification is a Request without an ID. Previously "" or 0 were considered as notifications
Remove
#eventsuffix from ID from an event response (partially fixes Responses to "subscribe" sent over WebSocket don't conform to RPC 2.0 specification #2949) ID must be either string, int or null AND must be equal to request's ID. Now, because we've implemented events as responses, WS clients are tripping when they see Response.ID("0#event") != Request.ID("0"). Implementing events as requests would require a lot of time (~ 2 days to completely rewrite WS client and server)generate unique ID for each request
switch to integer IDs instead of "json-client-XYZ"
id=0 method=/subscribe
id=0 result=...
id=1 method=/abci_query
id=1 result=...
TODO:
[ ] send events (resulting from
ctx.WSConn.TryWriteRPCResponse(
rpctypes.NewRPCSuccessResponse(
ctx.WSConn.Codec(),
ctx.JSONReq.ID,
resultEvent,
))
/subscribe) as notifications (not responses) https://github.com/ethereum/go-ethereum/wiki/RPC-PUB-SUBtendermint/rpc/core/events.go
Lines 180 to 185 in 2f32b9f
From spec: "A Notification is a Request object"