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 9 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
147 changes: 146 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,151 @@ 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 major breaking changes to be aware of are:
Copy link
Contributor

Choose a reason for hiding this comment

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

Amazing release! Nice work! 🚀


### Server backpressure

This release changes the server to be "backpressured" and it mostly concerns subscriptions.
New APIs has been introduced because that and the API `pipe_from_stream` has been removed.
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 {
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 call return type is 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>`

This affects the APIs `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.
Be aware that [the client APIs don't support this yet](https://github.com/paritytech/jsonrpsee/issues/1067)

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 API is changed.

jsonrpsee now spawns the subscriptions via `tokio::spawn` and it's sufficient to provide an async block in `register_subscription`

Further, the subscription API had an explicit close API for closing subscriptions which was hard to understand and
to get right. This has been removed and everything is handled by the return value/type of the async block instead.

Example:

```rust
module
.register_subscription::<RpcResult<(), _, _>::("sub", "s", "unsub", |_, pending, _| async move {
// This just answers the RPC call and if this fails => no close notification is sent out.
pending.accept().await?;
// This is sent out as a `close notification/message`.
Err(anyhow::anyhow!("The subscription failed"))?;
})
.unwrap();
```

The return value in example above needs to implement `IntoSubscriptionCloseResponse` and in this case it's `Result<(), E>` which
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
implies that any value after `pending.accept().await?`.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved

Because `Result<(), E>` is used here then close notification will sent out as error notification and it's also possible
to ignore the return value by using `()` or implement `IntoSubscriptionCloseResponse` for some other behaviour.
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved

### [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))
- fix(rpc module): subscription close bug ([#1011](https://github.com/paritytech/jsonrpsee/pull/1011))
- fix: customized server error codes ([#1004](https://github.com/paritytech/jsonrpsee/pull/1004))

### [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))
- client: rename `max_notifs_per_subscription` to `max_buffer_capacity_per_subscription` ([#1012](https://github.com/paritytech/jsonrpsee/pull/1012))
- 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 Expand Up @@ -38,7 +183,7 @@ Both HTTP and WebSocket are still enabled by default.

v0.16.0 is a breaking release and the major changes are:

- The server now support WS and HTTP on the same socket and the `jsonrpsee-http-server` and `jsonrpsee-ws-server` crates are moved to the `jsonrpsee-server` crate instead.
- The server now support WS and HTTP on the same socket and the `jsonrpsee-http-server` and `jsonrpsee-ws-server` crates are moved to the `jsonrpsee-server` crate instead.
- The client batch request API is improved such as the errors and valid responses can be iterated over.
- The server has `tower middleware` support.
- The server now adds a tracing span for each connection to distinguish logs per connection.
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" }