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

rpc: bump jsonrpsee v0.22 and fix race in rpc v2 chain_head #3230

Merged
merged 30 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3f7e94b
jsonrpsee v0.22
niklasad1 Feb 6, 2024
250f109
fix race in chainhead
niklasad1 Feb 6, 2024
8bc7fd7
fix some nits
niklasad1 Feb 6, 2024
b0769b7
fix bad Cargo.toml fmt
niklasad1 Feb 6, 2024
3d16db8
make test compile
niklasad1 Feb 6, 2024
a7032d9
fix tests
niklasad1 Feb 7, 2024
be5052a
jsonrpsee v0.22
niklasad1 Feb 7, 2024
6326b34
fix more nits
niklasad1 Feb 7, 2024
dc856ac
Merge remote-tracking branch 'origin/master' into na-bump-jsonrpsee-v…
niklasad1 Feb 7, 2024
6d088e1
Update cumulus/client/relay-chain-interface/Cargo.toml
niklasad1 Feb 7, 2024
b77a992
update Cargo.lock
niklasad1 Feb 7, 2024
4802cc4
fix rustdocs
niklasad1 Feb 7, 2024
485393f
remove needless box
niklasad1 Feb 8, 2024
bdc42f6
address grumbles
niklasad1 Feb 8, 2024
8bf3636
Update substrate/client/rpc-servers/src/lib.rs
niklasad1 Feb 8, 2024
3a78c54
clarify breaking ws pings
niklasad1 Feb 8, 2024
118480d
fix nits
niklasad1 Feb 8, 2024
104dc2d
Merge remote-tracking branch 'origin/master' into na-bump-jsonrpsee-v…
niklasad1 Feb 9, 2024
91437e9
Merge remote-tracking branch 'origin/master' into na-bump-jsonrpsee-v…
niklasad1 Feb 14, 2024
6d96bd6
add prdoc
niklasad1 Feb 14, 2024
467f11b
improve prdoc
niklasad1 Feb 14, 2024
8a9e5c7
fix prdoc
niklasad1 Feb 14, 2024
1ad6d28
fix bad merge
niklasad1 Feb 14, 2024
1a61781
Update prdoc/pr_3230.prdoc
niklasad1 Feb 14, 2024
5936168
Update prdoc/pr_3230.prdoc
niklasad1 Feb 14, 2024
70b98a2
Update prdoc/pr_3230.prdoc
niklasad1 Feb 14, 2024
18b636e
improve subscription drop log
niklasad1 Feb 14, 2024
25a5320
Merge remote-tracking branch 'origin/na-bump-jsonrpsee-v0.22' into na…
niklasad1 Feb 14, 2024
5f892f2
Merge branch 'master' into na-bump-jsonrpsee-v0.22
niklasad1 Feb 14, 2024
0cbd07a
fix merge nits
niklasad1 Feb 14, 2024
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
270 changes: 186 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cumulus/client/relay-chain-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ sc-client-api = { path = "../../../substrate/client/api" }
futures = "0.3.28"
async-trait = "0.1.74"
thiserror = "1.0.48"
jsonrpsee-core = "0.20.3"
jsonrpsee-core = "0.22"
parity-scale-codec = "3.6.4"
2 changes: 1 addition & 1 deletion cumulus/client/relay-chain-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sc_client_api::StorageProof;
use futures::Stream;

use async_trait::async_trait;
use jsonrpsee_core::Error as JsonRpcError;
use jsonrpsee_core::ClientError as JsonRpcError;
use parity_scale_codec::Error as CodecError;
use sp_api::ApiError;

Expand Down
2 changes: 1 addition & 1 deletion cumulus/client/relay-chain-rpc-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tokio-util = { version = "0.7.8", features = ["compat"] }
futures = "0.3.28"
futures-timer = "3.0.2"
parity-scale-codec = "3.6.4"
jsonrpsee = { version = "0.20.3", features = ["ws-client"] }
jsonrpsee = { version = "0.22", features = ["ws-client"] }
tracing = "0.1.37"
async-trait = "0.1.74"
url = "2.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
//! we treat the light-client as a normal JsonRPC target.

