@@ -4,6 +4,168 @@ The format is based on [Keep a Changelog].
4
4
5
5
[ Keep a Changelog ] : http://keepachangelog.com/en/1.0.0/
6
6
7
+ ## [ v0.17.0] - 2023-04-17
8
+
9
+ This is a significant release and the major breaking changes to be aware of are:
10
+
11
+ ### Server backpressure
12
+
13
+ This release changes the server to be "backpressured" and it mostly concerns subscriptions.
14
+ New APIs has been introduced because of that and the API ` pipe_from_stream ` has been removed.
15
+
16
+ Before it was possible to do:
17
+
18
+ ``` rust
19
+ module
20
+ . register_subscription (" sub" , " s" , " unsub" , | _ , sink , _ | async move {
21
+ let stream = stream_of_integers ();
22
+
23
+ tokio :: spawn (async move {
24
+ sink . pipe_from_stream (stream )
25
+ });
26
+ })
27
+ . unwrap ();
28
+ ```
29
+
30
+ After this release one must do something like:
31
+
32
+ ``` rust
33
+ // This is just a example helper.
34
+ //
35
+ // Other examples:
36
+ // - <https://github.com/paritytech/jsonrpsee/blob/master/examples/examples/ws_pubsub_broadcast.rs>
37
+ // - <https://github.com/paritytech/jsonrpsee/blob/master/examples/examples/ws_pubsub_with_params.rs>
38
+ async fn pipe_from_stream <T : Serialize >(
39
+ pending : PendingSubscriptionSink ,
40
+ mut stream : impl Stream <Item = T > + Unpin ,
41
+ ) -> Result <(), anyhow :: Error > {
42
+ let mut sink = pending . accept (). await ? ;
43
+
44
+ loop {
45
+ tokio :: select! {
46
+ _ = sink . closed () => break Ok (()),
47
+
48
+ maybe_item = stream . next () => {
49
+ let Some (item ) = match maybe_item else {
50
+ break Ok (()),
51
+ };
52
+
53
+ let msg = SubscriptionMessage :: from_json (& item )? ;
54
+
55
+ if let Err (e ) = sink . send_timeout (msg , Duration :: from_secs (60 )). await {
56
+ match e {
57
+ // The subscription or connection was closed.
58
+ SendTimeoutError :: Closed (_ ) => break Ok (()),
59
+ /// The subscription send timeout expired
60
+ /// the message is returned and you could save that message
61
+ /// and retry again later.
62
+ SendTimeoutError :: Timeout (_ ) => break Err (anyhow :: anyhow! (" Subscription timeout expired" )),
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+
71
+ module
72
+ . register_subscription (" sub" , " s" , " unsub" , | _ , pending , _ | async move {
73
+ let stream = stream ();
74
+ pipe_from_stream (sink , stream ). await
75
+ })
76
+ . unwrap ();
77
+ ```
78
+
79
+ ### Method call return type is more flexible
80
+
81
+ This release also introduces a trait called ` IntoResponse ` which is makes it possible to return custom types and/or error
82
+ types instead of enforcing everything to return ` Result<T, jsonrpsee::core::Error> `
83
+
84
+ This affects the APIs ` RpcModule::register_method ` , ` RpcModule::register_async_method ` and ` RpcModule::register_blocking_method `
85
+ and when these are used in the proc macro API are affected by this change.
86
+ Be aware that [ the client APIs don't support this yet] ( https://github.com/paritytech/jsonrpsee/issues/1067 )
87
+
88
+ The ` IntoResponse ` trait is already implemented for ` Result<T, jsonrpsee::core::Error> ` and for the primitive types
89
+
90
+ Before it was possible to do:
91
+
92
+ ``` rust
93
+ // This would return Result<&str, jsonrpsee::core::Error>
94
+ module . register_method (" say_hello" , | _ , _ | Ok (" lo" ))? ;
95
+ ```
96
+
97
+ After this release it's possible to do:
98
+
99
+ ``` rust
100
+ // Note, this method call is infallible and you might not want to return Result.
101
+ module . register_method (" say_hello" , | _ , _ | " lo" )? ;
102
+ ```
103
+
104
+ ### Subscription API is changed.
105
+
106
+ jsonrpsee now spawns the subscriptions via ` tokio::spawn ` and it's sufficient to provide an async block in ` register_subscription `
107
+
108
+ Further, the subscription API had an explicit close API for closing subscriptions which was hard to understand and
109
+ to get right. This has been removed and everything is handled by the return value/type of the async block instead.
110
+
111
+ Example:
112
+
113
+ ``` rust
114
+ module
115
+ . register_subscription :: <RpcResult <(), _ , _ >:: (" sub" , " s" , " unsub" , | _ , pending , _ | async move {
116
+ // This just answers the RPC call and if this fails => no close notification is sent out.
117
+ pending . accept (). await ? ;
118
+ // This is sent out as a `close notification/message`.
119
+ Err (anyhow :: anyhow! (" The subscription failed" ))? ;
120
+ })
121
+ . unwrap ();
122
+ ```
123
+
124
+ The return value in the example above needs to implement ` IntoSubscriptionCloseResponse ` and
125
+ any value that is returned after that the subscription has been accepted will be treated as a ` IntoSubscriptionCloseResponse ` .
126
+
127
+ Because ` Result<(), E> ` is used here the close notification will be sent out as error notification but it's possible to
128
+ disable the subscription close response by using ` () ` instead of ` Result<(), E> ` or implement ` IntoSubscriptionCloseResponse ` for other behaviour.
129
+
130
+ ### [ Added]
131
+ - feat(server): configurable limit for batch requests. ([ #1073 ] ( https://github.com/paritytech/jsonrpsee/pull/1073 ) )
132
+ - feat(http client): add tower middleware ([ #981 ] ( https://github.com/paritytech/jsonrpsee/pull/981 ) )
133
+
134
+ ### [ Fixed]
135
+ - add tests for ErrorObject ([ #1078 ] ( https://github.com/paritytech/jsonrpsee/pull/1078 ) )
136
+ - fix: tokio v1.27 ([ #1062 ] ( https://github.com/paritytech/jsonrpsee/pull/1062 ) )
137
+ - fix: remove needless ` Semaphore::(u32::MAX) ` ([ #1051 ] ( https://github.com/paritytech/jsonrpsee/pull/1051 ) )
138
+ - fix server: don't send error on JSON-RPC notifications ([ #1021 ] ( https://github.com/paritytech/jsonrpsee/pull/1021 ) )
139
+ - fix: add ` max_log_length ` APIs and use missing configs ([ #956 ] ( https://github.com/paritytech/jsonrpsee/pull/956 ) )
140
+ - fix(rpc module): subscription close bug ([ #1011 ] ( https://github.com/paritytech/jsonrpsee/pull/1011 ) )
141
+ - fix: customized server error codes ([ #1004 ] ( https://github.com/paritytech/jsonrpsee/pull/1004 ) )
142
+
143
+ ### [ Changed]
144
+ - docs: introduce workspace attributes and add keywords ([ #1077 ] ( https://github.com/paritytech/jsonrpsee/pull/1077 ) )
145
+ - refactor(server): downgrade connection log ([ #1076 ] ( https://github.com/paritytech/jsonrpsee/pull/1076 ) )
146
+ - chore(deps): update webpki-roots and tls ([ #1068 ] ( https://github.com/paritytech/jsonrpsee/pull/1068 ) )
147
+ - rpc module: refactor subscriptions to return ` impl IntoSubscriptionResponse ` ([ #1034 ] ( https://github.com/paritytech/jsonrpsee/pull/1034 ) )
148
+ - add ` IntoResponse ` trait for method calls ([ #1057 ] ( https://github.com/paritytech/jsonrpsee/pull/1057 ) )
149
+ - Make ` jsonrpc ` protocol version field in ` Response ` as ` Option ` ([ #1046 ] ( https://github.com/paritytech/jsonrpsee/pull/1046 ) )
150
+ - server: remove dependency http ([ #1037 ] ( https://github.com/paritytech/jsonrpsee/pull/1037 ) )
151
+ - chore(deps): update tower-http requirement from 0.3.4 to 0.4.0 ([ #1033 ] ( https://github.com/paritytech/jsonrpsee/pull/1033 ) )
152
+ - chore(deps): update socket2 requirement from 0.4.7 to 0.5.1 ([ #1032 ] ( https://github.com/paritytech/jsonrpsee/pull/1032 ) )
153
+ - Update bound type name ([ #1029 ] ( https://github.com/paritytech/jsonrpsee/pull/1029 ) )
154
+ - rpc module: remove ` SubscriptionAnswer ` ([ #1025 ] ( https://github.com/paritytech/jsonrpsee/pull/1025 ) )
155
+ - make verify_and_insert pub ([ #1028 ] ( https://github.com/paritytech/jsonrpsee/pull/1028 ) )
156
+ - update MethodKind ([ #1026 ] ( https://github.com/paritytech/jsonrpsee/pull/1026 ) )
157
+ - remove batch response ([ #1020 ] ( https://github.com/paritytech/jsonrpsee/pull/1020 ) )
158
+ - remove debug log ([ #1024 ] ( https://github.com/paritytech/jsonrpsee/pull/1024 ) )
159
+ - client: rename ` max_notifs_per_subscription ` to ` max_buffer_capacity_per_subscription ` ([ #1012 ] ( https://github.com/paritytech/jsonrpsee/pull/1012 ) )
160
+ - client: feature gate tls cert store ([ #994 ] ( https://github.com/paritytech/jsonrpsee/pull/994 ) )
161
+ - server: bounded channels and backpressure ([ #962 ] ( https://github.com/paritytech/jsonrpsee/pull/962 ) )
162
+ - client: use tokio channels ([ #999 ] ( https://github.com/paritytech/jsonrpsee/pull/999 ) )
163
+ - chore: update gloo-net ^0.2.6 ([ #978 ] ( https://github.com/paritytech/jsonrpsee/pull/978 ) )
164
+ - Custom errors ([ #977 ] ( https://github.com/paritytech/jsonrpsee/pull/977 ) )
165
+ - client: distinct APIs to configure max request and response sizes ([ #967 ] ( https://github.com/paritytech/jsonrpsee/pull/967 ) )
166
+ - server: replace ` FutureDriver ` with ` tokio::spawn ` ([ #1080 ] ( https://github.com/paritytech/jsonrpsee/pull/1080 ) )
167
+ - server: uniform whitespace handling in rpc calls ([ #1082 ] ( https://github.com/paritytech/jsonrpsee/pull/1082 ) )
168
+
7
169
## [ v0.16.2] - 2022-12-01
8
170
9
171
This release adds ` Clone ` and ` Copy ` implementations.
@@ -38,7 +200,7 @@ Both HTTP and WebSocket are still enabled by default.
38
200
39
201
v0.16.0 is a breaking release and the major changes are:
40
202
41
- - 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.
203
+ - 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.
42
204
- The client batch request API is improved such as the errors and valid responses can be iterated over.
43
205
- The server has ` tower middleware ` support.
44
206
- The server now adds a tracing span for each connection to distinguish logs per connection.
0 commit comments