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

Bumped jsonrpsee to v0.22 and added rpc limiter from upstream #14

Merged
merged 1 commit into from
Aug 7, 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
289 changes: 215 additions & 74 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-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 = "0.4.20"
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
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 = "0.4.17"
rand = "0.8"
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
rpc_max_subs_per_conn: Default::default(),
rpc_port: 9944,
rpc_message_buffer_capacity: Default::default(),
rpc_rate_limit: None,
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
rpc_max_subs_per_conn: Default::default(),
rpc_port: 9944,
rpc_message_buffer_capacity: Default::default(),
rpc_rate_limit: None,
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
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
18 changes: 17 additions & 1 deletion substrate/client/cli/src/commands/run_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ use sc_service::{
ChainSpec, Role,
};
use sc_telemetry::TelemetryEndpoints;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
num::NonZeroU32,
};

/// The `run` command used to run a node.
#[derive(Debug, Clone, Parser)]
Expand Down Expand Up @@ -82,6 +85,15 @@ pub struct RunCmd {
)]
pub rpc_methods: RpcMethods,

/// RPC rate limiting (calls/minute) for each connection.
///
/// This is disabled by default.
///
/// For example `--rpc-rate-limit 10` will maximum allow
/// 10 calls per minute per connection.
#[arg(long)]
pub rpc_rate_limit: Option<NonZeroU32>,

/// Set the maximum RPC request payload size for both HTTP and WS in megabytes.
#[arg(long, default_value_t = RPC_DEFAULT_MAX_REQUEST_SIZE_MB)]
pub rpc_max_request_size: u32,
Expand Down Expand Up @@ -399,6 +411,10 @@ impl CliConfiguration for RunCmd {
Ok(self.rpc_max_subscriptions_per_connection)
}

fn rpc_rate_limit(&self) -> Result<Option<NonZeroU32>> {
Ok(self.rpc_rate_limit)
}

fn transaction_pool(&self, is_dev: bool) -> Result<TransactionPoolOptions> {
Ok(self.pool_config.transaction_pool(is_dev))
}
Expand Down
15 changes: 11 additions & 4 deletions substrate/client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use sc_service::{
BlocksPruning, ChainSpec, TracingReceiver,
};
use sc_tracing::logging::LoggerBuilder;
use std::{net::SocketAddr, path::PathBuf};
use std::{net::SocketAddr, num::NonZeroU32, path::PathBuf};

/// The maximum number of characters for a node name.
pub(crate) const NODE_NAME_MAX_LENGTH: usize = 64;
Expand Down Expand Up @@ -338,6 +338,11 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
Ok(RPC_DEFAULT_MESSAGE_CAPACITY_PER_CONN)
}

/// Rate limit calls per minute.
fn rpc_rate_limit(&self) -> Result<Option<NonZeroU32>> {
Ok(None)
}

/// Get the prometheus configuration (`None` if disabled)
///
/// By default this is `None`.
Expand Down Expand Up @@ -510,6 +515,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
rpc_max_subs_per_conn: self.rpc_max_subscriptions_per_connection()?,
rpc_port: DCV::rpc_listen_port(),
rpc_message_buffer_capacity: self.rpc_buffer_capacity_per_connection()?,
rpc_rate_limit: self.rpc_rate_limit()?,
prometheus_config: self
.prometheus_config(DCV::prometheus_listen_port(), &chain_spec)?,
telemetry_endpoints,
Expand Down Expand Up @@ -615,14 +621,15 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
logger.init()?;

match fdlimit::raise_fd_limit() {
Ok(fdlimit::Outcome::LimitRaised { to, .. }) =>
Ok(fdlimit::Outcome::LimitRaised { to, .. }) => {
if to < RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT {
warn!(
"Low open file descriptor limit configured for the process. \
Current value: {:?}, recommended value: {:?}.",
to, RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT,
);
},
}
},
Ok(fdlimit::Outcome::Unsupported) => {
// Unsupported platform (non-Linux)
},
Expand All @@ -648,7 +655,7 @@ pub fn generate_node_name() -> String {
let count = node_name.chars().count();

if count < NODE_NAME_MAX_LENGTH {
return node_name
return node_name;
}
}
}
1 change: 1 addition & 0 deletions substrate/client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ mod tests {
rpc_id_provider: Default::default(),
rpc_max_subs_per_conn: Default::default(),
rpc_message_buffer_capacity: Default::default(),
rpc_rate_limit: None,
rpc_port: 9944,
prometheus_config: None,
telemetry_endpoints: None,
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 = "0.4"
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 = "0.4.8"
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"] }
6 changes: 5 additions & 1 deletion substrate/client/rpc-servers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
jsonrpsee = { version = "0.20.3", features = ["server"] }
jsonrpsee = { version = "0.22", features = ["server"] }
log = "0.4.17"
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"
governor = "0.6.0"
Loading
Loading