difftreelog
add: westend-local launch config
in: master
3 files changed
launch-config-westend.jsondiffbeforeafterboth--- /dev/null
+++ b/launch-config-westend.json
@@ -0,0 +1,152 @@
+{
+ "relaychain": {
+ "bin": "../polkadot/target/release/polkadot",
+ "chain": "westend-local",
+ "nodes": [
+ {
+ "name": "alice",
+ "wsPort": 9844,
+ "rpcPort": 9843,
+ "port": 30444,
+ "flags": [
+ "--rpc-port=9843",
+ "-lparachain::candidate_validation=debug"
+ ]
+ },
+ {
+ "name": "bob",
+ "wsPort": 9855,
+ "rpcPort": 9854,
+ "port": 30555,
+ "flags": [
+ "--rpc-port=9854",
+ "-lparachain::candidate_validation=debug"
+ ]
+ },
+ {
+ "name": "charlie",
+ "wsPort": 9866,
+ "rpcPort": 9865,
+ "port": 30666,
+ "flags": [
+ "--rpc-port=9865",
+ "-lparachain::candidate_validation=debug"
+ ]
+ },
+ {
+ "name": "dave",
+ "wsPort": 9877,
+ "rpcPort": 9876,
+ "port": 30777,
+ "flags": [
+ "--rpc-port=9876",
+ "-lparachain::candidate_validation=debug"
+ ]
+ },
+ {
+ "name": "eve",
+ "wsPort": 9888,
+ "rpcPort": 9886,
+ "port": 30888,
+ "flags": [
+ "--rpc-port=9886",
+ "-lparachain::candidate_validation=debug"
+ ]
+ },
+ {
+ "name": "ferdie",
+ "wsPort": 9897,
+ "rpcPort": 9896,
+ "port": 30999,
+ "flags": [
+ "--rpc-port=9896",
+ "-lparachain::candidate_validation=debug"
+ ]
+ }
+ ],
+ "genesis": {
+ "runtime": {
+ "runtime_genesis_config": {
+ "parachainsConfiguration": {
+ "config": {
+ "validation_upgrade_frequency": 1,
+ "validation_upgrade_delay": 1
+ }
+ }
+ }
+ }
+ }
+ },
+ "parachains": [
+ {
+ "bin": "../unique-chain/target/release/nft",
+ "chain": "westend-local",
+ "balance": "1000000000000000000000",
+ "nodes": [
+ {
+ "port": 31200,
+ "wsPort": 9944,
+ "rpcPort": 9933,
+ "name": "alice",
+ "flags": [
+ "--rpc-cors=all",
+ "--rpc-port=9933",
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external"
+ ]
+ },
+ {
+ "port": 31201,
+ "wsPort": 9945,
+ "rpcPort": 9934,
+ "name": "bob",
+ "flags": [
+ "--rpc-cors=all",
+ "--rpc-port=9934",
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external"
+ ]
+ },
+ {
+ "port": 31202,
+ "wsPort": 9946,
+ "rpcPort": 9935,
+ "name": "charlie",
+ "flags": [
+ "--rpc-cors=all",
+ "--rpc-port=9935",
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external"
+ ]
+ },
+ {
+ "port": 31203,
+ "wsPort": 9947,
+ "rpcPort": 9936,
+ "name": "dave",
+ "flags": [
+ "--rpc-cors=all",
+ "--rpc-port=9936",
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external"
+ ]
+ },
+ {
+ "port": 31204,
+ "wsPort": 9948,
+ "rpcPort": 9937,
+ "name": "eve",
+ "flags": [
+ "--rpc-cors=all",
+ "--rpc-port=9937",
+ "--unsafe-rpc-external",
+ "--unsafe-ws-external"
+ ]
+ }
+ ]
+ }
+ ],
+ "simpleParachains": [],
+ "hrmpChannels": [],
+ "finalization": false
+}
node/cli/src/chain_spec.rsdiffbeforeafterboth--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -95,7 +95,7 @@
)
}
-pub fn local_testnet_config(id: ParaId) -> ChainSpec {
+pub fn local_testnet_rococo_config(id: ParaId) -> ChainSpec {
ChainSpec::from_genesis(
// Name
"Local Testnet",
@@ -144,6 +144,58 @@
)
}
+pub fn local_testnet_westend_config(id: ParaId) -> ChainSpec {
+ ChainSpec::from_genesis(
+ // Name
+ "Local Testnet",
+ // ID
+ "local_testnet",
+ ChainType::Local,
+ move || {
+ testnet_genesis(
+ // Sudo account
+ get_account_id_from_seed::<sr25519::Public>("Alice"),
+ vec![
+ get_from_seed::<AuraId>("Alice"),
+ get_from_seed::<AuraId>("Bob"),
+ get_from_seed::<AuraId>("Charlie"),
+ get_from_seed::<AuraId>("Dave"),
+ get_from_seed::<AuraId>("Eve"),
+ ],
+ // Pre-funded accounts
+ vec![
+ get_account_id_from_seed::<sr25519::Public>("Alice"),
+ get_account_id_from_seed::<sr25519::Public>("Bob"),
+ get_account_id_from_seed::<sr25519::Public>("Charlie"),
+ get_account_id_from_seed::<sr25519::Public>("Dave"),
+ get_account_id_from_seed::<sr25519::Public>("Eve"),
+ get_account_id_from_seed::<sr25519::Public>("Ferdie"),
+ get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
+ get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
+ get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
+ get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
+ get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
+ get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
+ ],
+ id,
+ )
+ },
+ // Bootnodes
+ vec![],
+ // Telemetry
+ None,
+ // Protocol ID
+ None,
+ // Properties
+ None,
+ // Extensions
+ Extensions {
+ relay_chain: "westend-local".into(),
+ para_id: id.into(),
+ },
+ )
+}
+
fn testnet_genesis(
root_key: AccountId,
initial_authorities: Vec<AuraId>,
node/cli/src/command.rsdiffbeforeafterboth1// This file is part of Substrate.23// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.4// SPDX-License-Identifier: Apache-2.056// Licensed under the Apache License, Version 2.0 (the "License");7// you may not use this file except in compliance with the License.8// You may obtain a copy of the License at9//10// http://www.apache.org/licenses/LICENSE-2.011//12// Unless required by applicable law or agreed to in writing, software13// distributed under the License is distributed on an "AS IS" BASIS,14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15// See the License for the specific language governing permissions and16// limitations under the License.1718use crate::{19 chain_spec,20 cli::{Cli, RelayChainCli, Subcommand},21 service::{new_partial, ParachainRuntimeExecutor},22};23use codec::Encode;24use cumulus_primitives_core::ParaId;25use cumulus_client_service::genesis::generate_genesis_block;26use log::info;27use nft_runtime::Block;28use polkadot_parachain::primitives::AccountIdConversion;29use sc_cli::{30 ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,31 NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,32};33use sc_service::{34 config::{BasePath, PrometheusConfig},35};36use sp_core::hexdisplay::HexDisplay;37use sp_runtime::traits::Block as BlockT;38use std::{io::Write, net::SocketAddr};3940fn load_spec(41 id: &str,42 para_id: ParaId,43) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {44 Ok(match id {45 "dev" => Box::new(chain_spec::development_config(para_id)),46 "" | "local" => Box::new(chain_spec::local_testnet_config(para_id)),47 path => Box::new(chain_spec::ChainSpec::from_json_file(48 std::path::PathBuf::from(path),49 )?),50 })51}5253impl SubstrateCli for Cli {54 // TODO use args55 fn impl_name() -> String {56 "Opal Node".into()57 }5859 fn impl_version() -> String {60 env!("SUBSTRATE_CLI_IMPL_VERSION").into()61 }62 // TODO use args63 fn description() -> String {64 format!(65 "Opal Node\n\nThe command-line arguments provided first will be \66 passed to the parachain node, while the arguments provided after -- will be passed \67 to the relaychain node.\n\n\68 {} [parachain-args] -- [relaychain-args]",69 Self::executable_name()70 )71 }7273 fn author() -> String {74 env!("CARGO_PKG_AUTHORS").into()75 }7677 //TODO use args78 fn support_url() -> String {79 "support@unique.network".into()80 }8182 fn copyright_start_year() -> i32 {83 201984 }8586 fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {87 load_spec(id, self.run.parachain_id.unwrap_or(200).into())88 }8990 fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {91 &nft_runtime::VERSION92 }93}9495impl SubstrateCli for RelayChainCli {96 // TODO use args97 fn impl_name() -> String {98 "Opal Node".into()99 }100101 fn impl_version() -> String {102 env!("SUBSTRATE_CLI_IMPL_VERSION").into()103 }104 // TODO use args105 fn description() -> String {106 "Opal Node\n\nThe command-line arguments provided first will be \107 passed to the parachain node, while the arguments provided after -- will be passed \108 to the relaychain node.\n\n\109 parachain-collator [parachain-args] -- [relaychain-args]"110 .into()111 }112113 fn author() -> String {114 env!("CARGO_PKG_AUTHORS").into()115 }116 // TODO use args117 fn support_url() -> String {118 "support@unique.network".into()119 }120121 fn copyright_start_year() -> i32 {122 2019123 }124125 fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {126 polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)127 }128129 fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {130 polkadot_cli::Cli::native_runtime_version(chain_spec)131 }132}133134#[allow(clippy::borrowed_box)]135fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {136 let mut storage = chain_spec.build_storage()?;137138 storage139 .top140 .remove(sp_core::storage::well_known_keys::CODE)141 .ok_or_else(|| "Could not find wasm file in genesis state!".into())142}143144macro_rules! construct_async_run {145 (|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{146 let runner = $cli.create_runner($cmd)?;147 runner.async_run(|$config| {148 let $components = new_partial::<149 _150 >(151 &$config,152 crate::service::parachain_build_import_queue,153 )?;154 let task_manager = $components.task_manager;155 { $( $code )* }.map(|v| (v, task_manager))156 })157 }}158}159160/// Parse command line arguments into service configuration.161pub fn run() -> Result<()> {162 let cli = Cli::from_args();163164 match &cli.subcommand {165 Some(Subcommand::BuildSpec(cmd)) => {166 let runner = cli.create_runner(cmd)?;167 runner.sync_run(|config| cmd.run(config.chain_spec, config.network))168 }169 Some(Subcommand::CheckBlock(cmd)) => {170 construct_async_run!(|components, cli, cmd, config| {171 Ok(cmd.run(components.client, components.import_queue))172 })173 }174 Some(Subcommand::ExportBlocks(cmd)) => {175 construct_async_run!(|components, cli, cmd, config| {176 Ok(cmd.run(components.client, config.database))177 })178 }179 Some(Subcommand::ExportState(cmd)) => {180 construct_async_run!(|components, cli, cmd, config| {181 Ok(cmd.run(components.client, config.chain_spec))182 })183 }184 Some(Subcommand::ImportBlocks(cmd)) => {185 construct_async_run!(|components, cli, cmd, config| {186 Ok(cmd.run(components.client, components.import_queue))187 })188 }189 Some(Subcommand::PurgeChain(cmd)) => {190 let runner = cli.create_runner(cmd)?;191192 runner.sync_run(|config| {193 let polkadot_cli = RelayChainCli::new(194 &config,195 [RelayChainCli::executable_name()]196 .iter()197 .chain(cli.relaychain_args.iter()),198 );199200 let polkadot_config = SubstrateCli::create_configuration(201 &polkadot_cli,202 &polkadot_cli,203 config.tokio_handle.clone(),204 )205 .map_err(|err| format!("Relay chain argument error: {}", err))?;206207 cmd.run(config, polkadot_config)208 })209 }210 Some(Subcommand::Revert(cmd)) => construct_async_run!(|components, cli, cmd, config| {211 Ok(cmd.run(components.client, components.backend))212 }),213 Some(Subcommand::ExportGenesisState(params)) => {214 let mut builder = sc_cli::LoggerBuilder::new("");215 builder.with_profiling(sc_tracing::TracingReceiver::Log, "");216 let _ = builder.init();217218 let block: Block = generate_genesis_block(&load_spec(219 ¶ms.chain.clone().unwrap_or_default(),220 params.parachain_id.unwrap_or(200).into(),221 )?)?;222 let raw_header = block.header().encode();223 let output_buf = if params.raw {224 raw_header225 } else {226 format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes()227 };228229 if let Some(output) = ¶ms.output {230 std::fs::write(output, output_buf)?;231 } else {232 std::io::stdout().write_all(&output_buf)?;233 }234235 Ok(())236 }237 Some(Subcommand::ExportGenesisWasm(params)) => {238 let mut builder = sc_cli::LoggerBuilder::new("");239 builder.with_profiling(sc_tracing::TracingReceiver::Log, "");240 let _ = builder.init();241242 let raw_wasm_blob =243 extract_genesis_wasm(&cli.load_spec(¶ms.chain.clone().unwrap_or_default())?)?;244 let output_buf = if params.raw {245 raw_wasm_blob246 } else {247 format!("0x{:?}", HexDisplay::from(&raw_wasm_blob)).into_bytes()248 };249250 if let Some(output) = ¶ms.output {251 std::fs::write(output, output_buf)?;252 } else {253 std::io::stdout().write_all(&output_buf)?;254 }255256 Ok(())257 }258 Some(Subcommand::Benchmark(cmd)) => {259 if cfg!(feature = "runtime-benchmarks") {260 let runner = cli.create_runner(cmd)?;261262 runner.sync_run(|config| cmd.run::<Block, ParachainRuntimeExecutor>(config))263 } else {264 Err("Benchmarking wasn't enabled when building the node. \265 You can enable it with `--features runtime-benchmarks`."266 .into())267 }268 }269 None => {270 let runner = cli.create_runner(&cli.run.normalize())?;271272 runner.run_node_until_exit(|config| async move {273 let para_id =274 chain_spec::Extensions::try_get(&*config.chain_spec).map(|e| e.para_id);275276 let polkadot_cli = RelayChainCli::new(277 &config,278 [RelayChainCli::executable_name()]279 .iter()280 .chain(cli.relaychain_args.iter()),281 );282283 let id = ParaId::from(cli.run.parachain_id.or(para_id).unwrap_or(200));284285 let parachain_account =286 AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);287288 let block: Block =289 generate_genesis_block(&config.chain_spec).map_err(|e| format!("{:?}", e))?;290 let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));291292 let polkadot_config = SubstrateCli::create_configuration(293 &polkadot_cli,294 &polkadot_cli,295 config.tokio_handle.clone(),296 )297 .map_err(|err| format!("Relay chain argument error: {}", err))?;298299 info!("Parachain id: {:?}", id);300 info!("Parachain Account: {}", parachain_account);301 info!("Parachain genesis state: {}", genesis_state);302 info!(303 "Is collating: {}",304 if config.role.is_authority() {305 "yes"306 } else {307 "no"308 }309 );310311 crate::service::start_node(config, polkadot_config, id)312 .await313 .map(|r| r.0)314 .map_err(Into::into)315 })316 }317 }318}319320impl DefaultConfigurationValues for RelayChainCli {321 fn p2p_listen_port() -> u16 {322 30334323 }324325 fn rpc_ws_listen_port() -> u16 {326 9945327 }328329 fn rpc_http_listen_port() -> u16 {330 9934331 }332333 fn prometheus_listen_port() -> u16 {334 9616335 }336}337338impl CliConfiguration<Self> for RelayChainCli {339 fn shared_params(&self) -> &SharedParams {340 self.base.base.shared_params()341 }342343 fn import_params(&self) -> Option<&ImportParams> {344 self.base.base.import_params()345 }346347 fn network_params(&self) -> Option<&NetworkParams> {348 self.base.base.network_params()349 }350351 fn keystore_params(&self) -> Option<&KeystoreParams> {352 self.base.base.keystore_params()353 }354355 fn base_path(&self) -> Result<Option<BasePath>> {356 Ok(self357 .shared_params()358 .base_path()359 .or_else(|| self.base_path.clone().map(Into::into)))360 }361362 fn rpc_http(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {363 self.base.base.rpc_http(default_listen_port)364 }365366 fn rpc_ipc(&self) -> Result<Option<String>> {367 self.base.base.rpc_ipc()368 }369370 fn rpc_ws(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {371 self.base.base.rpc_ws(default_listen_port)372 }373374 fn prometheus_config(&self, default_listen_port: u16) -> Result<Option<PrometheusConfig>> {375 self.base.base.prometheus_config(default_listen_port)376 }377378 fn init<C: SubstrateCli>(&self) -> Result<()> {379 unreachable!("PolkadotCli is never initialized; qed");380 }381382 fn chain_id(&self, is_dev: bool) -> Result<String> {383 let chain_id = self.base.base.chain_id(is_dev)?;384385 Ok(if chain_id.is_empty() {386 self.chain_id.clone().unwrap_or_default()387 } else {388 chain_id389 })390 }391392 fn role(&self, is_dev: bool) -> Result<sc_service::Role> {393 self.base.base.role(is_dev)394 }395396 fn transaction_pool(&self) -> Result<sc_service::config::TransactionPoolOptions> {397 self.base.base.transaction_pool()398 }399400 fn state_cache_child_ratio(&self) -> Result<Option<usize>> {401 self.base.base.state_cache_child_ratio()402 }403404 fn rpc_methods(&self) -> Result<sc_service::config::RpcMethods> {405 self.base.base.rpc_methods()406 }407408 fn rpc_ws_max_connections(&self) -> Result<Option<usize>> {409 self.base.base.rpc_ws_max_connections()410 }411412 fn rpc_cors(&self, is_dev: bool) -> Result<Option<Vec<String>>> {413 self.base.base.rpc_cors(is_dev)414 }415416 fn default_heap_pages(&self) -> Result<Option<u64>> {417 self.base.base.default_heap_pages()418 }419420 fn force_authoring(&self) -> Result<bool> {421 self.base.base.force_authoring()422 }423424 fn disable_grandpa(&self) -> Result<bool> {425 self.base.base.disable_grandpa()426 }427428 fn max_runtime_instances(&self) -> Result<Option<usize>> {429 self.base.base.max_runtime_instances()430 }431432 fn announce_block(&self) -> Result<bool> {433 self.base.base.announce_block()434 }435436 fn telemetry_endpoints(437 &self,438 chain_spec: &Box<dyn ChainSpec>,439 ) -> Result<Option<sc_telemetry::TelemetryEndpoints>> {440 self.base.base.telemetry_endpoints(chain_spec)441 }442}1// This file is part of Substrate.23// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.4// SPDX-License-Identifier: Apache-2.056// Licensed under the Apache License, Version 2.0 (the "License");7// you may not use this file except in compliance with the License.8// You may obtain a copy of the License at9//10// http://www.apache.org/licenses/LICENSE-2.011//12// Unless required by applicable law or agreed to in writing, software13// distributed under the License is distributed on an "AS IS" BASIS,14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15// See the License for the specific language governing permissions and16// limitations under the License.1718use crate::{19 chain_spec,20 cli::{Cli, RelayChainCli, Subcommand},21 service::{new_partial, ParachainRuntimeExecutor},22};23use codec::Encode;24use cumulus_primitives_core::ParaId;25use cumulus_client_service::genesis::generate_genesis_block;26use log::info;27use nft_runtime::Block;28use polkadot_parachain::primitives::AccountIdConversion;29use sc_cli::{30 ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,31 NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,32};33use sc_service::{34 config::{BasePath, PrometheusConfig},35};36use sp_core::hexdisplay::HexDisplay;37use sp_runtime::traits::Block as BlockT;38use std::{io::Write, net::SocketAddr};3940fn load_spec(41 id: &str,42 para_id: ParaId,43) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {44 Ok(match id {45 "westend-local" => Box::new(chain_spec::local_testnet_westend_config(para_id)),46 "dev" => Box::new(chain_spec::development_config(para_id)),47 "" | "local" => Box::new(chain_spec::local_testnet_rococo_config(para_id)),48 path => Box::new(chain_spec::ChainSpec::from_json_file(49 std::path::PathBuf::from(path),50 )?),51 })52}5354impl SubstrateCli for Cli {55 // TODO use args56 fn impl_name() -> String {57 "Opal Node".into()58 }5960 fn impl_version() -> String {61 env!("SUBSTRATE_CLI_IMPL_VERSION").into()62 }63 // TODO use args64 fn description() -> String {65 format!(66 "Opal Node\n\nThe command-line arguments provided first will be \67 passed to the parachain node, while the arguments provided after -- will be passed \68 to the relaychain node.\n\n\69 {} [parachain-args] -- [relaychain-args]",70 Self::executable_name()71 )72 }7374 fn author() -> String {75 env!("CARGO_PKG_AUTHORS").into()76 }7778 //TODO use args79 fn support_url() -> String {80 "support@unique.network".into()81 }8283 fn copyright_start_year() -> i32 {84 201985 }8687 fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {88 load_spec(id, self.run.parachain_id.unwrap_or(2000).into())89 }9091 fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {92 &nft_runtime::VERSION93 }94}9596impl SubstrateCli for RelayChainCli {97 // TODO use args98 fn impl_name() -> String {99 "Opal Node".into()100 }101102 fn impl_version() -> String {103 env!("SUBSTRATE_CLI_IMPL_VERSION").into()104 }105 // TODO use args106 fn description() -> String {107 "Opal Node\n\nThe command-line arguments provided first will be \108 passed to the parachain node, while the arguments provided after -- will be passed \109 to the relaychain node.\n\n\110 parachain-collator [parachain-args] -- [relaychain-args]"111 .into()112 }113114 fn author() -> String {115 env!("CARGO_PKG_AUTHORS").into()116 }117 // TODO use args118 fn support_url() -> String {119 "support@unique.network".into()120 }121122 fn copyright_start_year() -> i32 {123 2019124 }125126 fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {127 polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)128 }129130 fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {131 polkadot_cli::Cli::native_runtime_version(chain_spec)132 }133}134135#[allow(clippy::borrowed_box)]136fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {137 let mut storage = chain_spec.build_storage()?;138139 storage140 .top141 .remove(sp_core::storage::well_known_keys::CODE)142 .ok_or_else(|| "Could not find wasm file in genesis state!".into())143}144145macro_rules! construct_async_run {146 (|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{147 let runner = $cli.create_runner($cmd)?;148 runner.async_run(|$config| {149 let $components = new_partial::<150 _151 >(152 &$config,153 crate::service::parachain_build_import_queue,154 )?;155 let task_manager = $components.task_manager;156 { $( $code )* }.map(|v| (v, task_manager))157 })158 }}159}160161/// Parse command line arguments into service configuration.162pub fn run() -> Result<()> {163 let cli = Cli::from_args();164165 match &cli.subcommand {166 Some(Subcommand::BuildSpec(cmd)) => {167 let runner = cli.create_runner(cmd)?;168 runner.sync_run(|config| cmd.run(config.chain_spec, config.network))169 }170 Some(Subcommand::CheckBlock(cmd)) => {171 construct_async_run!(|components, cli, cmd, config| {172 Ok(cmd.run(components.client, components.import_queue))173 })174 }175 Some(Subcommand::ExportBlocks(cmd)) => {176 construct_async_run!(|components, cli, cmd, config| {177 Ok(cmd.run(components.client, config.database))178 })179 }180 Some(Subcommand::ExportState(cmd)) => {181 construct_async_run!(|components, cli, cmd, config| {182 Ok(cmd.run(components.client, config.chain_spec))183 })184 }185 Some(Subcommand::ImportBlocks(cmd)) => {186 construct_async_run!(|components, cli, cmd, config| {187 Ok(cmd.run(components.client, components.import_queue))188 })189 }190 Some(Subcommand::PurgeChain(cmd)) => {191 let runner = cli.create_runner(cmd)?;192193 runner.sync_run(|config| {194 let polkadot_cli = RelayChainCli::new(195 &config,196 [RelayChainCli::executable_name()]197 .iter()198 .chain(cli.relaychain_args.iter()),199 );200201 let polkadot_config = SubstrateCli::create_configuration(202 &polkadot_cli,203 &polkadot_cli,204 config.tokio_handle.clone(),205 )206 .map_err(|err| format!("Relay chain argument error: {}", err))?;207208 cmd.run(config, polkadot_config)209 })210 }211 Some(Subcommand::Revert(cmd)) => construct_async_run!(|components, cli, cmd, config| {212 Ok(cmd.run(components.client, components.backend))213 }),214 Some(Subcommand::ExportGenesisState(params)) => {215 let mut builder = sc_cli::LoggerBuilder::new("");216 builder.with_profiling(sc_tracing::TracingReceiver::Log, "");217 let _ = builder.init();218219 let block: Block = generate_genesis_block(&load_spec(220 ¶ms.chain.clone().unwrap_or_default(),221 params.parachain_id.unwrap_or(2000).into(),222 )?)?;223 let raw_header = block.header().encode();224 let output_buf = if params.raw {225 raw_header226 } else {227 format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes()228 };229230 if let Some(output) = ¶ms.output {231 std::fs::write(output, output_buf)?;232 } else {233 std::io::stdout().write_all(&output_buf)?;234 }235236 Ok(())237 }238 Some(Subcommand::ExportGenesisWasm(params)) => {239 let mut builder = sc_cli::LoggerBuilder::new("");240 builder.with_profiling(sc_tracing::TracingReceiver::Log, "");241 let _ = builder.init();242243 let raw_wasm_blob =244 extract_genesis_wasm(&cli.load_spec(¶ms.chain.clone().unwrap_or_default())?)?;245 let output_buf = if params.raw {246 raw_wasm_blob247 } else {248 format!("0x{:?}", HexDisplay::from(&raw_wasm_blob)).into_bytes()249 };250251 if let Some(output) = ¶ms.output {252 std::fs::write(output, output_buf)?;253 } else {254 std::io::stdout().write_all(&output_buf)?;255 }256257 Ok(())258 }259 Some(Subcommand::Benchmark(cmd)) => {260 if cfg!(feature = "runtime-benchmarks") {261 let runner = cli.create_runner(cmd)?;262263 runner.sync_run(|config| cmd.run::<Block, ParachainRuntimeExecutor>(config))264 } else {265 Err("Benchmarking wasn't enabled when building the node. \266 You can enable it with `--features runtime-benchmarks`."267 .into())268 }269 }270 None => {271 let runner = cli.create_runner(&cli.run.normalize())?;272273 runner.run_node_until_exit(|config| async move {274 let para_id =275 chain_spec::Extensions::try_get(&*config.chain_spec).map(|e| e.para_id);276277 let polkadot_cli = RelayChainCli::new(278 &config,279 [RelayChainCli::executable_name()]280 .iter()281 .chain(cli.relaychain_args.iter()),282 );283284 let id = ParaId::from(cli.run.parachain_id.or(para_id).unwrap_or(2000));285286 let parachain_account =287 AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);288289 let block: Block =290 generate_genesis_block(&config.chain_spec).map_err(|e| format!("{:?}", e))?;291 let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));292293 let polkadot_config = SubstrateCli::create_configuration(294 &polkadot_cli,295 &polkadot_cli,296 config.tokio_handle.clone(),297 )298 .map_err(|err| format!("Relay chain argument error: {}", err))?;299300 info!("Parachain id: {:?}", id);301 info!("Parachain Account: {}", parachain_account);302 info!("Parachain genesis state: {}", genesis_state);303 info!(304 "Is collating: {}",305 if config.role.is_authority() {306 "yes"307 } else {308 "no"309 }310 );311312 crate::service::start_node(config, polkadot_config, id)313 .await314 .map(|r| r.0)315 .map_err(Into::into)316 })317 }318 }319}320321impl DefaultConfigurationValues for RelayChainCli {322 fn p2p_listen_port() -> u16 {323 30334324 }325326 fn rpc_ws_listen_port() -> u16 {327 9945328 }329330 fn rpc_http_listen_port() -> u16 {331 9934332 }333334 fn prometheus_listen_port() -> u16 {335 9616336 }337}338339impl CliConfiguration<Self> for RelayChainCli {340 fn shared_params(&self) -> &SharedParams {341 self.base.base.shared_params()342 }343344 fn import_params(&self) -> Option<&ImportParams> {345 self.base.base.import_params()346 }347348 fn network_params(&self) -> Option<&NetworkParams> {349 self.base.base.network_params()350 }351352 fn keystore_params(&self) -> Option<&KeystoreParams> {353 self.base.base.keystore_params()354 }355356 fn base_path(&self) -> Result<Option<BasePath>> {357 Ok(self358 .shared_params()359 .base_path()360 .or_else(|| self.base_path.clone().map(Into::into)))361 }362363 fn rpc_http(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {364 self.base.base.rpc_http(default_listen_port)365 }366367 fn rpc_ipc(&self) -> Result<Option<String>> {368 self.base.base.rpc_ipc()369 }370371 fn rpc_ws(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {372 self.base.base.rpc_ws(default_listen_port)373 }374375 fn prometheus_config(&self, default_listen_port: u16) -> Result<Option<PrometheusConfig>> {376 self.base.base.prometheus_config(default_listen_port)377 }378379 fn init<C: SubstrateCli>(&self) -> Result<()> {380 unreachable!("PolkadotCli is never initialized; qed");381 }382383 fn chain_id(&self, is_dev: bool) -> Result<String> {384 let chain_id = self.base.base.chain_id(is_dev)?;385386 Ok(if chain_id.is_empty() {387 self.chain_id.clone().unwrap_or_default()388 } else {389 chain_id390 })391 }392393 fn role(&self, is_dev: bool) -> Result<sc_service::Role> {394 self.base.base.role(is_dev)395 }396397 fn transaction_pool(&self) -> Result<sc_service::config::TransactionPoolOptions> {398 self.base.base.transaction_pool()399 }400401 fn state_cache_child_ratio(&self) -> Result<Option<usize>> {402 self.base.base.state_cache_child_ratio()403 }404405 fn rpc_methods(&self) -> Result<sc_service::config::RpcMethods> {406 self.base.base.rpc_methods()407 }408409 fn rpc_ws_max_connections(&self) -> Result<Option<usize>> {410 self.base.base.rpc_ws_max_connections()411 }412413 fn rpc_cors(&self, is_dev: bool) -> Result<Option<Vec<String>>> {414 self.base.base.rpc_cors(is_dev)415 }416417 fn default_heap_pages(&self) -> Result<Option<u64>> {418 self.base.base.default_heap_pages()419 }420421 fn force_authoring(&self) -> Result<bool> {422 self.base.base.force_authoring()423 }424425 fn disable_grandpa(&self) -> Result<bool> {426 self.base.base.disable_grandpa()427 }428429 fn max_runtime_instances(&self) -> Result<Option<usize>> {430 self.base.base.max_runtime_instances()431 }432433 fn announce_block(&self) -> Result<bool> {434 self.base.base.announce_block()435 }436437 fn telemetry_endpoints(438 &self,439 chain_spec: &Box<dyn ChainSpec>,440 ) -> Result<Option<sc_telemetry::TelemetryEndpoints>> {441 self.base.base.telemetry_endpoints(chain_spec)442 }443}