-
Notifications
You must be signed in to change notification settings - Fork 19
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
soroban-rpc: adding optional params breaks clients using params array format #13
Comments
@leighmcculloch do you have any idea of how prevalent is the usage of arrays? (if I am honest, I didn't even know it was allowed until I saw it in this ticket) |
Given the inbound complaints when the params change went out, with folks discussing that the JS and CLI were broken it suggests some clients are using arrays, or were at least. It's difficult to know what the usage will be going forward or what other uses existed. We selected JSON-RPC as the API format for this service, and with that we accepted both forms of interacting with it. I think it'd be difficult for us to say array params are unsupported since a JSON-RPC client may use that format and that could be out of control of the developer using the client. To find the answer to this question one avenue might be for you to take a look at the JSON-RPC clients in different languages and see which use arrays in their requests. |
If we were to discontinue support for array style requests or discontinue support for maintaining them in a backwards compatible way, it would be ideal to actually disable support for that request type, so that no one could use it in the first place. Again, this would probably require some research that there aren't clients out there that support only it. |
I think we have 3 options:
I would go for (2), but it's a bit awkward. I wonder how other libraries deal with this (I haven't looked into this yet). |
From discussions on the jsonrpc mailing list it sounds like it is common for jsonrpc implementations to allow optional parameters to be ommitted in the params (see https://groups.google.com/g/json-rpc/c/n4kiH9yKBww/m/0ssppnkGpv8J). |
The upstream library is about to merge a way to disable array parameters. creachadair/jrpc2#114 So, now it's becoming a real possibility. |
We could do a little reach out in Discord and through folks we know are developing on the RPC API and query them if they are using the array format. |
Good idea! |
Another point of information is that our openrpc spec indicates that all methods are So, in theory we could claim that |
I think that's reasonable from a specification point-of-view, except that in practice the service has worked with arrays up until now, and even the js-stellar-sdk/soroban-client and soroban-cli have utilitized arrays. So if anyone else was using arrays, I would find that reasonable too. Given how new the service is and that it would be better long to support only JSON objects for clarity of requests, I think it's reasonable for us to pursue turning off arrays. We should communicate it in the release notes, and probably also do some shout outs about it in the Discord before the release. (cc @tyvdh) |
One point that is probably worth noting here:
While JSON-RPC requires parameters to be specified as arrays or objects, that doesn't mean your API has to accept both if they don't make sense for your method. It only means they have to be one or the other to be a valid request message (or omitted entirely). The method is still free to reject one or the other (or both, if it doesn't want there to be any parameters) without violating the spec. That's what the -32602 (Invalid Params) error code is meant for. I realize in this case you may need to work around some existing use, but you can freely tighten the rules on new API methods within the JSON-RPC rules. YMMV, but perhaps that will help simplify your decision making a bit. |
fwiw I'm not terribly concerned with disabling arrays from a backwards compatibility perspective. It'll be an easy tweak I believe and most folks are using SDKs anyway vs querying the RPC directly. Soroban by now has a long and colorful history of breaking things and as long as we're pre-mainnet we can afford a few more breaking changes to client software like this. It does need to be communicated to SDK developers but I don't foresee many issues here. I will say the syntax here is really odd though. Can you simulate things other than a transaction? Why is this an object or an array at all in the first place? Or is this just a nuance of the JSON-RPC spec? |
OK, then we should probably disable array-based requests. |
If we disable all array-based requests, that is technically a breaking change. However, if we don't implement this change, then the next time that we want to add an optional parameter to a request, that change will be breaking (where normally adding optional params would not be). Given that with pubnet launch approaching we'll likely be starting to get more developer feedback/requests, it seems likely to be that this will be inevitable, and in that case it might just be better to do it sooner rather than later. So I'm also inclined to go forward with disabling it. We could also just wait until we get a feature request that necessitates adding a new optional parameter and decide at that point. But regardless, we should probably file issues with ecosystem SDKs and queue up work to update the JS SDK now. @janewang thoughts? |
Another option you could consider, if you're concerned about compatibility with existing use, is to write custom unmarshalers for your various parameter types that special-case the "old" (existing) usage, but require new fields to be specified as objects. This way, old code that doesn't need the new fields will still work, but you can still enforce that optional parameters are plumbed via an object. Example: https://go.dev/play/p/VBLyRI5td1J |
I'm a +1 for simply turning off array requests. If we're going to do it, doing it sooner is better than later. Writing custom unmarshalers to handle the old format also makes sense, but given the recent breakage probably pushed people to switching, hopefully it would be unnecessary to write the unmarshalers. |
+1 on deprecating array format. I suggest we do this in the upcoming protocol 20 release as it is a breaking change |
It’s an easy change, but we first need our SDKs to only use objects (CC @Shaptic ) |
@janewang should we make an announcement in discord about this upcoming change? |
We will tee it up for protocol 21 announcements. |
What version are you using?
v20.1.0
What did you do?
• Request the
simulateTransaction
endpoint using array format with a single argument in that params list:What did you expect to see?
The request to be accepted as it is with soroban-rpc
v20.0.2
.What did you see instead?
Also, if I make the same request, but with the params passed as a JSON objected with named fields, it is accepted:
Discussion
This issue has been discussed in these places:
This issue arises because in v20.1.0 the soroban-rpc's simulateTransaction endpoint had a new optional parameter added to it's request object:
The jsonrpc specification doesn't say how optional parameters should behave, it is implementation specific, and the jsonrpc library in use by the soroban-rpc allows optional parameters when the
params
are defined as a JSON object, but requires them when theparams
are defined as a JSON array.From discussions on the jsonrpc mailing list it sounds like it is common for jsonrpc implementations to allow optional parameters to be ommitted in the params (see https://groups.google.com/g/json-rpc/c/n4kiH9yKBww/m/0ssppnkGpv8J), but that behavior isn't supported by the jsonrpc library the soroban-rpc is using.
Until the soroban-rpc's jsonrpc implementation supports omitting optional parameters in the
params
array format, I don't see how we can ever add an optional parameter though, since doing so may break any client that is using array format, as what we saw with the above v20.1.0 release.cc @Shaptic @mollykarcher
The text was updated successfully, but these errors were encountered: