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

Close #2992 

Breaking changes:
- rpc server grafana metric `substrate_rpc_requests_started` is removed
(not possible to implement anymore)
- rpc server grafana metric `substrate_rpc_requests_finished` is removed
(not possible to implement anymore)
- rpc server ws ping/pong not ACK:ed within 30 seconds more than three
times then the connection will be closed

Added
- rpc server grafana metric `substrate_rpc_sessions_time` is added to
get the duration for each websocket session
This commit is contained in:
Niklas Adolfsson
2024-02-14 23:18:22 +01:00
committed by GitHub
parent 7e7c488ba8
commit c7c4fe0184
53 changed files with 777 additions and 468 deletions
@@ -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"
@@ -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]
@@ -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);
}
}
@@ -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"] }
@@ -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]
@@ -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
}
@@ -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> {
@@ -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"] }
@@ -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]
@@ -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]
@@ -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> {
@@ -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" }