Skip to content
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

chore release v0.17 #1083

Merged
merged 19 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 183 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,189 @@ The format is based on [Keep a Changelog].

[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [v0.17.0] - 2023-04-14

This is a significant release and the important changes to be aware of are:

### Server backpressure

This release changed the server to be "backpressured", before the API used unbounded channels and
now one needs to explicitly handle what do when a channel becomes full as it's highly application dependent.

It mostly changes the subscription APIs and now both non-blocking and async APIs are provided.

As a consequence the old API pipe_from_stream has been removed and jsonrpsee only provides async primitives to implement
something similar depending on the use-case.

Before it was possible to do:

```rust
module
.register_subscription("sub", "s", "unsub", |_, sink, _| async move {
let stream = stream_of_integers();

tokio::spawn(async move {
sink.pipe_from_stream(stream)
});
})
.unwrap();
```

After this release one must do something like:

```rust
module
.register_subscription("sub", "s", "unsub", |_, pending, _| async move {
pending.accept().await?;

let stream = stream_of_integers();

loop {
tokio::select! {
_ = sink.closed() => break Ok(()),
maybe_item = stream.next() => {
let Some(item) = maybe_item else {
break Ok(())
};
let msg = SubscriptionMessage::from_json(&item)?;
if let Err(e) = sink.send_timeout(msg) {
match e {
// The subscription is closed.
Err(TrySendError::Closed(_)) => break Ok(()),
// Channel is full, just drop the subscription
Err(TrySendError::Full(_)) => break Ok(()),
}
}
}
}
}
})
.unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth just pointing to some example where we've used this (I think we used it in a few places) too because they also show that one can write some helper function to do it if needed in multiple places :)

```

### Method calls return type are more flexible

This release also introduces a trait called `IntoResponse` which is makes it possible to return custom types and/or error
types instead of enforcing everything to return `Result<T, jsonrpsee::core::Error>`

The return values from `RpcModule::register_method`, `RpcModule::register_async_method` and `RpcModule::register_blocking_method`
and when these are used in the proc macro API are affected by this change.

The `IntoResponse` trait is already implemented for `Result<T, jsonrpsee::core::Error>` and for the primitive types

Before it was possible to do:

```rust
// This would return Result<&str, jsonrpsee::core::Error>
module.register_method("say_hello", |_, _| Ok("lo"))?;
```

After this release it possible to do:
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved

```rust
// Note, this method call is infallible and you might not want to return Result.
module.register_method("say_hello", |_, _| "lo")?;
```

### Subscription close API is simplified

Before the subscription API had a dedicated API for sending something that was called `close notifications`
which was hard to understand and to get right then this errors were not propagated the client just logged on the server side.

To elaborate why this `close API` can be useful is that if a server is closing a subscription it's possible that
the client won't be notified unless a separate notification is sent before the subscription is dropped. In those
scenarios it could be useful to use the `close API` instead of defining your own messages.

To cope with that a new trait called `IntoSubscriptionCloseResponse` has been introduced to make that easier.
After the `subscription` has been accepted then return value from that async block can be sent out as close notification.
It's implemented for Result<T, E> and can be implemented for custom types/behaviour as well.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved

Before it was possible to do:

```rust
module
.register_subscription("sub", "s", "unsub", |_, sink, _| async move {
let stream = stream_of_integers();

tokio::spawn(async move {
match sink.pipe_from_try_stream(stream).await {
SubscriptionClosed::Success => {
sink.close(SubscriptionClosed::Success);
}
SubscriptionClosed::RemotePeerAborted => (),
SubscriptionClosed::Failed(err) => {
sink.close(err);
}
}
});
})
.unwrap();
```

After this release it possible to do:

```rust
module
.register_subscription("sub", "s", "unsub", |_, pending, _| async move {
pending.accept().await?;
let stream = stream_of_integers();

// Errors here returned here will be sent out as a close notification.
loop {
tokio::select! {
_ = sink.closed() => break Ok(()),
maybe_item = stream.next() => {
let Some(item) = maybe_item else {
break Ok(())
};
let msg = SubscriptionMessage::from_json(&item)?;
sink.send.await(msg).map_err(|_| anyhow::anyhow!("The subscription failed"))?;
}
}
}
})
.unwrap();
```

### [Added]
- feat(server): configurable limit for batch requests. ([#1073](https://github.com/paritytech/jsonrpsee/pull/1073))
- feat(http client): add tower middleware ([#981](https://github.com/paritytech/jsonrpsee/pull/981))

### [Fixed]
- add tests for ErrorObject ([#1078](https://github.com/paritytech/jsonrpsee/pull/1078))
- fix: tokio v1.27 ([#1062](https://github.com/paritytech/jsonrpsee/pull/1062))
- fix: remove needless `Semaphore::(u32::MAX)` ([#1051](https://github.com/paritytech/jsonrpsee/pull/1051))
- fix server: don't send error on JSON-RPC notifications ([#1021](https://github.com/paritytech/jsonrpsee/pull/1021))
- fix: add `max_log_length` APIs and use missing configs ([#956](https://github.com/paritytech/jsonrpsee/pull/956))

### [Changed]
- docs: introduce workspace attributes and add keywords ([#1077](https://github.com/paritytech/jsonrpsee/pull/1077))
- refactor(server): downgrade connection log ([#1076](https://github.com/paritytech/jsonrpsee/pull/1076))
- chore(deps): update webpki-roots and tls ([#1068](https://github.com/paritytech/jsonrpsee/pull/1068))
- rpc module: refactor subscriptions to return `impl IntoSubscriptionResponse` ([#1034](https://github.com/paritytech/jsonrpsee/pull/1034))
- add `IntoResponse` trait for method calls ([#1057](https://github.com/paritytech/jsonrpsee/pull/1057))
- Make `jsonrpc` protocol version field in `Response` as `Option` ([#1046](https://github.com/paritytech/jsonrpsee/pull/1046))
- server: remove dependency http ([#1037](https://github.com/paritytech/jsonrpsee/pull/1037))
- chore(deps): update tower-http requirement from 0.3.4 to 0.4.0 ([#1033](https://github.com/paritytech/jsonrpsee/pull/1033))
- chore(deps): update socket2 requirement from 0.4.7 to 0.5.1 ([#1032](https://github.com/paritytech/jsonrpsee/pull/1032))
- Update bound type name ([#1029](https://github.com/paritytech/jsonrpsee/pull/1029))
- rpc module: remove `SubscriptionAnswer` ([#1025](https://github.com/paritytech/jsonrpsee/pull/1025))
- make verify_and_insert pub ([#1028](https://github.com/paritytech/jsonrpsee/pull/1028))
- update MethodKind ([#1026](https://github.com/paritytech/jsonrpsee/pull/1026))
- remove batch response ([#1020](https://github.com/paritytech/jsonrpsee/pull/1020))
- remove debug log ([#1024](https://github.com/paritytech/jsonrpsee/pull/1024))
- fix(rpc module): subscription close bug ([#1011](https://github.com/paritytech/jsonrpsee/pull/1011))
- client: rename `max_notifs_per_subscription` to `max_buffer_capacity_per_subscription` ([#1012](https://github.com/paritytech/jsonrpsee/pull/1012))
- Update error codes ([#1004](https://github.com/paritytech/jsonrpsee/pull/1004))
- client: feature gate tls cert store ([#994](https://github.com/paritytech/jsonrpsee/pull/994))
- server: bounded channels and backpressure ([#962](https://github.com/paritytech/jsonrpsee/pull/962))
- client: use tokio channels ([#999](https://github.com/paritytech/jsonrpsee/pull/999))
- chore: update gloo-net ^0.2.6 ([#978](https://github.com/paritytech/jsonrpsee/pull/978))
- Custom errors ([#977](https://github.com/paritytech/jsonrpsee/pull/977))
- client: distinct APIs to configure max request and response sizes ([#967](https://github.com/paritytech/jsonrpsee/pull/967))
- server: replace `FutureDriver` with `tokio::spawn` ([#1080](https://github.com/paritytech/jsonrpsee/pull/1080))
- server: uniform whitespace handling in rpc calls ([#1082](https://github.com/paritytech/jsonrpsee/pull/1082))

## [v0.16.2] - 2022-12-01

This release adds `Clone` and `Copy` implementations.
Expand Down
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resolver = "2"

[workspace.package]
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
version = "0.16.2"
version = "0.17.0"
edition = "2021"
rust-version = "1.64.0"
license = "MIT"
Expand All @@ -30,11 +30,11 @@ keywords = ["jsonrpc", "json", "http", "websocket", "WASM"]
readme = "README.md"

[workspace.dependencies]
jsonrpsee-types = { path = "types", version = "0.16.2" }
jsonrpsee-core = { path = "core", version = "0.16.2" }
jsonrpsee-server = { path = "server", version = "0.16.2" }
jsonrpsee-ws-client = { path = "client/ws-client", version = "0.16.2" }
jsonrpsee-http-client = { path = "client/http-client", version = "0.16.2" }
jsonrpsee-wasm-client = { path = "client/wasm-client", version = "0.16.2" }
jsonrpsee-client-transport = { path = "client/transport", version = "0.16.2" }
jsonrpsee-proc-macros = { path = "proc-macros", version = "0.16.2" }
jsonrpsee-types = { path = "types", version = "0.17.0" }
jsonrpsee-core = { path = "core", version = "0.17.0" }
jsonrpsee-server = { path = "server", version = "0.17.0" }
jsonrpsee-ws-client = { path = "client/ws-client", version = "0.17.0" }
jsonrpsee-http-client = { path = "client/http-client", version = "0.17.0" }
jsonrpsee-wasm-client = { path = "client/wasm-client", version = "0.17.0" }
jsonrpsee-client-transport = { path = "client/transport", version = "0.17.0" }
jsonrpsee-proc-macros = { path = "proc-macros", version = "0.17.0" }