Skip to content

Commit 09254eb

Browse files
niklasad1skunert
andauthored
rpc server: listen to ipv6 socket if available and --experimental-rpc-endpoint CLI option (paritytech#4792)
Close paritytech#3488, paritytech#4331 This changes/adds the following: 1. The default setting is that substrate starts a rpc server that listens to localhost both Ipv4 and Ipv6 on the same port. Ipv6 is allowed to fail because some platforms may not support it 2. A new RPC CLI option `--experimental-rpc-endpoint` which allow to configure arbitrary listen addresses including the port, if this is enabled no other interfaces are enabled. 3. If the local addr is not found for any of the sockets the server is not started throws an error. 4. Remove the deny_unsafe from the RPC implementations instead this is an extension to allow different polices for different interfaces/sockets such one may enable unsafe on local interface and safe on only the external interface. So for instance in this PR it's now possible to start up three RPC endpoints as follows: ``` $ polkadot --experimental-rpc-endpoint "listen-addr=127.0.0.1:9944,rpc-methods=unsafe" --experimental-rpc-endpoint "listen-addr=0.0.0.0:9945,rpc-methods=safe,rate-limit=100" --experimental-rpc-endpoint "listen-addr=[::1]:9944,optional=true" ``` #### Needs to be addressed ~1. Support binding to a random port if it's fails with the default stuff for backward compatible reasons~ ~2. How to sync that the rpc CLI params and that the rpc-listen-addr align, hard to maintain...~ ~3. Add similar warning prints for exposing unsafe methods on external interfaces..~ ~4. Inline todos + the hacky String conversion from rpc params.~ #### Cons with this PR Manual strings parsing impl more error-prone than relying on clap.... //cc @jsdw @BulatSaif @PierreBesson @bkchr --------- Co-authored-by: Sebastian Kunert <[email protected]>
1 parent f0fd083 commit 09254eb

File tree

62 files changed

+1472
-647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1472
-647
lines changed

Cargo.lock

+33-43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,8 @@ isahc = { version = "1.2" }
812812
itertools = { version = "0.11" }
813813
jobserver = { version = "0.1.26" }
814814
jsonpath_lib = { version = "0.3" }
815-
jsonrpsee = { version = "0.23.2" }
816-
jsonrpsee-core = { version = "0.23.2" }
815+
jsonrpsee = { version = "0.24.3" }
816+
jsonrpsee-core = { version = "0.24.3" }
817817
k256 = { version = "0.13.3", default-features = false }
818818
kitchensink-runtime = { path = "substrate/bin/node/runtime" }
819819
kvdb = { version = "0.13.0" }

cumulus/client/cli/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
use std::{
2222
fs,
2323
io::{self, Write},
24-
net::SocketAddr,
2524
path::PathBuf,
2625
sync::Arc,
2726
};
2827

2928
use codec::Encode;
3029
use sc_chain_spec::ChainSpec;
30+
use sc_cli::RpcEndpoint;
3131
use sc_client_api::HeaderBackend;
3232
use sc_service::{
3333
config::{PrometheusConfig, RpcBatchRequestConfig, TelemetryEndpoints},
@@ -423,7 +423,7 @@ impl sc_cli::CliConfiguration for NormalizedRunCmd {
423423
self.base.rpc_cors(is_dev)
424424
}
425425

426-
fn rpc_addr(&self, default_listen_port: u16) -> sc_cli::Result<Option<SocketAddr>> {
426+
fn rpc_addr(&self, default_listen_port: u16) -> sc_cli::Result<Option<Vec<RpcEndpoint>>> {
427427
self.base.rpc_addr(default_listen_port)
428428
}
429429

cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ use clap::{Command, CommandFactory, FromArgMatches};
2525
use sc_chain_spec::ChainSpec;
2626
use sc_cli::{
2727
CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams,
28-
SharedParams, SubstrateCli,
28+
RpcEndpoint, SharedParams, SubstrateCli,
2929
};
3030
use sc_service::{config::PrometheusConfig, BasePath};
31-
use std::{fmt::Debug, marker::PhantomData, net::SocketAddr, path::PathBuf};
31+
use std::{fmt::Debug, marker::PhantomData, path::PathBuf};
3232

3333
/// Trait that can be used to customize some of the customer-facing info related to the node binary
3434
/// that is being built using this library.
@@ -300,7 +300,7 @@ impl<Config: CliConfig> CliConfiguration<Self> for RelayChainCli<Config> {
300300
.or_else(|| self.base_path.clone().map(Into::into)))
301301
}
302302

303-
fn rpc_addr(&self, default_listen_port: u16) -> sc_cli::Result<Option<SocketAddr>> {
303+
fn rpc_addr(&self, default_listen_port: u16) -> sc_cli::Result<Option<Vec<RpcEndpoint>>> {
304304
self.base.base.rpc_addr(default_listen_port)
305305
}
306306

cumulus/polkadot-parachain/polkadot-parachain-lib/src/rpc.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ use crate::{
2424
};
2525
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
2626
use parachains_common::{AccountId, Balance, Block, Nonce};
27-
use sc_rpc::{
28-
dev::{Dev, DevApiServer},
29-
DenyUnsafe,
30-
};
27+
use sc_rpc::dev::{Dev, DevApiServer};
3128
use std::{marker::PhantomData, sync::Arc};
3229
use substrate_frame_rpc_system::{System, SystemApiServer};
3330
use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer};
@@ -37,7 +34,6 @@ pub type RpcExtension = jsonrpsee::RpcModule<()>;
3734

3835
pub(crate) trait BuildRpcExtensions<Client, Backend, Pool> {
3936
fn build_rpc_extensions(
40-
deny_unsafe: DenyUnsafe,
4137
client: Arc<Client>,
4238
backend: Arc<Backend>,
4339
pool: Arc<Pool>,
@@ -56,7 +52,6 @@ where
5652
RuntimeApi: ConstructNodeRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
5753
{
5854
fn build_rpc_extensions(
59-
_deny_unsafe: DenyUnsafe,
6055
_client: Arc<ParachainClient<RuntimeApi>>,
6156
_backend: Arc<ParachainBackend>,
6257
_pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>>,
@@ -79,18 +74,17 @@ where
7974
+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
8075
{
8176
fn build_rpc_extensions(
82-
deny_unsafe: DenyUnsafe,
8377
client: Arc<ParachainClient<RuntimeApi>>,
8478
backend: Arc<ParachainBackend>,
8579
pool: Arc<sc_transaction_pool::FullPool<Block, ParachainClient<RuntimeApi>>>,
8680
) -> sc_service::error::Result<RpcExtension> {
8781
let build = || -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>> {
8882
let mut module = RpcExtension::new(());
8983

90-
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
84+
module.merge(System::new(client.clone(), pool).into_rpc())?;
9185
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
92-
module.merge(StateMigration::new(client.clone(), backend, deny_unsafe).into_rpc())?;
93-
module.merge(Dev::new(client, deny_unsafe).into_rpc())?;
86+
module.merge(StateMigration::new(client.clone(), backend).into_rpc())?;
87+
module.merge(Dev::new(client).into_rpc())?;
9488

9589
Ok(module)
9690
};

0 commit comments

Comments
 (0)