-
Notifications
You must be signed in to change notification settings - Fork 209
[client] use types v2 (less alloc) #269
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
Conversation
benches/benches/bench.rs
Outdated
| pub fn jsonrpsee_types_v2(crit: &mut Criterion) { | ||
| crit.bench_function("jsonrpsee_types_v2", |b| { | ||
| b.iter(|| { | ||
| let params: JsonRpcParams<_> = vec![&1, &2].into(); |
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.
provide a macro for this:...
maybe: params_postional![1, 2, 3], params_by_key!["key" => val]?
| Ok(quote!(#ident::types)) | ||
| } | ||
| Ok(FoundCrate::Itself) => panic!("Deriving RPC methods in any of the `jsonrpsee crates` is not supported"), | ||
| Err(_) => match (crate_name("jsonrpsee-http-client"), crate_name("jsonrpsee-ws-client")) { |
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.
This was a bug before we searched only for the clients crates in Cargo.toml.
So now:
- Search for
jsonrpsee crate - if not found search for
client crates
|
|
||
| /// JSONRPC error code | ||
| #[derive(Error, Debug, PartialEq, Copy, Clone)] | ||
| pub enum ErrorCode { |
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.
copy-pasted from old jsonrpc types with some minor tweaks.
types/src/v2/mod.rs
Outdated
| Str(String), | ||
| } | ||
|
|
||
| impl From<SubscriptionId> for JsonValue { |
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.
avoid to call serde_json::to_value and it's infallible
Manual implementation of serialize/deserialize to get rid of duplicated message string
| } | ||
|
|
||
| impl<'a> serde::Deserialize<'a> for ErrorCode { | ||
| fn deserialize<D>(deserializer: D) -> Result<ErrorCode, D::Error> |
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.
these are ser/deser is a little bit weird (not symmetrical) but essentially the error message can be deduced from the error code so no need to store the message as allocated string.
|
|
||
| pub use beef::Cow; | ||
| pub use client::*; | ||
| pub use error::Error; |
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.
we could revisit this error type but it's quite hard to understand the different error types.
Technically we could kill the huge enum and have each client/server to have their own error type instead.
| /// JSON-RPC version. | ||
| pub jsonrpc: TwoPointZero, | ||
| /// Error. | ||
| pub error: ErrorCode, |
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.
@maciejhirsz I removed your type https://github.com/paritytech/jsonrpsee/blob/master/types/src/v2/mod.rs#L85-#L90. ErrorCode should be as cheap I think and more readable
| #[derive(Debug, PartialEq, Clone, Hash, Eq, Deserialize, Serialize)] | ||
| #[serde(deny_unknown_fields)] | ||
| #[serde(untagged)] | ||
| pub enum Id { |
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.
decided to bring this back, currently we just use Number in the clients and the servers is using RawValue
but probably worth to comply with the spec
maciejhirsz
left a comment
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.
LGTM
| let curr = self.current_pending.load(Ordering::Relaxed); | ||
| if curr > 0 { | ||
| self.current_pending.store(curr - 1, Ordering::Relaxed); |
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.
There is a pretty nasty race condition here :)
Migrate to
jsonrpsee_types::v2which causes lots of related changes.The major change is the client traits and related
JsonRpcParamtype,The changes were easy to port to
http clientbut withwebsocket clientI had to major refactoring and decided to make the transport abstraction clean i.e, doesn't know anything aboutjsonrpcit just sends messages. Thus, the clients are responsible for constructing the messages.Follow up:
JsonRpcParams([jsonrpsee types]: provide macro for constructing JsonRpcParams #275)Closing #249 #219 #225