difftreelog
feat unify unique nodes
in: master
6 files changed
client/rpc/Cargo.tomldiffbeforeafterboth--- a/client/rpc/Cargo.toml
+++ b/client/rpc/Cargo.toml
@@ -36,11 +36,17 @@
sc-executor = { workspace = true }
-opal-runtime = { workspace = true }
+opal-runtime = { workspace = true, optional = true }
quartz-runtime = { workspace = true, optional = true }
unique-runtime = { workspace = true, optional = true }
[features]
+default = ['opal-runtime']
+all-runtimes = [
+ 'opal-runtime',
+ 'quartz-runtime',
+ 'unique-runtime',
+]
pov-estimate = [
'opal-runtime/pov-estimate',
'quartz-runtime?/pov-estimate',
node/cli/Cargo.tomldiffbeforeafterboth--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -99,6 +99,11 @@
[features]
default = ["opal-runtime"]
+all-runtimes = [
+ 'opal-runtime',
+ 'quartz-runtime',
+ 'unique-runtime',
+]
pov-estimate = [
'opal-runtime/pov-estimate',
'quartz-runtime?/pov-estimate',
node/cli/src/cli.rsdiffbeforeafterboth--- a/node/cli/src/cli.rs
+++ b/node/cli/src/cli.rs
@@ -15,11 +15,9 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use crate::chain_spec;
-use std::{path::PathBuf, env};
+use std::path::PathBuf;
use clap::Parser;
-const NODE_NAME_ENV: &str = "UNIQUE_NODE_NAME";
-
/// Sub-commands supported by the collator.
#[derive(Debug, Parser)]
pub enum Subcommand {
@@ -99,21 +97,7 @@
impl Cli {
pub fn node_name() -> String {
- match env::var(NODE_NAME_ENV).ok() {
- Some(name) => name,
- None => {
- if cfg!(feature = "unique-runtime") {
- "Unique"
- } else if cfg!(feature = "sapphire-runtime") {
- "Sapphire"
- } else if cfg!(feature = "quartz-runtime") {
- "Quartz"
- } else {
- "Opal"
- }
- }
- .into(),
- }
+ "Unique".into()
}
}
node/cli/src/service.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// std18use std::sync::Arc;19use std::sync::Mutex;20use std::collections::BTreeMap;21use std::time::Duration;22use std::pin::Pin;23use fc_rpc_core::types::FeeHistoryCache;24use futures::{25 Stream, StreamExt,26 stream::select,27 task::{Context, Poll},28};29use tokio::time::Interval;3031use unique_rpc::overrides_handle;3233use serde::{Serialize, Deserialize};3435// Cumulus Imports36use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};37use cumulus_client_consensus_common::{38 ParachainConsensus, ParachainBlockImport as TParachainBlockImport,39};40use cumulus_client_service::{41 prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,42};43use cumulus_client_cli::CollatorOptions;44use cumulus_client_network::BlockAnnounceValidator;45use cumulus_primitives_core::ParaId;46use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;47use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};48use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;4950// Substrate Imports51use sp_api::BlockT;52use sc_executor::NativeElseWasmExecutor;53use sc_executor::NativeExecutionDispatch;54use sc_network::{NetworkService, NetworkBlock};55use sc_service::{BasePath, Configuration, PartialComponents, TaskManager};56use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};57use sp_keystore::SyncCryptoStorePtr;58use sp_runtime::traits::BlakeTwo256;59use substrate_prometheus_endpoint::Registry;60use sc_client_api::BlockchainEvents;61use sc_consensus::ImportQueue;6263use polkadot_service::CollatorPair;6465// Frontier Imports66use fc_rpc_core::types::FilterPool;67use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};6869use up_common::types::opaque::*;7071#[cfg(feature = "pov-estimate")]72use crate::chain_spec::RuntimeIdentification;7374/// Unique native executor instance.75#[cfg(feature = "unique-runtime")]76pub struct UniqueRuntimeExecutor;7778#[cfg(feature = "quartz-runtime")]79/// Quartz native executor instance.80pub struct QuartzRuntimeExecutor;8182/// Opal native executor instance.83pub struct OpalRuntimeExecutor;8485#[cfg(all(feature = "unique-runtime", feature = "runtime-benchmarks"))]86pub type DefaultRuntimeExecutor = UniqueRuntimeExecutor;8788#[cfg(all(89 not(feature = "unique-runtime"),90 feature = "quartz-runtime",91 feature = "runtime-benchmarks"92))]93pub type DefaultRuntimeExecutor = QuartzRuntimeExecutor;9495#[cfg(all(96 not(feature = "unique-runtime"),97 not(feature = "quartz-runtime"),98 feature = "runtime-benchmarks"99))]100pub type DefaultRuntimeExecutor = OpalRuntimeExecutor;101102#[cfg(feature = "unique-runtime")]103impl NativeExecutionDispatch for UniqueRuntimeExecutor {104 /// Only enable the benchmarking host functions when we actually want to benchmark.105 #[cfg(feature = "runtime-benchmarks")]106 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;107 /// Otherwise we only use the default Substrate host functions.108 #[cfg(not(feature = "runtime-benchmarks"))]109 type ExtendHostFunctions = ();110111 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {112 unique_runtime::api::dispatch(method, data)113 }114115 fn native_version() -> sc_executor::NativeVersion {116 unique_runtime::native_version()117 }118}119120#[cfg(feature = "quartz-runtime")]121impl NativeExecutionDispatch for QuartzRuntimeExecutor {122 /// Only enable the benchmarking host functions when we actually want to benchmark.123 #[cfg(feature = "runtime-benchmarks")]124 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;125 /// Otherwise we only use the default Substrate host functions.126 #[cfg(not(feature = "runtime-benchmarks"))]127 type ExtendHostFunctions = ();128129 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {130 quartz_runtime::api::dispatch(method, data)131 }132133 fn native_version() -> sc_executor::NativeVersion {134 quartz_runtime::native_version()135 }136}137138impl NativeExecutionDispatch for OpalRuntimeExecutor {139 /// Only enable the benchmarking host functions when we actually want to benchmark.140 #[cfg(feature = "runtime-benchmarks")]141 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;142 /// Otherwise we only use the default Substrate host functions.143 #[cfg(not(feature = "runtime-benchmarks"))]144 type ExtendHostFunctions = ();145146 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {147 opal_runtime::api::dispatch(method, data)148 }149150 fn native_version() -> sc_executor::NativeVersion {151 opal_runtime::native_version()152 }153}154155pub struct AutosealInterval {156 interval: Interval,157}158159impl AutosealInterval {160 pub fn new(config: &Configuration, interval: Duration) -> Self {161 let _tokio_runtime = config.tokio_handle.enter();162 let interval = tokio::time::interval(interval);163164 Self { interval }165 }166}167168impl Stream for AutosealInterval {169 type Item = tokio::time::Instant;170171 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {172 self.interval.poll_tick(cx).map(Some)173 }174}175176pub fn open_frontier_backend<Block: BlockT, C: sp_blockchain::HeaderBackend<Block>>(177 client: Arc<C>,178 config: &Configuration,179) -> Result<Arc<fc_db::Backend<Block>>, String> {180 let config_dir = config181 .base_path182 .as_ref()183 .map(|base_path| base_path.config_dir(config.chain_spec.id()))184 .unwrap_or_else(|| {185 BasePath::from_project("", "", "unique").config_dir(config.chain_spec.id())186 });187 let database_dir = config_dir.join("frontier").join("db");188189 Ok(Arc::new(fc_db::Backend::<Block>::new(190 client,191 &fc_db::DatabaseSettings {192 source: fc_db::DatabaseSource::RocksDb {193 path: database_dir,194 cache_size: 0,195 },196 },197 )?))198}199200type FullClient<RuntimeApi, ExecutorDispatch> =201 sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;202type FullBackend = sc_service::TFullBackend<Block>;203type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;204type ParachainBlockImport<RuntimeApi, ExecutorDispatch> =205 TParachainBlockImport<Block, Arc<FullClient<RuntimeApi, ExecutorDispatch>>, FullBackend>;206207/// Starts a `ServiceBuilder` for a full service.208///209/// Use this macro if you don't actually need the full service, but just the builder in order to210/// be able to perform chain operations.211#[allow(clippy::type_complexity)]212pub fn new_partial<RuntimeApi, ExecutorDispatch, BIQ>(213 config: &Configuration,214 build_import_queue: BIQ,215) -> Result<216 PartialComponents<217 FullClient<RuntimeApi, ExecutorDispatch>,218 FullBackend,219 FullSelectChain,220 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,221 sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,222 (223 Option<Telemetry>,224 Option<FilterPool>,225 Arc<fc_db::Backend<Block>>,226 Option<TelemetryWorkerHandle>,227 FeeHistoryCache,228 ),229 >,230 sc_service::Error,231>232where233 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,234 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>235 + Send236 + Sync237 + 'static,238 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,239 ExecutorDispatch: NativeExecutionDispatch + 'static,240 BIQ: FnOnce(241 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,242 Arc<FullBackend>,243 &Configuration,244 Option<TelemetryHandle>,245 &TaskManager,246 ) -> Result<247 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,248 sc_service::Error,249 >,250{251 let _telemetry = config252 .telemetry_endpoints253 .clone()254 .filter(|x| !x.is_empty())255 .map(|endpoints| -> Result<_, sc_telemetry::Error> {256 let worker = TelemetryWorker::new(16)?;257 let telemetry = worker.handle().new_telemetry(endpoints);258 Ok((worker, telemetry))259 })260 .transpose()?;261262 let telemetry = config263 .telemetry_endpoints264 .clone()265 .filter(|x| !x.is_empty())266 .map(|endpoints| -> Result<_, sc_telemetry::Error> {267 let worker = TelemetryWorker::new(16)?;268 let telemetry = worker.handle().new_telemetry(endpoints);269 Ok((worker, telemetry))270 })271 .transpose()?;272273 let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(274 config.wasm_method,275 config.default_heap_pages,276 config.max_runtime_instances,277 config.runtime_cache_size,278 );279280 let (client, backend, keystore_container, task_manager) =281 sc_service::new_full_parts::<Block, RuntimeApi, _>(282 config,283 telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),284 executor,285 )?;286 let client = Arc::new(client);287288 let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());289290 let telemetry = telemetry.map(|(worker, telemetry)| {291 task_manager292 .spawn_handle()293 .spawn("telemetry", None, worker.run());294 telemetry295 });296297 let select_chain = sc_consensus::LongestChain::new(backend.clone());298299 let transaction_pool = sc_transaction_pool::BasicPool::new_full(300 config.transaction_pool.clone(),301 config.role.is_authority().into(),302 config.prometheus_registry(),303 task_manager.spawn_essential_handle(),304 client.clone(),305 );306307 let filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));308309 let frontier_backend = open_frontier_backend(client.clone(), config)?;310311 let import_queue = build_import_queue(312 client.clone(),313 backend.clone(),314 config,315 telemetry.as_ref().map(|telemetry| telemetry.handle()),316 &task_manager,317 )?;318 let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));319320 let params = PartialComponents {321 backend,322 client,323 import_queue,324 keystore_container,325 task_manager,326 transaction_pool,327 select_chain,328 other: (329 telemetry,330 filter_pool,331 frontier_backend,332 telemetry_worker_handle,333 fee_history_cache,334 ),335 };336337 Ok(params)338}339340async fn build_relay_chain_interface(341 polkadot_config: Configuration,342 parachain_config: &Configuration,343 telemetry_worker_handle: Option<TelemetryWorkerHandle>,344 task_manager: &mut TaskManager,345 collator_options: CollatorOptions,346 hwbench: Option<sc_sysinfo::HwBench>,347) -> RelayChainResult<(348 Arc<(dyn RelayChainInterface + 'static)>,349 Option<CollatorPair>,350)> {351 if collator_options.relay_chain_rpc_urls.is_empty() {352 build_inprocess_relay_chain(353 polkadot_config,354 parachain_config,355 telemetry_worker_handle,356 task_manager,357 hwbench,358 )359 } else {360 build_minimal_relay_chain_node(361 polkadot_config,362 task_manager,363 collator_options.relay_chain_rpc_urls,364 )365 .await366 }367}368369/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.370///371/// This is the actual implementation that is abstract over the executor and the runtime api.372#[sc_tracing::logging::prefix_logs_with("Parachain")]373async fn start_node_impl<Runtime, RuntimeApi, ExecutorDispatch, BIQ, BIC>(374 parachain_config: Configuration,375 polkadot_config: Configuration,376 collator_options: CollatorOptions,377 id: ParaId,378 build_import_queue: BIQ,379 build_consensus: BIC,380 hwbench: Option<sc_sysinfo::HwBench>,381) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>382where383 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,384 Runtime: RuntimeInstance + Send + Sync + 'static,385 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,386 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,387 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>388 + Send389 + Sync390 + 'static,391 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>392 + fp_rpc::EthereumRuntimeRPCApi<Block>393 + fp_rpc::ConvertTransactionRuntimeApi<Block>394 + sp_session::SessionKeys<Block>395 + sp_block_builder::BlockBuilder<Block>396 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>397 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>398 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>399 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>400 + up_pov_estimate_rpc::PovEstimateApi<Block>401 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>402 + sp_api::Metadata<Block>403 + sp_offchain::OffchainWorkerApi<Block>404 + cumulus_primitives_core::CollectCollationInfo<Block>,405 ExecutorDispatch: NativeExecutionDispatch + 'static,406 BIQ: FnOnce(407 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,408 Arc<FullBackend>,409 &Configuration,410 Option<TelemetryHandle>,411 &TaskManager,412 ) -> Result<413 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,414 sc_service::Error,415 >,416 BIC: FnOnce(417 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,418 Arc<FullBackend>,419 Option<&Registry>,420 Option<TelemetryHandle>,421 &TaskManager,422 Arc<dyn RelayChainInterface>,423 Arc<sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>>,424 Arc<NetworkService<Block, Hash>>,425 SyncCryptoStorePtr,426 bool,427 ) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,428{429 let parachain_config = prepare_node_config(parachain_config);430431 let params =432 new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(¶chain_config, build_import_queue)?;433 let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =434 params.other;435436 let client = params.client.clone();437 let backend = params.backend.clone();438 let mut task_manager = params.task_manager;439440 let (relay_chain_interface, collator_key) = build_relay_chain_interface(441 polkadot_config,442 ¶chain_config,443 telemetry_worker_handle,444 &mut task_manager,445 collator_options.clone(),446 hwbench.clone(),447 )448 .await449 .map_err(|e| match e {450 RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,451 s => s.to_string().into(),452 })?;453454 let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);455456 let force_authoring = parachain_config.force_authoring;457 let validator = parachain_config.role.is_authority();458 let prometheus_registry = parachain_config.prometheus_registry().cloned();459 let transaction_pool = params.transaction_pool.clone();460 let import_queue_service = params.import_queue.service();461462 let (network, system_rpc_tx, tx_handler_controller, start_network) =463 sc_service::build_network(sc_service::BuildNetworkParams {464 config: ¶chain_config,465 client: client.clone(),466 transaction_pool: transaction_pool.clone(),467 spawn_handle: task_manager.spawn_handle(),468 import_queue: params.import_queue,469 block_announce_validator_builder: Some(Box::new(|_| {470 Box::new(block_announce_validator)471 })),472 warp_sync: None,473 })?;474475 let rpc_client = client.clone();476 let rpc_pool = transaction_pool.clone();477 let select_chain = params.select_chain.clone();478 let rpc_network = network.clone();479480 let rpc_frontier_backend = frontier_backend.clone();481482 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(483 task_manager.spawn_handle(),484 overrides_handle::<_, _, Runtime>(client.clone()),485 50,486 50,487 prometheus_registry.clone(),488 ));489490 task_manager.spawn_essential_handle().spawn(491 "frontier-mapping-sync-worker",492 None,493 MappingSyncWorker::new(494 client.import_notification_stream(),495 Duration::new(6, 0),496 client.clone(),497 backend.clone(),498 frontier_backend.clone(),499 3,500 0,501 SyncStrategy::Normal,502 )503 .for_each(|()| futures::future::ready(())),504 );505506 #[cfg(feature = "pov-estimate")]507 let rpc_backend = backend.clone();508509 #[cfg(feature = "pov-estimate")]510 let runtime_id = parachain_config.chain_spec.runtime_id();511512 let rpc_builder = Box::new(move |deny_unsafe, subscription_task_executor| {513 let full_deps = unique_rpc::FullDeps {514 #[cfg(feature = "pov-estimate")]515 runtime_id: runtime_id.clone(),516517 #[cfg(feature = "pov-estimate")]518 exec_params: uc_rpc::pov_estimate::ExecutorParams {519 wasm_method: parachain_config.wasm_method,520 default_heap_pages: parachain_config.default_heap_pages,521 max_runtime_instances: parachain_config.max_runtime_instances,522 runtime_cache_size: parachain_config.runtime_cache_size,523 },524525 #[cfg(feature = "pov-estimate")]526 backend: rpc_backend.clone(),527528 eth_backend: rpc_frontier_backend.clone(),529 deny_unsafe,530 client: rpc_client.clone(),531 pool: rpc_pool.clone(),532 graph: rpc_pool.pool().clone(),533 // TODO: Unhardcode534 enable_dev_signer: false,535 filter_pool: filter_pool.clone(),536 network: rpc_network.clone(),537 select_chain: select_chain.clone(),538 is_authority: validator,539 // TODO: Unhardcode540 max_past_logs: 10000,541 block_data_cache: block_data_cache.clone(),542 fee_history_cache: fee_history_cache.clone(),543 // TODO: Unhardcode544 fee_history_limit: 2048,545 };546547 unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(548 full_deps,549 subscription_task_executor,550 )551 .map_err(Into::into)552 });553554 sc_service::spawn_tasks(sc_service::SpawnTasksParams {555 rpc_builder,556 client: client.clone(),557 transaction_pool: transaction_pool.clone(),558 task_manager: &mut task_manager,559 config: parachain_config,560 keystore: params.keystore_container.sync_keystore(),561 backend: backend.clone(),562 network: network.clone(),563 system_rpc_tx,564 telemetry: telemetry.as_mut(),565 tx_handler_controller,566 })?;567568 if let Some(hwbench) = hwbench {569 sc_sysinfo::print_hwbench(&hwbench);570571 if let Some(ref mut telemetry) = telemetry {572 let telemetry_handle = telemetry.handle();573 task_manager.spawn_handle().spawn(574 "telemetry_hwbench",575 None,576 sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),577 );578 }579 }580581 let announce_block = {582 let network = network.clone();583 Arc::new(Box::new(move |hash, data| {584 network.announce_block(hash, data)585 }))586 };587588 let relay_chain_slot_duration = Duration::from_secs(6);589590 if validator {591 let parachain_consensus = build_consensus(592 client.clone(),593 backend.clone(),594 prometheus_registry.as_ref(),595 telemetry.as_ref().map(|t| t.handle()),596 &task_manager,597 relay_chain_interface.clone(),598 transaction_pool,599 network,600 params.keystore_container.sync_keystore(),601 force_authoring,602 )?;603604 let spawner = task_manager.spawn_handle();605606 let params = StartCollatorParams {607 para_id: id,608 block_status: client.clone(),609 announce_block,610 client: client.clone(),611 task_manager: &mut task_manager,612 spawner,613 parachain_consensus,614 import_queue: import_queue_service,615 collator_key: collator_key.expect("Command line arguments do not allow this. qed"),616 relay_chain_interface,617 relay_chain_slot_duration,618 };619620 start_collator(params).await?;621 } else {622 let params = StartFullNodeParams {623 client: client.clone(),624 announce_block,625 task_manager: &mut task_manager,626 para_id: id,627 import_queue: import_queue_service,628 relay_chain_interface,629 relay_chain_slot_duration,630 };631632 start_full_node(params)?;633 }634635 start_network.start_network();636637 Ok((task_manager, client))638}639640/// Build the import queue for the the parachain runtime.641pub fn parachain_build_import_queue<RuntimeApi, ExecutorDispatch>(642 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,643 backend: Arc<FullBackend>,644 config: &Configuration,645 telemetry: Option<TelemetryHandle>,646 task_manager: &TaskManager,647) -> Result<648 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,649 sc_service::Error,650>651where652 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>653 + Send654 + Sync655 + 'static,656 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>657 + sp_block_builder::BlockBuilder<Block>658 + sp_consensus_aura::AuraApi<Block, AuraId>659 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,660 ExecutorDispatch: NativeExecutionDispatch + 'static,661{662 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;663664 let block_import = ParachainBlockImport::new(client.clone(), backend.clone());665666 cumulus_client_consensus_aura::import_queue::<667 sp_consensus_aura::sr25519::AuthorityPair,668 _,669 _,670 _,671 _,672 _,673 >(cumulus_client_consensus_aura::ImportQueueParams {674 block_import,675 client: client.clone(),676 create_inherent_data_providers: move |_, _| async move {677 let time = sp_timestamp::InherentDataProvider::from_system_time();678679 let slot =680 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(681 *time,682 slot_duration,683 );684685 Ok((slot, time))686 },687 registry: config.prometheus_registry(),688 spawner: &task_manager.spawn_essential_handle(),689 telemetry,690 })691 .map_err(Into::into)692}693694/// Start a normal parachain node.695pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(696 parachain_config: Configuration,697 polkadot_config: Configuration,698 collator_options: CollatorOptions,699 id: ParaId,700 hwbench: Option<sc_sysinfo::HwBench>,701) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>702where703 Runtime: RuntimeInstance + Send + Sync + 'static,704 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,705 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,706 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>707 + Send708 + Sync709 + 'static,710 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>711 + fp_rpc::EthereumRuntimeRPCApi<Block>712 + fp_rpc::ConvertTransactionRuntimeApi<Block>713 + sp_session::SessionKeys<Block>714 + sp_block_builder::BlockBuilder<Block>715 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>716 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>717 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>718 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>719 + up_pov_estimate_rpc::PovEstimateApi<Block>720 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>721 + sp_api::Metadata<Block>722 + sp_offchain::OffchainWorkerApi<Block>723 + cumulus_primitives_core::CollectCollationInfo<Block>724 + sp_consensus_aura::AuraApi<Block, AuraId>,725 ExecutorDispatch: NativeExecutionDispatch + 'static,726{727 start_node_impl::<Runtime, RuntimeApi, ExecutorDispatch, _, _>(728 parachain_config,729 polkadot_config,730 collator_options,731 id,732 parachain_build_import_queue,733 |client,734 backend,735 prometheus_registry,736 telemetry,737 task_manager,738 relay_chain_interface,739 transaction_pool,740 sync_oracle,741 keystore,742 force_authoring| {743 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;744745 let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(746 task_manager.spawn_handle(),747 client.clone(),748 transaction_pool,749 prometheus_registry,750 telemetry.clone(),751 );752753 let block_import = ParachainBlockImport::new(client.clone(), backend.clone());754755 Ok(AuraConsensus::build::<756 sp_consensus_aura::sr25519::AuthorityPair,757 _,758 _,759 _,760 _,761 _,762 _,763 >(BuildAuraConsensusParams {764 proposer_factory,765 create_inherent_data_providers: move |_, (relay_parent, validation_data)| {766 let relay_chain_interface = relay_chain_interface.clone();767 async move {768 let parachain_inherent =769 cumulus_primitives_parachain_inherent::ParachainInherentData::create_at(770 relay_parent,771 &relay_chain_interface,772 &validation_data,773 id,774 ).await;775776 let time = sp_timestamp::InherentDataProvider::from_system_time();777778 let slot =779 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(780 *time,781 slot_duration,782 );783784 let parachain_inherent = parachain_inherent.ok_or_else(|| {785 Box::<dyn std::error::Error + Send + Sync>::from(786 "Failed to create parachain inherent",787 )788 })?;789 Ok((slot, time, parachain_inherent))790 }791 },792 block_import,793 para_client: client,794 backoff_authoring_blocks: Option::<()>::None,795 sync_oracle,796 keystore,797 force_authoring,798 slot_duration,799 // We got around 500ms for proposing800 block_proposal_slot_portion: SlotProportion::new(1f32 / 24f32),801 telemetry,802 max_block_proposal_slot_portion: None,803 }))804 },805 hwbench,806 )807 .await808}809810fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(811 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,812 _: Arc<FullBackend>,813 config: &Configuration,814 _: Option<TelemetryHandle>,815 task_manager: &TaskManager,816) -> Result<817 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,818 sc_service::Error,819>820where821 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>822 + Send823 + Sync824 + 'static,825 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>826 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,827 ExecutorDispatch: NativeExecutionDispatch + 'static,828{829 Ok(sc_consensus_manual_seal::import_queue(830 Box::new(client.clone()),831 &task_manager.spawn_essential_handle(),832 config.prometheus_registry(),833 ))834}835836/// Builds a new development service. This service uses instant seal, and mocks837/// the parachain inherent838pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(839 config: Configuration,840 autoseal_interval: Duration,841) -> sc_service::error::Result<TaskManager>842where843 Runtime: RuntimeInstance + Send + Sync + 'static,844 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,845 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,846 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>847 + Send848 + Sync849 + 'static,850 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>851 + fp_rpc::EthereumRuntimeRPCApi<Block>852 + fp_rpc::ConvertTransactionRuntimeApi<Block>853 + sp_session::SessionKeys<Block>854 + sp_block_builder::BlockBuilder<Block>855 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>856 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>857 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>858 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>859 + up_pov_estimate_rpc::PovEstimateApi<Block>860 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>861 + sp_api::Metadata<Block>862 + sp_offchain::OffchainWorkerApi<Block>863 + cumulus_primitives_core::CollectCollationInfo<Block>864 + sp_consensus_aura::AuraApi<Block, AuraId>,865 ExecutorDispatch: NativeExecutionDispatch + 'static,866{867 use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};868 use fc_consensus::FrontierBlockImport;869 use sc_client_api::HeaderBackend;870871 let sc_service::PartialComponents {872 client,873 backend,874 mut task_manager,875 import_queue,876 keystore_container,877 select_chain: maybe_select_chain,878 transaction_pool,879 other:880 (telemetry, filter_pool, frontier_backend, _telemetry_worker_handle, fee_history_cache),881 } = new_partial::<RuntimeApi, ExecutorDispatch, _>(882 &config,883 dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,884 )?;885 let prometheus_registry = config.prometheus_registry().cloned();886887 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(888 task_manager.spawn_handle(),889 overrides_handle::<_, _, Runtime>(client.clone()),890 50,891 50,892 prometheus_registry.clone(),893 ));894895 let (network, system_rpc_tx, tx_handler_controller, network_starter) =896 sc_service::build_network(sc_service::BuildNetworkParams {897 config: &config,898 client: client.clone(),899 transaction_pool: transaction_pool.clone(),900 spawn_handle: task_manager.spawn_handle(),901 import_queue,902 block_announce_validator_builder: None,903 warp_sync: None,904 })?;905906 if config.offchain_worker.enabled {907 sc_service::build_offchain_workers(908 &config,909 task_manager.spawn_handle(),910 client.clone(),911 network.clone(),912 );913 }914915 let collator = config.role.is_authority();916917 let select_chain = maybe_select_chain.clone();918919 if collator {920 let block_import =921 FrontierBlockImport::new(client.clone(), client.clone(), frontier_backend.clone());922923 let env = sc_basic_authorship::ProposerFactory::new(924 task_manager.spawn_handle(),925 client.clone(),926 transaction_pool.clone(),927 prometheus_registry.as_ref(),928 telemetry.as_ref().map(|x| x.handle()),929 );930931 let transactions_commands_stream: Box<932 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,933 > = Box::new(934 transaction_pool935 .pool()936 .validated_pool()937 .import_notification_stream()938 .map(|_| EngineCommand::SealNewBlock {939 create_empty: true,940 finalize: false, // todo:collator finalize true941 parent_hash: None,942 sender: None,943 }),944 );945946 let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));947 let idle_commands_stream: Box<948 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,949 > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {950 create_empty: true,951 finalize: false, // todo:collator finalize true952 parent_hash: None,953 sender: None,954 }));955956 let commands_stream = select(transactions_commands_stream, idle_commands_stream);957958 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;959 let client_set_aside_for_cidp = client.clone();960961 task_manager.spawn_essential_handle().spawn_blocking(962 "authorship_task",963 Some("block-authoring"),964 run_manual_seal(ManualSealParams {965 block_import,966 env,967 client: client.clone(),968 pool: transaction_pool.clone(),969 commands_stream,970 select_chain: select_chain.clone(),971 consensus_data_provider: None,972 create_inherent_data_providers: move |block: Hash, ()| {973 let current_para_block = client_set_aside_for_cidp974 .number(block)975 .expect("Header lookup should succeed")976 .expect("Header passed in as parent should be present in backend.");977978 let client_for_xcm = client_set_aside_for_cidp.clone();979 async move {980 let time = sp_timestamp::InherentDataProvider::from_system_time();981982 let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {983 current_para_block,984 relay_offset: 1000,985 relay_blocks_per_para_block: 2,986 para_blocks_per_relay_epoch: 0,987 xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(988 &*client_for_xcm,989 block,990 Default::default(),991 Default::default(),992 ),993 relay_randomness_config: (),994 raw_downward_messages: vec![],995 raw_horizontal_messages: vec![],996 };997998 let slot =999 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(1000 *time,1001 slot_duration,1002 );10031004 Ok((time, slot, mocked_parachain))1005 }1006 },1007 }),1008 );1009 }10101011 task_manager.spawn_essential_handle().spawn(1012 "frontier-mapping-sync-worker",1013 Some("block-authoring"),1014 MappingSyncWorker::new(1015 client.import_notification_stream(),1016 Duration::new(6, 0),1017 client.clone(),1018 backend.clone(),1019 frontier_backend.clone(),1020 3,1021 0,1022 SyncStrategy::Normal,1023 )1024 .for_each(|()| futures::future::ready(())),1025 );10261027 let rpc_client = client.clone();1028 let rpc_pool = transaction_pool.clone();1029 let rpc_network = network.clone();1030 let rpc_frontier_backend = frontier_backend.clone();10311032 #[cfg(feature = "pov-estimate")]1033 let rpc_backend = backend.clone();10341035 #[cfg(feature = "pov-estimate")]1036 let runtime_id = config.chain_spec.runtime_id();10371038 let rpc_builder = Box::new(move |deny_unsafe, subscription_executor| {1039 let full_deps = unique_rpc::FullDeps {1040 #[cfg(feature = "pov-estimate")]1041 runtime_id: runtime_id.clone(),10421043 #[cfg(feature = "pov-estimate")]1044 exec_params: uc_rpc::pov_estimate::ExecutorParams {1045 wasm_method: config.wasm_method,1046 default_heap_pages: config.default_heap_pages,1047 max_runtime_instances: config.max_runtime_instances,1048 runtime_cache_size: config.runtime_cache_size,1049 },10501051 #[cfg(feature = "pov-estimate")]1052 backend: rpc_backend.clone(),1053 eth_backend: rpc_frontier_backend.clone(),1054 deny_unsafe,1055 client: rpc_client.clone(),1056 pool: rpc_pool.clone(),1057 graph: rpc_pool.pool().clone(),1058 // TODO: Unhardcode1059 enable_dev_signer: false,1060 filter_pool: filter_pool.clone(),1061 network: rpc_network.clone(),1062 select_chain: select_chain.clone(),1063 is_authority: collator,1064 // TODO: Unhardcode1065 max_past_logs: 10000,1066 block_data_cache: block_data_cache.clone(),1067 fee_history_cache: fee_history_cache.clone(),1068 // TODO: Unhardcode1069 fee_history_limit: 2048,1070 };10711072 unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(1073 full_deps,1074 subscription_executor,1075 )1076 .map_err(Into::into)1077 });10781079 sc_service::spawn_tasks(sc_service::SpawnTasksParams {1080 network,1081 client,1082 keystore: keystore_container.sync_keystore(),1083 task_manager: &mut task_manager,1084 transaction_pool,1085 rpc_builder,1086 backend,1087 system_rpc_tx,1088 config,1089 telemetry: None,1090 tx_handler_controller,1091 })?;10921093 network_starter.start_network();1094 Ok(task_manager)1095}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// std18use std::sync::Arc;19use std::sync::Mutex;20use std::collections::BTreeMap;21use std::time::Duration;22use std::pin::Pin;23use fc_rpc_core::types::FeeHistoryCache;24use futures::{25 Stream, StreamExt,26 stream::select,27 task::{Context, Poll},28};29use tokio::time::Interval;3031use unique_rpc::overrides_handle;3233use serde::{Serialize, Deserialize};3435// Cumulus Imports36use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};37use cumulus_client_consensus_common::{38 ParachainConsensus, ParachainBlockImport as TParachainBlockImport,39};40use cumulus_client_service::{41 prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,42};43use cumulus_client_cli::CollatorOptions;44use cumulus_client_network::BlockAnnounceValidator;45use cumulus_primitives_core::ParaId;46use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain;47use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayChainResult};48use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node;4950// Substrate Imports51use sp_api::BlockT;52use sc_executor::NativeElseWasmExecutor;53use sc_executor::NativeExecutionDispatch;54use sc_network::{NetworkService, NetworkBlock};55use sc_service::{BasePath, Configuration, PartialComponents, TaskManager};56use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};57use sp_keystore::SyncCryptoStorePtr;58use sp_runtime::traits::BlakeTwo256;59use substrate_prometheus_endpoint::Registry;60use sc_client_api::BlockchainEvents;61use sc_consensus::ImportQueue;6263use polkadot_service::CollatorPair;6465// Frontier Imports66use fc_rpc_core::types::FilterPool;67use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};6869use up_common::types::opaque::*;7071use crate::chain_spec::RuntimeIdentification;7273/// Unique native executor instance.74#[cfg(feature = "unique-runtime")]75pub struct UniqueRuntimeExecutor;7677#[cfg(feature = "quartz-runtime")]78/// Quartz native executor instance.79pub struct QuartzRuntimeExecutor;8081/// Opal native executor instance.82pub struct OpalRuntimeExecutor;8384#[cfg(all(feature = "unique-runtime", feature = "runtime-benchmarks"))]85pub type DefaultRuntimeExecutor = UniqueRuntimeExecutor;8687#[cfg(all(88 not(feature = "unique-runtime"),89 feature = "quartz-runtime",90 feature = "runtime-benchmarks"91))]92pub type DefaultRuntimeExecutor = QuartzRuntimeExecutor;9394#[cfg(all(95 not(feature = "unique-runtime"),96 not(feature = "quartz-runtime"),97 feature = "runtime-benchmarks"98))]99pub type DefaultRuntimeExecutor = OpalRuntimeExecutor;100101#[cfg(feature = "unique-runtime")]102impl NativeExecutionDispatch for UniqueRuntimeExecutor {103 /// Only enable the benchmarking host functions when we actually want to benchmark.104 #[cfg(feature = "runtime-benchmarks")]105 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;106 /// Otherwise we only use the default Substrate host functions.107 #[cfg(not(feature = "runtime-benchmarks"))]108 type ExtendHostFunctions = ();109110 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {111 unique_runtime::api::dispatch(method, data)112 }113114 fn native_version() -> sc_executor::NativeVersion {115 unique_runtime::native_version()116 }117}118119#[cfg(feature = "quartz-runtime")]120impl NativeExecutionDispatch for QuartzRuntimeExecutor {121 /// Only enable the benchmarking host functions when we actually want to benchmark.122 #[cfg(feature = "runtime-benchmarks")]123 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;124 /// Otherwise we only use the default Substrate host functions.125 #[cfg(not(feature = "runtime-benchmarks"))]126 type ExtendHostFunctions = ();127128 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {129 quartz_runtime::api::dispatch(method, data)130 }131132 fn native_version() -> sc_executor::NativeVersion {133 quartz_runtime::native_version()134 }135}136137impl NativeExecutionDispatch for OpalRuntimeExecutor {138 /// Only enable the benchmarking host functions when we actually want to benchmark.139 #[cfg(feature = "runtime-benchmarks")]140 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;141 /// Otherwise we only use the default Substrate host functions.142 #[cfg(not(feature = "runtime-benchmarks"))]143 type ExtendHostFunctions = ();144145 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {146 opal_runtime::api::dispatch(method, data)147 }148149 fn native_version() -> sc_executor::NativeVersion {150 opal_runtime::native_version()151 }152}153154pub struct AutosealInterval {155 interval: Interval,156}157158impl AutosealInterval {159 pub fn new(config: &Configuration, interval: Duration) -> Self {160 let _tokio_runtime = config.tokio_handle.enter();161 let interval = tokio::time::interval(interval);162163 Self { interval }164 }165}166167impl Stream for AutosealInterval {168 type Item = tokio::time::Instant;169170 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {171 self.interval.poll_tick(cx).map(Some)172 }173}174175pub fn open_frontier_backend<Block: BlockT, C: sp_blockchain::HeaderBackend<Block>>(176 client: Arc<C>,177 config: &Configuration,178) -> Result<Arc<fc_db::Backend<Block>>, String> {179 let config_dir = config180 .base_path181 .as_ref()182 .map(|base_path| base_path.config_dir(config.chain_spec.id()))183 .unwrap_or_else(|| {184 BasePath::from_project("", "", "unique").config_dir(config.chain_spec.id())185 });186 let database_dir = config_dir.join("frontier").join("db");187188 Ok(Arc::new(fc_db::Backend::<Block>::new(189 client,190 &fc_db::DatabaseSettings {191 source: fc_db::DatabaseSource::RocksDb {192 path: database_dir,193 cache_size: 0,194 },195 },196 )?))197}198199type FullClient<RuntimeApi, ExecutorDispatch> =200 sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;201type FullBackend = sc_service::TFullBackend<Block>;202type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;203type ParachainBlockImport<RuntimeApi, ExecutorDispatch> =204 TParachainBlockImport<Block, Arc<FullClient<RuntimeApi, ExecutorDispatch>>, FullBackend>;205206/// Starts a `ServiceBuilder` for a full service.207///208/// Use this macro if you don't actually need the full service, but just the builder in order to209/// be able to perform chain operations.210#[allow(clippy::type_complexity)]211pub fn new_partial<RuntimeApi, ExecutorDispatch, BIQ>(212 config: &Configuration,213 build_import_queue: BIQ,214) -> Result<215 PartialComponents<216 FullClient<RuntimeApi, ExecutorDispatch>,217 FullBackend,218 FullSelectChain,219 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,220 sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,221 (222 Option<Telemetry>,223 Option<FilterPool>,224 Arc<fc_db::Backend<Block>>,225 Option<TelemetryWorkerHandle>,226 FeeHistoryCache,227 ),228 >,229 sc_service::Error,230>231where232 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,233 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>234 + Send235 + Sync236 + 'static,237 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,238 ExecutorDispatch: NativeExecutionDispatch + 'static,239 BIQ: FnOnce(240 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,241 Arc<FullBackend>,242 &Configuration,243 Option<TelemetryHandle>,244 &TaskManager,245 ) -> Result<246 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,247 sc_service::Error,248 >,249{250 let _telemetry = config251 .telemetry_endpoints252 .clone()253 .filter(|x| !x.is_empty())254 .map(|endpoints| -> Result<_, sc_telemetry::Error> {255 let worker = TelemetryWorker::new(16)?;256 let telemetry = worker.handle().new_telemetry(endpoints);257 Ok((worker, telemetry))258 })259 .transpose()?;260261 let telemetry = config262 .telemetry_endpoints263 .clone()264 .filter(|x| !x.is_empty())265 .map(|endpoints| -> Result<_, sc_telemetry::Error> {266 let worker = TelemetryWorker::new(16)?;267 let telemetry = worker.handle().new_telemetry(endpoints);268 Ok((worker, telemetry))269 })270 .transpose()?;271272 let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(273 config.wasm_method,274 config.default_heap_pages,275 config.max_runtime_instances,276 config.runtime_cache_size,277 );278279 let (client, backend, keystore_container, task_manager) =280 sc_service::new_full_parts::<Block, RuntimeApi, _>(281 config,282 telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),283 executor,284 )?;285 let client = Arc::new(client);286287 let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());288289 let telemetry = telemetry.map(|(worker, telemetry)| {290 task_manager291 .spawn_handle()292 .spawn("telemetry", None, worker.run());293 telemetry294 });295296 let select_chain = sc_consensus::LongestChain::new(backend.clone());297298 let transaction_pool = sc_transaction_pool::BasicPool::new_full(299 config.transaction_pool.clone(),300 config.role.is_authority().into(),301 config.prometheus_registry(),302 task_manager.spawn_essential_handle(),303 client.clone(),304 );305306 let filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));307308 let frontier_backend = open_frontier_backend(client.clone(), config)?;309310 let import_queue = build_import_queue(311 client.clone(),312 backend.clone(),313 config,314 telemetry.as_ref().map(|telemetry| telemetry.handle()),315 &task_manager,316 )?;317 let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));318319 let params = PartialComponents {320 backend,321 client,322 import_queue,323 keystore_container,324 task_manager,325 transaction_pool,326 select_chain,327 other: (328 telemetry,329 filter_pool,330 frontier_backend,331 telemetry_worker_handle,332 fee_history_cache,333 ),334 };335336 Ok(params)337}338339async fn build_relay_chain_interface(340 polkadot_config: Configuration,341 parachain_config: &Configuration,342 telemetry_worker_handle: Option<TelemetryWorkerHandle>,343 task_manager: &mut TaskManager,344 collator_options: CollatorOptions,345 hwbench: Option<sc_sysinfo::HwBench>,346) -> RelayChainResult<(347 Arc<(dyn RelayChainInterface + 'static)>,348 Option<CollatorPair>,349)> {350 if collator_options.relay_chain_rpc_urls.is_empty() {351 build_inprocess_relay_chain(352 polkadot_config,353 parachain_config,354 telemetry_worker_handle,355 task_manager,356 hwbench,357 )358 } else {359 build_minimal_relay_chain_node(360 polkadot_config,361 task_manager,362 collator_options.relay_chain_rpc_urls,363 )364 .await365 }366}367368/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.369///370/// This is the actual implementation that is abstract over the executor and the runtime api.371#[sc_tracing::logging::prefix_logs_with("Parachain")]372async fn start_node_impl<Runtime, RuntimeApi, ExecutorDispatch, BIQ, BIC>(373 parachain_config: Configuration,374 polkadot_config: Configuration,375 collator_options: CollatorOptions,376 id: ParaId,377 build_import_queue: BIQ,378 build_consensus: BIC,379 hwbench: Option<sc_sysinfo::HwBench>,380) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>381where382 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,383 Runtime: RuntimeInstance + Send + Sync + 'static,384 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,385 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,386 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>387 + Send388 + Sync389 + 'static,390 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>391 + fp_rpc::EthereumRuntimeRPCApi<Block>392 + fp_rpc::ConvertTransactionRuntimeApi<Block>393 + sp_session::SessionKeys<Block>394 + sp_block_builder::BlockBuilder<Block>395 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>396 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>397 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>398 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>399 + up_pov_estimate_rpc::PovEstimateApi<Block>400 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>401 + sp_api::Metadata<Block>402 + sp_offchain::OffchainWorkerApi<Block>403 + cumulus_primitives_core::CollectCollationInfo<Block>,404 ExecutorDispatch: NativeExecutionDispatch + 'static,405 BIQ: FnOnce(406 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,407 Arc<FullBackend>,408 &Configuration,409 Option<TelemetryHandle>,410 &TaskManager,411 ) -> Result<412 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,413 sc_service::Error,414 >,415 BIC: FnOnce(416 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,417 Arc<FullBackend>,418 Option<&Registry>,419 Option<TelemetryHandle>,420 &TaskManager,421 Arc<dyn RelayChainInterface>,422 Arc<sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>>,423 Arc<NetworkService<Block, Hash>>,424 SyncCryptoStorePtr,425 bool,426 ) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,427{428 let parachain_config = prepare_node_config(parachain_config);429430 let params =431 new_partial::<RuntimeApi, ExecutorDispatch, BIQ>(¶chain_config, build_import_queue)?;432 let (mut telemetry, filter_pool, frontier_backend, telemetry_worker_handle, fee_history_cache) =433 params.other;434435 let client = params.client.clone();436 let backend = params.backend.clone();437 let mut task_manager = params.task_manager;438439 let (relay_chain_interface, collator_key) = build_relay_chain_interface(440 polkadot_config,441 ¶chain_config,442 telemetry_worker_handle,443 &mut task_manager,444 collator_options.clone(),445 hwbench.clone(),446 )447 .await448 .map_err(|e| match e {449 RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x,450 s => s.to_string().into(),451 })?;452453 let block_announce_validator = BlockAnnounceValidator::new(relay_chain_interface.clone(), id);454455 let force_authoring = parachain_config.force_authoring;456 let validator = parachain_config.role.is_authority();457 let prometheus_registry = parachain_config.prometheus_registry().cloned();458 let transaction_pool = params.transaction_pool.clone();459 let import_queue_service = params.import_queue.service();460461 let (network, system_rpc_tx, tx_handler_controller, start_network) =462 sc_service::build_network(sc_service::BuildNetworkParams {463 config: ¶chain_config,464 client: client.clone(),465 transaction_pool: transaction_pool.clone(),466 spawn_handle: task_manager.spawn_handle(),467 import_queue: params.import_queue,468 block_announce_validator_builder: Some(Box::new(|_| {469 Box::new(block_announce_validator)470 })),471 warp_sync: None,472 })?;473474 let rpc_client = client.clone();475 let rpc_pool = transaction_pool.clone();476 let select_chain = params.select_chain.clone();477 let rpc_network = network.clone();478479 let rpc_frontier_backend = frontier_backend.clone();480481 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(482 task_manager.spawn_handle(),483 overrides_handle::<_, _, Runtime>(client.clone()),484 50,485 50,486 prometheus_registry.clone(),487 ));488489 task_manager.spawn_essential_handle().spawn(490 "frontier-mapping-sync-worker",491 None,492 MappingSyncWorker::new(493 client.import_notification_stream(),494 Duration::new(6, 0),495 client.clone(),496 backend.clone(),497 frontier_backend.clone(),498 3,499 0,500 SyncStrategy::Normal,501 )502 .for_each(|()| futures::future::ready(())),503 );504505 #[cfg(feature = "pov-estimate")]506 let rpc_backend = backend.clone();507508 let runtime_id = parachain_config.chain_spec.runtime_id();509510 let rpc_builder = Box::new(move |deny_unsafe, subscription_task_executor| {511 let full_deps = unique_rpc::FullDeps {512 runtime_id: runtime_id.clone(),513514 #[cfg(feature = "pov-estimate")]515 exec_params: uc_rpc::pov_estimate::ExecutorParams {516 wasm_method: parachain_config.wasm_method,517 default_heap_pages: parachain_config.default_heap_pages,518 max_runtime_instances: parachain_config.max_runtime_instances,519 runtime_cache_size: parachain_config.runtime_cache_size,520 },521522 #[cfg(feature = "pov-estimate")]523 backend: rpc_backend.clone(),524525 eth_backend: rpc_frontier_backend.clone(),526 deny_unsafe,527 client: rpc_client.clone(),528 pool: rpc_pool.clone(),529 graph: rpc_pool.pool().clone(),530 // TODO: Unhardcode531 enable_dev_signer: false,532 filter_pool: filter_pool.clone(),533 network: rpc_network.clone(),534 select_chain: select_chain.clone(),535 is_authority: validator,536 // TODO: Unhardcode537 max_past_logs: 10000,538 block_data_cache: block_data_cache.clone(),539 fee_history_cache: fee_history_cache.clone(),540 // TODO: Unhardcode541 fee_history_limit: 2048,542 };543544 unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(545 full_deps,546 subscription_task_executor,547 )548 .map_err(Into::into)549 });550551 sc_service::spawn_tasks(sc_service::SpawnTasksParams {552 rpc_builder,553 client: client.clone(),554 transaction_pool: transaction_pool.clone(),555 task_manager: &mut task_manager,556 config: parachain_config,557 keystore: params.keystore_container.sync_keystore(),558 backend: backend.clone(),559 network: network.clone(),560 system_rpc_tx,561 telemetry: telemetry.as_mut(),562 tx_handler_controller,563 })?;564565 if let Some(hwbench) = hwbench {566 sc_sysinfo::print_hwbench(&hwbench);567568 if let Some(ref mut telemetry) = telemetry {569 let telemetry_handle = telemetry.handle();570 task_manager.spawn_handle().spawn(571 "telemetry_hwbench",572 None,573 sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),574 );575 }576 }577578 let announce_block = {579 let network = network.clone();580 Arc::new(Box::new(move |hash, data| {581 network.announce_block(hash, data)582 }))583 };584585 let relay_chain_slot_duration = Duration::from_secs(6);586587 if validator {588 let parachain_consensus = build_consensus(589 client.clone(),590 backend.clone(),591 prometheus_registry.as_ref(),592 telemetry.as_ref().map(|t| t.handle()),593 &task_manager,594 relay_chain_interface.clone(),595 transaction_pool,596 network,597 params.keystore_container.sync_keystore(),598 force_authoring,599 )?;600601 let spawner = task_manager.spawn_handle();602603 let params = StartCollatorParams {604 para_id: id,605 block_status: client.clone(),606 announce_block,607 client: client.clone(),608 task_manager: &mut task_manager,609 spawner,610 parachain_consensus,611 import_queue: import_queue_service,612 collator_key: collator_key.expect("Command line arguments do not allow this. qed"),613 relay_chain_interface,614 relay_chain_slot_duration,615 };616617 start_collator(params).await?;618 } else {619 let params = StartFullNodeParams {620 client: client.clone(),621 announce_block,622 task_manager: &mut task_manager,623 para_id: id,624 import_queue: import_queue_service,625 relay_chain_interface,626 relay_chain_slot_duration,627 };628629 start_full_node(params)?;630 }631632 start_network.start_network();633634 Ok((task_manager, client))635}636637/// Build the import queue for the the parachain runtime.638pub fn parachain_build_import_queue<RuntimeApi, ExecutorDispatch>(639 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,640 backend: Arc<FullBackend>,641 config: &Configuration,642 telemetry: Option<TelemetryHandle>,643 task_manager: &TaskManager,644) -> Result<645 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,646 sc_service::Error,647>648where649 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>650 + Send651 + Sync652 + 'static,653 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>654 + sp_block_builder::BlockBuilder<Block>655 + sp_consensus_aura::AuraApi<Block, AuraId>656 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,657 ExecutorDispatch: NativeExecutionDispatch + 'static,658{659 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;660661 let block_import = ParachainBlockImport::new(client.clone(), backend.clone());662663 cumulus_client_consensus_aura::import_queue::<664 sp_consensus_aura::sr25519::AuthorityPair,665 _,666 _,667 _,668 _,669 _,670 >(cumulus_client_consensus_aura::ImportQueueParams {671 block_import,672 client: client.clone(),673 create_inherent_data_providers: move |_, _| async move {674 let time = sp_timestamp::InherentDataProvider::from_system_time();675676 let slot =677 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(678 *time,679 slot_duration,680 );681682 Ok((slot, time))683 },684 registry: config.prometheus_registry(),685 spawner: &task_manager.spawn_essential_handle(),686 telemetry,687 })688 .map_err(Into::into)689}690691/// Start a normal parachain node.692pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(693 parachain_config: Configuration,694 polkadot_config: Configuration,695 collator_options: CollatorOptions,696 id: ParaId,697 hwbench: Option<sc_sysinfo::HwBench>,698) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>699where700 Runtime: RuntimeInstance + Send + Sync + 'static,701 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,702 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,703 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>704 + Send705 + Sync706 + 'static,707 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>708 + fp_rpc::EthereumRuntimeRPCApi<Block>709 + fp_rpc::ConvertTransactionRuntimeApi<Block>710 + sp_session::SessionKeys<Block>711 + sp_block_builder::BlockBuilder<Block>712 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>713 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>714 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>715 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>716 + up_pov_estimate_rpc::PovEstimateApi<Block>717 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>718 + sp_api::Metadata<Block>719 + sp_offchain::OffchainWorkerApi<Block>720 + cumulus_primitives_core::CollectCollationInfo<Block>721 + sp_consensus_aura::AuraApi<Block, AuraId>,722 ExecutorDispatch: NativeExecutionDispatch + 'static,723{724 start_node_impl::<Runtime, RuntimeApi, ExecutorDispatch, _, _>(725 parachain_config,726 polkadot_config,727 collator_options,728 id,729 parachain_build_import_queue,730 |client,731 backend,732 prometheus_registry,733 telemetry,734 task_manager,735 relay_chain_interface,736 transaction_pool,737 sync_oracle,738 keystore,739 force_authoring| {740 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;741742 let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(743 task_manager.spawn_handle(),744 client.clone(),745 transaction_pool,746 prometheus_registry,747 telemetry.clone(),748 );749750 let block_import = ParachainBlockImport::new(client.clone(), backend.clone());751752 Ok(AuraConsensus::build::<753 sp_consensus_aura::sr25519::AuthorityPair,754 _,755 _,756 _,757 _,758 _,759 _,760 >(BuildAuraConsensusParams {761 proposer_factory,762 create_inherent_data_providers: move |_, (relay_parent, validation_data)| {763 let relay_chain_interface = relay_chain_interface.clone();764 async move {765 let parachain_inherent =766 cumulus_primitives_parachain_inherent::ParachainInherentData::create_at(767 relay_parent,768 &relay_chain_interface,769 &validation_data,770 id,771 ).await;772773 let time = sp_timestamp::InherentDataProvider::from_system_time();774775 let slot =776 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(777 *time,778 slot_duration,779 );780781 let parachain_inherent = parachain_inherent.ok_or_else(|| {782 Box::<dyn std::error::Error + Send + Sync>::from(783 "Failed to create parachain inherent",784 )785 })?;786 Ok((slot, time, parachain_inherent))787 }788 },789 block_import,790 para_client: client,791 backoff_authoring_blocks: Option::<()>::None,792 sync_oracle,793 keystore,794 force_authoring,795 slot_duration,796 // We got around 500ms for proposing797 block_proposal_slot_portion: SlotProportion::new(1f32 / 24f32),798 telemetry,799 max_block_proposal_slot_portion: None,800 }))801 },802 hwbench,803 )804 .await805}806807fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(808 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,809 _: Arc<FullBackend>,810 config: &Configuration,811 _: Option<TelemetryHandle>,812 task_manager: &TaskManager,813) -> Result<814 sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,815 sc_service::Error,816>817where818 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>819 + Send820 + Sync821 + 'static,822 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>823 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>,824 ExecutorDispatch: NativeExecutionDispatch + 'static,825{826 Ok(sc_consensus_manual_seal::import_queue(827 Box::new(client.clone()),828 &task_manager.spawn_essential_handle(),829 config.prometheus_registry(),830 ))831}832833/// Builds a new development service. This service uses instant seal, and mocks834/// the parachain inherent835pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(836 config: Configuration,837 autoseal_interval: Duration,838) -> sc_service::error::Result<TaskManager>839where840 Runtime: RuntimeInstance + Send + Sync + 'static,841 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,842 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,843 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>844 + Send845 + Sync846 + 'static,847 RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>848 + fp_rpc::EthereumRuntimeRPCApi<Block>849 + fp_rpc::ConvertTransactionRuntimeApi<Block>850 + sp_session::SessionKeys<Block>851 + sp_block_builder::BlockBuilder<Block>852 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>853 + sp_api::ApiExt<Block, StateBackend = sc_client_api::StateBackendFor<FullBackend, Block>>854 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>855 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>856 + up_pov_estimate_rpc::PovEstimateApi<Block>857 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>858 + sp_api::Metadata<Block>859 + sp_offchain::OffchainWorkerApi<Block>860 + cumulus_primitives_core::CollectCollationInfo<Block>861 + sp_consensus_aura::AuraApi<Block, AuraId>,862 ExecutorDispatch: NativeExecutionDispatch + 'static,863{864 use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};865 use fc_consensus::FrontierBlockImport;866 use sc_client_api::HeaderBackend;867868 let sc_service::PartialComponents {869 client,870 backend,871 mut task_manager,872 import_queue,873 keystore_container,874 select_chain: maybe_select_chain,875 transaction_pool,876 other:877 (telemetry, filter_pool, frontier_backend, _telemetry_worker_handle, fee_history_cache),878 } = new_partial::<RuntimeApi, ExecutorDispatch, _>(879 &config,880 dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,881 )?;882 let prometheus_registry = config.prometheus_registry().cloned();883884 let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new(885 task_manager.spawn_handle(),886 overrides_handle::<_, _, Runtime>(client.clone()),887 50,888 50,889 prometheus_registry.clone(),890 ));891892 let (network, system_rpc_tx, tx_handler_controller, network_starter) =893 sc_service::build_network(sc_service::BuildNetworkParams {894 config: &config,895 client: client.clone(),896 transaction_pool: transaction_pool.clone(),897 spawn_handle: task_manager.spawn_handle(),898 import_queue,899 block_announce_validator_builder: None,900 warp_sync: None,901 })?;902903 if config.offchain_worker.enabled {904 sc_service::build_offchain_workers(905 &config,906 task_manager.spawn_handle(),907 client.clone(),908 network.clone(),909 );910 }911912 let collator = config.role.is_authority();913914 let select_chain = maybe_select_chain.clone();915916 if collator {917 let block_import =918 FrontierBlockImport::new(client.clone(), client.clone(), frontier_backend.clone());919920 let env = sc_basic_authorship::ProposerFactory::new(921 task_manager.spawn_handle(),922 client.clone(),923 transaction_pool.clone(),924 prometheus_registry.as_ref(),925 telemetry.as_ref().map(|x| x.handle()),926 );927928 let transactions_commands_stream: Box<929 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,930 > = Box::new(931 transaction_pool932 .pool()933 .validated_pool()934 .import_notification_stream()935 .map(|_| EngineCommand::SealNewBlock {936 create_empty: true,937 finalize: false, // todo:collator finalize true938 parent_hash: None,939 sender: None,940 }),941 );942943 let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));944 let idle_commands_stream: Box<945 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,946 > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {947 create_empty: true,948 finalize: false, // todo:collator finalize true949 parent_hash: None,950 sender: None,951 }));952953 let commands_stream = select(transactions_commands_stream, idle_commands_stream);954955 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;956 let client_set_aside_for_cidp = client.clone();957958 task_manager.spawn_essential_handle().spawn_blocking(959 "authorship_task",960 Some("block-authoring"),961 run_manual_seal(ManualSealParams {962 block_import,963 env,964 client: client.clone(),965 pool: transaction_pool.clone(),966 commands_stream,967 select_chain: select_chain.clone(),968 consensus_data_provider: None,969 create_inherent_data_providers: move |block: Hash, ()| {970 let current_para_block = client_set_aside_for_cidp971 .number(block)972 .expect("Header lookup should succeed")973 .expect("Header passed in as parent should be present in backend.");974975 let client_for_xcm = client_set_aside_for_cidp.clone();976 async move {977 let time = sp_timestamp::InherentDataProvider::from_system_time();978979 let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {980 current_para_block,981 relay_offset: 1000,982 relay_blocks_per_para_block: 2,983 para_blocks_per_relay_epoch: 0,984 xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(985 &*client_for_xcm,986 block,987 Default::default(),988 Default::default(),989 ),990 relay_randomness_config: (),991 raw_downward_messages: vec![],992 raw_horizontal_messages: vec![],993 };994995 let slot =996 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(997 *time,998 slot_duration,999 );10001001 Ok((time, slot, mocked_parachain))1002 }1003 },1004 }),1005 );1006 }10071008 task_manager.spawn_essential_handle().spawn(1009 "frontier-mapping-sync-worker",1010 Some("block-authoring"),1011 MappingSyncWorker::new(1012 client.import_notification_stream(),1013 Duration::new(6, 0),1014 client.clone(),1015 backend.clone(),1016 frontier_backend.clone(),1017 3,1018 0,1019 SyncStrategy::Normal,1020 )1021 .for_each(|()| futures::future::ready(())),1022 );10231024 let rpc_client = client.clone();1025 let rpc_pool = transaction_pool.clone();1026 let rpc_network = network.clone();1027 let rpc_frontier_backend = frontier_backend.clone();10281029 #[cfg(feature = "pov-estimate")]1030 let rpc_backend = backend.clone();10311032 let runtime_id = config.chain_spec.runtime_id();10331034 let rpc_builder = Box::new(move |deny_unsafe, subscription_executor| {1035 let full_deps = unique_rpc::FullDeps {1036 runtime_id: runtime_id.clone(),10371038 #[cfg(feature = "pov-estimate")]1039 exec_params: uc_rpc::pov_estimate::ExecutorParams {1040 wasm_method: config.wasm_method,1041 default_heap_pages: config.default_heap_pages,1042 max_runtime_instances: config.max_runtime_instances,1043 runtime_cache_size: config.runtime_cache_size,1044 },10451046 #[cfg(feature = "pov-estimate")]1047 backend: rpc_backend.clone(),1048 eth_backend: rpc_frontier_backend.clone(),1049 deny_unsafe,1050 client: rpc_client.clone(),1051 pool: rpc_pool.clone(),1052 graph: rpc_pool.pool().clone(),1053 // TODO: Unhardcode1054 enable_dev_signer: false,1055 filter_pool: filter_pool.clone(),1056 network: rpc_network.clone(),1057 select_chain: select_chain.clone(),1058 is_authority: collator,1059 // TODO: Unhardcode1060 max_past_logs: 10000,1061 block_data_cache: block_data_cache.clone(),1062 fee_history_cache: fee_history_cache.clone(),1063 // TODO: Unhardcode1064 fee_history_limit: 2048,1065 };10661067 unique_rpc::create_full::<_, _, _, _, Runtime, RuntimeApi, _>(1068 full_deps,1069 subscription_executor,1070 )1071 .map_err(Into::into)1072 });10731074 sc_service::spawn_tasks(sc_service::SpawnTasksParams {1075 network,1076 client,1077 keystore: keystore_container.sync_keystore(),1078 task_manager: &mut task_manager,1079 transaction_pool,1080 rpc_builder,1081 backend,1082 system_rpc_tx,1083 config,1084 telemetry: None,1085 tx_handler_controller,1086 })?;10871088 network_starter.start_network();1089 Ok(task_manager)1090}node/rpc/Cargo.tomldiffbeforeafterboth--- a/node/rpc/Cargo.toml
+++ b/node/rpc/Cargo.toml
@@ -44,4 +44,3 @@
default = []
pov-estimate = ['uc-rpc/pov-estimate']
std = []
-unique-runtime = []
node/rpc/src/lib.rsdiffbeforeafterboth--- a/node/rpc/src/lib.rs
+++ b/node/rpc/src/lib.rs
@@ -80,7 +80,7 @@
/// EthFilterApi pool.
pub filter_pool: Option<FilterPool>,
- #[cfg(feature = "pov-estimate")]
+ /// Runtime identification (read from the chain spec)
pub runtime_id: RuntimeId,
/// Executor params for PoV estimating
#[cfg(feature = "pov-estimate")]
@@ -197,8 +197,7 @@
deny_unsafe,
filter_pool,
- #[cfg(feature = "pov-estimate")]
- runtime_id,
+ runtime_id: _,
#[cfg(feature = "pov-estimate")]
exec_params,