mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 11:41:04 +00:00
rpc server: break legacy CLI options and remove "backward compatible HTTP server" (#13384)
* jsonrpsee v0.16 * breaking: remove old CLI configs * remove patch.crates-io * fix bad merge * fix clippy * fix bad merge * fix grumbles * Update client/service/src/lib.rs Co-authored-by: Bastian Köcher <git@kchr.de> * revert block_in_place * add issue link in todo * Update client/cli/src/config.rs Co-authored-by: Dmitry Markin <dmitry@markin.tech> * grumbles: add ipv6 loopback address * Revert "grumbles: add ipv6 loopback address" This reverts commit 3a0b1ece6c4e36055d666896c29d1da55ffa1c4f. * remove nits * bump zombienet version * adress grumbles: provide structopt default_val_t * remove duplicate from structopt * bump zombienet v1.3.47 * bump zombienet version --------- Co-authored-by: Bastian Köcher <git@kchr.de> Co-authored-by: Dmitry Markin <dmitry@markin.tech> Co-authored-by: Javier Viola <javier@parity.io>
This commit is contained in:
@@ -83,34 +83,24 @@ pub struct Configuration {
|
||||
pub wasm_runtime_overrides: Option<PathBuf>,
|
||||
/// Execution strategies.
|
||||
pub execution_strategies: ExecutionStrategies,
|
||||
/// RPC over HTTP binding address. `None` if disabled.
|
||||
pub rpc_http: Option<SocketAddr>,
|
||||
/// RPC over Websockets binding address. `None` if disabled.
|
||||
pub rpc_ws: Option<SocketAddr>,
|
||||
/// RPC over IPC binding path. `None` if disabled.
|
||||
pub rpc_ipc: Option<String>,
|
||||
/// Maximum number of connections for WebSockets RPC server. `None` if default.
|
||||
pub rpc_ws_max_connections: Option<usize>,
|
||||
/// JSON-RPC server binding address.
|
||||
pub rpc_addr: Option<SocketAddr>,
|
||||
/// Maximum number of connections for JSON-RPC server.
|
||||
pub rpc_max_connections: u32,
|
||||
/// CORS settings for HTTP & WS servers. `None` if all origins are allowed.
|
||||
pub rpc_cors: Option<Vec<String>>,
|
||||
/// RPC methods to expose (by default only a safe subset or all of them).
|
||||
pub rpc_methods: RpcMethods,
|
||||
/// Maximum payload of rpc request/responses.
|
||||
pub rpc_max_payload: Option<usize>,
|
||||
/// Maximum payload of a rpc request
|
||||
pub rpc_max_request_size: Option<usize>,
|
||||
/// Maximum payload of a rpc request
|
||||
pub rpc_max_response_size: Option<usize>,
|
||||
pub rpc_max_request_size: u32,
|
||||
/// Maximum payload of a rpc response.
|
||||
pub rpc_max_response_size: u32,
|
||||
/// Custom JSON-RPC subscription ID provider.
|
||||
///
|
||||
/// Default: [`crate::RandomStringSubscriptionId`].
|
||||
pub rpc_id_provider: Option<Box<dyn crate::RpcSubscriptionIdProvider>>,
|
||||
/// Maximum allowed subscriptions per rpc connection
|
||||
///
|
||||
/// Default: 1024.
|
||||
pub rpc_max_subs_per_conn: Option<usize>,
|
||||
/// Maximum size of the output buffer capacity for websocket connections.
|
||||
pub ws_max_out_buffer_capacity: Option<usize>,
|
||||
pub rpc_max_subs_per_conn: u32,
|
||||
/// Prometheus endpoint configuration. `None` if disabled.
|
||||
pub prometheus_config: Option<PrometheusConfig>,
|
||||
/// Telemetry service URL. `None` if disabled.
|
||||
|
||||
@@ -380,57 +380,37 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
let (max_request_size, ws_max_response_size, http_max_response_size) =
|
||||
legacy_cli_parsing(config);
|
||||
|
||||
let random_port = |mut addr: SocketAddr| {
|
||||
// if binding the specified port failed then a random port is assigned by the OS.
|
||||
let backup_port = |mut addr: SocketAddr| {
|
||||
addr.set_port(0);
|
||||
addr
|
||||
};
|
||||
|
||||
let ws_addr = config
|
||||
.rpc_ws
|
||||
.unwrap_or_else(|| "127.0.0.1:9944".parse().expect("valid sockaddr; qed"));
|
||||
let ws_addr2 = random_port(ws_addr);
|
||||
|
||||
let http_addr = config
|
||||
.rpc_http
|
||||
.unwrap_or_else(|| "127.0.0.1:9933".parse().expect("valid sockaddr; qed"));
|
||||
let http_addr2 = random_port(http_addr);
|
||||
|
||||
let addr = config.rpc_addr.unwrap_or(([127, 0, 0, 1], 9944).into());
|
||||
let backup_addr = backup_port(addr);
|
||||
let metrics = sc_rpc_server::RpcMetrics::new(config.prometheus_registry())?;
|
||||
|
||||
let server_config = sc_rpc_server::WsConfig {
|
||||
max_connections: config.rpc_ws_max_connections,
|
||||
max_payload_in_mb: max_request_size,
|
||||
max_payload_out_mb: ws_max_response_size,
|
||||
let server_config = sc_rpc_server::Config {
|
||||
addrs: [addr, backup_addr],
|
||||
max_connections: config.rpc_max_connections,
|
||||
max_payload_in_mb: config.rpc_max_request_size,
|
||||
max_payload_out_mb: config.rpc_max_response_size,
|
||||
max_subs_per_conn: config.rpc_max_subs_per_conn,
|
||||
rpc_api: gen_rpc_module(deny_unsafe(addr, &config.rpc_methods))?,
|
||||
metrics,
|
||||
id_provider: rpc_id_provider,
|
||||
cors: config.rpc_cors.as_ref(),
|
||||
tokio_handle: config.tokio_handle.clone(),
|
||||
};
|
||||
|
||||
let http_fut = sc_rpc_server::start_http(
|
||||
[http_addr, http_addr2],
|
||||
config.rpc_cors.as_ref(),
|
||||
max_request_size,
|
||||
http_max_response_size,
|
||||
metrics.clone(),
|
||||
gen_rpc_module(deny_unsafe(http_addr, &config.rpc_methods))?,
|
||||
config.tokio_handle.clone(),
|
||||
);
|
||||
|
||||
let ws_fut = sc_rpc_server::start(
|
||||
[ws_addr, ws_addr2],
|
||||
config.rpc_cors.as_ref(),
|
||||
server_config.clone(),
|
||||
metrics.clone(),
|
||||
gen_rpc_module(deny_unsafe(ws_addr, &config.rpc_methods))?,
|
||||
config.tokio_handle.clone(),
|
||||
rpc_id_provider,
|
||||
);
|
||||
|
||||
// TODO: https://github.com/paritytech/substrate/issues/13773
|
||||
//
|
||||
// `block_in_place` is a hack to allow callers to call `block_on` prior to
|
||||
// calling `start_rpc_servers`.
|
||||
match tokio::task::block_in_place(|| {
|
||||
config.tokio_handle.block_on(futures::future::try_join(http_fut, ws_fut))
|
||||
config.tokio_handle.block_on(sc_rpc_server::start_server(server_config))
|
||||
}) {
|
||||
Ok((http, ws)) => Ok(Box::new((waiting::Server(Some(http)), waiting::Server(Some(ws))))),
|
||||
Ok(server) => Ok(Box::new(waiting::Server(Some(server)))),
|
||||
Err(e) => Err(Error::Application(e)),
|
||||
}
|
||||
}
|
||||
@@ -534,51 +514,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn legacy_cli_parsing(config: &Configuration) -> (Option<usize>, Option<usize>, Option<usize>) {
|
||||
let ws_max_response_size = match (
|
||||
config.ws_max_out_buffer_capacity,
|
||||
config.rpc_max_response_size,
|
||||
) {
|
||||
(Some(legacy_max), max) => {
|
||||
eprintln!("DEPRECATED: `--ws_max_out_buffer_capacity` has been removed; use `rpc-max-response-size or rpc-max-request-size` instead");
|
||||
eprintln!("Setting WS `rpc-max-response-size` to `max(ws_max_out_buffer_capacity, rpc_max_response_size)`");
|
||||
Some(std::cmp::max(legacy_max, max.unwrap_or(0)))
|
||||
},
|
||||
(None, Some(m)) => Some(m),
|
||||
(None, None) => None,
|
||||
};
|
||||
|
||||
let max_request_size = match (config.rpc_max_payload, config.rpc_max_request_size) {
|
||||
(Some(legacy_max), max) => {
|
||||
eprintln!("DEPRECATED: `--rpc_max_payload` has been removed use `rpc-max-response-size or rpc-max-request-size` instead");
|
||||
eprintln!(
|
||||
"Setting `rpc-max-response-size` to `max(rpc_max_payload, rpc_max_request_size)`"
|
||||
);
|
||||
Some(std::cmp::max(legacy_max, max.unwrap_or(0)))
|
||||
},
|
||||
(None, Some(max)) => Some(max),
|
||||
(None, None) => None,
|
||||
};
|
||||
|
||||
let http_max_response_size = match (config.rpc_max_payload, config.rpc_max_response_size) {
|
||||
(Some(legacy_max), max) => {
|
||||
eprintln!("DEPRECATED: `--rpc_max_payload` has been removed use `rpc-max-response-size or rpc-max-request-size` instead");
|
||||
eprintln!(
|
||||
"Setting HTTP `rpc-max-response-size` to `max(rpc_max_payload, rpc_max_response_size)`"
|
||||
);
|
||||
Some(std::cmp::max(legacy_max, max.unwrap_or(0)))
|
||||
},
|
||||
(None, Some(max)) => Some(max),
|
||||
(None, None) => None,
|
||||
};
|
||||
|
||||
if config.rpc_ipc.is_some() {
|
||||
eprintln!("DEPRECATED: `--ipc-path` has no effect anymore IPC support has been removed");
|
||||
}
|
||||
|
||||
(max_request_size, ws_max_response_size, http_max_response_size)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user