Skip to content

Commit

Permalink
rpc server: break legacy CLI options and remove "backward compatible …
Browse files Browse the repository at this point in the history
…HTTP server" (paritytech#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 3a0b1ec.

* 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>
  • Loading branch information
4 people authored and nathanwhit committed Jul 19, 2023
1 parent 070dfa2 commit e02c6a6
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 394 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ variables:

NEXTEST_FAILURE_OUTPUT: immediate-final
NEXTEST_SUCCESS_OUTPUT: final
ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.43"
ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.48"

default:
retry:
Expand Down
16 changes: 6 additions & 10 deletions bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,14 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
offchain_worker: execution_strategy,
other: execution_strategy,
},
rpc_http: None,
rpc_ws: None,
rpc_ipc: None,
rpc_ws_max_connections: None,
rpc_addr: None,
rpc_max_connections: Default::default(),
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,
rpc_max_subs_per_conn: None,
ws_max_out_buffer_capacity: None,
rpc_max_request_size: Default::default(),
rpc_max_response_size: Default::default(),
rpc_id_provider: Default::default(),
rpc_max_subs_per_conn: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
16 changes: 6 additions & 10 deletions bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,14 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
offchain_worker: sc_client_api::ExecutionStrategy::NativeWhenPossible,
other: sc_client_api::ExecutionStrategy::NativeWhenPossible,
},
rpc_http: None,
rpc_ws: None,
rpc_ipc: None,
rpc_ws_max_connections: None,
rpc_addr: None,
rpc_max_connections: Default::default(),
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,
rpc_max_subs_per_conn: None,
ws_max_out_buffer_capacity: None,
rpc_max_request_size: Default::default(),
rpc_max_response_size: Default::default(),
rpc_id_provider: Default::default(),
rpc_max_subs_per_conn: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
98 changes: 21 additions & 77 deletions client/cli/src/commands/run_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct RunCmd {
/// RPC methods to expose.
/// - `unsafe`: Exposes every RPC method.
/// - `safe`: Exposes only a safe subset of RPC methods, denying unsafe RPC methods.
/// - `auto`: Acts as `safe` if RPC is served externally, e.g. when `--{rpc,ws}-external` is
/// - `auto`: Acts as `safe` if RPC is served externally, e.g. when `--rpc--external` is
/// passed, otherwise acts as `unsafe`.
#[arg(
long,
Expand All @@ -77,58 +77,25 @@ pub struct RunCmd {
)]
pub rpc_methods: RpcMethods,

/// Listen to all Websocket interfaces.
/// Default is local. Note: not all RPC methods are safe to be exposed publicly. Use an RPC
/// proxy server to filter out dangerous methods. More details:
/// <https://docs.substrate.io/main-docs/build/custom-rpc/#public-rpcs>.
/// Use `--unsafe-ws-external` to suppress the warning if you understand the risks.
#[arg(long)]
pub ws_external: bool,

/// Listen to all Websocket interfaces.
/// Same as `--ws-external` but doesn't warn you about it.
#[arg(long)]
pub unsafe_ws_external: bool,

/// DEPRECATED, this has no affect anymore. Use `rpc_max_request_size` or
/// `rpc_max_response_size` instead.
#[arg(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.
#[arg(long)]
pub rpc_max_request_size: Option<usize>,
#[arg(long, default_value_t = 15)]
pub rpc_max_request_size: u32,

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

/// Set the the maximum concurrent subscriptions per connection.
/// Default is 1024.
#[arg(long)]
pub rpc_max_subscriptions_per_connection: Option<usize>,
#[arg(long, default_value_t = 1024)]
pub rpc_max_subscriptions_per_connection: u32,

/// DEPRECATED, IPC support has been removed.
#[arg(long, value_name = "PATH")]
pub ipc_path: Option<String>,
/// Specify JSON-RPC server TCP port.
#[arg(long, value_name = "PORT", default_value_t = 9944)]
pub rpc_port: u16,

/// Specify HTTP RPC server TCP port.
#[arg(long, value_name = "PORT")]
pub rpc_port: Option<u16>,

