Skip to content

Commit

Permalink
jsonrpsee v0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 committed Sep 28, 2023
1 parent fa4c672 commit 59a74ad
Show file tree
Hide file tree
Showing 106 changed files with 1,221 additions and 1,065 deletions.
236 changes: 140 additions & 96 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,6 @@ wasmi = { opt-level = 3 }
x25519-dalek = { opt-level = 3 }
yamux = { opt-level = 3 }
zeroize = { opt-level = 3 }

[patch.crates-io]
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee", branch = "na-debug-branch" }
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 @@ -17,5 +17,5 @@ sc-client-api = { path = "../../../substrate/client/api" }
futures = "0.3.28"
async-trait = "0.1.73"
thiserror = "1.0.48"
jsonrpsee-core = "0.16.2"
jsonrpsee-core = "0.20.1"
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 @@ -28,7 +28,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.16.2", features = ["ws-client"] }
jsonrpsee = { version = "0.20", features = ["ws-client"] }
tracing = "0.1.37"
async-trait = "0.1.73"
url = "2.4.0"
Expand Down
16 changes: 10 additions & 6 deletions cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,16 @@ impl RelayChainRpcClient {
))
})?;

let value = rx.await.map_err(|err| {
RelayChainError::WorkerCommunicationError(format!(
"Unexpected channel close on RPC worker side: {}",
err
))
})??;
// TODO(niklasad1): fix this.
let value = rx
.await
.map_err(|err| {
RelayChainError::WorkerCommunicationError(format!(
"Unexpected channel close on RPC worker side: {}",
err
))
})?
.unwrap();

