Commit 944c3d7f authored by Niklas Adolfsson's avatar Niklas Adolfsson
Browse files

Merge remote-tracking branch 'origin/master' into HEAD

parents 7b4d14d4 21e557d2
Pipeline #206656 passed with stages
in 5 minutes
...@@ -4,7 +4,52 @@ The format is based on [Keep a Changelog]. ...@@ -4,7 +4,52 @@ The format is based on [Keep a Changelog].
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
## [Unreleased] ## [v0.15.1] - 2022-07-29
This release fixes some incorrect tracing spans.
### [Fixed]
- [Bug Fix] - Incorrect trace caused by use of Span::enter in asynchronous code [#835](https://github.com/paritytech/jsonrpsee/pull/835)
## [v0.15.0] - 2022-07-20
v0.15.0 is a breaking release. The main changes are:
- It's now possible to apply resource limits to subscriptions as well as regular calls.
- We now allow trait bounds to be overridden in the proc macros. See `examples/examples/proc_macro_bounds.rs` for examples.
- We've tidied up the subscription API, removing the `PendingSink` concept (you can still manually accept or reject a sink, but otherwise it'll be accepted automatically if you send a message down it) ([#799](https://github.com/paritytech/jsonrpsee/pull/799)).
- Our logging `Middleware` trait has been split into `HttpMiddleware` and `WsMiddleware` to better capture the differences between the two. if you use custom middleware, you'll need to implement one or the other trait on it depending on your used transport method ([#793](https://github.com/paritytech/jsonrpsee/pull/793)). We also provide params and the method type to middleware calls now, too ([#820](https://github.com/paritytech/jsonrpsee/pull/820)).
- We've consistified the API for setting headers across HTTP and WS clients ([#799](https://github.com/paritytech/jsonrpsee/pull/814)).
Here's the full list of changes:
### [Fixed]
- Fix client generation with param_kind = map [#805](https://github.com/paritytech/jsonrpsee/pull/805)
- ws-server: Handle soketto::Incoming::Closed frames [#815](https://github.com/paritytech/jsonrpsee/pull/815)
- fix(ws server): reply HTTP 403 on all failed conns [#819](https://github.com/paritytech/jsonrpsee/pull/819)
- fix clippy [#817](https://github.com/paritytech/jsonrpsee/pull/817)
### [Added]
- Add resource limiting for Subscriptions [#786](https://github.com/paritytech/jsonrpsee/pull/786)
- feat(logging): add tracing span per JSON-RPC call [#722](https://github.com/paritytech/jsonrpsee/pull/722)
- feat(clients): add explicit unsubscribe API [#789](https://github.com/paritytech/jsonrpsee/pull/789)
- Allow trait bounds to be overridden in macro [#808](https://github.com/paritytech/jsonrpsee/pull/808)
### [Changed]
- Point to a new v1.0 milestone in the README.md [#801](https://github.com/paritytech/jsonrpsee/pull/801)
- chore(deps): upgrade tracing v0.1.34 [#800](https://github.com/paritytech/jsonrpsee/pull/800)
- Replace cargo-nextest with cargo-test for running tests [#802](https://github.com/paritytech/jsonrpsee/pull/802)
- Remove deny_unknown_fields from Request and Response [#803](https://github.com/paritytech/jsonrpsee/pull/803)
- substrate-subxt -> subxt [#807](https://github.com/paritytech/jsonrpsee/pull/807)
- chore(deps): update pprof requirement from 0.9 to 0.10 [#810](https://github.com/paritytech/jsonrpsee/pull/810)
- Return error from subscription callbacks [#799](https://github.com/paritytech/jsonrpsee/pull/799)
- middleware refactoring [#793](https://github.com/paritytech/jsonrpsee/pull/793)
- feat(middleware): expose type of the method call [#820](https://github.com/paritytech/jsonrpsee/pull/820)
- Uniform API for custom headers between clients [#814](https://github.com/paritytech/jsonrpsee/pull/814)
- Update links to client directories. [#822](https://github.com/paritytech/jsonrpsee/pull/822)
## [v0.14.0] - 2022-06-14 ## [v0.14.0] - 2022-06-14
......
...@@ -9,10 +9,10 @@ Designed to be the successor to [ParityTech's JSONRPC crate](https://github.com/ ...@@ -9,10 +9,10 @@ Designed to be the successor to [ParityTech's JSONRPC crate](https://github.com/
Support `WebSocket` and `HTTP` transports for both client and server. Support `WebSocket` and `HTTP` transports for both client and server.
## Sub-projects ## Sub-projects
- [jsonrpsee-http-client](./http-client) [![crates.io][http-client-image]][http-client-url] - [jsonrpsee-http-client](./client/http-client) [![crates.io][http-client-image]][http-client-url]
- [jsonrpsee-http-server](./http-server) [![crates.io][http-server-image]][http-server-url] - [jsonrpsee-http-server](./http-server) [![crates.io][http-server-image]][http-server-url]
- [jsonrpsee-proc-macros](./proc-macros) [![crates.io][proc-macros-image]][proc-macros-url] - [jsonrpsee-proc-macros](./proc-macros) [![crates.io][proc-macros-image]][proc-macros-url]
- [jsonrpsee-ws-client](./ws-client) [![crates.io][ws-client-image]][ws-client-url] - [jsonrpsee-ws-client](./client/ws-client) [![crates.io][ws-client-image]][ws-client-url]
- [jsonrpsee-ws-server](./ws-server) [![crates.io][ws-server-image]][ws-server-url] - [jsonrpsee-ws-server](./ws-server) [![crates.io][ws-server-image]][ws-server-url]
[http-client-image]: https://img.shields.io/crates/v/jsonrpsee-http-client.svg [http-client-image]: https://img.shields.io/crates/v/jsonrpsee-http-client.svg
...@@ -32,7 +32,7 @@ Support `WebSocket` and `HTTP` transports for both client and server. ...@@ -32,7 +32,7 @@ Support `WebSocket` and `HTTP` transports for both client and server.
- [WebSocket](./examples/examples/ws.rs) - [WebSocket](./examples/examples/ws.rs)
- [WebSocket pubsub](./examples/examples/ws_pubsub_broadcast.rs) - [WebSocket pubsub](./examples/examples/ws_pubsub_broadcast.rs)
- [API generation with proc macro](./examples/examples/proc_macro.rs) - [API generation with proc macro](./examples/examples/proc_macro.rs)
- [Middleware](./examples/examples/multi_middleware.rs) - [Logger](./examples/examples/multi_logger.rs)
- [CORS server](./examples/examples/cors_server.rs) - [CORS server](./examples/examples/cors_server.rs)
- [Core client](./examples/examples/core_client.rs) - [Core client](./examples/examples/core_client.rs)
......
# How to release `jsonrpsee` # Release Checklist
These steps assume that you've checked out the Jsonrpsee repository and are in the root directory of it.
We also assume that ongoing work done is being merged directly to the `master` branch.
1. Ensure that everything you'd like to see released is on the `master` branch.
2. Create a release branch off `master`, for example `chore-release-v0.15.0`. Decide how far the version needs to be bumped based
on the changes to date. If unsure what to bump the version to (e.g. is it a major, minor or patch release), check with the
Parity Tools team.
3. Bump the crate versions in `Cargo.toml` to whatever was decided in step 2. The easiest approach is to search and replace, checking
that you didn't replace any other crate versions along the way.
4. Update `CHANGELOG.md` to reflect the difference between this release and the last. If you're unsure of
what to add, check with the Tools team. See the `CHANGELOG.md` file for details of the format it follows.
First, if there have been any significant changes, add a description of those changes to the top of the
changelog entry for this release. This will help people to understand the impact of the change and what they need to do
to adopt it.
Next, you can use the following script to generate the merged PRs between releases:
```
./scripts/generate_changelog.sh
```
Ensure that the script picked the latest published release tag (e.g. if releasing `v0.15.0`, the script should
provide something like `[+] Latest release tag: v0.14.0` ). Then group the PRs into "Fixed", "Added" and "Changed" sections,
and make any other adjustments that you feel are necessary for clarity.
5. Commit any of the above changes to the release branch and open a PR in GitHub with a base of `master`. Name the branch something
like `chore(release): v0.15.0`.
6. Once the branch has been reviewed and passes CI, merge it.
7. Now, we're ready to publish the release to crates.io. Run `./scripts/publish.sh` to publish all crates in the correct order.
8. If the release was successful, tag the commit that we released in the `master` branch with the
version that we just released, for example:
```
git tag -s v0.15.0 # use the version number you've just published to crates.io, not this
git push --tags
```
Once this is pushed, go along to [the releases page on GitHub](https://github.com/paritytech/jsonrpsee/releases)
and draft a new release which points to the tag you just pushed to `master` above. Copy the changelog comments
for the current release into the release description.
1. Bump the version of all crates
1. Run all tests
1. In the `CHANGELOG.md` file, move everything under "Unreleased" to a new section named `## [vx.y.z] – YYYY-MM-DD`
1. Publish: `./scripts/publish.sh`
1. Once published, make sure to "create a release" for the pushed tag on github.
[package] [package]
name = "jsonrpsee-benchmarks" name = "jsonrpsee-benchmarks"
version = "0.14.0" version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
description = "Benchmarks for jsonrpsee" description = "Benchmarks for jsonrpsee"
edition = "2021" edition = "2021"
......
[package] [package]
name = "jsonrpsee-http-client" name = "jsonrpsee-http-client"
version = "0.14.0" version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"] authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "HTTP client for JSON-RPC" description = "HTTP client for JSON-RPC"
edition = "2021" edition = "2021"
...@@ -14,8 +14,8 @@ async-trait = "0.1" ...@@ -14,8 +14,8 @@ async-trait = "0.1"
rustc-hash = "1" rustc-hash = "1"
hyper = { version = "0.14.10", features = ["client", "http1", "http2", "tcp"] } hyper = { version = "0.14.10", features = ["client", "http1", "http2", "tcp"] }
hyper-rustls = { version = "0.23", optional = true } hyper-rustls = { version = "0.23", optional = true }
jsonrpsee-types = { path = "../../types", version = "0.14.0" } jsonrpsee-types = { path = "../../types", version = "0.15.1" }
jsonrpsee-core = { path = "../../core", version = "0.14.0", features = ["client", "http-helpers"] } jsonrpsee-core = { path = "../../core", version = "0.15.1", features = ["client", "http-helpers"] }
serde = { version = "1.0", default-features = false, features = ["derive"] } serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "1.0" thiserror = "1.0"
......
...@@ -168,17 +168,19 @@ pub struct HttpClient { ...@@ -168,17 +168,19 @@ pub struct HttpClient {
impl ClientT for HttpClient { impl ClientT for HttpClient {
async fn notification<'a>(&self, method: &'a str, params: Option<ParamsSer<'a>>) -> Result<(), Error> { async fn notification<'a>(&self, method: &'a str, params: Option<ParamsSer<'a>>) -> Result<(), Error> {
let trace = RpcTracing::notification(method); let trace = RpcTracing::notification(method);
let _enter = trace.span().enter(); async {
let notif = serde_json::to_string(&NotificationSer::new(method, params)).map_err(Error::ParseError)?;
let notif = serde_json::to_string(&NotificationSer::new(method, params)).map_err(Error::ParseError)?; let fut = self.transport.send(notif);
let fut = self.transport.send(notif).in_current_span(); match tokio::time::timeout(self.request_timeout, fut).await {
Ok(Ok(ok)) => Ok(ok),
match tokio::time::timeout(self.request_timeout, fut).await { Err(_) => Err(Error::RequestTimeout),
Ok(Ok(ok)) => Ok(ok), Ok(Err(e)) => Err(Error::Transport(e.into())),
Err(_) => Err(Error::RequestTimeout), }
Ok(Err(e)) => Err(Error::Transport(e.into())),
} }
.instrument(trace.into_span())
.await
} }
/// Perform a request towards the server. /// Perform a request towards the server.
...@@ -190,34 +192,37 @@ impl ClientT for HttpClient { ...@@ -190,34 +192,37 @@ impl ClientT for HttpClient {
let id = guard.inner(); let id = guard.inner();
let request = RequestSer::new(&id, method, params); let request = RequestSer::new(&id, method, params);
let trace = RpcTracing::method_call(method); let trace = RpcTracing::method_call(method);
let _enter = trace.span().enter();
let raw = serde_json::to_string(&request).map_err(Error::ParseError)?; async {
let raw = serde_json::to_string(&request).map_err(Error::ParseError)?;
let fut = self.transport.send_and_read_body(raw).in_current_span(); let fut = self.transport.send_and_read_body(raw);
let body = match tokio::time::timeout(self.request_timeout, fut).await { let body = match tokio::time::timeout(self.request_timeout, fut).await {
Ok(Ok(body)) => body, Ok(Ok(body)) => body,
Err(_e) => { Err(_e) => {
return Err(Error::RequestTimeout); return Err(Error::RequestTimeout);
} }
Ok(Err(e)) => { Ok(Err(e)) => {
return Err(Error::Transport(e.into())); return Err(Error::Transport(e.into()));
} }
}; };
let response: Response<_> = match serde_json::from_slice(&body) { let response: Response<_> = match serde_json::from_slice(&body) {
Ok(response) => response, Ok(response) => response,
Err(_) => { Err(_) => {
let err: ErrorResponse = serde_json::from_slice(&body).map_err(Error::ParseError)?; let err: ErrorResponse = serde_json::from_slice(&body).map_err(Error::ParseError)?;
return Err(Error::Call(CallError::Custom(err.error_object().clone().into_owned()))); return Err(Error::Call(CallError::Custom(err.error_object().clone().into_owned())));
} }
}; };
if response.id == id { if response.id == id {
Ok(response.result) Ok(response.result)
} else { } else {
Err(Error::InvalidRequestId) Err(Error::InvalidRequestId)
}
} }
.instrument(trace.into_span())
.await
} }
async fn batch_request<'a, R>(&self, batch: Vec<(&'a str, Option<ParamsSer<'a>>)>) -> Result<Vec<R>, Error> async fn batch_request<'a, R>(&self, batch: Vec<(&'a str, Option<ParamsSer<'a>>)>) -> Result<Vec<R>, Error>
...@@ -227,46 +232,47 @@ impl ClientT for HttpClient { ...@@ -227,46 +232,47 @@ impl ClientT for HttpClient {
let guard = self.id_manager.next_request_ids(batch.len())?; let guard = self.id_manager.next_request_ids(batch.len())?;
let ids: Vec<Id> = guard.inner(); let ids: Vec<Id> = guard.inner();
let trace = RpcTracing::batch(); let trace = RpcTracing::batch();
let _enter = trace.span().enter();
let mut batch_request = Vec::with_capacity(batch.len()); async {
// NOTE(niklasad1): `ID` is not necessarily monotonically increasing. let mut batch_request = Vec::with_capacity(batch.len());
let mut ordered_requests = Vec::with_capacity(batch.len()); // NOTE(niklasad1): `ID` is not necessarily monotonically increasing.
let mut request_set = FxHashMap::with_capacity_and_hasher(batch.len(), Default::default()); let mut ordered_requests = Vec::with_capacity(batch.len());
let mut request_set = FxHashMap::with_capacity_and_hasher(batch.len(), Default::default());
for (pos, (method, params)) in batch.into_iter().enumerate() { for (pos, (method, params)) in batch.into_iter().enumerate() {
batch_request.push(RequestSer::new(&ids[pos], method, params)); batch_request.push(RequestSer::new(&ids[pos], method, params));
ordered_requests.push(&ids[pos]); ordered_requests.push(&ids[pos]);
request_set.insert(&ids[pos], pos); request_set.insert(&ids[pos], pos);
} }
let fut = self let fut =
.transport self.transport.send_and_read_body(serde_json::to_string(&batch_request).map_err(Error::ParseError)?);
.send_and_read_body(serde_json::to_string(&batch_request).map_err(Error::ParseError)?)
.in_current_span();
let body = match tokio::time::timeout(self.request_timeout, fut).await { let body = match tokio::time::timeout(self.request_timeout, fut).await {
Ok(Ok(body)) => body, Ok(Ok(body)) => body,
Err(_e) => return Err(Error::RequestTimeout), Err(_e) => return Err(Error::RequestTimeout),
Ok(Err(e)) => return Err(Error::Transport(e.into())), Ok(Err(e)) => return Err(Error::Transport(e.into())),
}; };
let rps: Vec<Response<_>> = let rps: Vec<Response<_>> =
serde_json::from_slice(&body).map_err(|_| match serde_json::from_slice::<ErrorResponse>(&body) { serde_json::from_slice(&body).map_err(|_| match serde_json::from_slice::<ErrorResponse>(&body) {
Ok(e) => Error::Call(CallError::Custom(e.error_object().clone().into_owned())), Ok(e) => Error::Call(CallError::Custom(e.error_object().clone().into_owned())),
Err(e) => Error::ParseError(e), Err(e) => Error::ParseError(e),
})?; })?;
// NOTE: `R::default` is placeholder and will be replaced in loop below. // NOTE: `R::default` is placeholder and will be replaced in loop below.
let mut responses = vec![R::default(); ordered_requests.len()]; let mut responses = vec![R::default(); ordered_requests.len()];
for rp in rps { for rp in rps {
let pos = match request_set.get(&rp.id) { let pos = match request_set.get(&rp.id) {
Some(pos) => *pos, Some(pos) => *pos,
None => return Err(Error::InvalidRequestId), None => return Err(Error::InvalidRequestId),
}; };
responses[pos] = rp.result responses[pos] = rp.result
}
Ok(responses)
} }
Ok(responses) .instrument(trace.into_span())
.await
} }
} }
......
[package] [package]
name = "jsonrpsee-client-transport" name = "jsonrpsee-client-transport"
version = "0.14.0" version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"] authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "WebSocket client for JSON-RPC" description = "WebSocket client for JSON-RPC"
edition = "2021" edition = "2021"
...@@ -10,8 +10,8 @@ homepage = "https://github.com/paritytech/jsonrpsee" ...@@ -10,8 +10,8 @@ homepage = "https://github.com/paritytech/jsonrpsee"
documentation = "https://docs.rs/jsonrpsee-ws-client" documentation = "https://docs.rs/jsonrpsee-ws-client"
[dependencies] [dependencies]
jsonrpsee-types = { path = "../../types", version = "0.14.0", optional = true } jsonrpsee-types = { path = "../../types", version = "0.15.1", optional = true }
jsonrpsee-core = { path = "../../core", version = "0.14.0", features = ["client"] } jsonrpsee-core = { path = "../../core", version = "0.15.1", features = ["client"] }
tracing = "0.1.34" tracing = "0.1.34"
# optional # optional
......
[package] [package]
name = "jsonrpsee-wasm-client" name = "jsonrpsee-wasm-client"
version = "0.14.0" version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"] authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "WASM client for JSON-RPC" description = "WASM client for JSON-RPC"
edition = "2021" edition = "2021"
...@@ -10,9 +10,9 @@ homepage = "https://github.com/paritytech/jsonrpsee" ...@@ -10,9 +10,9 @@ homepage = "https://github.com/paritytech/jsonrpsee"
documentation = "https://docs.rs/jsonrpsee-ws-client" documentation = "https://docs.rs/jsonrpsee-ws-client"
[dependencies] [dependencies]
jsonrpsee-types = { path = "../../types", version = "0.14.0" } jsonrpsee-types = { path = "../../types", version = "0.15.1" }
jsonrpsee-client-transport = { path = "../transport", version = "0.14.0", features = ["web"] } jsonrpsee-client-transport = { path = "../transport", version = "0.15.1", features = ["web"] }
jsonrpsee-core = { path = "../../core", version = "0.14.0", features = ["async-wasm-client"] } jsonrpsee-core = { path = "../../core", version = "0.15.1", features = ["async-wasm-client"] }
[dev-dependencies] [dev-dependencies]
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] } tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
......
[package] [package]
name = "jsonrpsee-ws-client" name = "jsonrpsee-ws-client"
version = "0.14.0" version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"] authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "WebSocket client for JSON-RPC" description = "WebSocket client for JSON-RPC"
edition = "2021" edition = "2021"
...@@ -10,9 +10,9 @@ homepage = "https://github.com/paritytech/jsonrpsee" ...@@ -10,9 +10,9 @@ homepage = "https://github.com/paritytech/jsonrpsee"
documentation = "https://docs.rs/jsonrpsee-ws-client" documentation = "https://docs.rs/jsonrpsee-ws-client"
[dependencies] [dependencies]
jsonrpsee-types = { path = "../../types", version = "0.14.0" } jsonrpsee-types = { path = "../../types", version = "0.15.1" }
jsonrpsee-client-transport = { path = "../transport", version = "0.14.0", features = ["ws"] } jsonrpsee-client-transport = { path = "../transport", version = "0.15.1", features = ["ws"] }
jsonrpsee-core = { path = "../../core", version = "0.14.0", features = ["async-client"] } jsonrpsee-core = { path = "../../core", version = "0.15.1", features = ["async-client"] }
http = "0.2.0" http = "0.2.0"
[dev-dependencies] [dev-dependencies]
......
[package] [package]
name = "jsonrpsee-core" name = "jsonrpsee-core"
version = "0.14.0" version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
description = "Utilities for jsonrpsee" description = "Utilities for jsonrpsee"
edition = "2021" edition = "2021"
...@@ -11,7 +11,7 @@ anyhow = "1" ...@@ -11,7 +11,7 @@ anyhow = "1"
async-trait = "0.1" async-trait = "0.1"
beef = { version = "0.5.1", features = ["impl_serde"] } beef = { version = "0.5.1", features = ["impl_serde"] }
futures-channel = "0.3.14" futures-channel = "0.3.14"
jsonrpsee-types = { path = "../types", version = "0.14.0" } jsonrpsee-types = { path = "../types", version = "0.15.1" }
thiserror = "1" thiserror = "1"
serde = { version = "1.0", default-features = false, features = ["derive"] } serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = { version = "1", features = ["raw_value"] } serde_json = { version = "1", features = ["raw_value"] }
...@@ -51,6 +51,7 @@ server = [ ...@@ -51,6 +51,7 @@ server = [
"lazy_static", "lazy_static",
"unicase", "unicase",
"http", "http",
"hyper",
] ]
client = ["futures-util/sink", "futures-channel/sink", "futures-channel/std"] client = ["futures-util/sink", "futures-channel/sink", "futures-channel/std"]
async-client = [ async-client = [
......
...@@ -243,102 +243,104 @@ impl Drop for Client { ...@@ -243,102 +243,104 @@ impl Drop for Client {
#[async_trait] #[async_trait]
impl ClientT for Client { impl ClientT for Client {
async fn notification<'a>(&self, method: &'a str, params: Option<ParamsSer<'a>>) -> Result<(), Error> { async fn notification<'a>(&self, method: &'a str, params: Option<ParamsSer<'a>>) -> Result<(), Error> {
// NOTE: we use this to guard against max number of concurrent requests. // NOTE: we use this to guard against max number of concurrent requests.
let _req_id = self.id_manager.next_request_id()?; let _req_id = self.id_manager.next_request_id()?;
let notif = NotificationSer::new(method, params); let notif = NotificationSer::new(method, params);
let trace = RpcTracing::batch(); let trace = RpcTracing::batch();
let _enter = trace.span().enter();
async {
let raw = serde_json::to_string(&notif).map_err(Error::ParseError)?; let raw = serde_json::to_string(&notif).map_err(Error::ParseError)?;
tx_log_from_str(&raw, self.max_log_length); tx_log_from_str(&raw, self.max_log_length);
let mut sender = self.to_back.clone(); let mut sender = self.to_back.clone();
let fut = sender.send(FrontToBack::Notification(raw)).in_current_span(); let fut = sender.send(FrontToBack::Notification(raw));
match future::select(fut, Delay::new(self.request_timeout)).await { match future::select(fut, Delay::new(self.request_timeout)).await {
Either::Left((Ok(()), _)) => Ok(()), Either::Left((Ok(()), _)) => Ok(()),
Either::Left((Err(_), _)) => Err(self.read_error_from_backend().await), Either::Left((Err(_), _)) => Err(self.read_error_from_backend().await),
Either::Right((_, _)) => Err(Error::RequestTimeout), Either::Right((_, _)) => Err(Error::RequestTimeout),
} }
} }.instrument(trace.into_span()).await
}
async fn request<'a, R>(&self, method: &'a str, params: Option<ParamsSer<'a>>) -> Result<R, Error> async fn request<'a, R>(&self, method: &'a str, params: Option<ParamsSer<'a>>) -> Result<R, Error>
where where
R: DeserializeOwned, R: DeserializeOwned,
{ {
let (send_back_tx, send_back_rx) = oneshot::channel(); let (send_back_tx, send_back_rx) = oneshot::channel();
let guard = self.id_manager.next_request_id()?; let guard = self.id_manager.next_request_id()?;
let id = guard.inner(); let id = guard.inner();
let trace = RpcTracing::method_call(method); let trace = RpcTracing::method_call(method);
let _enter = trace.span().enter();
async {
let raw = serde_json::to_string(&RequestSer::new(&id, method, params)).map_err(Error::ParseError)?; let raw = serde_json::to_string(&RequestSer::new(&id, method, params)).map_err(Error::ParseError)?;
tx_log_from_str(&raw, self.max_log_length); tx_log_from_str(&raw, self.max_log_length);
if self if self
.to_back .to_back
.clone() .clone()
.send(FrontToBack::Request(RequestMessage { raw, id: id.clone(), send_back: Some(send_back_tx) })) .send(FrontToBack::Request(RequestMessage { raw, id: id.clone(), send_back: Some(send_back_tx) }))
.await .await
.is_err() .is_err()
{ {
return Err(self.read_error_from_backend().await); return Err(self.read_error_from_backend().await);
} }
let res = call_with_timeout(self.request_timeout, send_back_rx).in_current_span().await; let res = call_with_timeout(self.request_timeout, send_back_rx).await;
let json_value = match res { let json_value = match res {