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

Update jsonrpsee to v0.21 #707

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
137 changes: 88 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ serde_json = { version = "1.0.79", default-features = false }
url = { version = "2.0.0", optional = true }

# websocket dependent features
jsonrpsee = { version = "0.16", optional = true, features = ["async-client", "client-ws-transport", "jsonrpsee-types"] }
jsonrpsee = { version = "0.21", optional = true, features = ["async-client", "client-ws-transport-native-tls", "jsonrpsee-types"] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is less on this PR but a general question: It seems wrong to me, that we explicitly reference the different websocket libraries here. This does mean, that I have to include tungstenite, even when I'm using the api client with jsonrpsee. Is this correct?

On the specific code here: What if I want to use the api client with jsonrpsee, but without the native-tls feature? As far as I understand, there's no reason to not allow this. But it seems to be prevented by this.

Copy link
Contributor Author

@haerdib haerdib Feb 12, 2024

Choose a reason for hiding this comment

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

This does mean, that I have to include tungstenite, even when I'm using the api client with jsonrpsee. Is this correct?

No, that is not correct. The dependency imports of the rpc-clients are optional and only included if the correspondent feature is chosen.

What if I want to use the api client with jsonrpsee, but without the native-tls feature? As far as I understand, there's no reason to not allow this. But it seems to be prevented by this.

Do you have something in mind? We could forward the features of the jsonrpsee client, but that would mean more features on our side, I believe… or is there a way around it?
Or we could allow that the user constructs his/her own jsonrpsee client and just wraps our wrapper struct around it: https://github.com/scs/substrate-api-client/blob/master/src/rpc/jsonrpsee_client/mod.rs#L30-L33:

// Something like this:
let jsonrpsee_client = ClientBuilder::default()
		.max_buffer_capacity_per_subscription(4096)
		.build_with_tokio(tx, rx);
let api_client = JsonrpseeClient { inner: Arc::new(client) };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I'm not sure if my first approach would work as long as we are constructing our own jsonrpsee-client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After discussion, see the proposal #714

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks!

tungstenite = { version = "0.21", optional = true, features = ["native-tls"] }
ws = { version = "0.9.2", optional = true, features = ["ssl"] }

Expand Down
14 changes: 6 additions & 8 deletions src/rpc/jsonrpsee_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use crate::rpc::{Error, Request, Result, RpcParams, Subscribe};
use jsonrpsee::{
client_transport::ws::{Uri, WsTransportClientBuilder},
client_transport::ws::{Url, WsTransportClientBuilder},
core::{
client::{Client, ClientBuilder, ClientT, SubscriptionClientT},
traits::ToRpcParams,
Expand All @@ -38,13 +38,13 @@ impl JsonrpseeClient {
}

pub async fn new(url: &str) -> Result<Self> {
let uri: Uri = url.parse().map_err(|e| Error::Client(Box::new(e)))?;
let parsed_url: Url = url.parse().map_err(|e| Error::Client(Box::new(e)))?;
let (tx, rx) = WsTransportClientBuilder::default()
.build(uri)
.build(parsed_url)
.await
.map_err(|e| Error::Client(Box::new(e)))?;
let client = ClientBuilder::default()
.max_notifs_per_subscription(4096)
.max_buffer_capacity_per_subscription(4096)
.build_with_tokio(tx, rx);
Ok(Self { inner: Arc::new(client) })
}
Expand Down Expand Up @@ -81,11 +81,9 @@ impl Subscribe for JsonrpseeClient {
struct RpcParamsWrapper(RpcParams);

impl ToRpcParams for RpcParamsWrapper {
fn to_rpc_params(self) -> core::result::Result<Option<Box<RawValue>>, jsonrpsee::core::Error> {
fn to_rpc_params(self) -> core::result::Result<Option<Box<RawValue>>, serde_json::Error> {
if let Some(json) = self.0.build() {
RawValue::from_string(json)
.map(Some)
.map_err(jsonrpsee::core::Error::ParseError)
RawValue::from_string(json).map(Some)
} else {
Ok(None)
}
Expand Down
Loading