-
Notifications
You must be signed in to change notification settings - Fork 911
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
Make RPC transports responsible for preparing payloads #3186
Make RPC transports responsible for preparing payloads #3186
Conversation
🦋 Changeset detectedLatest commit: f62ca3a The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @lorisleiva and the rest of your teammates on Graphite |
0d3222d
to
2e132bb
Compare
cf99f67
to
de2bb81
Compare
6d224dd
to
56c4dbc
Compare
de2bb81
to
e8fc7ad
Compare
56c4dbc
to
4430dda
Compare
e8fc7ad
to
efdef44
Compare
4430dda
to
dd8d6b7
Compare
efdef44
to
50e9859
Compare
dd8d6b7
to
70bfa6f
Compare
50e9859
to
191c075
Compare
70bfa6f
to
3a681f1
Compare
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.
So, this makes sense if you think of the transport as particularly a JSON-RPC transport. I expected that we'd stop short of this thing knowing anything about JSON-RPC.
These are the levels of ‘knowing about stuff.’
- I know how to send and receive bytes over HTTP
- I know how to send and receive JavaScript objects over HTTP
- I know how to prepare JSON-RPC method calls as JavaScript objects and interpret the responses
- I know how to fulfil
@solana/web3.js
API calls.
This is how I thought we'd divide these responsibilities up.
createHttpTransport()
makes something that just ferries bytes (as text) back and forthcreateHttpTransportForSolanaRpc()
something that wrapscreateHttpTransport
. Inputs and outputs are JavaScript primitives (asunknown
). It looks inside them (ie. check if it's an object, then a JSON-RPC message, then one of the allowlisted methods) to see if it should muck around with them or not according to the specific rules we have around upcasts. Ultimately passes text to the underlying transport.createSolanaRpcApi
knows about the JSON-RPC protocol. Can prepare a struct representing a JSON-RPC method call and interpret a response struct.- Delegates userland API calls to the
RpcApi
as normal.
This would mean that these calls live at these levels.
fetch
- Your fancy
JSON.stringify
implementation,isJsonRpcMessage(payload)
, bigint upcast stuff createRpcMessage(request)
- the usual crap
The implication of this architecture is that you could swap out 1 & 2 for the createCarrierPigeon()
transport, and as long as the carrier pigeon knew how to take the JavaScript object {jsonrpc: '2.0', method: 'getSlot'. id: 1}
to its destination and to bring back the JavaScript object {id: 1, result: 123n}
everything else continues to work without modification. Carrier pigeons, after all, understand large numbers and don't need our stupid JSON serialization code.
191c075
to
e1dfb2c
Compare
3a681f1
to
23f22d1
Compare
23f22d1
to
f62ca3a
Compare
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |
This PR slightly adjusts the boundaries of the RPC Transport layer by making RPC transports responsible for creating the payload they will send over the wire.
This mean, the
RpcRequest
type flows from the RPC API layer to the RPC Transport layer (with the addition of the abort signal when reaching thesend
method).In other words, this is the key change this PR makes: