diff --git a/Cargo.lock b/Cargo.lock
index 4148b660cd3c..a67f9fdee31b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -13844,19 +13844,48 @@ dependencies = [
name = "polkadot-parachain-bin"
version = "4.0.0"
dependencies = [
- "assert_cmd",
"asset-hub-rococo-runtime",
"asset-hub-westend-runtime",
- "async-trait",
"bridge-hub-rococo-runtime",
"bridge-hub-westend-runtime",
- "clap 4.5.11",
"collectives-westend-runtime",
"color-eyre",
- "color-print",
"contracts-rococo-runtime",
"coretime-rococo-runtime",
"coretime-westend-runtime",
+ "cumulus-primitives-core",
+ "glutton-westend-runtime",
+ "hex-literal",
+ "log",
+ "parachains-common",
+ "penpal-runtime",
+ "people-rococo-runtime",
+ "people-westend-runtime",
+ "polkadot-parachain-lib",
+ "polkadot-service",
+ "rococo-parachain-runtime",
+ "sc-chain-spec",
+ "sc-cli",
+ "sc-service",
+ "seedling-runtime",
+ "serde",
+ "serde_json",
+ "shell-runtime",
+ "sp-core",
+ "sp-runtime",
+ "staging-xcm",
+ "substrate-build-script-utils",
+ "testnet-parachains-constants",
+]
+
+[[package]]
+name = "polkadot-parachain-lib"
+version = "0.1.0"
+dependencies = [
+ "assert_cmd",
+ "async-trait",
+ "clap 4.5.11",
+ "color-print",
"cumulus-client-cli",
"cumulus-client-collator",
"cumulus-client-consensus-aura",
@@ -13875,8 +13904,6 @@ dependencies = [
"frame-system-rpc-runtime-api",
"frame-try-runtime",
"futures",
- "glutton-westend-runtime",
- "hex-literal",
"jsonrpsee",
"log",
"nix 0.28.0",
@@ -13885,13 +13912,8 @@ dependencies = [
"pallet-transaction-payment-rpc-runtime-api",
"parachains-common",
"parity-scale-codec",
- "penpal-runtime",
- "people-rococo-runtime",
- "people-westend-runtime",
"polkadot-cli",
"polkadot-primitives",
- "polkadot-service",
- "rococo-parachain-runtime",
"sc-basic-authorship",
"sc-chain-spec",
"sc-cli",
@@ -13899,42 +13921,30 @@ dependencies = [
"sc-consensus",
"sc-executor",
"sc-network",
- "sc-network-sync",
"sc-rpc",
"sc-service",
"sc-sysinfo",
"sc-telemetry",
"sc-tracing",
"sc-transaction-pool",
- "sc-transaction-pool-api",
- "seedling-runtime",
"serde",
"serde_json",
- "shell-runtime",
"sp-api",
"sp-block-builder",
- "sp-blockchain",
"sp-consensus-aura",
"sp-core",
"sp-genesis-builder",
"sp-inherents",
- "sp-io",
"sp-keystore",
- "sp-offchain",
"sp-runtime",
"sp-session",
- "sp-std 14.0.0",
"sp-timestamp",
- "sp-tracing 16.0.0",
"sp-transaction-pool",
"sp-version",
- "staging-xcm",
- "substrate-build-script-utils",
+ "sp-weights",
"substrate-frame-rpc-system",
"substrate-prometheus-endpoint",
"substrate-state-trie-migration-rpc",
- "tempfile",
- "testnet-parachains-constants",
"tokio",
"wait-timeout",
]
@@ -14366,6 +14376,7 @@ dependencies = [
"polkadot-node-subsystem-types",
"polkadot-node-subsystem-util",
"polkadot-overseer",
+ "polkadot-parachain-lib",
"polkadot-parachain-primitives",
"polkadot-primitives",
"polkadot-rpc",
diff --git a/Cargo.toml b/Cargo.toml
index ebe9dc0dab3e..397163b3cce1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -136,6 +136,7 @@ members = [
"cumulus/parachains/runtimes/testing/penpal",
"cumulus/parachains/runtimes/testing/rococo-parachain",
"cumulus/polkadot-parachain",
+ "cumulus/polkadot-parachain/polkadot-parachain-lib",
"cumulus/primitives/aura",
"cumulus/primitives/core",
"cumulus/primitives/parachain-inherent",
@@ -535,6 +536,7 @@ members = [
]
default-members = [
+ "cumulus/polkadot-parachain",
"polkadot",
"substrate/bin/node/cli",
]
@@ -1041,6 +1043,7 @@ polkadot-node-subsystem-test-helpers = { path = "polkadot/node/subsystem-test-he
polkadot-node-subsystem-types = { path = "polkadot/node/subsystem-types", default-features = false }
polkadot-node-subsystem-util = { path = "polkadot/node/subsystem-util", default-features = false }
polkadot-overseer = { path = "polkadot/node/overseer", default-features = false }
+polkadot-parachain-lib = { path = "cumulus/polkadot-parachain/polkadot-parachain-lib", default-features = false }
polkadot-parachain-primitives = { path = "polkadot/parachain", default-features = false }
polkadot-primitives = { path = "polkadot/primitives", default-features = false }
polkadot-primitives-test-helpers = { path = "polkadot/primitives/test-helpers" }
diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml
index 5d6548447463..383e0f158bf4 100644
--- a/cumulus/polkadot-parachain/Cargo.toml
+++ b/cumulus/polkadot-parachain/Cargo.toml
@@ -2,9 +2,9 @@
name = "polkadot-parachain-bin"
version = "4.0.0"
authors.workspace = true
-build = "build.rs"
edition.workspace = true
-description = "Runs a polkadot parachain node which could be a collator."
+build = "build.rs"
+description = "Runs a polkadot parachain node"
license = "Apache-2.0"
[lints]
@@ -15,19 +15,14 @@ name = "polkadot-parachain"
path = "src/main.rs"
[dependencies]
-async-trait = { workspace = true }
-clap = { features = ["derive"], workspace = true }
-codec = { workspace = true, default-features = true }
color-eyre = { workspace = true }
-color-print = { workspace = true }
-futures = { workspace = true }
hex-literal = { workspace = true, default-features = true }
log = { workspace = true, default-features = true }
serde = { features = ["derive"], workspace = true, default-features = true }
serde_json = { workspace = true, default-features = true }
-docify = { workspace = true }
# Local
+polkadot-parachain-lib = { features = ["rococo-native", "westend-native"], workspace = true }
rococo-parachain-runtime = { workspace = true }
shell-runtime = { workspace = true }
glutton-westend-runtime = { workspace = true }
@@ -41,7 +36,6 @@ coretime-rococo-runtime = { workspace = true }
coretime-westend-runtime = { workspace = true }
bridge-hub-westend-runtime = { workspace = true, default-features = true }
penpal-runtime = { workspace = true }
-jsonrpsee = { features = ["server"], workspace = true }
people-rococo-runtime = { workspace = true }
people-westend-runtime = { workspace = true }
parachains-common = { workspace = true, default-features = true }
@@ -51,83 +45,32 @@ testnet-parachains-constants = { features = [
], workspace = true }
# Substrate
-frame-benchmarking = { workspace = true, default-features = true }
-frame-benchmarking-cli = { workspace = true, default-features = true }
sp-runtime = { workspace = true }
-sp-io = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
-sp-session = { workspace = true, default-features = true }
-frame-try-runtime = { optional = true, workspace = true, default-features = true }
-sc-consensus = { workspace = true, default-features = true }
-sp-tracing = { workspace = true, default-features = true }
-frame-support = { workspace = true, default-features = true }
sc-cli = { workspace = true, default-features = true }
-sc-client-api = { workspace = true, default-features = true }
-sc-executor = { workspace = true, default-features = true }
sc-service = { workspace = true, default-features = true }
-sc-telemetry = { workspace = true, default-features = true }
-sc-transaction-pool = { workspace = true, default-features = true }
-sp-transaction-pool = { workspace = true, default-features = true }
-sc-network = { workspace = true, default-features = true }
-sc-network-sync = { workspace = true, default-features = true }
-sc-basic-authorship = { workspace = true, default-features = true }
-sp-timestamp = { workspace = true, default-features = true }
-sp-blockchain = { workspace = true, default-features = true }
-sp-genesis-builder = { workspace = true }
-sp-block-builder = { workspace = true, default-features = true }
-sp-keystore = { workspace = true, default-features = true }
sc-chain-spec = { workspace = true, default-features = true }
-sc-rpc = { workspace = true, default-features = true }
-sp-version = { workspace = true, default-features = true }
-sc-tracing = { workspace = true, default-features = true }
-sp-offchain = { workspace = true, default-features = true }
-frame-system-rpc-runtime-api = { workspace = true, default-features = true }
-pallet-transaction-payment = { workspace = true, default-features = true }
-pallet-transaction-payment-rpc-runtime-api = { workspace = true, default-features = true }
-sp-std = { workspace = true, default-features = true }
-sp-inherents = { workspace = true, default-features = true }
-sp-api = { workspace = true, default-features = true }
-sp-consensus-aura = { workspace = true, default-features = true }
-sc-sysinfo = { workspace = true, default-features = true }
-prometheus-endpoint = { workspace = true, default-features = true }
-sc-transaction-pool-api = { workspace = true, default-features = true }
-substrate-frame-rpc-system = { workspace = true, default-features = true }
-pallet-transaction-payment-rpc = { workspace = true, default-features = true }
-substrate-state-trie-migration-rpc = { workspace = true, default-features = true }
# Polkadot
-# Use rococo-native as this is currently the default "local" relay chain
-polkadot-cli = { features = ["rococo-native", "westend-native"], workspace = true, default-features = true }
-polkadot-primitives = { workspace = true, default-features = true }
polkadot-service = { workspace = true, default-features = true }
xcm = { workspace = true, default-features = true }
# Cumulus
-cumulus-client-cli = { workspace = true, default-features = true }
-cumulus-client-collator = { workspace = true, default-features = true }
-cumulus-client-consensus-aura = { workspace = true, default-features = true }
-cumulus-client-consensus-relay-chain = { workspace = true, default-features = true }
-cumulus-client-consensus-common = { workspace = true, default-features = true }
-cumulus-client-consensus-proposer = { workspace = true, default-features = true }
-cumulus-client-parachain-inherent = { workspace = true, default-features = true }
-cumulus-client-service = { workspace = true, default-features = true }
-cumulus-primitives-aura = { workspace = true, default-features = true }
cumulus-primitives-core = { workspace = true, default-features = true }
-cumulus-relay-chain-interface = { workspace = true, default-features = true }
[build-dependencies]
substrate-build-script-utils = { workspace = true, default-features = true }
-[dev-dependencies]
-assert_cmd = { workspace = true }
-nix = { features = ["signal"], workspace = true }
-tempfile = { workspace = true }
-tokio = { version = "1.32.0", features = ["macros", "parking_lot", "time"] }
-wait-timeout = { workspace = true }
-
[features]
default = []
runtime-benchmarks = [
+ "cumulus-primitives-core/runtime-benchmarks",
+ "parachains-common/runtime-benchmarks",
+ "polkadot-parachain-lib/runtime-benchmarks",
+ "polkadot-service/runtime-benchmarks",
+ "sc-service/runtime-benchmarks",
+ "sp-runtime/runtime-benchmarks",
+
"asset-hub-rococo-runtime/runtime-benchmarks",
"asset-hub-westend-runtime/runtime-benchmarks",
"bridge-hub-rococo-runtime/runtime-benchmarks",
@@ -136,23 +79,17 @@ runtime-benchmarks = [
"contracts-rococo-runtime/runtime-benchmarks",
"coretime-rococo-runtime/runtime-benchmarks",
"coretime-westend-runtime/runtime-benchmarks",
- "cumulus-primitives-core/runtime-benchmarks",
- "frame-benchmarking-cli/runtime-benchmarks",
- "frame-benchmarking/runtime-benchmarks",
- "frame-support/runtime-benchmarks",
"glutton-westend-runtime/runtime-benchmarks",
- "parachains-common/runtime-benchmarks",
"penpal-runtime/runtime-benchmarks",
"people-rococo-runtime/runtime-benchmarks",
"people-westend-runtime/runtime-benchmarks",
- "polkadot-cli/runtime-benchmarks",
- "polkadot-primitives/runtime-benchmarks",
- "polkadot-service/runtime-benchmarks",
"rococo-parachain-runtime/runtime-benchmarks",
- "sc-service/runtime-benchmarks",
- "sp-runtime/runtime-benchmarks",
]
try-runtime = [
+ "polkadot-parachain-lib/try-runtime",
+ "polkadot-service/try-runtime",
+ "sp-runtime/try-runtime",
+
"asset-hub-rococo-runtime/try-runtime",
"asset-hub-westend-runtime/try-runtime",
"bridge-hub-rococo-runtime/try-runtime",
@@ -161,17 +98,11 @@ try-runtime = [
"contracts-rococo-runtime/try-runtime",
"coretime-rococo-runtime/try-runtime",
"coretime-westend-runtime/try-runtime",
- "frame-support/try-runtime",
- "frame-try-runtime/try-runtime",
"glutton-westend-runtime/try-runtime",
- "pallet-transaction-payment/try-runtime",
"penpal-runtime/try-runtime",
"people-rococo-runtime/try-runtime",
"people-westend-runtime/try-runtime",
- "polkadot-cli/try-runtime",
- "polkadot-service/try-runtime",
"shell-runtime/try-runtime",
- "sp-runtime/try-runtime",
]
fast-runtime = [
"bridge-hub-rococo-runtime/fast-runtime",
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml
new file mode 100644
index 000000000000..09bde034cf26
--- /dev/null
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/Cargo.toml
@@ -0,0 +1,117 @@
+[package]
+name = "polkadot-parachain-lib"
+version = "0.1.0"
+authors.workspace = true
+edition.workspace = true
+description = "Helper library that can be used to build a parachain node"
+license = "Apache-2.0"
+
+[lints]
+workspace = true
+
+[lib]
+path = "src/lib.rs"
+
+[dependencies]
+async-trait = { workspace = true }
+clap = { features = ["derive"], workspace = true }
+codec = { workspace = true, default-features = true }
+color-print = { workspace = true }
+futures = { workspace = true }
+log = { workspace = true, default-features = true }
+serde = { features = ["derive"], workspace = true, default-features = true }
+serde_json = { workspace = true, default-features = true }
+docify = { workspace = true }
+
+# Local
+jsonrpsee = { features = ["server"], workspace = true }
+parachains-common = { workspace = true, default-features = true }
+
+# Substrate
+frame-benchmarking = { optional = true, workspace = true, default-features = true }
+frame-benchmarking-cli = { workspace = true, default-features = true }
+sp-runtime = { workspace = true }
+sp-core = { workspace = true, default-features = true }
+sp-session = { workspace = true, default-features = true }
+frame-try-runtime = { optional = true, workspace = true, default-features = true }
+sc-consensus = { workspace = true, default-features = true }
+frame-support = { optional = true, workspace = true, default-features = true }
+sc-cli = { workspace = true, default-features = true }
+sc-client-api = { workspace = true, default-features = true }
+sc-executor = { workspace = true, default-features = true }
+sc-service = { workspace = true, default-features = true }
+sc-telemetry = { workspace = true, default-features = true }
+sc-transaction-pool = { workspace = true, default-features = true }
+sp-transaction-pool = { workspace = true, default-features = true }
+sc-network = { workspace = true, default-features = true }
+sc-basic-authorship = { workspace = true, default-features = true }
+sp-timestamp = { workspace = true, default-features = true }
+sp-genesis-builder = { workspace = true }
+sp-block-builder = { workspace = true, default-features = true }
+sp-keystore = { workspace = true, default-features = true }
+sc-chain-spec = { workspace = true, default-features = true }
+sc-rpc = { workspace = true, default-features = true }
+sp-version = { workspace = true, default-features = true }
+sp-weights = { workspace = true, default-features = true }
+sc-tracing = { workspace = true, default-features = true }
+frame-system-rpc-runtime-api = { workspace = true, default-features = true }
+pallet-transaction-payment = { workspace = true, default-features = true }
+pallet-transaction-payment-rpc-runtime-api = { workspace = true, default-features = true }
+sp-inherents = { workspace = true, default-features = true }
+sp-api = { workspace = true, default-features = true }
+sp-consensus-aura = { workspace = true, default-features = true }
+sc-sysinfo = { workspace = true, default-features = true }
+prometheus-endpoint = { workspace = true, default-features = true }
+substrate-frame-rpc-system = { workspace = true, default-features = true }
+pallet-transaction-payment-rpc = { workspace = true, default-features = true }
+substrate-state-trie-migration-rpc = { workspace = true, default-features = true }
+
+# Polkadot
+polkadot-cli = { workspace = true, default-features = true }
+polkadot-primitives = { workspace = true, default-features = true }
+
+# Cumulus
+cumulus-client-cli = { workspace = true, default-features = true }
+cumulus-client-collator = { workspace = true, default-features = true }
+cumulus-client-consensus-aura = { workspace = true, default-features = true }
+cumulus-client-consensus-relay-chain = { workspace = true, default-features = true }
+cumulus-client-consensus-common = { workspace = true, default-features = true }
+cumulus-client-consensus-proposer = { workspace = true, default-features = true }
+cumulus-client-parachain-inherent = { workspace = true, default-features = true }
+cumulus-client-service = { workspace = true, default-features = true }
+cumulus-primitives-aura = { workspace = true, default-features = true }
+cumulus-primitives-core = { workspace = true, default-features = true }
+cumulus-relay-chain-interface = { workspace = true, default-features = true }
+
+[dev-dependencies]
+assert_cmd = { workspace = true }
+nix = { features = ["signal"], workspace = true }
+tokio = { version = "1.32.0", features = ["macros", "parking_lot", "time"] }
+wait-timeout = { workspace = true }
+
+[features]
+default = []
+rococo-native = [
+ "polkadot-cli/rococo-native",
+]
+westend-native = [
+ "polkadot-cli/westend-native",
+]
+runtime-benchmarks = [
+ "cumulus-primitives-core/runtime-benchmarks",
+ "frame-benchmarking-cli/runtime-benchmarks",
+ "frame-benchmarking/runtime-benchmarks",
+ "frame-support/runtime-benchmarks",
+ "parachains-common/runtime-benchmarks",
+ "polkadot-cli/runtime-benchmarks",
+ "polkadot-primitives/runtime-benchmarks",
+ "sc-service/runtime-benchmarks",
+ "sp-runtime/runtime-benchmarks",
+]
+try-runtime = [
+ "frame-support/try-runtime",
+ "frame-try-runtime/try-runtime",
+ "pallet-transaction-payment/try-runtime",
+ "polkadot-cli/try-runtime",
+ "sp-runtime/try-runtime",
+]
diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs
new file mode 100644
index 000000000000..2aa2b10fbb67
--- /dev/null
+++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/cli.rs
@@ -0,0 +1,391 @@
+// Copyright (C) Parity Technologies (UK) Ltd.
+// This file is part of Cumulus.
+
+// Cumulus is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Cumulus is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Cumulus. If not, see .
+
+use crate::{
+ chain_spec::DiskChainSpecLoader,
+ common::{
+ chain_spec::{Extensions, LoadSpec},
+ NodeExtraArgs,
+ },
+};
+use clap::{Command, CommandFactory, FromArgMatches};
+use sc_chain_spec::ChainSpec;
+use sc_cli::{
+ CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams,
+ SharedParams, SubstrateCli,
+};
+use sc_service::{config::PrometheusConfig, BasePath};
+use std::{fmt::Debug, marker::PhantomData, net::SocketAddr, path::PathBuf};
+
+/// Trait that can be used to customize some of the customer-facing info related to the node binary
+/// that is being built using this library.
+///
+/// The related info is shown to the customer as part of logs or help messages.
+/// It does not impact functionality.
+pub trait CliConfig {
+ fn impl_version() -> String;
+
+ fn description(executable_name: String) -> String {
+ format!(
+ "The command-line arguments provided first will be passed to the parachain node, \n\
+ and the arguments provided after -- will be passed to the relay chain node. \n\
+ \n\
+ Example: \n\
+ \n\
+ {} [parachain-args] -- [relay-chain-args]",
+ executable_name
+ )
+ }
+
+ fn author() -> String;
+
+ fn support_url() -> String;
+
+ fn copyright_start_year() -> u16;
+}
+
+/// Sub-commands supported by the collator.
+#[derive(Debug, clap::Subcommand)]
+pub enum Subcommand {
+ /// Key management CLI utilities
+ #[command(subcommand)]
+ Key(sc_cli::KeySubcommand),
+
+ /// Build a chain specification.
+ BuildSpec(sc_cli::BuildSpecCmd),
+
+ /// Validate blocks.
+ CheckBlock(sc_cli::CheckBlockCmd),
+
+ /// Export blocks.
+ ExportBlocks(sc_cli::ExportBlocksCmd),
+
+ /// Export the state of a given block into a chain spec.
+ ExportState(sc_cli::ExportStateCmd),
+
+ /// Import blocks.
+ ImportBlocks(sc_cli::ImportBlocksCmd),
+
+ /// Revert the chain to a previous state.
+ Revert(sc_cli::RevertCmd),
+
+ /// Remove the whole chain.
+ PurgeChain(cumulus_client_cli::PurgeChainCmd),
+
+ /// Export the genesis state of the parachain.
+ #[command(alias = "export-genesis-state")]
+ ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand),
+
+ /// Export the genesis wasm of the parachain.
+ ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand),
+
+ /// Sub-commands concerned with benchmarking.
+ /// The pallet benchmarking moved to the `pallet` sub-command.
+ #[command(subcommand)]
+ Benchmark(frame_benchmarking_cli::BenchmarkCmd),
+}
+
+#[derive(clap::Parser)]
+#[command(
+ propagate_version = true,
+ args_conflicts_with_subcommands = true,
+ subcommand_negates_reqs = true
+)]
+pub struct Cli {
+ #[arg(skip)]
+ pub(crate) chain_spec_loader: Option>,
+
+ #[command(subcommand)]
+ pub subcommand: Option,
+
+ #[command(flatten)]
+ pub run: cumulus_client_cli::RunCmd,
+
+ /// EXPERIMENTAL: Use slot-based collator which can handle elastic scaling.
+ ///
+ /// Use with care, this flag is unstable and subject to change.
+ #[arg(long)]
+ pub experimental_use_slot_based: bool,
+
+ /// Disable automatic hardware benchmarks.
+ ///
+ /// By default these benchmarks are automatically ran at startup and measure
+ /// the CPU speed, the memory bandwidth and the disk speed.
+ ///
+ /// The results are then printed out in the logs, and also sent as part of
+ /// telemetry, if telemetry is enabled.
+ #[arg(long)]
+ pub no_hardware_benchmarks: bool,
+
+ /// Export all `PoVs` build by this collator to the given folder.
+ ///
+ /// This is useful for debugging issues that are occurring while validating these `PoVs` on the
+ /// relay chain.
+ #[arg(long)]
+ pub export_pov_to_path: Option,
+
+ /// Relay chain arguments
+ #[arg(raw = true)]
+ pub relay_chain_args: Vec,
+
+ #[arg(skip)]
+ pub(crate) _phantom: PhantomData,
+}
+
+impl Cli {
+ pub(crate) fn node_extra_args(&self) -> NodeExtraArgs {
+ NodeExtraArgs {
+ use_slot_based_consensus: self.experimental_use_slot_based,
+ export_pov: self.export_pov_to_path.clone(),
+ }
+ }
+}
+
+impl SubstrateCli for Cli {
+ fn impl_name() -> String {
+ Self::executable_name()
+ }
+
+ fn impl_version() -> String {
+ Config::impl_version()
+ }
+
+ fn description() -> String {
+ Config::description(Self::executable_name())
+ }
+
+ fn author() -> String {
+ Config::author()
+ }
+
+ fn support_url() -> String {
+ Config::support_url()
+ }
+
+ fn copyright_start_year() -> i32 {
+ Config::copyright_start_year() as i32
+ }
+
+ fn load_spec(&self, id: &str) -> Result, String> {
+ match &self.chain_spec_loader {
+ Some(chain_spec_loader) => chain_spec_loader.load_spec(id),
+ None => DiskChainSpecLoader.load_spec(id),
+ }
+ }
+}
+
+#[derive(Debug)]
+pub struct RelayChainCli {
+ /// The actual relay chain cli object.
+ pub base: polkadot_cli::RunCmd,
+
+ /// Optional chain id that should be passed to the relay chain.
+ pub chain_id: Option,
+
+ /// The base path that should be used by the relay chain.
+ pub base_path: Option,
+
+ _phantom: PhantomData,
+}
+
+impl RelayChainCli {
+ fn polkadot_cmd() -> Command {
+ let help_template = color_print::cformat!(
+ "The arguments that are passed to the relay chain node. \n\
+ \n\
+ RELAY_CHAIN_ARGS:>> \n\
+ {{options}}",
+ );
+
+ polkadot_cli::RunCmd::command()
+ .no_binary_name(true)
+ .help_template(help_template)
+ }
+
+ /// Parse the relay chain CLI parameters using the parachain `Configuration`.
+ pub fn new<'a>(
+ para_config: &sc_service::Configuration,
+ relay_chain_args: impl Iterator- ,
+ ) -> Self {
+ let polkadot_cmd = Self::polkadot_cmd();
+ let matches = polkadot_cmd.get_matches_from(relay_chain_args);
+ let base = FromArgMatches::from_arg_matches(&matches).unwrap_or_else(|e| e.exit());
+
+ let extension = Extensions::try_get(&*para_config.chain_spec);
+ let chain_id = extension.map(|e| e.relay_chain.clone());
+
+ let base_path = para_config.base_path.path().join("polkadot");
+ Self { base, chain_id, base_path: Some(base_path), _phantom: Default::default() }
+ }
+}
+
+impl SubstrateCli for RelayChainCli {
+ fn impl_name() -> String {
+ Cli::::impl_name()
+ }
+
+ fn impl_version() -> String {
+ Cli::::impl_version()
+ }
+
+ fn description() -> String {
+ Cli::::description()
+ }
+
+ fn author() -> String {
+ Cli::::author()
+ }
+
+ fn support_url() -> String {
+ Cli::::support_url()
+ }
+
+ fn copyright_start_year() -> i32 {
+ Cli::::copyright_start_year()
+ }
+
+ fn load_spec(&self, id: &str) -> std::result::Result, String> {
+ polkadot_cli::Cli::from_iter([Self::executable_name()].iter()).load_spec(id)
+ }
+}
+
+impl DefaultConfigurationValues for RelayChainCli {
+ fn p2p_listen_port() -> u16 {
+ 30334
+ }
+
+ fn rpc_listen_port() -> u16 {
+ 9945
+ }
+
+ fn prometheus_listen_port() -> u16 {
+ 9616
+ }
+}
+
+impl CliConfiguration for RelayChainCli {
+ fn shared_params(&self) -> &SharedParams {
+ self.base.base.shared_params()
+ }
+
+ fn import_params(&self) -> Option<&ImportParams> {
+ self.base.base.import_params()
+ }
+
+ fn network_params(&self) -> Option<&NetworkParams> {
+ self.base.base.network_params()
+ }
+
+ fn keystore_params(&self) -> Option<&KeystoreParams> {
+ self.base.base.keystore_params()
+ }
+
+ fn base_path(&self) -> sc_cli::Result