/// Specify WebSockets RPC server TCP port.
#[arg(long, value_name = "PORT")]
pub ws_port: Option<u16>,

/// Maximum number of WS RPC server connections.
#[arg(long, value_name = "COUNT")]
pub ws_max_connections: Option<usize>,

/// DEPRECATED, this has no affect anymore. Use `rpc_max_response_size` instead.
#[arg(long)]
pub ws_max_out_buffer_capacity: Option<usize>,
/// Maximum number of RPC server connections.
#[arg(long, value_name = "COUNT", default_value_t = 100)]
pub rpc_max_connections: u32,

/// Specify browser Origins allowed to access the HTTP & WS RPC servers.
/// A comma-separated list of origins (protocol://domain or special `null`
Expand Down Expand Up @@ -344,8 +311,8 @@ impl CliConfiguration for RunCmd {
Ok(self.no_grandpa)
}

fn rpc_ws_max_connections(&self) -> Result<Option<usize>> {
Ok(self.ws_max_connections)
fn rpc_max_connections(&self) -> Result<u32> {
Ok(self.rpc_max_connections)
}

fn rpc_cors(&self, is_dev: bool) -> Result<Option<Vec<String>>> {
Expand All @@ -369,56 +336,33 @@ impl CliConfiguration for RunCmd {
.into())
}

fn rpc_http(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {
fn rpc_addr(&self, _default_listen_port: u16) -> Result<Option<SocketAddr>> {
let interface = rpc_interface(
self.rpc_external,
self.unsafe_rpc_external,
self.rpc_methods,
self.validator,
)?;

Ok(Some(SocketAddr::new(interface, self.rpc_port.unwrap_or(default_listen_port))))
}

fn rpc_ipc(&self) -> Result<Option<String>> {
Ok(self.ipc_path.clone())
}

fn rpc_ws(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {
let interface = rpc_interface(
self.ws_external,
self.unsafe_ws_external,
self.rpc_methods,
self.validator,
)?;

Ok(Some(SocketAddr::new(interface, self.ws_port.unwrap_or(default_listen_port))))
Ok(Some(SocketAddr::new(interface, self.rpc_port)))
}

fn rpc_methods(&self) -> Result<sc_service::config::RpcMethods> {
Ok(self.rpc_methods.into())
}

fn rpc_max_payload(&self) -> Result<Option<usize>> {
Ok(self.rpc_max_payload)
}

fn rpc_max_request_size(&self) -> Result<Option<usize>> {
fn rpc_max_request_size(&self) -> Result<u32> {
Ok(self.rpc_max_request_size)
}

fn rpc_max_response_size(&self) -> Result<Option<usize>> {
fn rpc_max_response_size(&self) -> Result<u32> {
Ok(self.rpc_max_response_size)
}

fn rpc_max_subscriptions_per_connection(&self) -> Result<Option<usize>> {
fn rpc_max_subscriptions_per_connection(&self) -> Result<u32> {
Ok(self.rpc_max_subscriptions_per_connection)
}

fn ws_max_out_buffer_capacity(&self) -> Result<Option<usize>> {
Ok(self.ws_max_out_buffer_capacity)
}

fn transaction_pool(&self, is_dev: bool) -> Result<TransactionPoolOptions> {
Ok(self.pool_config.transaction_pool(is_dev))
}
Expand Down Expand Up @@ -475,7 +419,7 @@ fn rpc_interface(
) -> Result<IpAddr> {
if is_external && is_validator && rpc_methods != RpcMethods::Unsafe {
return Err(Error::Input(
"--rpc-external and --ws-external options shouldn't be used if the node is running as \
"--rpc-external option shouldn't be used if the node is running as \
a validator. Use `--unsafe-rpc-external` or `--rpc-methods=unsafe` if you understand \
the risks. See the options description for more information."
.to_owned(),
Expand Down
69 changes: 15 additions & 54 deletions client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,13 @@ pub trait DefaultConfigurationValues {
30333
}

/// The port Substrate should listen on for websocket connections.
/// The port Substrate should listen on for JSON-RPC connections.
///
/// By default this is `9944`.
fn rpc_ws_listen_port() -> u16 {
fn rpc_listen_port() -> u16 {
9944
}

/// The port Substrate should listen on for http connections.
///
/// By default this is `9933`.
fn rpc_http_listen_port() -> u16 {
9933
}

/// The port Substrate should listen on for prometheus connections.
///
/// By default this is `9615`.
Expand Down Expand Up @@ -302,24 +295,8 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
.unwrap_or_default())
}

/// Get the RPC HTTP address (`None` if disabled).
///
/// By default this is `None`.
fn rpc_http(&self, _default_listen_port: u16) -> Result<Option<SocketAddr>> {
Ok(None)
}

/// Get the RPC IPC path (`None` if disabled).
///
/// By default this is `None`.
fn rpc_ipc(&self) -> Result<Option<String>> {
Ok(None)
}

/// Get the RPC websocket address (`None` if disabled).
///
/// By default this is `None`.
fn rpc_ws(&self, _default_listen_port: u16) -> Result<Option<SocketAddr>> {
/// Get the RPC address.
fn rpc_addr(&self, _default_listen_port: u16) -> Result<Option<SocketAddr>> {
Ok(None)
}

Expand All @@ -331,11 +308,9 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
Ok(Default::default())
}

/// Get the RPC websockets maximum connections (`None` if unlimited).
///
/// By default this is `None`.
fn rpc_ws_max_connections(&self) -> Result<Option<usize>> {
Ok(None)
/// Get the maximum number of RPC server connections.
fn rpc_max_connections(&self) -> Result<u32> {
Ok(Default::default())
}

/// Get the RPC cors (`None` if disabled)
Expand All @@ -345,29 +320,19 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
Ok(Some(Vec::new()))
}

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

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

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

/// Get maximum number of subscriptions per connection.
fn rpc_max_subscriptions_per_connection(&self) -> Result<Option<usize>> {
Ok(None)
}

/// Get maximum WS output buffer capacity.
fn ws_max_out_buffer_capacity(&self) -> Result<Option<usize>> {
Ok(None)
fn rpc_max_subscriptions_per_connection(&self) -> Result<u32> {
Ok(Default::default())
}

/// Get the prometheus configuration (`None` if disabled)
Expand Down Expand Up @@ -532,18 +497,14 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
wasm_method: self.wasm_method()?,
wasm_runtime_overrides: self.wasm_runtime_overrides(),
execution_strategies: self.execution_strategies(is_dev, is_validator)?,
rpc_http: self.rpc_http(DCV::rpc_http_listen_port())?,
rpc_ws: self.rpc_ws(DCV::rpc_ws_listen_port())?,
rpc_ipc: self.rpc_ipc()?,
rpc_addr: self.rpc_addr(DCV::rpc_listen_port())?,
rpc_methods: self.rpc_methods()?,
rpc_ws_max_connections: self.rpc_ws_max_connections()?,
rpc_max_connections: self.rpc_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,
rpc_max_subs_per_conn: self.rpc_max_subscriptions_per_connection()?,
ws_max_out_buffer_capacity: self.ws_max_out_buffer_capacity()?,
prometheus_config: self
.prometheus_config(DCV::prometheus_listen_port(), &chain_spec)?,
telemetry_endpoints,
Expand Down
16 changes: 6 additions & 10 deletions client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,14 @@ mod tests {
wasm_method: Default::default(),
wasm_runtime_overrides: None,
execution_strategies: Default::default(),
rpc_http: None,
rpc_ws: None,
rpc_ipc: None,
rpc_ws_max_connections: None,
rpc_addr: None,
rpc_max_connections: Default::default(),
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,
rpc_max_subs_per_conn: None,
ws_max_out_buffer_capacity: None,
rpc_max_request_size: Default::default(),
rpc_max_response_size: Default::default(),
rpc_id_provider: Default::default(),
rpc_max_subs_per_conn: Default::default(),
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down

0 comments on commit e02c6a6

Please sign in to comment.