difftreelog
Implement autoseal in dev mode
in: master
4 files changed
node/cli/Cargo.tomldiffbeforeafterboth--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -168,6 +168,9 @@
[dependencies.serde_json]
version = '1.0.68'
+[dependencies.sc-consensus-manual-seal]
+git = 'https://github.com/paritytech/substrate.git'
+branch = 'polkadot-v0.9.17'
################################################################################
# Cumulus dependencies
node/cli/src/chain_spec.rsdiffbeforeafterboth--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -68,6 +68,25 @@
}
}
+pub enum ServiceId {
+ Prod,
+ Dev
+}
+
+pub trait ServiceIdentification {
+ fn service_id(&self) -> ServiceId;
+}
+
+impl ServiceIdentification for Box<dyn sc_service::ChainSpec> {
+ fn service_id(&self) -> ServiceId {
+ if self.id().ends_with("dev") {
+ ServiceId::Dev
+ } else {
+ ServiceId::Prod
+ }
+ }
+}
+
/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
node/cli/src/command.rsdiffbeforeafterboth1// 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::{self, RuntimeId, RuntimeIdentification},37 cli::{Cli, RelayChainCli, Subcommand},38 service::new_partial,39};4041#[cfg(feature = "unique-runtime")]42use crate::service::UniqueRuntimeExecutor;4344#[cfg(feature = "quartz-runtime")]45use crate::service::QuartzRuntimeExecutor;4647use crate::service::OpalRuntimeExecutor;4849use codec::Encode;50use cumulus_primitives_core::ParaId;51use cumulus_client_service::genesis::generate_genesis_block;52use log::info;53use polkadot_parachain::primitives::AccountIdConversion;54use sc_cli::{55 ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,56 NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,57};58use sc_service::{59 config::{BasePath, PrometheusConfig},60};61use sp_core::hexdisplay::HexDisplay;62use sp_runtime::traits::Block as BlockT;63use std::{io::Write, net::SocketAddr};6465use unique_runtime_common::types::Block;6667macro_rules! no_runtime_err {68 ($chain_name:expr) => {69 format!(70 "No runtime valid runtime was found for chain {}",71 $chain_name72 )73 };74}7576fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {77 Ok(match id {78 "westend-local" => Box::new(chain_spec::local_testnet_westend_config()),79 "rococo-local" => Box::new(chain_spec::local_testnet_rococo_config()),80 "dev" => Box::new(chain_spec::development_config()),81 "" | "local" => Box::new(chain_spec::local_testnet_rococo_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 "Unique Node".into()105 }106107 fn impl_version() -> String {108 env!("SUBSTRATE_CLI_IMPL_VERSION").into()109 }110 // TODO use args111 fn description() -> String {112 format!(113 "Unique 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::executable_name()118 )119 }120121 fn author() -> String {122 env!("CARGO_PKG_AUTHORS").into()123 }124125 //TODO use args126 fn support_url() -> String {127 "support@unique.network".into()128 }129130 fn copyright_start_year() -> i32 {131 2019132 }133134 fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {135 load_spec(id)136 }137138 fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {139 match chain_spec.runtime_id() {140 #[cfg(feature = "unique-runtime")]141 RuntimeId::Unique => &unique_runtime::VERSION,142143 #[cfg(feature = "quartz-runtime")]144 RuntimeId::Quartz => &quartz_runtime::VERSION,145146 RuntimeId::Opal => &opal_runtime::VERSION,147 RuntimeId::Unknown(chain) => panic!("{}", no_runtime_err!(chain)),148 }149 }150}151152impl SubstrateCli for RelayChainCli {153 // TODO use args154 fn impl_name() -> String {155 "Unique Node".into()156 }157158 fn impl_version() -> String {159 env!("SUBSTRATE_CLI_IMPL_VERSION").into()160 }161 // TODO use args162 fn description() -> String {163 "Unique Node\n\nThe command-line arguments provided first will be \164 passed to the parachain node, while the arguments provided after -- will be passed \165 to the relaychain node.\n\n\166 parachain-collator [parachain-args] -- [relaychain-args]"167 .into()168 }169170 fn author() -> String {171 env!("CARGO_PKG_AUTHORS").into()172 }173 // TODO use args174 fn support_url() -> String {175 "support@unique.network".into()176 }177178 fn copyright_start_year() -> i32 {179 2019180 }181182 fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {183 polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)184 }185186 fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {187 polkadot_cli::Cli::native_runtime_version(chain_spec)188 }189}190191#[allow(clippy::borrowed_box)]192fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {193 let mut storage = chain_spec.build_storage()?;194195 storage196 .top197 .remove(sp_core::storage::well_known_keys::CODE)198 .ok_or_else(|| "Could not find wasm file in genesis state!".into())199}200201macro_rules! async_run_with_runtime {202 (203 $runtime_api:path, $executor:path,204 $runner:ident, $components:ident, $cli:ident, $cmd:ident, $config:ident,205 $( $code:tt )*206 ) => {207 $runner.async_run(|$config| {208 let $components = new_partial::<209 $runtime_api, $executor, _210 >(211 &$config,212 crate::service::parachain_build_import_queue,213 )?;214 let task_manager = $components.task_manager;215216 { $( $code )* }.map(|v| (v, task_manager))217 })218 };219}220221macro_rules! construct_async_run {222 (|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{223 let runner = $cli.create_runner($cmd)?;224225 match runner.config().chain_spec.runtime_id() {226 #[cfg(feature = "unique-runtime")]227 RuntimeId::Unique => async_run_with_runtime!(228 unique_runtime::RuntimeApi, UniqueRuntimeExecutor,229 runner, $components, $cli, $cmd, $config, $( $code )*230 ),231232 #[cfg(feature = "quartz-runtime")]233 RuntimeId::Quartz => async_run_with_runtime!(234 quartz_runtime::RuntimeApi, QuartzRuntimeExecutor,235 runner, $components, $cli, $cmd, $config, $( $code )*236 ),237238 RuntimeId::Opal => async_run_with_runtime!(239 opal_runtime::RuntimeApi, OpalRuntimeExecutor,240 runner, $components, $cli, $cmd, $config, $( $code )*241 ),242243 RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into())244 }245 }}246}247248/// Parse command line arguments into service configuration.249pub fn run() -> Result<()> {250 let cli = Cli::from_args();251252 match &cli.subcommand {253 Some(Subcommand::BuildSpec(cmd)) => {254 let runner = cli.create_runner(cmd)?;255 runner.sync_run(|config| cmd.run(config.chain_spec, config.network))256 }257 Some(Subcommand::CheckBlock(cmd)) => {258 construct_async_run!(|components, cli, cmd, config| {259 Ok(cmd.run(components.client, components.import_queue))260 })261 }262 Some(Subcommand::ExportBlocks(cmd)) => {263 construct_async_run!(|components, cli, cmd, config| {264 Ok(cmd.run(components.client, config.database))265 })266 }267 Some(Subcommand::ExportState(cmd)) => {268 construct_async_run!(|components, cli, cmd, config| {269 Ok(cmd.run(components.client, config.chain_spec))270 })271 }272 Some(Subcommand::ImportBlocks(cmd)) => {273 construct_async_run!(|components, cli, cmd, config| {274 Ok(cmd.run(components.client, components.import_queue))275 })276 }277 Some(Subcommand::PurgeChain(cmd)) => {278 let runner = cli.create_runner(cmd)?;279280 runner.sync_run(|config| {281 let polkadot_cli = RelayChainCli::new(282 &config,283 [RelayChainCli::executable_name()]284 .iter()285 .chain(cli.relaychain_args.iter()),286 );287288 let polkadot_config = SubstrateCli::create_configuration(289 &polkadot_cli,290 &polkadot_cli,291 config.tokio_handle.clone(),292 )293 .map_err(|err| format!("Relay chain argument error: {}", err))?;294295 cmd.run(config, polkadot_config)296 })297 }298 Some(Subcommand::Revert(cmd)) => construct_async_run!(|components, cli, cmd, config| {299 Ok(cmd.run(components.client, components.backend))300 }),301 Some(Subcommand::ExportGenesisState(params)) => {302 let mut builder = sc_cli::LoggerBuilder::new("");303 builder.with_profiling(sc_tracing::TracingReceiver::Log, "");304 let _ = builder.init();305306 let spec = load_spec(¶ms.chain.clone().unwrap_or_default())?;307 let state_version = Cli::native_runtime_version(&spec).state_version();308 let block: Block = generate_genesis_block(&spec, state_version)?;309 let raw_header = block.header().encode();310 let output_buf = if params.raw {311 raw_header312 } else {313 format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes()314 };315316 if let Some(output) = ¶ms.output {317 std::fs::write(output, output_buf)?;318 } else {319 std::io::stdout().write_all(&output_buf)?;320 }321322 Ok(())323 }324 Some(Subcommand::ExportGenesisWasm(params)) => {325 let mut builder = sc_cli::LoggerBuilder::new("");326 builder.with_profiling(sc_tracing::TracingReceiver::Log, "");327 let _ = builder.init();328329 let raw_wasm_blob =330 extract_genesis_wasm(&cli.load_spec(¶ms.chain.clone().unwrap_or_default())?)?;331 let output_buf = if params.raw {332 raw_wasm_blob333 } else {334 format!("0x{:?}", HexDisplay::from(&raw_wasm_blob)).into_bytes()335 };336337 if let Some(output) = ¶ms.output {338 std::fs::write(output, output_buf)?;339 } else {340 std::io::stdout().write_all(&output_buf)?;341 }342343 Ok(())344 }345 Some(Subcommand::Benchmark(cmd)) => {346 if cfg!(feature = "runtime-benchmarks") {347 let runner = cli.create_runner(cmd)?;348 runner.sync_run(|config| match config.chain_spec.runtime_id() {349 #[cfg(feature = "unique-runtime")]350 RuntimeId::Unique => cmd.run::<Block, UniqueRuntimeExecutor>(config),351352 #[cfg(feature = "quartz-runtime")]353 RuntimeId::Quartz => cmd.run::<Block, QuartzRuntimeExecutor>(config),354355 RuntimeId::Opal => cmd.run::<Block, OpalRuntimeExecutor>(config),356 RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into()),357 })358 } else {359 Err("Benchmarking wasn't enabled when building the node. \360 You can enable it with `--features runtime-benchmarks`."361 .into())362 }363 }364 None => {365 let runner = cli.create_runner(&cli.run.normalize())?;366367 runner.run_node_until_exit(|config| async move {368 let para_id = chain_spec::Extensions::try_get(&*config.chain_spec)369 .map(|e| e.para_id)370 .ok_or("Could not find parachain ID in chain-spec.")?;371372 let polkadot_cli = RelayChainCli::new(373 &config,374 [RelayChainCli::executable_name()]375 .iter()376 .chain(cli.relaychain_args.iter()),377 );378379 let id = ParaId::from(para_id);380381 let parachain_account =382 AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(&id);383384 let state_version =385 RelayChainCli::native_runtime_version(&config.chain_spec).state_version();386 let block: Block = generate_genesis_block(&config.chain_spec, state_version)387 .map_err(|e| format!("{:?}", e))?;388 let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));389 let genesis_hash = format!("0x{:?}", HexDisplay::from(&block.header().hash().0));390391 let polkadot_config = SubstrateCli::create_configuration(392 &polkadot_cli,393 &polkadot_cli,394 config.tokio_handle.clone(),395 )396 .map_err(|err| format!("Relay chain argument error: {}", err))?;397398 info!("Parachain id: {:?}", id);399 info!("Parachain Account: {}", parachain_account);400 info!("Parachain genesis state: {}", genesis_state);401 info!("Parachain genesis hash: {}", genesis_hash);402 info!(403 "Is collating: {}",404 if config.role.is_authority() {405 "yes"406 } else {407 "no"408 }409 );410411 match config.chain_spec.runtime_id() {412 #[cfg(feature = "unique-runtime")]413 RuntimeId::Unique => crate::service::start_node::<414 unique_runtime::Runtime,415 unique_runtime::RuntimeApi,416 UniqueRuntimeExecutor,417 >(config, polkadot_config, id)418 .await419 .map(|r| r.0)420 .map_err(Into::into),421422 #[cfg(feature = "quartz-runtime")]423 RuntimeId::Quartz => crate::service::start_node::<424 quartz_runtime::Runtime,425 quartz_runtime::RuntimeApi,426 QuartzRuntimeExecutor,427 >(config, polkadot_config, id)428 .await429 .map(|r| r.0)430 .map_err(Into::into),431432 RuntimeId::Opal => crate::service::start_node::<433 opal_runtime::Runtime,434 opal_runtime::RuntimeApi,435 OpalRuntimeExecutor,436 >(config, polkadot_config, id)437 .await438 .map(|r| r.0)439 .map_err(Into::into),440441 RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into()),442 }443 })444 }445 }446}447448impl DefaultConfigurationValues for RelayChainCli {449 fn p2p_listen_port() -> u16 {450 30334451 }452453 fn rpc_ws_listen_port() -> u16 {454 9945455 }456457 fn rpc_http_listen_port() -> u16 {458 9934459 }460461 fn prometheus_listen_port() -> u16 {462 9616463 }464}465466impl CliConfiguration<Self> for RelayChainCli {467 fn shared_params(&self) -> &SharedParams {468 self.base.base.shared_params()469 }470471 fn import_params(&self) -> Option<&ImportParams> {472 self.base.base.import_params()473 }474475 fn network_params(&self) -> Option<&NetworkParams> {476 self.base.base.network_params()477 }478479 fn keystore_params(&self) -> Option<&KeystoreParams> {480 self.base.base.keystore_params()481 }482483 fn base_path(&self) -> Result<Option<BasePath>> {484 Ok(self485 .shared_params()486 .base_path()487 .or_else(|| self.base_path.clone().map(Into::into)))488 }489490 fn rpc_http(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {491 self.base.base.rpc_http(default_listen_port)492 }493494 fn rpc_ipc(&self) -> Result<Option<String>> {495 self.base.base.rpc_ipc()496 }497498 fn rpc_ws(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {499 self.base.base.rpc_ws(default_listen_port)500 }501502 fn prometheus_config(503 &self,504 default_listen_port: u16,505 chain_spec: &Box<dyn ChainSpec>,506 ) -> Result<Option<PrometheusConfig>> {507 self.base508 .base509 .prometheus_config(default_listen_port, chain_spec)510 }511512 fn init<F>(513 &self,514 _support_url: &String,515 _impl_version: &String,516 _logger_hook: F,517 _config: &sc_service::Configuration,518 ) -> Result<()> {519 unreachable!("PolkadotCli is never initialized; qed");520 }521522 fn chain_id(&self, is_dev: bool) -> Result<String> {523 let chain_id = self.base.base.chain_id(is_dev)?;524525 Ok(if chain_id.is_empty() {526 self.chain_id.clone().unwrap_or_default()527 } else {528 chain_id529 })530 }531532 fn role(&self, is_dev: bool) -> Result<sc_service::Role> {533 self.base.base.role(is_dev)534 }535536 fn transaction_pool(&self) -> Result<sc_service::config::TransactionPoolOptions> {537 self.base.base.transaction_pool()538 }539540 fn state_cache_child_ratio(&self) -> Result<Option<usize>> {541 self.base.base.state_cache_child_ratio()542 }543544 fn rpc_methods(&self) -> Result<sc_service::config::RpcMethods> {545 self.base.base.rpc_methods()546 }547548 fn rpc_ws_max_connections(&self) -> Result<Option<usize>> {549 self.base.base.rpc_ws_max_connections()550 }551552 fn rpc_cors(&self, is_dev: bool) -> Result<Option<Vec<String>>> {553 self.base.base.rpc_cors(is_dev)554 }555556 fn default_heap_pages(&self) -> Result<Option<u64>> {557 self.base.base.default_heap_pages()558 }559560 fn force_authoring(&self) -> Result<bool> {561 self.base.base.force_authoring()562 }563564 fn disable_grandpa(&self) -> Result<bool> {565 self.base.base.disable_grandpa()566 }567568 fn max_runtime_instances(&self) -> Result<Option<usize>> {569 self.base.base.max_runtime_instances()570 }571572 fn announce_block(&self) -> Result<bool> {573 self.base.base.announce_block()574 }575576 fn telemetry_endpoints(577 &self,578 chain_spec: &Box<dyn ChainSpec>,579 ) -> Result<Option<sc_telemetry::TelemetryEndpoints>> {580 self.base.base.telemetry_endpoints(chain_spec)581 }582}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::{self, RuntimeId, RuntimeIdentification, ServiceId, ServiceIdentification},37 cli::{Cli, RelayChainCli, Subcommand},38 service::{new_partial, start_node, start_dev_node},39};4041#[cfg(feature = "unique-runtime")]42use crate::service::UniqueRuntimeExecutor;4344#[cfg(feature = "quartz-runtime")]45use crate::service::QuartzRuntimeExecutor;4647use crate::service::OpalRuntimeExecutor;4849use codec::Encode;50use cumulus_primitives_core::ParaId;51use cumulus_client_service::genesis::generate_genesis_block;52use log::info;53use polkadot_parachain::primitives::AccountIdConversion;54use sc_cli::{55 ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,56 NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,57};58use sc_service::{59 config::{BasePath, PrometheusConfig},60};61use sp_core::hexdisplay::HexDisplay;62use sp_runtime::traits::Block as BlockT;63use std::{io::Write, net::SocketAddr};6465use unique_runtime_common::types::Block;6667macro_rules! no_runtime_err {68 ($chain_name:expr) => {69 format!(70 "No runtime valid runtime was found for chain {}",71 $chain_name72 )73 };74}7576fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {77 Ok(match id {78 "westend-local" => Box::new(chain_spec::local_testnet_westend_config()),79 "rococo-local" => Box::new(chain_spec::local_testnet_rococo_config()),80 "dev" => Box::new(chain_spec::development_config()),81 "" | "local" => Box::new(chain_spec::local_testnet_rococo_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 "Unique Node".into()105 }106107 fn impl_version() -> String {108 env!("SUBSTRATE_CLI_IMPL_VERSION").into()109 }110 // TODO use args111 fn description() -> String {112 format!(113 "Unique 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::executable_name()118 )119 }120121 fn author() -> String {122 env!("CARGO_PKG_AUTHORS").into()123 }124125 //TODO use args126 fn support_url() -> String {127 "support@unique.network".into()128 }129130 fn copyright_start_year() -> i32 {131 2019132 }133134 fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {135 load_spec(id)136 }137138 fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {139 match chain_spec.runtime_id() {140 #[cfg(feature = "unique-runtime")]141 RuntimeId::Unique => &unique_runtime::VERSION,142143 #[cfg(feature = "quartz-runtime")]144 RuntimeId::Quartz => &quartz_runtime::VERSION,145146 RuntimeId::Opal => &opal_runtime::VERSION,147 RuntimeId::Unknown(chain) => panic!("{}", no_runtime_err!(chain)),148 }149 }150}151152impl SubstrateCli for RelayChainCli {153 // TODO use args154 fn impl_name() -> String {155 "Unique Node".into()156 }157158 fn impl_version() -> String {159 env!("SUBSTRATE_CLI_IMPL_VERSION").into()160 }161 // TODO use args162 fn description() -> String {163 "Unique Node\n\nThe command-line arguments provided first will be \164 passed to the parachain node, while the arguments provided after -- will be passed \165 to the relaychain node.\n\n\166 parachain-collator [parachain-args] -- [relaychain-args]"167 .into()168 }169170 fn author() -> String {171 env!("CARGO_PKG_AUTHORS").into()172 }173 // TODO use args174 fn support_url() -> String {175 "support@unique.network".into()176 }177178 fn copyright_start_year() -> i32 {179 2019180 }181182 fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {183 polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)184 }185186 fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {187 polkadot_cli::Cli::native_runtime_version(chain_spec)188 }189}190191#[allow(clippy::borrowed_box)]192fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {193 let mut storage = chain_spec.build_storage()?;194195 storage196 .top197 .remove(sp_core::storage::well_known_keys::CODE)198 .ok_or_else(|| "Could not find wasm file in genesis state!".into())199}200201macro_rules! async_run_with_runtime {202 (203 $runtime_api:path, $executor:path,204 $runner:ident, $components:ident, $cli:ident, $cmd:ident, $config:ident,205 $( $code:tt )*206 ) => {207 $runner.async_run(|$config| {208 let $components = new_partial::<209 $runtime_api, $executor, _210 >(211 &$config,212 crate::service::parachain_build_import_queue,213 ServiceId::Prod,214 )?;215 let task_manager = $components.task_manager;216217 { $( $code )* }.map(|v| (v, task_manager))218 })219 };220}221222macro_rules! construct_async_run {223 (|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{224 let runner = $cli.create_runner($cmd)?;225226 match runner.config().chain_spec.runtime_id() {227 #[cfg(feature = "unique-runtime")]228 RuntimeId::Unique => async_run_with_runtime!(229 unique_runtime::RuntimeApi, UniqueRuntimeExecutor,230 runner, $components, $cli, $cmd, $config, $( $code )*231 ),232233 #[cfg(feature = "quartz-runtime")]234 RuntimeId::Quartz => async_run_with_runtime!(235 quartz_runtime::RuntimeApi, QuartzRuntimeExecutor,236 runner, $components, $cli, $cmd, $config, $( $code )*237 ),238239 RuntimeId::Opal => async_run_with_runtime!(240 opal_runtime::RuntimeApi, OpalRuntimeExecutor,241 runner, $components, $cli, $cmd, $config, $( $code )*242 ),243244 RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into())245 }246 }}247}248249macro_rules! start_node_using_chain_runtime {250 ($start_node_fn:ident($config:expr $(, $($args:expr),+)?) $($code:tt)*) => {251 match $config.chain_spec.runtime_id() {252 #[cfg(feature = "unique-runtime")]253 RuntimeId::Unique => $start_node_fn::<254 unique_runtime::Runtime,255 unique_runtime::RuntimeApi,256 UniqueRuntimeExecutor,257 >($config $(, $($args),+)?) $($code)*,258259 #[cfg(feature = "quartz-runtime")]260 RuntimeId::Quartz => $start_node_fn::<261 quartz_runtime::Runtime,262 quartz_runtime::RuntimeApi,263 QuartzRuntimeExecutor,264 >($config $(, $($args),+)?) $($code)*,265266 RuntimeId::Opal => $start_node_fn::<267 opal_runtime::Runtime,268 opal_runtime::RuntimeApi,269 OpalRuntimeExecutor,270 >($config $(, $($args),+)?) $($code)*,271272 RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into()),273 }274 };275}276277/// Parse command line arguments into service configuration.278pub fn run() -> Result<()> {279 let cli = Cli::from_args();280281 match &cli.subcommand {282 Some(Subcommand::BuildSpec(cmd)) => {283 let runner = cli.create_runner(cmd)?;284 runner.sync_run(|config| cmd.run(config.chain_spec, config.network))285 }286 Some(Subcommand::CheckBlock(cmd)) => {287 construct_async_run!(|components, cli, cmd, config| {288 Ok(cmd.run(components.client, components.import_queue))289 })290 }291 Some(Subcommand::ExportBlocks(cmd)) => {292 construct_async_run!(|components, cli, cmd, config| {293 Ok(cmd.run(components.client, config.database))294 })295 }296 Some(Subcommand::ExportState(cmd)) => {297 construct_async_run!(|components, cli, cmd, config| {298 Ok(cmd.run(components.client, config.chain_spec))299 })300 }301 Some(Subcommand::ImportBlocks(cmd)) => {302 construct_async_run!(|components, cli, cmd, config| {303 Ok(cmd.run(components.client, components.import_queue))304 })305 }306 Some(Subcommand::PurgeChain(cmd)) => {307 let runner = cli.create_runner(cmd)?;308309 runner.sync_run(|config| {310 let polkadot_cli = RelayChainCli::new(311 &config,312 [RelayChainCli::executable_name()]313 .iter()314 .chain(cli.relaychain_args.iter()),315 );316317 let polkadot_config = SubstrateCli::create_configuration(318 &polkadot_cli,319 &polkadot_cli,320 config.tokio_handle.clone(),321 )322 .map_err(|err| format!("Relay chain argument error: {}", err))?;323324 cmd.run(config, polkadot_config)325 })326 }327 Some(Subcommand::Revert(cmd)) => construct_async_run!(|components, cli, cmd, config| {328 Ok(cmd.run(components.client, components.backend))329 }),330 Some(Subcommand::ExportGenesisState(params)) => {331 let mut builder = sc_cli::LoggerBuilder::new("");332 builder.with_profiling(sc_tracing::TracingReceiver::Log, "");333 let _ = builder.init();334335 let spec = load_spec(¶ms.chain.clone().unwrap_or_default())?;336 let state_version = Cli::native_runtime_version(&spec).state_version();337 let block: Block = generate_genesis_block(&spec, state_version)?;338 let raw_header = block.header().encode();339 let output_buf = if params.raw {340 raw_header341 } else {342 format!("0x{:?}", HexDisplay::from(&block.header().encode())).into_bytes()343 };344345 if let Some(output) = ¶ms.output {346 std::fs::write(output, output_buf)?;347 } else {348 std::io::stdout().write_all(&output_buf)?;349 }350351 Ok(())352 }353 Some(Subcommand::ExportGenesisWasm(params)) => {354 let mut builder = sc_cli::LoggerBuilder::new("");355 builder.with_profiling(sc_tracing::TracingReceiver::Log, "");356 let _ = builder.init();357358 let raw_wasm_blob =359 extract_genesis_wasm(&cli.load_spec(¶ms.chain.clone().unwrap_or_default())?)?;360 let output_buf = if params.raw {361 raw_wasm_blob362 } else {363 format!("0x{:?}", HexDisplay::from(&raw_wasm_blob)).into_bytes()364 };365366 if let Some(output) = ¶ms.output {367 std::fs::write(output, output_buf)?;368 } else {369 std::io::stdout().write_all(&output_buf)?;370 }371372 Ok(())373 }374 Some(Subcommand::Benchmark(cmd)) => {375 if cfg!(feature = "runtime-benchmarks") {376 let runner = cli.create_runner(cmd)?;377 runner.sync_run(|config| match config.chain_spec.runtime_id() {378 #[cfg(feature = "unique-runtime")]379 RuntimeId::Unique => cmd.run::<Block, UniqueRuntimeExecutor>(config),380381 #[cfg(feature = "quartz-runtime")]382 RuntimeId::Quartz => cmd.run::<Block, QuartzRuntimeExecutor>(config),383384 RuntimeId::Opal => cmd.run::<Block, OpalRuntimeExecutor>(config),385 RuntimeId::Unknown(chain) => Err(no_runtime_err!(chain).into()),386 })387 } else {388 Err("Benchmarking wasn't enabled when building the node. \389 You can enable it with `--features runtime-benchmarks`."390 .into())391 }392 }393 None => {394 let runner = cli.create_runner(&cli.run.normalize())?;395396 runner.run_node_until_exit(|config| async move {397 let extensions = chain_spec::Extensions::try_get(&*config.chain_spec);398399 let service_id = config.chain_spec.service_id();400 let relay_chain_id = extensions.map(|e| e.relay_chain.clone());401 let is_dev_service = matches![service_id, ServiceId::Dev]402 || relay_chain_id == Some("dev-service".into());403404 if is_dev_service {405 return start_node_using_chain_runtime! {406 start_dev_node(config).map_err(Into::into)407 };408 };409410 let para_id = extensions411 .map(|e| e.para_id)412 .ok_or("Could not find parachain ID in chain-spec.")?;413414 let polkadot_cli = RelayChainCli::new(415 &config,416 [RelayChainCli::executable_name()]417 .iter()418 .chain(cli.relaychain_args.iter()),419 );420421 let para_id = ParaId::from(para_id);422423 let parachain_account =424 AccountIdConversion::<polkadot_primitives::v0::AccountId>::into_account(¶_id);425426 let state_version =427 RelayChainCli::native_runtime_version(&config.chain_spec).state_version();428 let block: Block = generate_genesis_block(&config.chain_spec, state_version)429 .map_err(|e| format!("{:?}", e))?;430 let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));431 let genesis_hash = format!("0x{:?}", HexDisplay::from(&block.header().hash().0));432433 let polkadot_config = SubstrateCli::create_configuration(434 &polkadot_cli,435 &polkadot_cli,436 config.tokio_handle.clone(),437 )438 .map_err(|err| format!("Relay chain argument error: {}", err))?;439440 info!("Parachain id: {:?}", para_id);441 info!("Parachain Account: {}", parachain_account);442 info!("Parachain genesis state: {}", genesis_state);443 info!("Parachain genesis hash: {}", genesis_hash);444 info!(445 "Is collating: {}",446 if config.role.is_authority() {447 "yes"448 } else {449 "no"450 }451 );452453 start_node_using_chain_runtime! {454 start_node(config, polkadot_config, para_id)455 .await456 .map(|r| r.0)457 .map_err(Into::into)458 }459 })460 }461 }462}463464impl DefaultConfigurationValues for RelayChainCli {465 fn p2p_listen_port() -> u16 {466 30334467 }468469 fn rpc_ws_listen_port() -> u16 {470 9945471 }472473 fn rpc_http_listen_port() -> u16 {474 9934475 }476477 fn prometheus_listen_port() -> u16 {478 9616479 }480}481482impl CliConfiguration<Self> for RelayChainCli {483 fn shared_params(&self) -> &SharedParams {484 self.base.base.shared_params()485 }486487 fn import_params(&self) -> Option<&ImportParams> {488 self.base.base.import_params()489 }490491 fn network_params(&self) -> Option<&NetworkParams> {492 self.base.base.network_params()493 }494495 fn keystore_params(&self) -> Option<&KeystoreParams> {496 self.base.base.keystore_params()497 }498499 fn base_path(&self) -> Result<Option<BasePath>> {500 Ok(self501 .shared_params()502 .base_path()503 .or_else(|| self.base_path.clone().map(Into::into)))504 }505506 fn rpc_http(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {507 self.base.base.rpc_http(default_listen_port)508 }509510 fn rpc_ipc(&self) -> Result<Option<String>> {511 self.base.base.rpc_ipc()512 }513514 fn rpc_ws(&self, default_listen_port: u16) -> Result<Option<SocketAddr>> {515 self.base.base.rpc_ws(default_listen_port)516 }517518 fn prometheus_config(519 &self,520 default_listen_port: u16,521 chain_spec: &Box<dyn ChainSpec>,522 ) -> Result<Option<PrometheusConfig>> {523 self.base524 .base525 .prometheus_config(default_listen_port, chain_spec)526 }527528 fn init<F>(529 &self,530 _support_url: &String,531 _impl_version: &String,532 _logger_hook: F,533 _config: &sc_service::Configuration,534 ) -> Result<()> {535 unreachable!("PolkadotCli is never initialized; qed");536 }537538 fn chain_id(&self, is_dev: bool) -> Result<String> {539 let chain_id = self.base.base.chain_id(is_dev)?;540541 Ok(if chain_id.is_empty() {542 self.chain_id.clone().unwrap_or_default()543 } else {544 chain_id545 })546 }547548 fn role(&self, is_dev: bool) -> Result<sc_service::Role> {549 self.base.base.role(is_dev)550 }551552 fn transaction_pool(&self) -> Result<sc_service::config::TransactionPoolOptions> {553 self.base.base.transaction_pool()554 }555556 fn state_cache_child_ratio(&self) -> Result<Option<usize>> {557 self.base.base.state_cache_child_ratio()558 }559560 fn rpc_methods(&self) -> Result<sc_service::config::RpcMethods> {561 self.base.base.rpc_methods()562 }563564 fn rpc_ws_max_connections(&self) -> Result<Option<usize>> {565 self.base.base.rpc_ws_max_connections()566 }567568 fn rpc_cors(&self, is_dev: bool) -> Result<Option<Vec<String>>> {569 self.base.base.rpc_cors(is_dev)570 }571572 fn default_heap_pages(&self) -> Result<Option<u64>> {573 self.base.base.default_heap_pages()574 }575576 fn force_authoring(&self) -> Result<bool> {577 self.base.base.force_authoring()578 }579580 fn disable_grandpa(&self) -> Result<bool> {581 self.base.base.disable_grandpa()582 }583584 fn max_runtime_instances(&self) -> Result<Option<usize>> {585 self.base.base.max_runtime_instances()586 }587588 fn announce_block(&self) -> Result<bool> {589 self.base.base.announce_block()590 }591592 fn telemetry_endpoints(593 &self,594 chain_spec: &Box<dyn ChainSpec>,595 ) -> Result<Option<sc_telemetry::TelemetryEndpoints>> {596 self.base.base.telemetry_endpoints(chain_spec)597 }598}node/cli/src/service.rsdiffbeforeafterboth--- a/node/cli/src/service.rs
+++ b/node/cli/src/service.rs
@@ -57,6 +57,7 @@
use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};
use unique_runtime_common::types::{AuraId, RuntimeInstance, AccountId, Balance, Index, Hash, Block};
+use crate::chain_spec::ServiceId;
/// Native executor instance.
pub struct UniqueRuntimeExecutor;
@@ -125,6 +126,7 @@
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
+type MaybeSelectChain = Option<FullSelectChain>;
/// Starts a `ServiceBuilder` for a full service.
///
@@ -134,11 +136,12 @@
pub fn new_partial<RuntimeApi, ExecutorDispatch, BIQ>(
config: &Configuration,
build_import_queue: BIQ,
+ service_id: ServiceId,
) -> Result<
PartialComponents<
FullClient<RuntimeApi, ExecutorDispatch>,
FullBackend,
- FullSelectChain,
+ MaybeSelectChain,
sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
(
@@ -215,7 +218,10 @@
telemetry
});
- let select_chain = sc_consensus::LongestChain::new(backend.clone());
+ let select_chain = match service_id {
+ ServiceId::Prod => Some(sc_consensus::LongestChain::new(backend.clone())),
+ ServiceId::Dev => None
+ };
let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
@@ -317,7 +323,9 @@
let parachain_config = prepare_node_config(parachain_config);
let params =
- new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(¶chain_config, build_import_queue)?;
+ new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(
+ ¶chain_config, build_import_queue, ServiceId::Prod
+ )?;
let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =
params.other;
@@ -356,7 +364,9 @@
let subscription_executor = sc_rpc::SubscriptionTaskExecutor::new(task_manager.spawn_handle());
let rpc_client = client.clone();
let rpc_pool = transaction_pool.clone();
- let select_chain = params.select_chain.clone();
+ let select_chain = params.select_chain
+ .expect("select_chain always exists when running Prod service; qed")
+ .clone();
let rpc_network = network.clone();
let rpc_frontier_backend = frontier_backend.clone();
@@ -638,3 +648,255 @@
)
.await
}
+
+fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(
+ client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,
+ config: &Configuration,
+ _: Option<TelemetryHandle>,
+ task_manager: &TaskManager,
+) -> Result<sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>, sc_service::Error>
+where
+ RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>
+ + Send
+ + Sync
+ + 'static,
+ RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,
+ ExecutorDispatch: NativeExecutionDispatch + 'static,
+{
+ Ok(sc_consensus_manual_seal::import_queue(
+ Box::new(client.clone()),
+ &task_manager.spawn_essential_handle(),
+ config.prometheus_registry(),
+ ))
+}
+
+/// Builds a new development service. This service uses instant seal, and mocks
+/// the parachain inherent
+pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(config: Configuration)
+ -> sc_service::error::Result<TaskManager>
+where
+ Runtime: RuntimeInstance + Send + Sync + 'static,
+ <Runtime as RuntimeInstance>::CrossAccountId: Serialize,
+ for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,
+ RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>
+ + Send
+ + Sync
+ + 'static,
+ RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ + fp_rpc::EthereumRuntimeRPCApi<Block>
+ + sp_session::SessionKeys<Block>
+ + sp_block_builder::BlockBuilder<Block>
+ + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>
+ + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>
+ + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>
+ + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+ + sp_api::Metadata<Block>
+ + sp_offchain::OffchainWorkerApi<Block>
+ + cumulus_primitives_core::CollectCollationInfo<Block>
+ + sp_consensus_aura::AuraApi<Block, AuraId>,
+ ExecutorDispatch: NativeExecutionDispatch + 'static,
+{
+ use futures::Stream;
+ use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};
+ use fc_consensus::FrontierBlockImport;
+ use sc_client_api::HeaderBackend;
+
+ let sc_service::PartialComponents {
+ client,
+ backend,
+ mut task_manager,
+ import_queue,
+ keystore_container,
+ select_chain: maybe_select_chain,
+ transaction_pool,
+ other:
+ (
+ telemetry,
+ filter_pool,
+ frontier_backend,
+ _telemetry_worker_handle,
+ fee_history_cache,
+ ),
+ } = new_partial::<RuntimeApi, ExecutorDispatch, _>(
+ &config,
+ dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,
+ ServiceId::Dev
+ )?;
+
+ let block_data_cache = Arc::new(fc_rpc::EthBlockDataCache::new(
+ task_manager.spawn_handle(),
+ overrides_handle::<_, _, Runtime>(client.clone()),
+ 50,
+ 50,
+ ));
+
+ let (network, system_rpc_tx, network_starter) =
+ sc_service::build_network(sc_service::BuildNetworkParams {
+ config: &config,
+ client: client.clone(),
+ transaction_pool: transaction_pool.clone(),
+ spawn_handle: task_manager.spawn_handle(),
+ import_queue,
+ block_announce_validator_builder: None,
+ warp_sync: None,
+ })?;
+
+ if config.offchain_worker.enabled {
+ sc_service::build_offchain_workers(
+ &config,
+ task_manager.spawn_handle(),
+ client.clone(),
+ network.clone(),
+ );
+ }
+
+ let prometheus_registry = config.prometheus_registry().cloned();
+ let collator = config.role.is_authority();
+
+ let select_chain = maybe_select_chain.clone().expect(
+ "`new_partial` builds a `LongestChainRule` when building dev service.\
+ We specified the dev service when calling `new_partial`.\
+ Therefore, a `LongestChainRule` is present. qed.",
+ );
+
+ if collator {
+ let block_import =
+ FrontierBlockImport::new(client.clone(), client.clone(), frontier_backend.clone());
+
+ let env = sc_basic_authorship::ProposerFactory::new(
+ task_manager.spawn_handle(),
+ client.clone(),
+ transaction_pool.clone(),
+ prometheus_registry.as_ref(),
+ telemetry.as_ref().map(|x| x.handle()),
+ );
+
+ let commands_stream: Box<dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin> =
+ Box::new(
+ // This bit cribbed from the implementation of instant seal.
+ transaction_pool
+ .pool()
+ .validated_pool()
+ .import_notification_stream()
+ .map(|_| EngineCommand::SealNewBlock {
+ create_empty: true, // was false in Moonbeam
+ finalize: false,
+ parent_hash: None,
+ sender: None,
+ }),
+ );
+
+ let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
+ let client_set_aside_for_cidp = client.clone();
+
+ task_manager.spawn_essential_handle().spawn_blocking(
+ "authorship_task",
+ Some("block-authoring"),
+ run_manual_seal(ManualSealParams {
+ block_import,
+ env,
+ client: client.clone(),
+ pool: transaction_pool.clone(),
+ commands_stream,
+ select_chain: select_chain.clone(),
+ consensus_data_provider: None,
+ create_inherent_data_providers: move |block: Hash, ()| {
+ let current_para_block = client_set_aside_for_cidp
+ .number(block)
+ .expect("Header lookup should succeed")
+ .expect("Header passed in as parent should be present in backend.");
+
+ let client_for_xcm = client_set_aside_for_cidp.clone();
+ async move {
+ let time = sp_timestamp::InherentDataProvider::from_system_time();
+
+ let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {
+ current_para_block,
+ relay_offset: 1000,
+ relay_blocks_per_para_block: 2,
+ xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(
+ &*client_for_xcm,
+ block,
+ Default::default(),
+ Default::default(),
+ ),
+ raw_downward_messages: vec![],
+ raw_horizontal_messages: vec![],
+ };
+
+ let slot =
+ sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration(
+ *time,
+ slot_duration.slot_duration(),
+ );
+
+ Ok((time, slot, mocked_parachain))
+ }
+ },
+ }),
+ );
+ }
+
+ task_manager.spawn_essential_handle().spawn(
+ "frontier-mapping-sync-worker",
+ Some("block-authoring"),
+ MappingSyncWorker::new(
+ client.import_notification_stream(),
+ Duration::new(6, 0),
+ client.clone(),
+ backend.clone(),
+ frontier_backend.clone(),
+ SyncStrategy::Normal,
+ )
+ .for_each(|()| futures::future::ready(())),
+ );
+
+ let subscription_executor = sc_rpc::SubscriptionTaskExecutor::new(task_manager.spawn_handle());
+ let rpc_client = client.clone();
+ let rpc_pool = transaction_pool.clone();
+ let rpc_network = network.clone();
+ let rpc_frontier_backend = frontier_backend.clone();
+ let rpc_extensions_builder = Box::new(move |deny_unsafe, _| {
+ let full_deps = unique_rpc::FullDeps {
+ backend: rpc_frontier_backend.clone(),
+ deny_unsafe,
+ client: rpc_client.clone(),
+ pool: rpc_pool.clone(),
+ graph: rpc_pool.pool().clone(),
+ // TODO: Unhardcode
+ enable_dev_signer: false,
+ filter_pool: filter_pool.clone(),
+ network: rpc_network.clone(),
+ select_chain: select_chain.clone(),
+ is_authority: collator,
+ // TODO: Unhardcode
+ max_past_logs: 10000,
+ block_data_cache: block_data_cache.clone(),
+ fee_history_cache: fee_history_cache.clone(),
+ // TODO: Unhardcode
+ fee_history_limit: 2048,
+ };
+
+ Ok(unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(
+ full_deps,
+ subscription_executor.clone(),
+ ))
+ });
+
+ sc_service::spawn_tasks(sc_service::SpawnTasksParams {
+ network,
+ client,
+ keystore: keystore_container.sync_keystore(),
+ task_manager: &mut task_manager,
+ transaction_pool,
+ rpc_extensions_builder,
+ backend,
+ system_rpc_tx,
+ config,
+ telemetry: None,
+ })?;
+
+ network_starter.start_network();
+ Ok(task_manager)
+}