-
Notifications
You must be signed in to change notification settings - Fork 653
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
feat: Separate jsonrpc
from rest of codebase, to prevent rpc
s to breaking due to refactoring.
#5516
Comments
I'd make this even more fine-grained: conceptually,
It's important to separate data type definitions into a separate crate. That way, if someone wants use the API using a different networking stack (eg, based on blocking IO), they get to re-use definitions of the JSON API iteslf, without brining in tokio and actix ecosystems. I think the end state here is that we publish
My suggested path there:
|
Also, from me personally: this is a hugely important bit of work which has multiplicative implications for both how effective are folks working at nearcore itself, as well as how robust is the ecosystem which builds on top of us. Kudos for spearheading the effort @pmnoxx ! |
cc @ChaoticTempest as one of the consures of RPC which cares a lot about Rust-level semver stability. |
@pmnoxx That might be not that clear of a win since actually some other projects might use and serialize those. Given that we publish near-primitives now with a 0.x semver-breaking releases, it is fine if we introduce breaking change since users will still be able to use whatever version they used before and rarely they actually need to upgrade near-primitives.
Well, |
@miraclx FYI, I had a chat with @matklad and suggested that he collaborate with you on this near-jsonrpc-primitives refactoring. This has been on my radar for quite a while, and I feel we can make these small steps toward better granularity of nearcore project and finally get to the point where we are comfortable releasing near-jsonrpc-client-rs 1.0 |
Had a design discussion with @miraclx, the write up is here: https://hackmd.io/WeCthH5LQqGrHiO1dxv6WA The most important bit is next steps:
Not that "remove nearcore dependencies from |
We should remove `serde` from `near-client-primitives`. It's only needed by `jsonrpc`. More changes will be required, to separate `jsonrpc` api, from rest of the code base, but that's a first step. See #5516 Blocks #5428 (review)
To clarify, removing |
We are planning to separate `jsonrpc` types from rest of the code base. We can start by separating types from `near-network-primitives` from `jsonrpc` by removing direct usage of `serde` from that crate. See #5516 TODO: (next PR) - Fix database memory leak.
Some extra observation about view types here: #6068 (comment). TL;DR at least one Lines 160 to 164 in dd8b28a
|
|
This was not fully addressed, see #6587 (comment) |
Another approach we should consider is defining the API in language-agnostic way and generating Rust-side of the API from the spec, rather than defining the spec in terms of rust impl. Here's a good example: https://www.twilio.com/docs/openapi/generating-a-rust-client-for-twilios-api#setup
This pulls language-agnostic JSON API spec from github and generates a bunch Rust structs with serde from it. This is going to be very labor intensive (we'd have to write the API spec essentially from scratch, reverse-engineering from current Rust structs), but should give us (and 3rd party developers!!) the best results. This also probably won't be incremental with respect to tactical refactors suggested above, so, if we do want to pursue this approach at some point, it makes sense to start that today. I am not familiar with the API specification languages landscape, so I can't vouch for openapi in particular, though I have to admit that the above one-command snippet looks great! I ... don't really understand why we didn't cover openapi-like approaches in https://hackmd.io/WeCthH5LQqGrHiO1dxv6WA |
OpenAPI gravitates towards REST-like APIs and it does not support sum-types (enums). We would need to redesign the API in order to make it OpenAPI-friendly (and developers-friendly as well), and while it has been a long-standing wish, we never had time to sit down and address it. |
We should refactor the code to separate
jsonrpc
from rest of the code base.Steps 1: remove usage of serde from crates other than
jsonrpc
.serde
is used mainly forSerialize
/Deserialize
of messages.serde
is used in following creates, simply becausejsonrpc
needs to serialize to json, to read/write messages to network. By removingserde
from those crates, we will be one step closer to cleaningjsonrpc
near-client-primitives
. #5515near-network
#5508serde
fromnear-primitives
(only usesserde
withtest_fetures
)serde
fromnear-network-primitives
#5546Step 2:
jsonrpc
and cleanup api, make sure it contains all types used.See #5428 (review)
The text was updated successfully, but these errors were encountered: