Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 25 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,7 @@ inherits = "release"
lto = "fat"
# https://doc.rust-lang.org/rustc/codegen-options/index.html#codegen-units
codegen-units = 1

[patch.crates-io]
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee" }

2 changes: 2 additions & 0 deletions bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
rpc_cors: None,
rpc_methods: Default::default(),
rpc_max_payload: None,
rpc_max_request_size: None,
rpc_max_response_size: None,
rpc_id_provider: None,
ws_max_out_buffer_capacity: None,
prometheus_config: None,
Expand Down
2 changes: 2 additions & 0 deletions bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
rpc_cors: None,
rpc_methods: Default::default(),
rpc_max_payload: None,
rpc_max_request_size: None,
rpc_max_response_size: None,
rpc_id_provider: None,
ws_max_out_buffer_capacity: None,
prometheus_config: None,
Expand Down
21 changes: 17 additions & 4 deletions client/cli/src/commands/run_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,28 @@ pub struct RunCmd {
#[clap(long)]
pub unsafe_ws_external: bool,

/// Set the the maximum RPC payload size for both requests and responses (both http and ws), in
/// megabytes. Default is 15MiB.
/// DEPERECATED, this has no affect anymore. Use `rpc_max_request_size` or

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// DEPERECATED, this has no affect anymore. Use `rpc_max_request_size` or
/// DEPRECATED, this has no affect anymore. Use `rpc_max_request_size` or

Is there automation in place to show this message to end users?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no unfortunately not what I'm aware of.

/// `rpc_max_response_size` instead.
#[clap(long)]
pub rpc_max_payload: Option<usize>,

/// Set the the maximum RPC request payload size for both HTTP and WS in megabytes.
/// Default is 15MiB.
#[clap(long)]
pub rpc_max_request_size: Option<usize>,

/// Set the the maximum RPC response payload size for both HTTP and WS in megabytes.
/// Default is 15MiB.
#[clap(long)]
pub rpc_max_response_size: Option<usize>,

/// Expose Prometheus exporter on all interfaces.
///
/// Default is local.
#[clap(long)]
pub prometheus_external: bool,

/// Specify IPC RPC server path
/// DEPERECATED, IPC support has been removed.
Comment thread
niklasad1 marked this conversation as resolved.
Outdated
#[clap(long, value_name = "PATH")]
pub ipc_path: Option<String>,

Expand All @@ -127,7 +137,7 @@ pub struct RunCmd {
#[clap(long, value_name = "COUNT")]
pub ws_max_connections: Option<usize>,

/// Set the the maximum WebSocket output buffer size in MiB. Default is 16.
/// DEPERECATED, this has no affect anymore. Use `rpc_max_response_size` instead.
Comment thread
niklasad1 marked this conversation as resolved.
Outdated
#[clap(long)]
pub ws_max_out_buffer_capacity: Option<usize>,

Expand Down Expand Up @@ -427,6 +437,7 @@ impl CliConfiguration for RunCmd {
}

fn rpc_ipc(&self) -> Result<Option<String>> {
eprintln!("DEPRECATED `--ipc-path` has no effect anymore IPC support has been removed");
Ok(self.ipc_path.clone())
}

Expand All @@ -446,10 +457,12 @@ impl CliConfiguration for RunCmd {
}

fn rpc_max_payload(&self) -> Result<Option<usize>> {
eprintln!("DEPRECATED `--rpc_max_payload` has been removed use `rpc-max-request-size` or `rpc-max-response-size` instead");
Ok(self.rpc_max_payload)
}

fn ws_max_out_buffer_capacity(&self) -> Result<Option<usize>> {
eprintln!("DEPRECATED `--ws_max_out_buffer_capacity` has no effect anymore, use `rpc-max-response-size` instead");
Ok(self.ws_max_out_buffer_capacity)
}

Expand Down
12 changes: 12 additions & 0 deletions client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
Ok(None)
}

/// Get maximum RPC request payload size.
fn rpc_max_request_size(&self) -> Result<Option<usize>> {
Ok(None)
}

/// Get maximum RPC response payload size.
fn rpc_max_response_size(&self) -> Result<Option<usize>> {
Ok(None)
}

/// Get maximum WS output buffer capacity.
fn ws_max_out_buffer_capacity(&self) -> Result<Option<usize>> {
Ok(None)
Expand Down Expand Up @@ -528,6 +538,8 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
rpc_ws_max_connections: self.rpc_ws_max_connections()?,
rpc_cors: self.rpc_cors(is_dev)?,
rpc_max_payload: self.rpc_max_payload()?,
rpc_max_request_size: self.rpc_max_request_size()?,
rpc_max_response_size: self.rpc_max_response_size()?,
rpc_id_provider: None,
ws_max_out_buffer_capacity: self.ws_max_out_buffer_capacity()?,
prometheus_config: self
Expand Down
2 changes: 1 addition & 1 deletion client/rpc-api/src/author/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub trait AuthorApi<Hash, BlockHash> {
/// transaction life cycle.
#[subscription(
name = "submitAndWatchExtrinsic" => "extrinsicUpdate",
unsubscribe_aliases = ["author_unwatchExtrinsic"],
unsubscribe = "author_unwatchExtrinsic",
item = TransactionStatus<Hash, BlockHash>,
)]
fn watch_extrinsic(&self, bytes: Bytes) -> RpcResult<()>;
Expand Down
31 changes: 19 additions & 12 deletions client/rpc-servers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ pub type WsServer = WsServerHandle;
pub fn start_http<M: Send + Sync + 'static>(
addrs: &[SocketAddr],
cors: Option<&Vec<String>>,
max_payload_mb: Option<usize>,
max_payload_in_mb: Option<usize>,
max_payload_out_mb: Option<usize>,
metrics: Option<RpcMetrics>,
rpc_api: RpcModule<M>,
rt: tokio::runtime::Handle,
) -> Result<HttpServerHandle, anyhow::Error> {
let max_request_body_size = max_payload_mb
.map(|mb| mb.saturating_mul(MEGABYTE))
.unwrap_or(RPC_MAX_PAYLOAD_DEFAULT);
let max_payload_in = payload_size_or_default(max_payload_in_mb);
let max_payload_out = payload_size_or_default(max_payload_out_mb);

let mut acl = AccessControlBuilder::new();

Expand All @@ -71,18 +71,19 @@ pub fn start_http<M: Send + Sync + 'static>(
};

let builder = HttpServerBuilder::new()
.max_request_body_size(max_request_body_size as u32)
.max_request_body_size(max_payload_in as u32)
.max_response_body_size(max_payload_out as u32)
.set_access_control(acl.build())
.custom_tokio_runtime(rt.clone());

let rpc_api = build_rpc_api(rpc_api);
let handle = if let Some(metrics) = metrics {
let middleware = RpcMiddleware::new(metrics, "http".into());
let builder = builder.set_middleware(middleware);
let server = tokio::task::block_in_place(|| rt.block_on(async { builder.build(addrs) }))?;
let server = tokio::task::block_in_place(|| rt.block_on(builder.build(addrs)))?;
server.start(rpc_api)?
} else {
let server = tokio::task::block_in_place(|| rt.block_on(async { builder.build(addrs) }))?;
let server = tokio::task::block_in_place(|| rt.block_on(builder.build(addrs)))?;
server.start(rpc_api)?
};

Expand All @@ -95,19 +96,21 @@ pub fn start_ws<M: Send + Sync + 'static>(
addrs: &[SocketAddr],
max_connections: Option<usize>,
cors: Option<&Vec<String>>,
max_payload_mb: Option<usize>,
max_payload_in_mb: Option<usize>,
max_payload_out_mb: Option<usize>,
metrics: Option<RpcMetrics>,
rpc_api: RpcModule<M>,
rt: tokio::runtime::Handle,
id_provider: Option<Box<dyn IdProvider>>,
) -> Result<WsServerHandle, anyhow::Error> {
let max_request_body_size = max_payload_mb
.map(|mb| mb.saturating_mul(MEGABYTE))
.unwrap_or(RPC_MAX_PAYLOAD_DEFAULT);
let max_payload_in = payload_size_or_default(max_payload_in_mb);
let max_payload_out = payload_size_or_default(max_payload_out_mb);

let max_connections = max_connections.unwrap_or(WS_MAX_CONNECTIONS);

let mut builder = WsServerBuilder::new()
.max_request_body_size(max_request_body_size as u32)
.max_request_body_size(max_payload_in as u32)
.max_response_body_size(max_payload_out as u32)
.max_connections(max_connections as u64)
.custom_tokio_runtime(rt.clone());

Expand Down Expand Up @@ -163,3 +166,7 @@ fn build_rpc_api<M: Send + Sync + 'static>(mut rpc_api: RpcModule<M>) -> RpcModu

rpc_api
}

fn payload_size_or_default(size_mb: Option<usize>) -> usize {
size_mb.map_or(RPC_MAX_PAYLOAD_DEFAULT, |mb| mb.saturating_mul(MEGABYTE))
}
6 changes: 3 additions & 3 deletions client/rpc/src/author/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use jsonrpsee::{
error::{SubscriptionClosed, SubscriptionClosedReason},
Error as RpcError,
},
types::EmptyParams,
types::{error::CallError, EmptyParams},
RpcModule,
};
use sc_transaction_pool::{BasicPool, FullChainApi};
Expand Down Expand Up @@ -107,7 +107,7 @@ async fn author_submit_transaction_should_not_cause_error() {

assert_matches!(
api.call::<_, H256>("author_submitExtrinsic", [xt]).await,
Err(RpcError::Request(e)) if e.contains("Already imported")
Err(RpcError::Call(CallError::Custom { message, ..})) if message.contains("Already imported")
);
}

Expand Down Expand Up @@ -287,7 +287,7 @@ async fn author_has_session_keys() {

assert_matches!(
api.call::<_, bool>("author_hasSessionKeys", vec![Bytes::from(vec![1, 2, 3])]).await,
Err(RpcError::Request(e)) if e.contains("Session keys are not encoded correctly")
Err(RpcError::Call(CallError::Custom { message, ..})) if message.as_str() == "Session keys are not encoded correctly"
);
}

Expand Down
4 changes: 2 additions & 2 deletions client/rpc/src/dev/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use super::*;
use assert_matches::assert_matches;
use jsonrpsee::core::Error as JsonRpseeError;
use jsonrpsee::{core::Error as JsonRpseeError, types::error::CallError};
use sc_block_builder::BlockBuilderProvider;
use sp_blockchain::HeaderBackend;
use sp_consensus::BlockOrigin;
Expand Down Expand Up @@ -64,6 +64,6 @@ async fn deny_unsafe_works() {
assert_matches!(
api.call::<_, Option<BlockStats>>("dev_getBlockStats", [client.info().best_hash])
.await,
Err(JsonRpseeError::Request(e)) if e.to_string().contains("RPC call is unsafe to be called externally")
Err(JsonRpseeError::Call(CallError::Custom { message, .. })) if message.as_str() == "RPC call is unsafe to be called externally"
);
}
Loading