serde_json::from_value(value).map_err(|_| {
trace_error(&RelayChainError::GenericError("Unable to deserialize value".to_string()));
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 @@ -15,7 +15,7 @@ clap = { version = "4.4.4", features = ["derive"] }
log = "0.4.20"
codec = { package = "parity-scale-codec", version = "3.0.0" }
serde = { version = "1.0.188", features = ["derive"] }
jsonrpsee = { version = "0.16.2", features = ["server"] }
jsonrpsee = { version = "0.20", features = ["server"] }
futures = "0.3.28"

# Local
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 @@ -34,7 +34,7 @@ bridge-hub-rococo-runtime = { path = "../parachains/runtimes/bridge-hubs/bridge-
bridge-hub-kusama-runtime = { path = "../parachains/runtimes/bridge-hubs/bridge-hub-kusama" }
bridge-hub-polkadot-runtime = { path = "../parachains/runtimes/bridge-hubs/bridge-hub-polkadot" }
penpal-runtime = { path = "../parachains/runtimes/testing/penpal" }
jsonrpsee = { version = "0.16.2", features = ["server"] }
jsonrpsee = { version = "0.20", features = ["server"] }
parachains-common = { path = "../parachains/common" }

# Substrate
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 @@ -14,7 +14,7 @@ async-trait = "0.1.73"
clap = { version = "4.4.4", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0.0" }
criterion = { version = "0.5.1", features = [ "async_tokio" ] }
jsonrpsee = { version = "0.16.2", features = ["server"] }
jsonrpsee = { version = "0.20", features = ["server"] }
rand = "0.8.5"
serde = { version = "1.0.188", features = ["derive"] }
tokio = { version = "1.32.0", features = ["macros"] }
Expand Down
1 change: 1 addition & 0 deletions cumulus/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ pub fn node_config(
rpc_id_provider: None,
rpc_max_subs_per_conn: Default::default(),
rpc_port: 9945,
rpc_message_buffer_capacity: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
1 change: 1 addition & 0 deletions polkadot/node/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub fn node_config(
rpc_id_provider: None,
rpc_max_subs_per_conn: Default::default(),
rpc_port: 9944,
rpc_message_buffer_capacity: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
2 changes: 1 addition & 1 deletion polkadot/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true
license.workspace = true

[dependencies]
jsonrpsee = { version = "0.16.2", features = ["server"] }
jsonrpsee = { version = "0.20", 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/node-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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.16.2", features = ["server"] }
jsonrpsee = { version = "0.20", 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 @@ -41,7 +41,7 @@ array-bytes = "6.1"
clap = { version = "4.4.4", features = ["derive"], optional = true }
codec = { package = "parity-scale-codec", version = "3.6.1" }
serde = { version = "1.0.188", features = ["derive"] }
jsonrpsee = { version = "0.16.2", features = ["server"] }
jsonrpsee = { version = "0.20", 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 @@ -82,6 +82,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
rpc_id_provider: Default::default(),
rpc_max_subs_per_conn: Default::default(),
rpc_port: 9944,
rpc_message_buffer_capacity: Default::default(),
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 @@ -78,6 +78,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
rpc_id_provider: Default::default(),
rpc_max_subs_per_conn: Default::default(),
rpc_port: 9944,
rpc_message_buffer_capacity: Default::default(),
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 @@ -13,7 +13,7 @@ publish = false
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
jsonrpsee = { version = "0.16.2", features = ["server"] }
jsonrpsee = { version = "0.20", 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
13 changes: 12 additions & 1 deletion substrate/client/cli/src/commands/run_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
},
CliConfiguration, PrometheusParams, RuntimeParams, TelemetryParams,
RPC_DEFAULT_MAX_CONNECTIONS, RPC_DEFAULT_MAX_REQUEST_SIZE_MB, RPC_DEFAULT_MAX_RESPONSE_SIZE_MB,
RPC_DEFAULT_MAX_SUBS_PER_CONN,
RPC_DEFAULT_MAX_SUBS_PER_CONN, RPC_DEFAULT_MESSAGE_CAPACITY_PER_CONN,
};
use clap::Parser;
use regex::Regex;
Expand Down Expand Up @@ -99,6 +99,17 @@ pub struct RunCmd {
#[arg(long, value_name = "COUNT", default_value_t = RPC_DEFAULT_MAX_CONNECTIONS)]
pub rpc_max_connections: u32,

/// The number of messages the RPC server is allowed to keep in memory.
///
/// If the buffer becomes full then the server will not process
/// new messages until the connected client start reading the
/// underlying messages.
///
/// This applies per connection which includes both
/// JSON-RPC methods calls and subscriptions.
#[arg(long, default_value_t = RPC_DEFAULT_MESSAGE_CAPACITY_PER_CONN)]
pub rpc_message_buffer_capacity_per_connection: u32,

/// Specify browser Origins allowed to access the HTTP & WS RPC servers.
/// A comma-separated list of origins (protocol://domain or special `null`
/// value). Value of `all` will disable origin validation. Default is to
Expand Down
13 changes: 12 additions & 1 deletion substrate/client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ pub const RPC_DEFAULT_MAX_SUBS_PER_CONN: u32 = 1024;
pub const RPC_DEFAULT_MAX_REQUEST_SIZE_MB: u32 = 15;
/// The default max response size in MB.
pub const RPC_DEFAULT_MAX_RESPONSE_SIZE_MB: u32 = 15;
/// The default number of connection..
/// The default concurrent connection limit.
pub const RPC_DEFAULT_MAX_CONNECTIONS: u32 = 100;
/// The default number of messages the RPC server
/// is allowed to keep in memory per connection.
pub const RPC_DEFAULT_MESSAGE_CAPACITY_PER_CONN: u32 = 64;

/// Default configuration values used by Substrate
///
Expand Down Expand Up @@ -330,6 +333,11 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
Ok(RPC_DEFAULT_MAX_SUBS_PER_CONN)
}

/// The number of messages the RPC server is allowed to keep in memory per connection.
fn rpc_buffer_capacity_per_connection(&self) -> Result<u32> {
Ok(RPC_DEFAULT_MESSAGE_CAPACITY_PER_CONN)
}

/// Get the prometheus configuration (`None` if disabled)
///
/// By default this is `None`.
Expand Down Expand Up @@ -440,6 +448,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
&self,
cli: &C,
tokio_handle: tokio::runtime::Handle,
rpc_tokio_handle: tokio::runtime::Handle,
) -> Result<Configuration> {
let is_dev = self.is_dev()?;
let chain_id = self.chain_id(is_dev)?;
Expand Down Expand Up @@ -473,6 +482,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
impl_name: C::impl_name(),
impl_version: C::impl_version(),
tokio_handle,
rpc_tokio_handle,
transaction_pool: self.transaction_pool(is_dev)?,
network: self.network_config(
&chain_spec,
Expand Down Expand Up @@ -501,6 +511,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
rpc_id_provider: None,
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()?,
prometheus_config: self
.prometheus_config(DCV::prometheus_listen_port(), &chain_spec)?,
telemetry_endpoints,
Expand Down
27 changes: 22 additions & 5 deletions substrate/client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ pub trait SubstrateCli: Sized {
&self,
command: &T,
tokio_handle: tokio::runtime::Handle,
rpc_tokio_runtime: tokio::runtime::Handle,
) -> error::Result<Configuration> {
command.create_configuration(self, tokio_handle)
command.create_configuration(self, tokio_handle, rpc_tokio_runtime)
}

/// Create a runner for the command provided in argument. This will create a Configuration and
Expand All @@ -201,15 +202,23 @@ pub trait SubstrateCli: Sized {
command: &T,
) -> error::Result<Runner<Self>> {
let tokio_runtime = build_runtime()?;
let rpc_tokio_runtime = tokio::runtime::Builder::new_multi_thread()
.thread_name("rpc server")
.enable_all()
.build()?;

// `capture` needs to be called in a tokio context.
// Also capture them as early as possible.
let signals = tokio_runtime.block_on(async { Signals::capture() })?;

let config = command.create_configuration(self, tokio_runtime.handle().clone())?;
let config = command.create_configuration(
self,
tokio_runtime.handle().clone(),
rpc_tokio_runtime.handle().clone(),
)?;

command.init(&Self::support_url(), &Self::impl_version(), |_, _| {}, &config)?;
Runner::new(config, tokio_runtime, signals)
Runner::new(config, tokio_runtime, signals, rpc_tokio_runtime)
}

/// Create a runner for the command provided in argument. The `logger_hook` can be used to setup
Expand Down Expand Up @@ -240,14 +249,22 @@ pub trait SubstrateCli: Sized {
F: FnOnce(&mut LoggerBuilder, &Configuration),
{
let tokio_runtime = build_runtime()?;
let rpc_tokio_runtime = tokio::runtime::Builder::new_multi_thread()
.thread_name("rpc server")
.enable_all()
.build()?;

// `capture` needs to be called in a tokio context.
// Also capture them as early as possible.
let signals = tokio_runtime.block_on(async { Signals::capture() })?;

let config = command.create_configuration(self, tokio_runtime.handle().clone())?;
let config = command.create_configuration(
self,
tokio_runtime.handle().clone(),
rpc_tokio_runtime.handle().clone(),
)?;

command.init(&Self::support_url(), &Self::impl_version(), logger_hook, &config)?;
Runner::new(config, tokio_runtime, signals)
Runner::new(config, tokio_runtime, signals, rpc_tokio_runtime)
}
}
11 changes: 10 additions & 1 deletion substrate/client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct Runner<C: SubstrateCli> {
tokio_runtime: tokio::runtime::Runtime,
signals: Signals,
phantom: PhantomData<C>,
_rpc_tokio_runtime: tokio::runtime::Runtime,
}

impl<C: SubstrateCli> Runner<C> {
Expand All @@ -52,8 +53,15 @@ impl<C: SubstrateCli> Runner<C> {
config: Configuration,
tokio_runtime: tokio::runtime::Runtime,
signals: Signals,
rpc_tokio_runtime: tokio::runtime::Runtime,
) -> Result<Runner<C>> {
Ok(Runner { config, tokio_runtime, signals, phantom: PhantomData })
Ok(Runner {
config,
tokio_runtime,
signals,
phantom: PhantomData,
_rpc_tokio_runtime: rpc_tokio_runtime,
})
}

/// Log information about the node itself.
Expand Down Expand Up @@ -274,6 +282,7 @@ mod tests {
rpc_id_provider: Default::default(),
rpc_max_subs_per_conn: Default::default(),
rpc_port: 9944,
rpc_message_buffer_capacity: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: 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 @@ -13,7 +13,7 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
jsonrpsee = { version = "0.16.2", features = ["client-core", "server", "macros"] }
jsonrpsee = { version = "0.20", features = ["client-core", "server", "macros"] }
futures = "0.3.21"
serde = { version = "1.0.188", features = ["derive"] }
thiserror = "1.0"
Expand Down
Loading

0 comments on commit 59a74ad

Please sign in to comment.