-
Notifications
You must be signed in to change notification settings - Fork 767
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
rpc: upgrade jsonrpsee v0.23 #4730
Merged
Merged
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
12c57c9
rpc: upgrade jsonrpsee v0.23
niklasad1 0aadd3d
Merge remote-tracking branch 'origin/master' into na-jsonrpsee-v0.23
niklasad1 15691d6
cleanup
niklasad1 f681f0e
make it compile
niklasad1 bd74645
fix test build
niklasad1 88a7c00
Merge remote-tracking branch 'origin/master' into na-jsonrpsee-v0.23
niklasad1 369db7e
jsonrpsee v0.23.1
niklasad1 fa8cda3
Merge remote-tracking branch 'origin/master' into na-jsonrpsee-v0.23
niklasad1 a2418a2
remove needless deps
niklasad1 489a598
Merge branch 'master' into na-jsonrpsee-v0.23
niklasad1 f3df0da
fix bad merge
niklasad1 0b0cabe
add prdoc
niklasad1 0237951
bridges: add `serde_json` dependency
niklasad1 0f90c4e
fix prdoc
niklasad1 3115029
fix prdoc again
niklasad1 d969257
Merge remote-tracking branch 'origin/master' into na-jsonrpsee-v0.23
niklasad1 f61b3ce
Update substrate/client/rpc-spec-v2/src/transaction/transaction_broad…
niklasad1 e3f02ce
Update substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs
niklasad1 45667bc
Update substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs
niklasad1 919065c
Update substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs
niklasad1 30dc44a
Update substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs
niklasad1 b83f1f9
Update substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs
niklasad1 fc80004
Update substrate/client/rpc-spec-v2/src/transaction/transaction_broad…
niklasad1 526ff76
Update substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs
niklasad1 cc99e40
Update substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs
niklasad1 2c8349a
Merge branch 'master' into na-jsonrpsee-v0.23
niklasad1 3002cd1
Merge remote-tracking branch 'origin/master' into na-jsonrpsee-v0.23
niklasad1 1ec6466
fix bad merge
niklasad1 2d310ff
fix taplo fmt
niklasad1 b63698c
move more deps to workspace
niklasad1 48d3d70
Merge remote-tracking branch 'origin/master' into na-jsonrpsee-v0.23
niklasad1 f9081de
jsonrpsee v0.23.2
niklasad1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
||
title: rpc upgrade jsonrpsee to v0.23.1 | ||
|
||
doc: | ||
- audience: Node Dev | ||
description: | | ||
Upgrade the rpc library jsonrpsee to v0.23.1 to utilize: | ||
|
||
- Add Extensions which we now is using to get the connection id (used by the rpc spec v2) | ||
- Update hyper to v1.0, http v1.0, soketto and related crates (hyper::service::make_service_fn is removed) | ||
- The subscription API for the client is modified to know why a subscription was closed. | ||
|
||
crates: | ||
- name: sc-rpc-spec-v2 | ||
bump: patch | ||
- name: sc-rpc | ||
bump: patch | ||
- name: sc-rpc-server | ||
bump: patch | ||
- name: cumulus-relay-chain-rpc-interface | ||
bump: patch | ||
- name: frame-remote-externalities | ||
bump: patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,16 +23,13 @@ | |
pub mod middleware; | ||
pub mod utils; | ||
|
||
use std::{ | ||
convert::Infallible, error::Error as StdError, net::SocketAddr, num::NonZeroU32, time::Duration, | ||
}; | ||
use std::{error::Error as StdError, net::SocketAddr, num::NonZeroU32, sync::Arc, time::Duration}; | ||
|
||
use hyper::{ | ||
server::conn::AddrStream, | ||
service::{make_service_fn, service_fn}, | ||
}; | ||
use jsonrpsee::{ | ||
server::{stop_channel, ws, PingConfig, StopHandle, TowerServiceBuilder}, | ||
core::BoxError, | ||
server::{ | ||
serve_with_graceful_shutdown, stop_channel, ws, PingConfig, StopHandle, TowerServiceBuilder, | ||
}, | ||
Methods, RpcModule, | ||
}; | ||
use middleware::NodeHealthProxyLayer; | ||
|
@@ -97,6 +94,7 @@ struct PerConnection<RpcMiddleware, HttpMiddleware> { | |
metrics: Option<RpcMetrics>, | ||
tokio_handle: tokio::runtime::Handle, | ||
service_builder: TowerServiceBuilder<RpcMiddleware, HttpMiddleware>, | ||
rate_limit_whitelisted_ips: Arc<Vec<IpNetwork>>, | ||
} | ||
|
||
/// Start RPC server listening on given address. | ||
|
@@ -124,8 +122,8 @@ where | |
rate_limit_trust_proxy_headers, | ||
} = config; | ||
|
||
let std_listener = TcpListener::bind(addrs.as_slice()).await?.into_std()?; | ||
let local_addr = std_listener.local_addr().ok(); | ||
let listener = TcpListener::bind(addrs.as_slice()).await?; | ||
let local_addr = listener.local_addr().ok(); | ||
let host_filter = host_filtering(cors.is_some(), local_addr); | ||
|
||
let http_middleware = tower::ServiceBuilder::new() | ||
|
@@ -161,20 +159,38 @@ where | |
methods: build_rpc_api(rpc_api).into(), | ||
service_builder: builder.to_service_builder(), | ||
metrics, | ||
tokio_handle, | ||
stop_handle: stop_handle.clone(), | ||
tokio_handle: tokio_handle.clone(), | ||
stop_handle, | ||
rate_limit_whitelisted_ips: Arc::new(rate_limit_whitelisted_ips), | ||
}; | ||
|
||
let make_service = make_service_fn(move |addr: &AddrStream| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hyper::service::make_service_fn is removed and we need to manage to socket ourselves. Using to low-level API should easy to add support for ipv6 sockets but I'll fix it another PR. |
||
let cfg = cfg.clone(); | ||
let rate_limit_whitelisted_ips = rate_limit_whitelisted_ips.clone(); | ||
let ip = addr.remote_addr().ip(); | ||
|
||
async move { | ||
let cfg = cfg.clone(); | ||
let rate_limit_whitelisted_ips = rate_limit_whitelisted_ips.clone(); | ||
tokio_handle.spawn(async move { | ||
loop { | ||
let (sock, remote_addr) = tokio::select! { | ||
res = listener.accept() => { | ||
match res { | ||
Ok(s) => s, | ||
Err(e) => { | ||
log::debug!(target: "rpc", "Failed to accept ipv4 connection: {:?}", e); | ||
continue; | ||
} | ||
} | ||
} | ||
_ = cfg.stop_handle.clone().shutdown() => break, | ||
}; | ||
|
||
let ip = remote_addr.ip(); | ||
let cfg2 = cfg.clone(); | ||
let svc = tower::service_fn(move |req: http::Request<hyper::body::Incoming>| { | ||
let PerConnection { | ||
methods, | ||
service_builder, | ||
metrics, | ||
tokio_handle, | ||
stop_handle, | ||
rate_limit_whitelisted_ips, | ||
} = cfg2.clone(); | ||
|
||
Ok::<_, Infallible>(service_fn(move |req| { | ||
let proxy_ip = | ||
if rate_limit_trust_proxy_headers { get_proxy_ip(&req) } else { None }; | ||
|
||
|
@@ -191,9 +207,6 @@ where | |
rate_limit | ||
}; | ||
|
||
let PerConnection { service_builder, metrics, tokio_handle, stop_handle, methods } = | ||
cfg.clone(); | ||
|
||
let is_websocket = ws::is_upgrade_request(&req); | ||
let transport_label = if is_websocket { "ws" } else { "http" }; | ||
|
||
|
@@ -213,7 +226,6 @@ where | |
|
||
let rpc_middleware = | ||
RpcServiceBuilder::new().option_layer(middleware_layer.clone()); | ||
|
||
let mut svc = | ||
service_builder.set_rpc_middleware(rpc_middleware).build(methods, stop_handle); | ||
|
||
|
@@ -230,17 +242,19 @@ where | |
}); | ||
} | ||
|
||
svc.call(req).await | ||
// https://github.com/rust-lang/rust/issues/102211 the error type can't be inferred | ||
// to be `Box<dyn std::error::Error + Send + Sync>` so we need to convert it to | ||
// a concrete type as workaround. | ||
svc.call(req).await.map_err(|e| BoxError::from(e)) | ||
} | ||
})) | ||
} | ||
}); | ||
|
||
let server = hyper::Server::from_tcp(std_listener)?.serve(make_service); | ||
}); | ||
|
||
tokio::spawn(async move { | ||
let graceful = server.with_graceful_shutdown(async move { stop_handle.shutdown().await }); | ||
let _ = graceful.await; | ||
cfg.tokio_handle.spawn(serve_with_graceful_shutdown( | ||
sock, | ||
svc, | ||
cfg.stop_handle.clone().shutdown(), | ||
)); | ||
} | ||
}); | ||
|
||
log::info!( | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//cc @skunert
This is slightly modified and only decoding can cause this error now.
Since this API was confusing before i.e, the subscription could be closed because it lagged (i.e, couldn't keep with server) or just closed.
We have added another API https://docs.rs/jsonrpsee-core/0.23.1/jsonrpsee_core/client/struct.Subscription.html#method.close_reason but not sure whether you care here....