use futures::{channel::mpsc::Sender, prelude::*, stream::FuturesUnordered};
use jsonrpsee::core::{
client::{
Client as JsonRpseeClient, ClientBuilder, ClientT, ReceivedMessage, TransportReceiverT,
TransportSenderT,
},
Error,
use jsonrpsee::core::client::{
Client as JsonRpseeClient, ClientBuilder, ClientT, Error, ReceivedMessage, TransportReceiverT,
TransportSenderT,
};
use smoldot_light::{ChainId, Client as SmoldotClient, JsonRpcResponses};
use std::{num::NonZeroU32, sync::Arc};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use jsonrpsee::{
core::{
client::{Client as JsonRpcClient, ClientT, Subscription},
params::ArrayParams,
Error as JsonRpseeError, JsonValue,
ClientError as JsonRpseeError, JsonValue,
},
ws_client::WsClientBuilder,
};
Expand Down
2 changes: 1 addition & 1 deletion cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use futures::channel::{
oneshot::Sender as OneshotSender,
};
use jsonrpsee::{
core::{params::ArrayParams, Error as JsonRpseeError},
core::{params::ArrayParams, ClientError as JsonRpseeError},
rpc_params,
};
use serde::de::DeserializeOwned;
Expand Down
2 changes: 1 addition & 1 deletion cumulus/parachain-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ clap = { version = "4.4.18", features = ["derive"] }
log = { workspace = true, default-features = true }
codec = { package = "parity-scale-codec", version = "3.0.0" }
serde = { version = "1.0.195", features = ["derive"] }
jsonrpsee = { version = "0.20.3", features = ["server"] }
jsonrpsee = { version = "0.22", features = ["server"] }
futures = "0.3.28"
serde_json = "1.0.111"

Expand Down
2 changes: 1 addition & 1 deletion cumulus/polkadot-parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ coretime-rococo-runtime = { path = "../parachains/runtimes/coretime/coretime-roc
coretime-westend-runtime = { path = "../parachains/runtimes/coretime/coretime-westend" }
bridge-hub-westend-runtime = { path = "../parachains/runtimes/bridge-hubs/bridge-hub-westend" }
penpal-runtime = { path = "../parachains/runtimes/testing/penpal" }
jsonrpsee = { version = "0.20.3", features = ["server"] }
jsonrpsee = { version = "0.22", features = ["server"] }
people-rococo-runtime = { path = "../parachains/runtimes/people/people-rococo" }
people-westend-runtime = { path = "../parachains/runtimes/people/people-westend" }
parachains-common = { path = "../parachains/common" }
Expand Down
2 changes: 1 addition & 1 deletion cumulus/test/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async-trait = "0.1.74"
clap = { version = "4.4.18", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0.0" }
criterion = { version = "0.5.1", features = ["async_tokio"] }
jsonrpsee = { version = "0.20.3", features = ["server"] }
jsonrpsee = { version = "0.22", features = ["server"] }
rand = "0.8.5"
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.111"
Expand Down
2 changes: 1 addition & 1 deletion polkadot/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "Polkadot specific RPC functionality."
workspace = true

[dependencies]
jsonrpsee = { version = "0.20.3", features = ["server"] }
jsonrpsee = { version = "0.22", features = ["server"] }
polkadot-primitives = { path = "../primitives" }
sc-client-api = { path = "../../substrate/client/api" }
sp-blockchain = { path = "../../substrate/primitives/blockchain" }
Expand Down
19 changes: 19 additions & 0 deletions prdoc/pr_3230.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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 server remove prometheus metrics `substrate_rpc_requests_started/finished` and refactor WS ping/pongs.

doc:
- audience: Node Operator
description: |
This PR updates the rpc server library to `jsonrpsee v0.22` to utilize new APIs.

Breaking changes:
- Remove prometheus RPC metrics `substrate_rpc_requests_started` and `substrate_rpc_requests_finished`.
- The RPC server now disconnects inactive peers that didn't acknowledge WebSocket
pings more than three times in time.

Added:
- Add prometheus RPC `substrate_rpc_sessions_time` to collect the duration for each WebSocket
session.
crates: [ ]
2 changes: 1 addition & 1 deletion substrate/bin/minimal/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ name = "minimal-node"
clap = { version = "4.4.18", features = ["derive"] }
futures = { version = "0.3.21", features = ["thread-pool"] }
futures-timer = "3.0.1"
jsonrpsee = { version = "0.20.3", features = ["server"] }
jsonrpsee = { version = "0.22", features = ["server"] }
serde_json = "1.0.111"

sc-cli = { path = "../../../client/cli" }
Expand Down
2 changes: 1 addition & 1 deletion substrate/bin/node-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ frame-system = { path = "../../../frame/system" }
pallet-transaction-payment = { path = "../../../frame/transaction-payment", default-features = false }

# These dependencies are used for the node template's RPCs
jsonrpsee = { version = "0.20.3", features = ["server"] }
jsonrpsee = { version = "0.22", features = ["server"] }
sp-api = { path = "../../../primitives/api" }
sc-rpc-api = { path = "../../../client/rpc-api" }
sp-blockchain = { path = "../../../primitives/blockchain" }
Expand Down
2 changes: 1 addition & 1 deletion substrate/bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ array-bytes = "6.1"
clap = { version = "4.4.18", features = ["derive"], optional = true }
codec = { package = "parity-scale-codec", version = "3.6.1" }
serde = { version = "1.0.195", features = ["derive"] }
jsonrpsee = { version = "0.20.3", features = ["server"] }
jsonrpsee = { version = "0.22", features = ["server"] }
futures = "0.3.21"
log = { workspace = true, default-features = true }
rand = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion substrate/bin/node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
jsonrpsee = { version = "0.20.3", features = ["server"] }
jsonrpsee = { version = "0.22", features = ["server"] }
node-primitives = { path = "../primitives" }
pallet-transaction-payment-rpc = { path = "../../../frame/transaction-payment/rpc" }
mmr-rpc = { path = "../../../client/merkle-mountain-range/rpc" }
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/consensus/babe/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
jsonrpsee = { version = "0.20.3", features = ["client-core", "macros", "server"] }
jsonrpsee = { version = "0.22", features = ["client-core", "macros", "server"] }
futures = "0.3.21"
serde = { version = "1.0.195", features = ["derive"] }
thiserror = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/consensus/babe/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ mod tests {
let (response, _) = api.raw_json_request(request, 1).await.unwrap();
let expected = r#"{"jsonrpc":"2.0","result":{"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY":{"primary":[0],"secondary":[1,2,4],"secondary_vrf":[]}},"id":1}"#;

assert_eq!(&response.result, expected);
assert_eq!(response, expected);
}

#[tokio::test]
Expand All @@ -272,6 +272,6 @@ mod tests {
let (response, _) = api.raw_json_request(request, 1).await.unwrap();
let expected = r#"{"jsonrpc":"2.0","error":{"code":-32601,"message":"RPC call is unsafe to be called externally"},"id":1}"#;

assert_eq!(&response.result, expected);
assert_eq!(response, expected);
}
}
2 changes: 1 addition & 1 deletion substrate/client/consensus/beefy/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ workspace = true
[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", features = ["derive"] }
futures = "0.3.21"
jsonrpsee = { version = "0.20.3", features = ["client-core", "macros", "server"] }
jsonrpsee = { version = "0.22", features = ["client-core", "macros", "server"] }
log = { workspace = true, default-features = true }
parking_lot = "0.12.1"
serde = { version = "1.0.195", features = ["derive"] }
Expand Down
16 changes: 7 additions & 9 deletions substrate/client/consensus/beefy/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ mod tests {
async fn uninitialized_rpc_handler() {
let (rpc, _) = setup_io_handler();
let request = r#"{"jsonrpc":"2.0","method":"beefy_getFinalizedHead","params":[],"id":1}"#;
let expected_response = r#"{"jsonrpc":"2.0","error":{"code":1,"message":"BEEFY RPC endpoint not ready"},"id":1}"#.to_string();
let expected_response = r#"{"jsonrpc":"2.0","error":{"code":1,"message":"BEEFY RPC endpoint not ready"},"id":1}"#;
let (response, _) = rpc.raw_json_request(&request, 1).await.unwrap();

assert_eq!(expected_response, response.result);
assert_eq!(expected_response, response);
}

#[tokio::test]
Expand All @@ -205,20 +205,18 @@ mod tests {
\"jsonrpc\":\"2.0\",\
\"result\":\"0x2f0039e93a27221fcf657fb877a1d4f60307106113e885096cb44a461cd0afbf\",\
\"id\":1\
}"
.to_string();
}";
let not_ready = "{\
\"jsonrpc\":\"2.0\",\
\"error\":{\"code\":1,\"message\":\"BEEFY RPC endpoint not ready\"},\
\"id\":1\
}"
.to_string();
}";

let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2);
while std::time::Instant::now() < deadline {
let (response, _) = io.raw_json_request(request, 1).await.expect("RPC requests work");
if response.result != not_ready {
assert_eq!(response.result, expected);
if response != not_ready {
assert_eq!(response, expected);
// Success
return
}
Expand Down Expand Up @@ -249,7 +247,7 @@ mod tests {
.unwrap();
let expected = r#"{"jsonrpc":"2.0","result":false,"id":1}"#;

assert_eq!(response.result, expected);
assert_eq!(response, expected);
}

fn create_finality_proof() -> BeefyVersionedFinalityProof<Block> {
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/consensus/grandpa/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ workspace = true
[dependencies]
finality-grandpa = { version = "0.16.2", features = ["derive-codec"] }
futures = "0.3.16"
jsonrpsee = { version = "0.20.3", features = ["client-core", "macros", "server"] }
jsonrpsee = { version = "0.22", features = ["client-core", "macros", "server"] }
log = { workspace = true, default-features = true }
parity-scale-codec = { version = "3.6.1", features = ["derive"] }
serde = { version = "1.0.195", features = ["derive"] }
Expand Down
6 changes: 3 additions & 3 deletions substrate/client/consensus/grandpa/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ mod tests {
let request = r#"{"jsonrpc":"2.0","method":"grandpa_roundState","params":[],"id":0}"#;
let (response, _) = rpc.raw_json_request(&request, 1).await.unwrap();

assert_eq!(expected_response, response.result);
assert_eq!(expected_response, response);
}

#[tokio::test]
Expand All @@ -295,7 +295,7 @@ mod tests {

let request = r#"{"jsonrpc":"2.0","method":"grandpa_roundState","params":[],"id":0}"#;
let (response, _) = rpc.raw_json_request(&request, 1).await.unwrap();
assert_eq!(expected_response, response.result);
assert_eq!(expected_response, response);
}

#[tokio::test]
Expand All @@ -317,7 +317,7 @@ mod tests {
.unwrap();
let expected = r#"{"jsonrpc":"2.0","result":false,"id":1}"#;

assert_eq!(response.result, expected);
assert_eq!(response, expected);
}

fn create_justification() -> GrandpaJustification<Block> {
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/consensus/manual-seal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
jsonrpsee = { version = "0.20.3", features = ["client-core", "macros", "server"] }
jsonrpsee = { version = "0.22", features = ["client-core", "macros", "server"] }
assert_matches = "1.3.0"
async-trait = "0.1.74"
codec = { package = "parity-scale-codec", version = "3.6.1" }
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/merkle-mountain-range/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1" }
jsonrpsee = { version = "0.20.3", features = ["client-core", "macros", "server"] }
jsonrpsee = { version = "0.22", features = ["client-core", "macros", "server"] }
serde = { version = "1.0.195", features = ["derive"] }
sp-api = { path = "../../../primitives/api" }
sp-blockchain = { path = "../../../primitives/blockchain" }
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/rpc-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ sp-core = { path = "../../primitives/core" }
sp-rpc = { path = "../../primitives/rpc" }
sp-runtime = { path = "../../primitives/runtime" }
sp-version = { path = "../../primitives/version" }
jsonrpsee = { version = "0.20.3", features = ["client-core", "macros", "server"] }
jsonrpsee = { version = "0.22", features = ["client-core", "macros", "server"] }
5 changes: 4 additions & 1 deletion substrate/client/rpc-servers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
jsonrpsee = { version = "0.20.3", features = ["server"] }
jsonrpsee = { version = "0.22", features = ["server"] }
log = { workspace = true, default-features = true }
serde_json = "1.0.111"
tokio = { version = "1.22.0", features = ["parking_lot"] }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus" }
tower-http = { version = "0.4.0", features = ["cors"] }
tower = { version = "0.4.13", features = ["util"] }
http = "0.2.8"
hyper = "0.14.27"
futures = "0.3.29"
pin-project = "1.1.3"
Loading
Loading