Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

fix cli: make rpc port Option<u16> again #14088

Merged
merged 1 commit into from
May 7, 2023
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
1 change: 1 addition & 0 deletions bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
rpc_max_response_size: Default::default(),
rpc_id_provider: Default::default(),
rpc_max_subs_per_conn: Default::default(),
rpc_port: 9944,
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
1 change: 1 addition & 0 deletions bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
rpc_max_response_size: Default::default(),
rpc_id_provider: Default::default(),
rpc_max_subs_per_conn: Default::default(),
rpc_port: 9944,
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
18 changes: 10 additions & 8 deletions client/cli/src/commands/run_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use crate::{
TransactionPoolParams,
},
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,
};
use clap::Parser;
use regex::Regex;
Expand Down Expand Up @@ -78,23 +80,23 @@ pub struct RunCmd {
pub rpc_methods: RpcMethods,

/// Set the the maximum RPC request payload size for both HTTP and WS in megabytes.
#[arg(long, default_value_t = 15)]
#[arg(long, default_value_t = RPC_DEFAULT_MAX_REQUEST_SIZE_MB)]
pub rpc_max_request_size: u32,

/// Set the the maximum RPC response payload size for both HTTP and WS in megabytes.
#[arg(long, default_value_t = 15)]
#[arg(long, default_value_t = RPC_DEFAULT_MAX_RESPONSE_SIZE_MB)]
pub rpc_max_response_size: u32,

/// Set the the maximum concurrent subscriptions per connection.
#[arg(long, default_value_t = 1024)]
#[arg(long, default_value_t = RPC_DEFAULT_MAX_SUBS_PER_CONN)]
pub rpc_max_subscriptions_per_connection: u32,

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

/// Maximum number of RPC server connections.
#[arg(long, value_name = "COUNT", default_value_t = 100)]
#[arg(long, value_name = "COUNT", default_value_t = RPC_DEFAULT_MAX_CONNECTIONS)]
pub rpc_max_connections: u32,

/// Specify browser Origins allowed to access the HTTP & WS RPC servers.
Expand Down Expand Up @@ -336,15 +338,15 @@ impl CliConfiguration for RunCmd {
.into())
}

fn rpc_addr(&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)))
Ok(Some(SocketAddr::new(interface, self.rpc_port.unwrap_or(default_listen_port))))
}

fn rpc_methods(&self) -> Result<sc_service::config::RpcMethods> {
Expand Down
24 changes: 18 additions & 6 deletions client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ pub(crate) const DEFAULT_NETWORK_CONFIG_PATH: &str = "network";
/// The recommended open file descriptor limit to be configured for the process.
const RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT: u64 = 10_000;

/// The default port.
pub const RPC_DEFAULT_PORT: u16 = 9944;
/// The default max number of subscriptions per connection.
pub const RPC_DEFAULT_MAX_SUBS_PER_CONN: u32 = 1024;
/// The default max request size in MB.
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..
pub const RPC_DEFAULT_MAX_CONNECTIONS: u32 = 100;

/// Default configuration values used by Substrate
///
/// These values will be used by [`CliConfiguration`] to set
Expand All @@ -61,7 +72,7 @@ pub trait DefaultConfigurationValues {
///
/// By default this is `9944`.
fn rpc_listen_port() -> u16 {
9944
RPC_DEFAULT_PORT
}

/// The port Substrate should listen on for prometheus connections.
Expand Down Expand Up @@ -303,14 +314,14 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
/// Returns the RPC method set to expose.
///
/// By default this is `RpcMethods::Auto` (unsafe RPCs are denied iff
/// `{rpc,ws}_external` returns true, respectively).
/// `rpc_external` returns true, respectively).
fn rpc_methods(&self) -> Result<RpcMethods> {
Ok(Default::default())
}

/// Get the maximum number of RPC server connections.
fn rpc_max_connections(&self) -> Result<u32> {
Ok(Default::default())
Ok(RPC_DEFAULT_MAX_CONNECTIONS)
}

/// Get the RPC cors (`None` if disabled)
Expand All @@ -322,17 +333,17 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {

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

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

/// Get maximum number of subscriptions per connection.
fn rpc_max_subscriptions_per_connection(&self) -> Result<u32> {
Ok(Default::default())
Ok(RPC_DEFAULT_MAX_SUBS_PER_CONN)
}

/// Get the prometheus configuration (`None` if disabled)
Expand Down Expand Up @@ -506,6 +517,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
rpc_max_response_size: self.rpc_max_response_size()?,
rpc_id_provider: None,
rpc_max_subs_per_conn: self.rpc_max_subscriptions_per_connection()?,
rpc_port: DCV::rpc_listen_port(),
prometheus_config: self
.prometheus_config(DCV::prometheus_listen_port(), &chain_spec)?,
telemetry_endpoints,
Expand Down
1 change: 1 addition & 0 deletions client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ mod tests {
rpc_max_response_size: Default::default(),
rpc_id_provider: Default::default(),
rpc_max_subs_per_conn: Default::default(),
rpc_port: 9944,
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down
2 changes: 2 additions & 0 deletions client/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ pub struct Configuration {
pub rpc_id_provider: Option<Box<dyn crate::RpcSubscriptionIdProvider>>,
/// Maximum allowed subscriptions per rpc connection
pub rpc_max_subs_per_conn: u32,
/// JSON-RPC server default port.
pub rpc_port: u16,
/// Prometheus endpoint configuration. `None` if disabled.
pub prometheus_config: Option<PrometheusConfig>,
/// Telemetry service URL. `None` if disabled.
Expand Down
2 changes: 1 addition & 1 deletion client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ where
addr
};

let addr = config.rpc_addr.unwrap_or(([127, 0, 0, 1], 9944).into());
let addr = config.rpc_addr.unwrap_or_else(|| ([127, 0, 0, 1], config.rpc_port).into());
let backup_addr = backup_port(addr);
let metrics = sc_rpc_server::RpcMetrics::new(config.prometheus_registry())?;

Expand Down
1 change: 1 addition & 0 deletions client/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ fn node_config<
rpc_max_response_size: Default::default(),
rpc_id_provider: Default::default(),
rpc_max_subs_per_conn: Default::default(),
rpc_port: 9944,
prometheus_config: None,
telemetry_endpoints: None,
default_heap_pages: None,
Expand Down