git.delta.rocks / unique-network / refs/commits / 1cbdff92adea

difftreelog

refactor add up-common

Daniel Shiposha2022-08-11parent: #7a36e4c.patch.diff
in: master

28 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1128,18 +1128,6 @@
 ]
 
 [[package]]
-name = "common-types"
-version = "0.9.24"
-dependencies = [
- "fp-rpc",
- "pallet-evm",
- "sp-consensus-aura",
- "sp-core",
- "sp-runtime",
- "sp-std",
-]
-
-[[package]]
 name = "concurrent-queue"
 version = "1.2.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -5294,7 +5282,6 @@
 name = "opal-runtime"
 version = "0.9.24"
 dependencies = [
- "common-types",
  "cumulus-pallet-aura-ext",
  "cumulus-pallet-dmp-queue",
  "cumulus-pallet-parachain-system",
@@ -5366,6 +5353,7 @@
  "sp-transaction-pool",
  "sp-version",
  "substrate-wasm-builder",
+ "up-common",
  "up-data-structs",
  "up-rpc",
  "up-sponsorship",
@@ -8610,7 +8598,6 @@
 name = "quartz-runtime"
 version = "0.9.24"
 dependencies = [
- "common-types",
  "cumulus-pallet-aura-ext",
  "cumulus-pallet-dmp-queue",
  "cumulus-pallet-parachain-system",
@@ -8682,6 +8669,7 @@
  "sp-transaction-pool",
  "sp-version",
  "substrate-wasm-builder",
+ "up-common",
  "up-data-structs",
  "up-rpc",
  "up-sponsorship",
@@ -11897,7 +11885,6 @@
 name = "tests"
 version = "0.1.0"
 dependencies = [
- "common-types",
  "evm-coder",
  "fp-evm-mapping",
  "frame-support",
@@ -12480,7 +12467,6 @@
 version = "0.9.24"
 dependencies = [
  "clap",
- "common-types",
  "cumulus-client-cli",
  "cumulus-client-collator",
  "cumulus-client-consensus-aura",
@@ -12559,6 +12545,7 @@
  "try-runtime-cli",
  "unique-rpc",
  "unique-runtime",
+ "up-common",
  "up-data-structs",
  "up-rpc",
 ]
@@ -12567,7 +12554,6 @@
 name = "unique-rpc"
 version = "0.1.0"
 dependencies = [
- "common-types",
  "fc-db",
  "fc-mapping-sync",
  "fc-rpc",
@@ -12608,6 +12594,7 @@
  "substrate-frame-rpc-system",
  "tokio 0.2.25",
  "uc-rpc",
+ "up-common",
  "up-data-structs",
  "up-rpc",
 ]
@@ -12616,7 +12603,6 @@
 name = "unique-runtime"
 version = "0.9.24"
 dependencies = [
- "common-types",
  "cumulus-pallet-aura-ext",
  "cumulus-pallet-dmp-queue",
  "cumulus-pallet-parachain-system",
@@ -12688,6 +12674,7 @@
  "sp-transaction-pool",
  "sp-version",
  "substrate-wasm-builder",
+ "up-common",
  "up-data-structs",
  "up-rpc",
  "up-sponsorship",
@@ -12725,6 +12712,19 @@
 checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
 
 [[package]]
+name = "up-common"
+version = "0.9.24"
+dependencies = [
+ "fp-rpc",
+ "frame-support",
+ "pallet-evm",
+ "sp-consensus-aura",
+ "sp-core",
+ "sp-runtime",
+ "sp-std",
+]
+
+[[package]]
 name = "up-data-structs"
 version = "0.2.1"
 dependencies = [
deletedcommon-types/Cargo.tomldiffbeforeafterboth
--- a/common-types/Cargo.toml
+++ /dev/null
@@ -1,50 +0,0 @@
-[package]
-authors = ['Unique Network <support@uniquenetwork.io>']
-description = 'Unique Runtime Common'
-edition = '2021'
-homepage = 'https://unique.network'
-license = 'All Rights Reserved'
-name = 'common-types'
-repository = 'https://github.com/UniqueNetwork/unique-chain'
-version = '0.9.24'
-
-[features]
-default = ['std']
-std = [
-    'sp-std/std',
-    'sp-runtime/std',
-    'sp-core/std',
-    'sp-consensus-aura/std',
-    'fp-rpc/std',
-    'pallet-evm/std',
-]
-
-[dependencies.sp-std]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.24"
-
-[dependencies.sp-runtime]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.24"
-
-[dependencies.sp-core]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.24"
-
-[dependencies.sp-consensus-aura]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.24"
-
-[dependencies.fp-rpc]
-default-features = false
-git = "https://github.com/uniquenetwork/frontier"
-branch = "unique-polkadot-v0.9.24"
-
-[dependencies.pallet-evm]
-default-features = false
-git = "https://github.com/uniquenetwork/frontier"
-branch = "unique-polkadot-v0.9.24"
deletedcommon-types/src/lib.rsdiffbeforeafterboth
--- a/common-types/src/lib.rs
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network 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.
-
-// Unique Network 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 Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-#![cfg_attr(not(feature = "std"), no_std)]
-
-use sp_runtime::{
-	generic,
-	traits::{Verify, IdentifyAccount},
-	MultiSignature,
-};
-
-/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
-/// the specifics of the runtime. They can then be made to be agnostic over specific formats
-/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
-/// to even the core data structures.
-pub mod opaque {
-	pub use sp_runtime::{generic, traits::BlakeTwo256, OpaqueExtrinsic as UncheckedExtrinsic};
-
-	pub use super::{BlockNumber, Signature, AccountId, Balance, Index, Hash, AuraId};
-
-	/// Opaque block header type.
-	pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
-
-	/// Opaque block type.
-	pub type Block = generic::Block<Header, UncheckedExtrinsic>;
-
-	pub trait RuntimeInstance {
-		type CrossAccountId: pallet_evm::account::CrossAccountId<sp_runtime::AccountId32>
-			+ Send
-			+ Sync
-			+ 'static;
-
-		type TransactionConverter: fp_rpc::ConvertTransaction<UncheckedExtrinsic>
-			+ Send
-			+ Sync
-			+ 'static;
-
-		fn get_transaction_converter() -> Self::TransactionConverter;
-	}
-}
-
-pub type SessionHandlers = ();
-
-/// An index to a block.
-pub type BlockNumber = u32;
-
-/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
-pub type Signature = MultiSignature;
-
-/// Some way of identifying an account on the chain. We intentionally make it equivalent
-/// to the public key of our transaction signing scheme.
-pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
-
-/// The type for looking up accounts. We don't expect more than 4 billion of them, but you
-/// never know...
-pub type AccountIndex = u32;
-
-/// Balance of an account.
-pub type Balance = u128;
-
-/// Index of a transaction in the chain.
-pub type Index = u32;
-
-/// A hash of some data used by the chain.
-pub type Hash = sp_core::H256;
-
-/// Digest item type.
-pub type DigestItem = generic::DigestItem;
-
-pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
modifiednode/cli/Cargo.tomldiffbeforeafterboth
--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -253,8 +253,8 @@
 ################################################################################
 # Local dependencies
 
-[dependencies.common-types]
-path = "../../common-types"
+[dependencies.up-common]
+path = "../../primitives/common"
 
 [dependencies.unique-runtime]
 path = '../../runtime/unique'
modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -23,7 +23,7 @@
 use serde::{Deserialize, Serialize};
 use serde_json::map::Map;
 
-use common_types::opaque::*;
+use up_common::types::opaque::*;
 
 #[cfg(feature = "unique-runtime")]
 pub use unique_runtime as default_runtime;
modifiednode/cli/src/command.rsdiffbeforeafterboth
before · node/cli/src/command.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license18// This file is part of Substrate.1920// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.21// SPDX-License-Identifier: Apache-2.02223// Licensed under the Apache License, Version 2.0 (the "License");24// you may not use this file except in compliance with the License.25// You may obtain a copy of the License at26//27// 	http://www.apache.org/licenses/LICENSE-2.028//29// Unless required by applicable law or agreed to in writing, software30// distributed under the License is distributed on an "AS IS" BASIS,31// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.32// See the License for the specific language governing permissions and33// limitations under the License.3435use crate::{36	chain_spec::{37		self, RuntimeId, RuntimeIdentification, ServiceId, ServiceIdentification, default_runtime,38	},39	cli::{Cli, RelayChainCli, Subcommand},40	service::{new_partial, start_node, start_dev_node},41};4243#[cfg(feature = "unique-runtime")]44use crate::service::UniqueRuntimeExecutor;4546#[cfg(feature = "quartz-runtime")]47use crate::service::QuartzRuntimeExecutor;4849use crate::service::{OpalRuntimeExecutor, DefaultRuntimeExecutor};5051use codec::Encode;52use cumulus_primitives_core::ParaId;53use cumulus_client_service::genesis::generate_genesis_block;54use std::{future::Future, pin::Pin};55use log::info;56use sc_cli::{57	ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,58	NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,59};60use sc_service::{61	config::{BasePath, PrometheusConfig},62};63use sp_core::hexdisplay::HexDisplay;64use sp_runtime::traits::{AccountIdConversion, Block as BlockT};65use std::{io::Write, net::SocketAddr, time::Duration};6667use common_types::opaque::Block;6869macro_rules! no_runtime_err {70	($chain_name:expr) => {71		format!(72			"No runtime valid runtime was found for chain {}",73			$chain_name74		)75	};76}7778fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {79	Ok(match id {80		"dev" => Box::new(chain_spec::development_config()),81		"" | "local" => Box::new(chain_spec::local_testnet_config()),82		path => {83			let path = std::path::PathBuf::from(path);84			let chain_spec = Box::new(chain_spec::OpalChainSpec::from_json_file(path.clone())?)85				as Box<dyn sc_service::ChainSpec>;8687			match chain_spec.runtime_id() {88				#[cfg(feature = "unique-runtime")]89				RuntimeId::Unique => Box::new(chain_spec::UniqueChainSpec::from_json_file(path)?),9091				#[cfg(feature = "quartz-runtime")]92				RuntimeId::Quartz => Box::new(chain_spec::QuartzChainSpec::from_json_file(path)?),9394				RuntimeId::Opal => chain_spec,95				RuntimeId::Unknown(chain) => return Err(no_runtime_err!(chain)),96			}97		}98	})99}100101impl SubstrateCli for Cli {102	// TODO use args103	fn impl_name() -> String {104		format!("{} Node", Self::node_name())105	}106107	fn impl_version() -> String {108		env!("SUBSTRATE_CLI_IMPL_VERSION").into()109	}110	// TODO use args111	fn description() -> String {112		format!(113			"{} Node\n\nThe command-line arguments provided first will be \114		passed to the parachain node, while the arguments provided after -- will be passed \115		to the relaychain node.\n\n\116		{} [parachain-args] -- [relaychain-args]",117			Self::node_name(),118			Self::executable_name()119		)120	}121122	fn author() -> String {123		env!("CARGO_PKG_AUTHORS").into()124	}125126	//TODO use args127	fn support_url() -> String {128		"support@unique.network".into()129	}130131	fn copyright_start_year() -> i32 {132		2019133	}134135	fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {136		load_spec(id)137	}138139	fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {140		match chain_spec.runtime_id() {141			#[cfg(feature = "unique-runtime")]142			RuntimeId::Unique => &unique_runtime::VERSION,143144			#[cfg(feature = "quartz-runtime")]145			RuntimeId::Quartz => &quartz_runtime::VERSION,146147			RuntimeId::Opal => &opal_runtime::VERSION,148			RuntimeId::Unknown(chain) => panic!("{}", no_runtime_err!(chain)),149		}150	}151}152153impl SubstrateCli for RelayChainCli {154	// TODO use args155	fn impl_name() -> String {156		format!("{} Node", Cli::node_name())157	}158159	fn impl_version() -> String {160		env!("SUBSTRATE_CLI_IMPL_VERSION").into()161	}162	// TODO use args163	fn description() -> String {164		format!(165			"{} Node\n\nThe command-line arguments provided first will be \166			passed to the parachain node, while the arguments provided after -- will be passed \167			to the relaychain node.\n\n\168			parachain-collator [parachain-args] -- [relaychain-args]",169			Cli::node_name()170		)171	}172173	fn author() -> String {174		env!("CARGO_PKG_AUTHORS").into()175	}176	// TODO use args177	fn support_url() -> String {178		"support@unique.network".into()179	}180181	fn copyright_start_year() -> i32 {182		2019183	}184185	fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {186		polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)187	}188189	fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {190		polkadot_cli::Cli::native_runtime_version(chain_spec)191	}192}193194#[allow(clippy::borrowed_box)]195fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {196	let mut storage = chain_spec.build_storage()?;197198	storage199		.top200		.remove(sp_core::storage::well_known_keys::CODE)201		.ok_or_else(|| "Could not find wasm file in genesis state!".into())202}203204macro_rules! async_run_with_runtime {205	(206		$runtime_api:path, $executor:path,207		$runner:ident, $components:ident, $cli:ident, $cmd:ident, $config:ident,208		$( $code:tt )*209	) => {210		$runner.async_run(|$config| {211			let $components = new_partial::<212				$runtime_api, $executor, _213			>(214				&$config,215				crate::service::parachain_build_import_queue,216			)?;217			let task_manager = $components.task_manager;218219			{ $( $code )* }.map(|v| (v, task_manager))220		})221	};222}223224macro_rules! construct_async_run {225	(|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{226		let runner = $cli.create_runner($cmd)?;227228		match runner.config().chain_spec.runtime_id() {229			#[cfg(feature = "unique-runtime")]230			RuntimeId::Unique => async_run_with_runtime!(231				unique_runtime::RuntimeApi, UniqueRuntimeExecutor,232				runner, $components, $cli, $cmd, $config, $( $code )*233			),234235			#[cfg(feature = "quartz-runtime")]236			RuntimeId::Quartz => async_run_with_runtime!(237				quartz_runtime::RuntimeApi, QuartzRuntimeExecutor,238				runner, $components, $cli, $cmd, $config, $( $code )*239			),240241			RuntimeId::Opal => async_run_with_runtime!(242				opal_runtime::RuntimeApi, OpalRuntimeExecutor,243				runner, $components, $cli, $cmd, $config, $( $code )*244			),245246			RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into())247		}248	}}249}250251macro_rules! start_node_using_chain_runtime {252	($start_node_fn:ident($config:expr $(, $($args:expr),+)?) $($code:tt)*) => {253		match $config.chain_spec.runtime_id() {254			#[cfg(feature = "unique-runtime")]255			RuntimeId::Unique => $start_node_fn::<256				unique_runtime::Runtime,257				unique_runtime::RuntimeApi,258				UniqueRuntimeExecutor,259			>($config $(, $($args),+)?) $($code)*,260261			#[cfg(feature = "quartz-runtime")]262			RuntimeId::Quartz => $start_node_fn::<263				quartz_runtime::Runtime,264				quartz_runtime::RuntimeApi,265				QuartzRuntimeExecutor,266			>($config $(, $($args),+)?) $($code)*,267268			RuntimeId::Opal => $start_node_fn::<269				opal_runtime::Runtime,270				opal_runtime::RuntimeApi,271				OpalRuntimeExecutor,272			>($config $(, $($args),+)?) $($code)*,273274			RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into()),275		}276	};277}278279/// Parse command line arguments into service configuration.280pub fn run() -> Result<()> {281	let cli = Cli::from_args();282283	match &cli.subcommand {284		Some(Subcommand::BuildSpec(cmd)) => {285			let runner = cli.create_runner(cmd)?;286			runner.sync_run(|config| cmd.run(config.chain_spec, config.network))287		}288		Some(Subcommand::CheckBlock(cmd)) => {289			construct_async_run!(|components, cli, cmd, config| {290				Ok(cmd.run(components.client, components.import_queue))291			})292		}293		Some(Subcommand::ExportBlocks(cmd)) => {294			construct_async_run!(|components, cli, cmd, config| {295				Ok(cmd.run(components.client, config.database))296			})297		}298		Some(Subcommand::ExportState(cmd)) => {299			construct_async_run!(|components, cli, cmd, config| {300				Ok(cmd.run(components.client, config.chain_spec))301			})302		}303		Some(Subcommand::ImportBlocks(cmd)) => {304			construct_async_run!(|components, cli, cmd, config| {305				Ok(cmd.run(components.client, components.import_queue))306			})307		}308		Some(Subcommand::PurgeChain(cmd)) => {309			let runner = cli.create_runner(cmd)?;310311			runner.sync_run(|config| {312				let polkadot_cli = RelayChainCli::new(313					&config,314					[RelayChainCli::executable_name()]315						.iter()316						.chain(cli.relaychain_args.iter()),317				);318319				let polkadot_config = SubstrateCli::create_configuration(320					&polkadot_cli,321					&polkadot_cli,322					config.tokio_handle.clone(),323				)324				.map_err(|err| format!("Relay chain argument error: {}", err))?;325326				cmd.run(config, polkadot_config)327			})328		}329		Some(Subcommand::Revert(cmd)) => construct_async_run!(|components, cli, cmd, config| {330			Ok(cmd.run(components.client, components.backend, None))331		}),332		Some(Subcommand::ExportGenesisState(params)) => {333			let mut builder = sc_cli::LoggerBuilder::new("");334			builder.with_profiling(sc_tracing::TracingReceiver::Log, "");335			let _ = builder.init();336337			let spec = load_spec(&params.chain.clone().unwrap_or_default())?;338			let state_version = Cli::native_runtime_version(&spec).state_version();339			let block: Block = generate_genesis_block(&spec, state_version)?;340			let raw_header = block.header().encode();341			let output_buf = if params.raw {342				raw_header343			} else {344				format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes()345			};346347			if let Some(output) = &params.output {348				std::fs::write(output, output_buf)?;349			} else {350				std::io::stdout().write_all(&output_buf)?;351			}352353			Ok(())354		}355		Some(Subcommand::ExportGenesisWasm(params)) => {356			let mut builder = sc_cli::LoggerBuilder::new("");357			builder.with_profiling(sc_tracing::TracingReceiver::Log, "");358			let _ = builder.init();359360			let raw_wasm_blob =361				extract_genesis_wasm(&cli.load_spec(&params.chain.clone().unwrap_or_default())?)?;362			let output_buf = if params.raw {363				raw_wasm_blob364			} else {365				format!("0x{:?}", HexDisplay::from(&raw_wasm_blob)).into_bytes()366			};367368			if let Some(output) = &params.output {369				std::fs::write(output, output_buf)?;370			} else {371				std::io::stdout().write_all(&output_buf)?;372			}373374			Ok(())375		}376		Some(Subcommand::Benchmark(cmd)) => {377			use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};378			let runner = cli.create_runner(cmd)?;379			// Switch on the concrete benchmark sub-command-380			match cmd {381				BenchmarkCmd::Pallet(cmd) => {382					if cfg!(feature = "runtime-benchmarks") {383						runner.sync_run(|config| cmd.run::<Block, DefaultRuntimeExecutor>(config))384					} else {385						Err("Benchmarking wasn't enabled when building the node. \386					You can enable it with `--features runtime-benchmarks`."387							.into())388					}389				}390				BenchmarkCmd::Block(cmd) => runner.sync_run(|config| {391					let partials = new_partial::<392						default_runtime::RuntimeApi,393						DefaultRuntimeExecutor,394						_,395					>(&config, crate::service::parachain_build_import_queue)?;396					cmd.run(partials.client)397				}),398				BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {399					let partials = new_partial::<400						default_runtime::RuntimeApi,401						DefaultRuntimeExecutor,402						_,403					>(&config, crate::service::parachain_build_import_queue)?;404					let db = partials.backend.expose_db();405					let storage = partials.backend.expose_storage();406407					cmd.run(config, partials.client.clone(), db, storage)408				}),409				BenchmarkCmd::Machine(cmd) => {410					runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()))411				}412				BenchmarkCmd::Overhead(_) => Err("Unsupported benchmarking command".into()),413			}414		}415		Some(Subcommand::TryRuntime(cmd)) => {416			if cfg!(feature = "try-runtime") {417				let runner = cli.create_runner(cmd)?;418419				// grab the task manager.420				let registry = &runner421					.config()422					.prometheus_config423					.as_ref()424					.map(|cfg| &cfg.registry);425				let task_manager =426					sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry)427						.map_err(|e| format!("Error: {:?}", e))?;428429				runner.async_run(|config| -> Result<(Pin<Box<dyn Future<Output = _>>>, _)> {430					Ok((431						match config.chain_spec.runtime_id() {432							#[cfg(feature = "unique-runtime")]433							RuntimeId::Unique => Box::pin(cmd.run::<Block, UniqueRuntimeExecutor>(config)),434435							#[cfg(feature = "quartz-runtime")]436							RuntimeId::Quartz => Box::pin(cmd.run::<Block, QuartzRuntimeExecutor>(config)),437438							RuntimeId::Opal => {439								Box::pin(cmd.run::<Block, OpalRuntimeExecutor>(config))440							}441							RuntimeId::Unknown(chain) => return Err(no_runtime_err!(chain).into()),442						},443						task_manager,444					))445				})446			} else {447				Err("Try-runtime must be enabled by `--features try-runtime`.".into())448			}449		}450		None => {451			let runner = cli.create_runner(&cli.run.normalize())?;452			let collator_options = cli.run.collator_options();453454			runner.run_node_until_exit(|config| async move {455				let hwbench = if !cli.no_hardware_benchmarks {456					config.database.path().map(|database_path| {457						let _ = std::fs::create_dir_all(&database_path);458						sc_sysinfo::gather_hwbench(Some(database_path))459					})460				} else {461					None462				};463464				let extensions = chain_spec::Extensions::try_get(&*config.chain_spec);465466				let service_id = config.chain_spec.service_id();467				let relay_chain_id = extensions.map(|e| e.relay_chain.clone());468				let is_dev_service = matches![service_id, ServiceId::Dev]469					|| relay_chain_id == Some("dev-service".into());470471				if is_dev_service {472					info!("Running Dev service");473474					let autoseal_interval = Duration::from_millis(cli.idle_autoseal_interval);475476					let mut config = config;477					if config.state_pruning == None {478						config.state_pruning = Some(sc_service::PruningMode::ArchiveAll);479					}480481					return start_node_using_chain_runtime! {482						start_dev_node(config, autoseal_interval).map_err(Into::into)483					};484				};485486				let para_id = extensions487					.map(|e| e.para_id)488					.ok_or("Could not find parachain ID in chain-spec.")?;489490				let polkadot_cli = RelayChainCli::new(491					&config,492					[RelayChainCli::executable_name()]493						.iter()494						.chain(cli.relaychain_args.iter()),495				);496497				let para_id = ParaId::from(para_id);498499				let parachain_account = AccountIdConversion::<polkadot_primitives::v2::AccountId>::into_account_truncating(&para_id);500501				let state_version =502					RelayChainCli::native_runtime_version(&config.chain_spec).state_version();503				let block: Block = generate_genesis_block(&config.chain_spec, state_version)504					.map_err(|e| format!("{:?}", e))?;505				let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));506				let genesis_hash = format!("0x{:?}", HexDisplay::from(&block.header().hash().0));507508				let polkadot_config = SubstrateCli::create_configuration(509					&polkadot_cli,510					&polkadot_cli,511					config.tokio_handle.clone(),512				)513				.map_err(|err| format!("Relay chain argument error: {}", err))?;514515				info!("Parachain id: {:?}", para_id);516				info!("Parachain Account: {}", parachain_account);517				info!("Parachain genesis state: {}", genesis_state);518				info!("Parachain genesis hash: {}", genesis_hash);519				info!(520					"Is collating: {}",521					if config.role.is_authority() {522						"yes"523					} else {524						"no"525					}526				);527528				start_node_using_chain_runtime! {529					start_node(config, polkadot_config, collator_options, para_id, hwbench)530						.await531						.map(|r| r.0)532						.map_err(Into::into)533				}534			})535		}536	}537}538539impl DefaultConfigurationValues for RelayChainCli {540	fn p2p_listen_port() -> u16 {541		30334542	}543544	fn rpc_ws_listen_port() -> u16 {545		9945546	}547548	fn rpc_http_listen_port() -> u16 {549		9934550	}551552	fn prometheus_listen_port() -> u16 {553		9616554	}555}556557impl CliConfiguration<Self> for RelayChainCli {558	fn shared_params(&self) -> &SharedParams {559		self.base.base.shared_params()560	}561562	fn import_params(&self) -> Option<&ImportParams> {563		self.base.base.import_params()564	}565566	fn network_params(&self) -> Option<&NetworkParams> {567		self.base.base.network_params()568	}569570	fn keystore_params(&self) -> Option<&KeystoreParams> {571		self.base.base.keystore_params()572	}573574	fn base_path(&self) -> Result<Option<BasePath>> {575		Ok(self576			.shared_params()577			.base_path()578			.or_else(|| self.base_path.clone().map(Into::into)))579	}580581	fn rpc_http(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {582		self.base.base.rpc_http(default_listen_port)583	}584585	fn rpc_ipc(&self) -> Result<Option<String>> {586		self.base.base.rpc_ipc()587	}588589	fn rpc_ws(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {590		self.base.base.rpc_ws(default_listen_port)591	}592593	fn prometheus_config(594		&self,595		default_listen_port: u16,596		chain_spec: &Box<dyn ChainSpec>,597	) -> Result<Option<PrometheusConfig>> {598		self.base599			.base600			.prometheus_config(default_listen_port, chain_spec)601	}602603	fn init<F>(604		&self,605		_support_url: &String,606		_impl_version: &String,607		_logger_hook: F,608		_config: &sc_service::Configuration,609	) -> Result<()> {610		unreachable!("PolkadotCli is never initialized; qed");611	}612613	fn chain_id(&self, is_dev: bool) -> Result<String> {614		let chain_id = self.base.base.chain_id(is_dev)?;615616		Ok(if chain_id.is_empty() {617			self.chain_id.clone().unwrap_or_default()618		} else {619			chain_id620		})621	}622623	fn role(&self, is_dev: bool) -> Result<sc_service::Role> {624		self.base.base.role(is_dev)625	}626627	fn transaction_pool(&self) -> Result<sc_service::config::TransactionPoolOptions> {628		self.base.base.transaction_pool()629	}630631	fn state_cache_child_ratio(&self) -> Result<Option<usize>> {632		self.base.base.state_cache_child_ratio()633	}634635	fn rpc_methods(&self) -> Result<sc_service::config::RpcMethods> {636		self.base.base.rpc_methods()637	}638639	fn rpc_ws_max_connections(&self) -> Result<Option<usize>> {640		self.base.base.rpc_ws_max_connections()641	}642643	fn rpc_cors(&self, is_dev: bool) -> Result<Option<Vec<String>>> {644		self.base.base.rpc_cors(is_dev)645	}646647	fn default_heap_pages(&self) -> Result<Option<u64>> {648		self.base.base.default_heap_pages()649	}650651	fn force_authoring(&self) -> Result<bool> {652		self.base.base.force_authoring()653	}654655	fn disable_grandpa(&self) -> Result<bool> {656		self.base.base.disable_grandpa()657	}658659	fn max_runtime_instances(&self) -> Result<Option<usize>> {660		self.base.base.max_runtime_instances()661	}662663	fn announce_block(&self) -> Result<bool> {664		self.base.base.announce_block()665	}666667	fn telemetry_endpoints(668		&self,669		chain_spec: &Box<dyn ChainSpec>,670	) -> Result<Option<sc_telemetry::TelemetryEndpoints>> {671		self.base.base.telemetry_endpoints(chain_spec)672	}673}
after · node/cli/src/command.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original license18// This file is part of Substrate.1920// Copyright (C) 2017-2021 Parity Technologies (UK) Ltd.21// SPDX-License-Identifier: Apache-2.02223// Licensed under the Apache License, Version 2.0 (the "License");24// you may not use this file except in compliance with the License.25// You may obtain a copy of the License at26//27// 	http://www.apache.org/licenses/LICENSE-2.028//29// Unless required by applicable law or agreed to in writing, software30// distributed under the License is distributed on an "AS IS" BASIS,31// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.32// See the License for the specific language governing permissions and33// limitations under the License.3435use crate::{36	chain_spec::{37		self, RuntimeId, RuntimeIdentification, ServiceId, ServiceIdentification, default_runtime,38	},39	cli::{Cli, RelayChainCli, Subcommand},40	service::{new_partial, start_node, start_dev_node},41};4243#[cfg(feature = "unique-runtime")]44use crate::service::UniqueRuntimeExecutor;4546#[cfg(feature = "quartz-runtime")]47use crate::service::QuartzRuntimeExecutor;4849use crate::service::{OpalRuntimeExecutor, DefaultRuntimeExecutor};5051use codec::Encode;52use cumulus_primitives_core::ParaId;53use cumulus_client_service::genesis::generate_genesis_block;54use std::{future::Future, pin::Pin};55use log::info;56use sc_cli::{57	ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,58	NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,59};60use sc_service::{61	config::{BasePath, PrometheusConfig},62};63use sp_core::hexdisplay::HexDisplay;64use sp_runtime::traits::{AccountIdConversion, Block as BlockT};65use std::{io::Write, net::SocketAddr, time::Duration};6667use up_common::types::opaque::Block;6869macro_rules! no_runtime_err {70	($chain_name:expr) => {71		format!(72			"No runtime valid runtime was found for chain {}",73			$chain_name74		)75	};76}7778fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {79	Ok(match id {80		"dev" => Box::new(chain_spec::development_config()),81		"" | "local" => Box::new(chain_spec::local_testnet_config()),82		path => {83			let path = std::path::PathBuf::from(path);84			let chain_spec = Box::new(chain_spec::OpalChainSpec::from_json_file(path.clone())?)85				as Box<dyn sc_service::ChainSpec>;8687			match chain_spec.runtime_id() {88				#[cfg(feature = "unique-runtime")]89				RuntimeId::Unique => Box::new(chain_spec::UniqueChainSpec::from_json_file(path)?),9091				#[cfg(feature = "quartz-runtime")]92				RuntimeId::Quartz => Box::new(chain_spec::QuartzChainSpec::from_json_file(path)?),9394				RuntimeId::Opal => chain_spec,95				RuntimeId::Unknown(chain) => return Err(no_runtime_err!(chain)),96			}97		}98	})99}100101impl SubstrateCli for Cli {102	// TODO use args103	fn impl_name() -> String {104		format!("{} Node", Self::node_name())105	}106107	fn impl_version() -> String {108		env!("SUBSTRATE_CLI_IMPL_VERSION").into()109	}110	// TODO use args111	fn description() -> String {112		format!(113			"{} Node\n\nThe command-line arguments provided first will be \114		passed to the parachain node, while the arguments provided after -- will be passed \115		to the relaychain node.\n\n\116		{} [parachain-args] -- [relaychain-args]",117			Self::node_name(),118			Self::executable_name()119		)120	}121122	fn author() -> String {123		env!("CARGO_PKG_AUTHORS").into()124	}125126	//TODO use args127	fn support_url() -> String {128		"support@unique.network".into()129	}130131	fn copyright_start_year() -> i32 {132		2019133	}134135	fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {136		load_spec(id)137	}138139	fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {140		match chain_spec.runtime_id() {141			#[cfg(feature = "unique-runtime")]142			RuntimeId::Unique => &unique_runtime::VERSION,143144			#[cfg(feature = "quartz-runtime")]145			RuntimeId::Quartz => &quartz_runtime::VERSION,146147			RuntimeId::Opal => &opal_runtime::VERSION,148			RuntimeId::Unknown(chain) => panic!("{}", no_runtime_err!(chain)),149		}150	}151}152153impl SubstrateCli for RelayChainCli {154	// TODO use args155	fn impl_name() -> String {156		format!("{} Node", Cli::node_name())157	}158159	fn impl_version() -> String {160		env!("SUBSTRATE_CLI_IMPL_VERSION").into()161	}162	// TODO use args163	fn description() -> String {164		format!(165			"{} Node\n\nThe command-line arguments provided first will be \166			passed to the parachain node, while the arguments provided after -- will be passed \167			to the relaychain node.\n\n\168			parachain-collator [parachain-args] -- [relaychain-args]",169			Cli::node_name()170		)171	}172173	fn author() -> String {174		env!("CARGO_PKG_AUTHORS").into()175	}176	// TODO use args177	fn support_url() -> String {178		"support@unique.network".into()179	}180181	fn copyright_start_year() -> i32 {182		2019183	}184185	fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {186		polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)187	}188189	fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {190		polkadot_cli::Cli::native_runtime_version(chain_spec)191	}192}193194#[allow(clippy::borrowed_box)]195fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {196	let mut storage = chain_spec.build_storage()?;197198	storage199		.top200		.remove(sp_core::storage::well_known_keys::CODE)201		.ok_or_else(|| "Could not find wasm file in genesis state!".into())202}203204macro_rules! async_run_with_runtime {205	(206		$runtime_api:path, $executor:path,207		$runner:ident, $components:ident, $cli:ident, $cmd:ident, $config:ident,208		$( $code:tt )*209	) => {210		$runner.async_run(|$config| {211			let $components = new_partial::<212				$runtime_api, $executor, _213			>(214				&$config,215				crate::service::parachain_build_import_queue,216			)?;217			let task_manager = $components.task_manager;218219			{ $( $code )* }.map(|v| (v, task_manager))220		})221	};222}223224macro_rules! construct_async_run {225	(|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{226		let runner = $cli.create_runner($cmd)?;227228		match runner.config().chain_spec.runtime_id() {229			#[cfg(feature = "unique-runtime")]230			RuntimeId::Unique => async_run_with_runtime!(231				unique_runtime::RuntimeApi, UniqueRuntimeExecutor,232				runner, $components, $cli, $cmd, $config, $( $code )*233			),234235			#[cfg(feature = "quartz-runtime")]236			RuntimeId::Quartz => async_run_with_runtime!(237				quartz_runtime::RuntimeApi, QuartzRuntimeExecutor,238				runner, $components, $cli, $cmd, $config, $( $code )*239			),240241			RuntimeId::Opal => async_run_with_runtime!(242				opal_runtime::RuntimeApi, OpalRuntimeExecutor,243				runner, $components, $cli, $cmd, $config, $( $code )*244			),245246			RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into())247		}248	}}249}250251macro_rules! start_node_using_chain_runtime {252	($start_node_fn:ident($config:expr $(, $($args:expr),+)?) $($code:tt)*) => {253		match $config.chain_spec.runtime_id() {254			#[cfg(feature = "unique-runtime")]255			RuntimeId::Unique => $start_node_fn::<256				unique_runtime::Runtime,257				unique_runtime::RuntimeApi,258				UniqueRuntimeExecutor,259			>($config $(, $($args),+)?) $($code)*,260261			#[cfg(feature = "quartz-runtime")]262			RuntimeId::Quartz => $start_node_fn::<263				quartz_runtime::Runtime,264				quartz_runtime::RuntimeApi,265				QuartzRuntimeExecutor,266			>($config $(, $($args),+)?) $($code)*,267268			RuntimeId::Opal => $start_node_fn::<269				opal_runtime::Runtime,270				opal_runtime::RuntimeApi,271				OpalRuntimeExecutor,272			>($config $(, $($args),+)?) $($code)*,273274			RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into()),275		}276	};277}278279/// Parse command line arguments into service configuration.280pub fn run() -> Result<()> {281	let cli = Cli::from_args();282283	match &cli.subcommand {284		Some(Subcommand::BuildSpec(cmd)) => {285			let runner = cli.create_runner(cmd)?;286			runner.sync_run(|config| cmd.run(config.chain_spec, config.network))287		}288		Some(Subcommand::CheckBlock(cmd)) => {289			construct_async_run!(|components, cli, cmd, config| {290				Ok(cmd.run(components.client, components.import_queue))291			})292		}293		Some(Subcommand::ExportBlocks(cmd)) => {294			construct_async_run!(|components, cli, cmd, config| {295				Ok(cmd.run(components.client, config.database))296			})297		}298		Some(Subcommand::ExportState(cmd)) => {299			construct_async_run!(|components, cli, cmd, config| {300				Ok(cmd.run(components.client, config.chain_spec))301			})302		}303		Some(Subcommand::ImportBlocks(cmd)) => {304			construct_async_run!(|components, cli, cmd, config| {305				Ok(cmd.run(components.client, components.import_queue))306			})307		}308		Some(Subcommand::PurgeChain(cmd)) => {309			let runner = cli.create_runner(cmd)?;310311			runner.sync_run(|config| {312				let polkadot_cli = RelayChainCli::new(313					&config,314					[RelayChainCli::executable_name()]315						.iter()316						.chain(cli.relaychain_args.iter()),317				);318319				let polkadot_config = SubstrateCli::create_configuration(320					&polkadot_cli,321					&polkadot_cli,322					config.tokio_handle.clone(),323				)324				.map_err(|err| format!("Relay chain argument error: {}", err))?;325326				cmd.run(config, polkadot_config)327			})328		}329		Some(Subcommand::Revert(cmd)) => construct_async_run!(|components, cli, cmd, config| {330			Ok(cmd.run(components.client, components.backend, None))331		}),332		Some(Subcommand::ExportGenesisState(params)) => {333			let mut builder = sc_cli::LoggerBuilder::new("");334			builder.with_profiling(sc_tracing::TracingReceiver::Log, "");335			let _ = builder.init();336337			let spec = load_spec(&params.chain.clone().unwrap_or_default())?;338			let state_version = Cli::native_runtime_version(&spec).state_version();339			let block: Block = generate_genesis_block(&spec, state_version)?;340			let raw_header = block.header().encode();341			let output_buf = if params.raw {342				raw_header343			} else {344				format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes()345			};346347			if let Some(output) = &params.output {348				std::fs::write(output, output_buf)?;349			} else {350				std::io::stdout().write_all(&output_buf)?;351			}352353			Ok(())354		}355		Some(Subcommand::ExportGenesisWasm(params)) => {356			let mut builder = sc_cli::LoggerBuilder::new("");357			builder.with_profiling(sc_tracing::TracingReceiver::Log, "");358			let _ = builder.init();359360			let raw_wasm_blob =361				extract_genesis_wasm(&cli.load_spec(&params.chain.clone().unwrap_or_default())?)?;362			let output_buf = if params.raw {363				raw_wasm_blob364			} else {365				format!("0x{:?}", HexDisplay::from(&raw_wasm_blob)).into_bytes()366			};367368			if let Some(output) = &params.output {369				std::fs::write(output, output_buf)?;370			} else {371				std::io::stdout().write_all(&output_buf)?;372			}373374			Ok(())375		}376		Some(Subcommand::Benchmark(cmd)) => {377			use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};378			let runner = cli.create_runner(cmd)?;379			// Switch on the concrete benchmark sub-command-380			match cmd {381				BenchmarkCmd::Pallet(cmd) => {382					if cfg!(feature = "runtime-benchmarks") {383						runner.sync_run(|config| cmd.run::<Block, DefaultRuntimeExecutor>(config))384					} else {385						Err("Benchmarking wasn't enabled when building the node. \386					You can enable it with `--features runtime-benchmarks`."387							.into())388					}389				}390				BenchmarkCmd::Block(cmd) => runner.sync_run(|config| {391					let partials = new_partial::<392						default_runtime::RuntimeApi,393						DefaultRuntimeExecutor,394						_,395					>(&config, crate::service::parachain_build_import_queue)?;396					cmd.run(partials.client)397				}),398				BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {399					let partials = new_partial::<400						default_runtime::RuntimeApi,401						DefaultRuntimeExecutor,402						_,403					>(&config, crate::service::parachain_build_import_queue)?;404					let db = partials.backend.expose_db();405					let storage = partials.backend.expose_storage();406407					cmd.run(config, partials.client.clone(), db, storage)408				}),409				BenchmarkCmd::Machine(cmd) => {410					runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()))411				}412				BenchmarkCmd::Overhead(_) => Err("Unsupported benchmarking command".into()),413			}414		}415		Some(Subcommand::TryRuntime(cmd)) => {416			if cfg!(feature = "try-runtime") {417				let runner = cli.create_runner(cmd)?;418419				// grab the task manager.420				let registry = &runner421					.config()422					.prometheus_config423					.as_ref()424					.map(|cfg| &cfg.registry);425				let task_manager =426					sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry)427						.map_err(|e| format!("Error: {:?}", e))?;428429				runner.async_run(|config| -> Result<(Pin<Box<dyn Future<Output = _>>>, _)> {430					Ok((431						match config.chain_spec.runtime_id() {432							#[cfg(feature = "unique-runtime")]433							RuntimeId::Unique => Box::pin(cmd.run::<Block, UniqueRuntimeExecutor>(config)),434435							#[cfg(feature = "quartz-runtime")]436							RuntimeId::Quartz => Box::pin(cmd.run::<Block, QuartzRuntimeExecutor>(config)),437438							RuntimeId::Opal => {439								Box::pin(cmd.run::<Block, OpalRuntimeExecutor>(config))440							}441							RuntimeId::Unknown(chain) => return Err(no_runtime_err!(chain).into()),442						},443						task_manager,444					))445				})446			} else {447				Err("Try-runtime must be enabled by `--features try-runtime`.".into())448			}449		}450		None => {451			let runner = cli.create_runner(&cli.run.normalize())?;452			let collator_options = cli.run.collator_options();453454			runner.run_node_until_exit(|config| async move {455				let hwbench = if !cli.no_hardware_benchmarks {456					config.database.path().map(|database_path| {457						let _ = std::fs::create_dir_all(&database_path);458						sc_sysinfo::gather_hwbench(Some(database_path))459					})460				} else {461					None462				};463464				let extensions = chain_spec::Extensions::try_get(&*config.chain_spec);465466				let service_id = config.chain_spec.service_id();467				let relay_chain_id = extensions.map(|e| e.relay_chain.clone());468				let is_dev_service = matches![service_id, ServiceId::Dev]469					|| relay_chain_id == Some("dev-service".into());470471				if is_dev_service {472					info!("Running Dev service");473474					let autoseal_interval = Duration::from_millis(cli.idle_autoseal_interval);475476					let mut config = config;477					if config.state_pruning == None {478						config.state_pruning = Some(sc_service::PruningMode::ArchiveAll);479					}480481					return start_node_using_chain_runtime! {482						start_dev_node(config, autoseal_interval).map_err(Into::into)483					};484				};485486				let para_id = extensions487					.map(|e| e.para_id)488					.ok_or("Could not find parachain ID in chain-spec.")?;489490				let polkadot_cli = RelayChainCli::new(491					&config,492					[RelayChainCli::executable_name()]493						.iter()494						.chain(cli.relaychain_args.iter()),495				);496497				let para_id = ParaId::from(para_id);498499				let parachain_account = AccountIdConversion::<polkadot_primitives::v2::AccountId>::into_account_truncating(&para_id);500501				let state_version =502					RelayChainCli::native_runtime_version(&config.chain_spec).state_version();503				let block: Block = generate_genesis_block(&config.chain_spec, state_version)504					.map_err(|e| format!("{:?}", e))?;505				let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));506				let genesis_hash = format!("0x{:?}", HexDisplay::from(&block.header().hash().0));507508				let polkadot_config = SubstrateCli::create_configuration(509					&polkadot_cli,510					&polkadot_cli,511					config.tokio_handle.clone(),512				)513				.map_err(|err| format!("Relay chain argument error: {}", err))?;514515				info!("Parachain id: {:?}", para_id);516				info!("Parachain Account: {}", parachain_account);517				info!("Parachain genesis state: {}", genesis_state);518				info!("Parachain genesis hash: {}", genesis_hash);519				info!(520					"Is collating: {}",521					if config.role.is_authority() {522						"yes"523					} else {524						"no"525					}526				);527528				start_node_using_chain_runtime! {529					start_node(config, polkadot_config, collator_options, para_id, hwbench)530						.await531						.map(|r| r.0)532						.map_err(Into::into)533				}534			})535		}536	}537}538539impl DefaultConfigurationValues for RelayChainCli {540	fn p2p_listen_port() -> u16 {541		30334542	}543544	fn rpc_ws_listen_port() -> u16 {545		9945546	}547548	fn rpc_http_listen_port() -> u16 {549		9934550	}551552	fn prometheus_listen_port() -> u16 {553		9616554	}555}556557impl CliConfiguration<Self> for RelayChainCli {558	fn shared_params(&self) -> &SharedParams {559		self.base.base.shared_params()560	}561562	fn import_params(&self) -> Option<&ImportParams> {563		self.base.base.import_params()564	}565566	fn network_params(&self) -> Option<&NetworkParams> {567		self.base.base.network_params()568	}569570	fn keystore_params(&self) -> Option<&KeystoreParams> {571		self.base.base.keystore_params()572	}573574	fn base_path(&self) -> Result<Option<BasePath>> {575		Ok(self576			.shared_params()577			.base_path()578			.or_else(|| self.base_path.clone().map(Into::into)))579	}580581	fn rpc_http(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {582		self.base.base.rpc_http(default_listen_port)583	}584585	fn rpc_ipc(&self) -> Result<Option<String>> {586		self.base.base.rpc_ipc()587	}588589	fn rpc_ws(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {590		self.base.base.rpc_ws(default_listen_port)591	}592593	fn prometheus_config(594		&self,595		default_listen_port: u16,596		chain_spec: &Box<dyn ChainSpec>,597	) -> Result<Option<PrometheusConfig>> {598		self.base599			.base600			.prometheus_config(default_listen_port, chain_spec)601	}602603	fn init<F>(604		&self,605		_support_url: &String,606		_impl_version: &String,607		_logger_hook: F,608		_config: &sc_service::Configuration,609	) -> Result<()> {610		unreachable!("PolkadotCli is never initialized; qed");611	}612613	fn chain_id(&self, is_dev: bool) -> Result<String> {614		let chain_id = self.base.base.chain_id(is_dev)?;615616		Ok(if chain_id.is_empty() {617			self.chain_id.clone().unwrap_or_default()618		} else {619			chain_id620		})621	}622623	fn role(&self, is_dev: bool) -> Result<sc_service::Role> {624		self.base.base.role(is_dev)625	}626627	fn transaction_pool(&self) -> Result<sc_service::config::TransactionPoolOptions> {628		self.base.base.transaction_pool()629	}630631	fn state_cache_child_ratio(&self) -> Result<Option<usize>> {632		self.base.base.state_cache_child_ratio()633	}634635	fn rpc_methods(&self) -> Result<sc_service::config::RpcMethods> {636		self.base.base.rpc_methods()637	}638639	fn rpc_ws_max_connections(&self) -> Result<Option<usize>> {640		self.base.base.rpc_ws_max_connections()641	}642643	fn rpc_cors(&self, is_dev: bool) -> Result<Option<Vec<String>>> {644		self.base.base.rpc_cors(is_dev)645	}646647	fn default_heap_pages(&self) -> Result<Option<u64>> {648		self.base.base.default_heap_pages()649	}650651	fn force_authoring(&self) -> Result<bool> {652		self.base.base.force_authoring()653	}654655	fn disable_grandpa(&self) -> Result<bool> {656		self.base.base.disable_grandpa()657	}658659	fn max_runtime_instances(&self) -> Result<Option<usize>> {660		self.base.base.max_runtime_instances()661	}662663	fn announce_block(&self) -> Result<bool> {664		self.base.base.announce_block()665	}666667	fn telemetry_endpoints(668		&self,669		chain_spec: &Box<dyn ChainSpec>,670	) -> Result<Option<sc_telemetry::TelemetryEndpoints>> {671		self.base.base.telemetry_endpoints(chain_spec)672	}673}
modifiednode/cli/src/service.rsdiffbeforeafterboth
--- a/node/cli/src/service.rs
+++ b/node/cli/src/service.rs
@@ -63,7 +63,7 @@
 use fc_rpc_core::types::FilterPool;
 use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};
 
-use common_types::opaque::{AuraId, RuntimeInstance, AccountId, Balance, Index, Hash, Block};
+use up_common::types::opaque::{AuraId, RuntimeInstance, AccountId, Balance, Index, Hash, Block};
 
 // RMRK
 use up_data_structs::{
modifiednode/rpc/Cargo.tomldiffbeforeafterboth
--- a/node/rpc/Cargo.toml
+++ b/node/rpc/Cargo.toml
@@ -49,7 +49,7 @@
 fc-mapping-sync = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.24" }
 
 pallet-common = { default-features = false, path = "../../pallets/common" }
-common-types = { path = "../../common-types" }
+up-common = { path = "../../primitives/common" }
 pallet-unique = { path = "../../pallets/unique" }
 uc-rpc = { path = "../../client/rpc" }
 up-rpc = { path = "../../primitives/rpc" }
modifiednode/rpc/src/lib.rsdiffbeforeafterboth
--- a/node/rpc/src/lib.rs
+++ b/node/rpc/src/lib.rs
@@ -40,7 +40,7 @@
 use sc_service::TransactionPool;
 use std::{collections::BTreeMap, sync::Arc};
 
-use common_types::opaque::{Hash, AccountId, RuntimeInstance, Index, Block, BlockNumber, Balance};
+use up_common::types::opaque::{Hash, AccountId, RuntimeInstance, Index, Block, BlockNumber, Balance};
 
 // RMRK
 use up_data_structs::{
modifiedruntime/common/config/ethereum.rsdiffbeforeafterboth
--- a/runtime/common/config/ethereum.rs
+++ b/runtime/common/config/ethereum.rs
@@ -7,12 +7,13 @@
 use sp_runtime::{RuntimeAppPublic, Perbill};
 use crate::{
 	runtime_common::{
-		constants::*, dispatch::CollectionDispatchT, ethereum::sponsoring::EvmSponsorshipHandler,
+		dispatch::CollectionDispatchT, ethereum::sponsoring::EvmSponsorshipHandler,
 		config::sponsoring::DefaultSponsoringRateLimit, DealWithFees,
 	},
 	Runtime, Aura, Balances, Event, ChainId,
 };
 use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping};
+use up_common::constants::*;
 
 pub type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;
 
modifiedruntime/common/config/orml.rsdiffbeforeafterboth
--- a/runtime/common/config/orml.rs
+++ b/runtime/common/config/orml.rs
@@ -16,8 +16,11 @@
 
 use frame_support::parameter_types;
 use frame_system::EnsureSigned;
-use crate::{runtime_common::constants::*, Runtime, Event, RelayChainBlockNumberProvider};
-use common_types::{AccountId, Balance};
+use crate::{Runtime, Event, RelayChainBlockNumberProvider};
+use up_common::{
+	types::{AccountId, Balance},
+	constants::*,
+};
 
 parameter_types! {
 	pub const MinVestedTransfer: Balance = 10 * UNIQUE;
modifiedruntime/common/config/pallets/mod.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -18,7 +18,6 @@
 use sp_runtime::traits::AccountIdConversion;
 use crate::{
 	runtime_common::{
-		constants::*,
 		dispatch::CollectionDispatchT,
 		config::{substrate::TreasuryModuleId, ethereum::EvmCollectionHelpersAddress},
 		weights::CommonWeights,
@@ -26,7 +25,10 @@
 	},
 	Runtime, Event, Call, Balances,
 };
-use common_types::{AccountId, Balance, BlockNumber};
+use up_common::{
+	types::{AccountId, Balance, BlockNumber},
+	constants::*,
+};
 use up_data_structs::{
 	mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},
 };
modifiedruntime/common/config/pallets/scheduler.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/scheduler.rs
+++ b/runtime/common/config/pallets/scheduler.rs
@@ -22,7 +22,7 @@
 	runtime_common::{scheduler::SchedulerPaymentExecutor, config::substrate::RuntimeBlockWeights},
 	Runtime, Call, Event, Origin, OriginCaller, Balances,
 };
-use common_types::AccountId;
+use up_common::types::AccountId;
 
 parameter_types! {
 	pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *
modifiedruntime/common/config/parachain.rsdiffbeforeafterboth
--- a/runtime/common/config/parachain.rs
+++ b/runtime/common/config/parachain.rs
@@ -15,7 +15,8 @@
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
 use frame_support::{weights::Weight, parameter_types};
-use crate::{runtime_common::constants::*, Runtime, Event, XcmpQueue, DmpQueue};
+use crate::{Runtime, Event, XcmpQueue, DmpQueue};
+use up_common::constants::*;
 
 parameter_types! {
 	pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;
modifiedruntime/common/config/sponsoring.rsdiffbeforeafterboth
--- a/runtime/common/config/sponsoring.rs
+++ b/runtime/common/config/sponsoring.rs
@@ -16,10 +16,10 @@
 
 use frame_support::parameter_types;
 use crate::{
-	runtime_common::{constants::*, sponsoring::UniqueSponsorshipHandler},
+	runtime_common::{sponsoring::UniqueSponsorshipHandler},
 	Runtime,
 };
-use common_types::BlockNumber;
+use up_common::{types::BlockNumber, constants::*};
 
 parameter_types! {
 	pub const DefaultSponsoringRateLimit: BlockNumber = 1 * DAYS;
modifiedruntime/common/config/substrate.rsdiffbeforeafterboth
--- a/runtime/common/config/substrate.rs
+++ b/runtime/common/config/substrate.rs
@@ -35,10 +35,10 @@
 use sp_arithmetic::traits::{BaseArithmetic, Unsigned};
 use smallvec::smallvec;
 use crate::{
-	runtime_common::{DealWithFees, constants::*},
-	Runtime, Event, Call, Origin, PalletInfo, System, Balances, Treasury, SS58Prefix, Version,
+	runtime_common::DealWithFees, Runtime, Event, Call, Origin, PalletInfo, System, Balances,
+	Treasury, SS58Prefix, Version,
 };
-use common_types::*;
+use up_common::{types::*, constants::*};
 
 parameter_types! {
 	pub const BlockHashCount: BlockNumber = 2400;
modifiedruntime/common/config/xcm.rsdiffbeforeafterboth
--- a/runtime/common/config/xcm.rs
+++ b/runtime/common/config/xcm.rs
@@ -44,10 +44,13 @@
 use xcm_executor::{Config, XcmExecutor, Assets};
 use sp_std::marker::PhantomData;
 use crate::{
-	runtime_common::{constants::*, config::substrate::LinearFee},
-	Runtime, Call, Event, Origin, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue,
+	runtime_common::config::substrate::LinearFee, Runtime, Call, Event, Origin, Balances,
+	ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue,
+};
+use up_common::{
+	types::{AccountId, Balance},
+	constants::*,
 };
-use common_types::{AccountId, Balance};
 
 parameter_types! {
 	pub const RelayLocation: MultiLocation = MultiLocation::parent();
modifiedruntime/common/constants.rsdiffbeforeafterboth
--- a/runtime/common/constants.rs
+++ b/runtime/common/constants.rs
@@ -19,7 +19,7 @@
 	parameter_types,
 	weights::{Weight, constants::WEIGHT_PER_SECOND},
 };
-use common_types::{BlockNumber, Balance};
+use up_common::types::{BlockNumber, Balance};
 
 pub const MILLISECS_PER_BLOCK: u64 = 12000;
 
modifiedruntime/common/instance.rsdiffbeforeafterboth
--- a/runtime/common/instance.rs
+++ b/runtime/common/instance.rs
@@ -4,7 +4,7 @@
 	},
 	Runtime,
 };
-use common_types::opaque::RuntimeInstance;
+use up_common::types::opaque::RuntimeInstance;
 
 impl RuntimeInstance for Runtime {
 	type CrossAccountId = CrossAccountId;
modifiedruntime/common/mod.rsdiffbeforeafterboth
--- a/runtime/common/mod.rs
+++ b/runtime/common/mod.rs
@@ -41,7 +41,7 @@
 	Runtime, Call, Balances, Treasury, Aura, Signature, AllPalletsReversedWithSystemFirst,
 	InherentDataExt,
 };
-use common_types::{AccountId, BlockNumber};
+use up_common::types::{AccountId, BlockNumber};
 
 #[macro_export]
 macro_rules! unsupported {
modifiedruntime/common/scheduler.rsdiffbeforeafterboth
--- a/runtime/common/scheduler.rs
+++ b/runtime/common/scheduler.rs
@@ -25,7 +25,7 @@
 	DispatchErrorWithPostInfo, DispatchError,
 };
 use crate::{Runtime, Call, Origin, Balances, ChargeTransactionPayment};
-use common_types::{AccountId, Balance};
+use up_common::types::{AccountId, Balance};
 use fp_self_contained::SelfContainedCall;
 use pallet_unique_scheduler::DispatchCall;
 
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -113,7 +113,7 @@
     'xcm/std',
     'xcm-builder/std',
     'xcm-executor/std',
-    'common-types/std',
+    'up-common/std',
     'rmrk-rpc/std',
     'evm-coder/std',
     'up-sponsorship/std',
@@ -403,7 +403,7 @@
 
 [dependencies]
 log = { version = "0.4.16", default-features = false }
-common-types = { path = "../../common-types", default-features = false }
+up-common = { path = "../../primitives/common", default-features = false }
 scale-info = { version = "2.0.1", default-features = false, features = [
     "derive",
 ] }
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -30,7 +30,7 @@
 use sp_version::RuntimeVersion;
 use sp_runtime::create_runtime_str;
 
-use common_types::*;
+use up_common::types::*;
 
 #[path = "../../common/mod.rs"]
 mod runtime_common;
modifiedruntime/quartz/Cargo.tomldiffbeforeafterboth
--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -113,7 +113,7 @@
     'xcm/std',
     'xcm-builder/std',
     'xcm-executor/std',
-    'common-types/std',
+    'up-common/std',
 
     "orml-vesting/std",
 ]
@@ -408,7 +408,7 @@
 
 [dependencies]
 log = { version = "0.4.16", default-features = false }
-common-types = { path = "../../common-types", default-features = false }
+up-common = { path = "../../primitives/common", default-features = false }
 scale-info = { version = "2.0.1", default-features = false, features = [
     "derive",
 ] }
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -30,7 +30,7 @@
 use sp_version::RuntimeVersion;
 use sp_runtime::create_runtime_str;
 
-use common_types::*;
+use up_common::types::*;
 
 #[path = "../../common/mod.rs"]
 mod runtime_common;
modifiedruntime/tests/Cargo.tomldiffbeforeafterboth
--- a/runtime/tests/Cargo.toml
+++ b/runtime/tests/Cargo.toml
@@ -42,6 +42,5 @@
 ] }
 scale-info = "*"
 
-common-types = { path = "../../common-types", default-features = false }
 evm-coder = { default-features = false, path = '../../crates/evm-coder' }
 up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = 'polkadot-v0.9.24' }
modifiedruntime/unique/Cargo.tomldiffbeforeafterboth
--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -114,7 +114,7 @@
     'xcm/std',
     'xcm-builder/std',
     'xcm-executor/std',
-    'common-types/std',
+    'up-common/std',
 
     "orml-vesting/std",
 ]
@@ -401,7 +401,7 @@
 
 [dependencies]
 log = { version = "0.4.16", default-features = false }
-common-types = { path = "../../common-types", default-features = false }
+up-common = { path = "../../primitives/common", default-features = false }
 scale-info = { version = "2.0.1", default-features = false, features = [
     "derive",
 ] }
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -30,7 +30,7 @@
 use sp_version::RuntimeVersion;
 use sp_runtime::create_runtime_str;
 
-use common_types::*;
+use up_common::types::*;
 
 #[path = "../../common/mod.rs"]
 mod runtime_common;