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

[JSON-RPC] - Upgrade jsonrpsee to v0.16.1 #6387

Merged
merged 6 commits into from
Nov 30, 2022
Merged

Conversation

patrickkuo
Copy link
Contributor

@patrickkuo patrickkuo commented Nov 26, 2022

  • removed WsServerBuilder and all websocket server code, jsonrpsee now support http and ws on the same server.

@patrickkuo patrickkuo force-pushed the pat/jsonrpsee_upgrade branch from b4da44d to c97d723 Compare November 27, 2022 09:35
@patrickkuo patrickkuo marked this pull request as ready for review November 28, 2022 13:51
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
let handle = Handle::current();
let _ = handle.enter();
let mut v = futures::executor::block_on(self.inner.lock());
Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot use another executor inside of a tokio runtime. This can lead to deadlocking. The way that tower services are supposed to work is that you have an owned service, not a wrapper around a shared one with Mutexes

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally services end up being clone-able and they're just cloned to handle concurrent requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly jsonrpsee's TowerService is not clone-able :( , I will fix this upstream

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR created upstream, paritytech/jsonrpsee#950

I am using a forked version instead until next jsonrpsee release


#[derive(Debug, Clone)]
pub struct JsonRpcMetricService<S> {
inner: Arc<Mutex<S>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should just be

Suggested change
inner: Arc<Mutex<S>>,
inner: S,

0.001, 0.005, 0.01, 0.05, 0.1, 0.25, 0.5, 1., 2.5, 5., 10., 20., 30., 60., 90.,
];

impl<S> JsonRpcMetricService<S> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this layer actually used anywhere, am i just missing where its used?

Copy link
Contributor Author

@patrickkuo patrickkuo Nov 29, 2022

Choose a reason for hiding this comment

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

This is the service used by the MetricsLayer, MetricsLayer is added to the middleware

removed WsServerBuilder and all websocket server code, jsonrpsee now support http and ws on the same server.
@patrickkuo patrickkuo force-pushed the pat/jsonrpsee_upgrade branch from dc4e800 to c532b64 Compare November 29, 2022 09:30
}
}

fn is_json(content_type: Option<&hyper::header::HeaderValue>) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks fragile. Is it too expensive to convert to lower case and check contains?

self.inner.poll_ready(cx).map_err(Into::into)
}

fn call(&mut self, req: Request<Body>) -> Self::Future {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this layer called before or after request deserialization? If it's before, it'd be helpful to record deser errors separately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the layer wraps the inner call, we can add logic before or after the actual jsonrpsee service call

let fut = inner.call(req);
let res = fut.await.map_err(|err| err.into())?;

This PR only upgrade the existing code to use new version of jsonrpsee, I can add deser errors in next PR.

Co-authored-by: Lu Zhang <8418040+longbowlu@users.noreply.github.com>
@patrickkuo patrickkuo merged commit 78cfd9b into main Nov 30, 2022
@patrickkuo patrickkuo deleted the pat/jsonrpsee_upgrade branch November 30, 2022 13:44
Jibz1 pushed a commit that referenced this pull request Dec 7, 2022
* upgrade jsonrpsee
removed WsServerBuilder and all websocket server code, jsonrpsee now support http and ws on the same server.

* regen hakari

* remove ws config from test and swarm

* fixup after rebase

* make service clonable instead of using mutex

* Update crates/test-utils/src/network.rs

Co-authored-by: Lu Zhang <8418040+longbowlu@users.noreply.github.com>

Co-authored-by: Lu Zhang <8418040+longbowlu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants