difftreelog
fix benchmarks
in: master
6 files changed
node/cli/src/command.rsdiffbeforeafterboth--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -42,10 +42,6 @@
use sp_runtime::traits::AccountIdConversion;
use up_common::types::opaque::RuntimeId;
-#[cfg(feature = "runtime-benchmarks")]
-use crate::chain_spec::default_runtime;
-#[cfg(feature = "runtime-benchmarks")]
-use crate::service::DefaultRuntimeExecutor;
#[cfg(feature = "quartz-runtime")]
use crate::service::QuartzRuntimeExecutor;
#[cfg(feature = "unique-runtime")]
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::{19 collections::BTreeMap,20 marker::PhantomData,21 pin::Pin,22 sync::{Arc, Mutex},23 time::Duration,24};2526use cumulus_client_cli::CollatorOptions;27use cumulus_client_collator::service::CollatorService;28#[cfg(not(feature = "lookahead"))]29use cumulus_client_consensus_aura::collators::basic::{30 run as run_aura, Params as BuildAuraConsensusParams,31};32#[cfg(feature = "lookahead")]33use cumulus_client_consensus_aura::collators::lookahead::{34 run as run_aura, Params as BuildAuraConsensusParams,35};36use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport;37use cumulus_client_consensus_proposer::Proposer;38use cumulus_client_network::RequireSecondedInBlockAnnounce;39use cumulus_client_service::{40 build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, DARecoveryProfile,41 StartRelayChainTasksParams,42};43use cumulus_primitives_core::ParaId;44use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};45use fc_mapping_sync::{kv::MappingSyncWorker, EthereumBlockNotificationSinks, SyncStrategy};46use fc_rpc::{47 frontier_backend_client::SystemAccountId32StorageOverride, EthBlockDataCacheTask, EthConfig,48 EthTask, OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override, SchemaV2Override,49 SchemaV3Override, StorageOverride,50};51use fc_rpc_core::types::{FeeHistoryCache, FilterPool};52use fp_rpc::EthereumRuntimeRPCApi;53use fp_storage::EthereumStorageSchema;54use futures::{55 stream::select,56 task::{Context, Poll},57 Stream, StreamExt,58};59use jsonrpsee::RpcModule;60use polkadot_service::CollatorPair;61use sc_client_api::{AuxStore, Backend, BlockOf, BlockchainEvents, StorageProvider};62use sc_consensus::ImportQueue;63use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch};64use sc_network::NetworkBlock;65use sc_network_sync::SyncingService;66use sc_rpc::SubscriptionTaskExecutor;67use sc_service::{Configuration, PartialComponents, TaskManager};68use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};69use serde::{Deserialize, Serialize};70use sp_api::{ProvideRuntimeApi, StateBackend};71use sp_block_builder::BlockBuilder;72use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};73use sp_consensus_aura::sr25519::AuthorityPair as AuraAuthorityPair;74use sp_keystore::KeystorePtr;75use sp_runtime::traits::BlakeTwo256;76use substrate_prometheus_endpoint::Registry;77use tokio::time::Interval;78use up_common::types::{opaque::*, Nonce};7980use crate::{81 chain_spec::RuntimeIdentification,82 rpc::{create_eth, create_full, EthDeps, FullDeps},83};8485/// Unique native executor instance.86#[cfg(feature = "unique-runtime")]87pub struct UniqueRuntimeExecutor;8889#[cfg(feature = "quartz-runtime")]90/// Quartz native executor instance.91pub struct QuartzRuntimeExecutor;9293/// Opal native executor instance.94pub struct OpalRuntimeExecutor;9596#[cfg(all(feature = "unique-runtime", feature = "runtime-benchmarks"))]97pub type DefaultRuntimeExecutor = UniqueRuntimeExecutor;9899#[cfg(all(100 not(feature = "unique-runtime"),101 feature = "quartz-runtime",102 feature = "runtime-benchmarks"103))]104pub type DefaultRuntimeExecutor = QuartzRuntimeExecutor;105106#[cfg(all(107 not(feature = "unique-runtime"),108 not(feature = "quartz-runtime"),109 feature = "runtime-benchmarks"110))]111pub type DefaultRuntimeExecutor = OpalRuntimeExecutor;112113#[cfg(feature = "unique-runtime")]114impl NativeExecutionDispatch for UniqueRuntimeExecutor {115 /// Only enable the benchmarking host functions when we actually want to benchmark.116 #[cfg(feature = "runtime-benchmarks")]117 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;118 /// Otherwise we only use the default Substrate host functions.119 #[cfg(not(feature = "runtime-benchmarks"))]120 type ExtendHostFunctions = ();121122 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {123 unique_runtime::api::dispatch(method, data)124 }125126 fn native_version() -> sc_executor::NativeVersion {127 unique_runtime::native_version()128 }129}130131#[cfg(feature = "quartz-runtime")]132impl NativeExecutionDispatch for QuartzRuntimeExecutor {133 /// Only enable the benchmarking host functions when we actually want to benchmark.134 #[cfg(feature = "runtime-benchmarks")]135 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;136 /// Otherwise we only use the default Substrate host functions.137 #[cfg(not(feature = "runtime-benchmarks"))]138 type ExtendHostFunctions = ();139140 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {141 quartz_runtime::api::dispatch(method, data)142 }143144 fn native_version() -> sc_executor::NativeVersion {145 quartz_runtime::native_version()146 }147}148149impl NativeExecutionDispatch for OpalRuntimeExecutor {150 /// Only enable the benchmarking host functions when we actually want to benchmark.151 #[cfg(feature = "runtime-benchmarks")]152 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;153 /// Otherwise we only use the default Substrate host functions.154 #[cfg(not(feature = "runtime-benchmarks"))]155 type ExtendHostFunctions = ();156157 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {158 opal_runtime::api::dispatch(method, data)159 }160161 fn native_version() -> sc_executor::NativeVersion {162 opal_runtime::native_version()163 }164}165166pub struct AutosealInterval {167 interval: Interval,168}169170impl AutosealInterval {171 pub fn new(config: &Configuration, interval: u64) -> Self {172 let _tokio_runtime = config.tokio_handle.enter();173 let interval = tokio::time::interval(Duration::from_millis(interval));174175 Self { interval }176 }177}178179impl Stream for AutosealInterval {180 type Item = tokio::time::Instant;181182 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {183 self.interval.poll_tick(cx).map(Some)184 }185}186187pub fn open_frontier_backend<C: HeaderBackend<Block>>(188 client: Arc<C>,189 config: &Configuration,190) -> Result<Arc<fc_db::kv::Backend<Block>>, String> {191 let config_dir = config.base_path.config_dir(config.chain_spec.id());192 let database_dir = config_dir.join("frontier").join("db");193194 Ok(Arc::new(fc_db::kv::Backend::<Block>::new(195 client,196 &fc_db::kv::DatabaseSettings {197 source: fc_db::DatabaseSource::RocksDb {198 path: database_dir,199 cache_size: 0,200 },201 },202 )?))203}204205type FullClient<RuntimeApi, ExecutorDispatch> =206 sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;207type FullBackend = sc_service::TFullBackend<Block>;208type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;209type ParachainBlockImport<RuntimeApi, ExecutorDispatch> =210 TParachainBlockImport<Block, Arc<FullClient<RuntimeApi, ExecutorDispatch>>, FullBackend>;211212/// Generate a supertrait based on bounds, and blanket impl for it.213macro_rules! ez_bounds {214 ($vis:vis trait $name:ident$(<$($gen:ident $(: $($(+)? $bound:path)*)?),* $(,)?>)? $(:)? $($(+)? $super:path)* {}) => {215 $vis trait $name $(<$($gen $(: $($bound+)*)?,)*>)?: $($super +)* {}216 impl<T, $($($gen $(: $($bound+)*)?,)*)?> $name$(<$($gen,)*>)? for T217 where T: $($super +)* {}218 }219}220ez_bounds!(221 pub trait RuntimeApiDep<Runtime: RuntimeInstance>:222 sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>223 + sp_consensus_aura::AuraApi<Block, AuraId>224 + fp_rpc::EthereumRuntimeRPCApi<Block>225 + sp_session::SessionKeys<Block>226 + sp_block_builder::BlockBuilder<Block>227 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>228 + sp_api::ApiExt<Block>229 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>230 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>231 + up_pov_estimate_rpc::PovEstimateApi<Block>232 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>233 + sp_api::Metadata<Block>234 + sp_offchain::OffchainWorkerApi<Block>235 + cumulus_primitives_core::CollectCollationInfo<Block>236 // Deprecated, not used.237 + fp_rpc::ConvertTransactionRuntimeApi<Block>238 {239 }240);241242/// Starts a `ServiceBuilder` for a full service.243///244/// Use this macro if you don't actually need the full service, but just the builder in order to245/// be able to perform chain operations.246#[allow(clippy::type_complexity)]247pub fn new_partial<Runtime, RuntimeApi, ExecutorDispatch, BIQ>(248 config: &Configuration,249 build_import_queue: BIQ,250) -> Result<251 PartialComponents<252 FullClient<RuntimeApi, ExecutorDispatch>,253 FullBackend,254 FullSelectChain,255 sc_consensus::DefaultImportQueue<Block>,256 sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,257 OtherPartial,258 >,259 sc_service::Error,260>261where262 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,263 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>264 + Send265 + Sync266 + 'static,267 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,268 Runtime: RuntimeInstance,269 ExecutorDispatch: NativeExecutionDispatch + 'static,270 BIQ: FnOnce(271 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,272 Arc<FullBackend>,273 &Configuration,274 Option<TelemetryHandle>,275 &TaskManager,276 ) -> Result<sc_consensus::DefaultImportQueue<Block>, sc_service::Error>,277{278 let telemetry = config279 .telemetry_endpoints280 .clone()281 .filter(|x| !x.is_empty())282 .map(|endpoints| -> Result<_, sc_telemetry::Error> {283 let worker = TelemetryWorker::new(16)?;284 let telemetry = worker.handle().new_telemetry(endpoints);285 Ok((worker, telemetry))286 })287 .transpose()?;288289 let executor = sc_service::new_native_or_wasm_executor(config);290291 let (client, backend, keystore_container, task_manager) =292 sc_service::new_full_parts::<Block, RuntimeApi, _>(293 config,294 telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),295 executor,296 )?;297 let client = Arc::new(client);298299 let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());300301 let telemetry = telemetry.map(|(worker, telemetry)| {302 task_manager303 .spawn_handle()304 .spawn("telemetry", None, worker.run());305 telemetry306 });307308 let select_chain = sc_consensus::LongestChain::new(backend.clone());309310 let transaction_pool = sc_transaction_pool::BasicPool::new_full(311 config.transaction_pool.clone(),312 config.role.is_authority().into(),313 config.prometheus_registry(),314 task_manager.spawn_essential_handle(),315 client.clone(),316 );317318 let eth_filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));319320 let eth_backend = open_frontier_backend(client.clone(), config)?;321322 let import_queue = build_import_queue(323 client.clone(),324 backend.clone(),325 config,326 telemetry.as_ref().map(|telemetry| telemetry.handle()),327 &task_manager,328 )?;329330 let params = PartialComponents {331 backend,332 client,333 import_queue,334 keystore_container,335 task_manager,336 transaction_pool,337 select_chain,338 other: OtherPartial {339 telemetry,340 eth_filter_pool,341 eth_backend,342 telemetry_worker_handle,343 },344 };345346 Ok(params)347}348349macro_rules! clone {350 ($($i:ident),* $(,)?) => {351 $(352 let $i = $i.clone();353 )*354 };355}356357/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.358///359/// This is the actual implementation that is abstract over the executor and the runtime api.360#[sc_tracing::logging::prefix_logs_with("Parachain")]361pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(362 parachain_config: Configuration,363 polkadot_config: Configuration,364 collator_options: CollatorOptions,365 para_id: ParaId,366 hwbench: Option<sc_sysinfo::HwBench>,367) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>368where369 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,370 Runtime: RuntimeInstance + Send + Sync + 'static,371 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,372 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,373 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>374 + Send375 + Sync376 + 'static,377 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,378 Runtime: RuntimeInstance,379 ExecutorDispatch: NativeExecutionDispatch + 'static,380{381 let parachain_config = prepare_node_config(parachain_config);382383 let params = new_partial::<Runtime, RuntimeApi, ExecutorDispatch, _>(384 ¶chain_config,385 parachain_build_import_queue,386 )?;387 let OtherPartial {388 mut telemetry,389 telemetry_worker_handle,390 eth_filter_pool,391 eth_backend,392 } = params.other;393 let net_config = sc_network::config::FullNetworkConfiguration::new(¶chain_config.network);394395 let client = params.client.clone();396 let backend = params.backend.clone();397 let mut task_manager = params.task_manager;398399 let (relay_chain_interface, collator_key) = build_relay_chain_interface(400 polkadot_config,401 ¶chain_config,402 telemetry_worker_handle,403 &mut task_manager,404 collator_options.clone(),405 hwbench.clone(),406 )407 .await408 .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?;409410 let block_announce_validator =411 RequireSecondedInBlockAnnounce::new(relay_chain_interface.clone(), para_id);412413 let validator = parachain_config.role.is_authority();414 let prometheus_registry = parachain_config.prometheus_registry().cloned();415 let transaction_pool = params.transaction_pool.clone();416 let import_queue_service = params.import_queue.service();417418 let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =419 sc_service::build_network(sc_service::BuildNetworkParams {420 config: ¶chain_config,421 net_config,422 client: client.clone(),423 transaction_pool: transaction_pool.clone(),424 spawn_handle: task_manager.spawn_handle(),425 import_queue: params.import_queue,426 block_announce_validator_builder: Some(Box::new(|_| {427 Box::new(block_announce_validator)428 })),429 warp_sync_params: None,430 })?;431432 let select_chain = params.select_chain.clone();433434 let runtime_id = parachain_config.chain_spec.runtime_id();435436 // Frontier437 let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));438 let fee_history_limit = 2048;439440 let eth_pubsub_notification_sinks: Arc<441 EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<Block>>,442 > = Default::default();443444 let overrides = overrides_handle(client.clone());445 let eth_block_data_cache = spawn_frontier_tasks(446 FrontierTaskParams {447 client: client.clone(),448 substrate_backend: backend.clone(),449 eth_filter_pool: eth_filter_pool.clone(),450 eth_backend: eth_backend.clone(),451 fee_history_limit,452 fee_history_cache: fee_history_cache.clone(),453 task_manager: &task_manager,454 prometheus_registry: prometheus_registry.clone(),455 overrides: overrides.clone(),456 sync_strategy: SyncStrategy::Parachain,457 },458 sync_service.clone(),459 eth_pubsub_notification_sinks.clone(),460 );461462 // Rpc463 let rpc_builder = Box::new({464 clone!(465 client,466 backend,467 eth_backend,468 eth_pubsub_notification_sinks,469 fee_history_cache,470 eth_block_data_cache,471 overrides,472 transaction_pool,473 network,474 sync_service,475 );476 move |deny_unsafe, subscription_task_executor: SubscriptionTaskExecutor| {477 clone!(478 backend,479 eth_block_data_cache,480 client,481 eth_backend,482 eth_filter_pool,483 eth_pubsub_notification_sinks,484 fee_history_cache,485 eth_block_data_cache,486 network,487 runtime_id,488 transaction_pool,489 select_chain,490 overrides,491 );492493 #[cfg(not(feature = "pov-estimate"))]494 let _ = backend;495496 let mut rpc_handle = RpcModule::new(());497498 let full_deps = FullDeps {499 client: client.clone(),500 runtime_id,501502 #[cfg(feature = "pov-estimate")]503 exec_params: uc_rpc::pov_estimate::ExecutorParams {504 wasm_method: parachain_config.wasm_method,505 default_heap_pages: parachain_config.default_heap_pages,506 max_runtime_instances: parachain_config.max_runtime_instances,507 runtime_cache_size: parachain_config.runtime_cache_size,508 },509510 #[cfg(feature = "pov-estimate")]511 backend,512513 deny_unsafe,514 pool: transaction_pool.clone(),515 select_chain,516 };517518 create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_handle, full_deps)?;519520 let eth_deps = EthDeps {521 client,522 graph: transaction_pool.pool().clone(),523 pool: transaction_pool,524 is_authority: validator,525 network,526 eth_backend,527 // TODO: Unhardcode528 max_past_logs: 10000,529 fee_history_limit,530 fee_history_cache,531 eth_block_data_cache,532 // TODO: Unhardcode533 enable_dev_signer: false,534 eth_filter_pool,535 eth_pubsub_notification_sinks,536 overrides,537 sync: sync_service.clone(),538 pending_create_inherent_data_providers: |_, ()| async move { Ok(()) },539 };540541 create_eth::<542 _,543 _,544 _,545 _,546 _,547 _,548 DefaultEthConfig<FullClient<RuntimeApi, ExecutorDispatch>>,549 >(550 &mut rpc_handle,551 eth_deps,552 subscription_task_executor.clone(),553 )?;554555 Ok(rpc_handle)556 }557 });558559 sc_service::spawn_tasks(sc_service::SpawnTasksParams {560 rpc_builder,561 client: client.clone(),562 transaction_pool: transaction_pool.clone(),563 task_manager: &mut task_manager,564 config: parachain_config,565 keystore: params.keystore_container.keystore(),566 backend: backend.clone(),567 network: network.clone(),568 sync_service: sync_service.clone(),569 system_rpc_tx,570 telemetry: telemetry.as_mut(),571 tx_handler_controller,572 })?;573574 if let Some(hwbench) = hwbench {575 sc_sysinfo::print_hwbench(&hwbench);576577 if let Some(ref mut telemetry) = telemetry {578 let telemetry_handle = telemetry.handle();579 task_manager.spawn_handle().spawn(580 "telemetry_hwbench",581 None,582 sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),583 );584 }585 }586587 let announce_block = {588 let sync_service = sync_service.clone();589 Arc::new(Box::new(move |hash, data| {590 sync_service.announce_block(hash, data)591 }))592 };593594 let relay_chain_slot_duration = Duration::from_secs(6);595596 let overseer_handle = relay_chain_interface597 .overseer_handle()598 .map_err(|e| sc_service::Error::Application(Box::new(e)))?;599600 start_relay_chain_tasks(StartRelayChainTasksParams {601 client: client.clone(),602 announce_block: announce_block.clone(),603 para_id,604 relay_chain_interface: relay_chain_interface.clone(),605 task_manager: &mut task_manager,606 da_recovery_profile: if validator {607 DARecoveryProfile::Collator608 } else {609 DARecoveryProfile::FullNode610 },611 import_queue: import_queue_service,612 relay_chain_slot_duration,613 recovery_handle: Box::new(overseer_handle.clone()),614 sync_service: sync_service.clone(),615 })?;616617 if validator {618 start_consensus(619 client.clone(),620 backend.clone(),621 prometheus_registry.as_ref(),622 telemetry.as_ref().map(|t| t.handle()),623 &task_manager,624 relay_chain_interface.clone(),625 transaction_pool,626 sync_service.clone(),627 params.keystore_container.keystore(),628 overseer_handle,629 relay_chain_slot_duration,630 para_id,631 collator_key.expect("cli args do not allow this"),632 announce_block,633 )?;634 }635636 start_network.start_network();637638 Ok((task_manager, client))639}640641/// Build the import queue for the the parachain runtime.642pub fn parachain_build_import_queue<Runtime, RuntimeApi, ExecutorDispatch>(643 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,644 backend: Arc<FullBackend>,645 config: &Configuration,646 telemetry: Option<TelemetryHandle>,647 task_manager: &TaskManager,648) -> Result<sc_consensus::DefaultImportQueue<Block>, sc_service::Error>649where650 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>651 + Send652 + Sync653 + 'static,654 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,655 Runtime: RuntimeInstance,656 ExecutorDispatch: NativeExecutionDispatch + 'static,657{658 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;659660 let block_import = ParachainBlockImport::new(client.clone(), backend);661662 cumulus_client_consensus_aura::import_queue::<663 sp_consensus_aura::sr25519::AuthorityPair,664 _,665 _,666 _,667 _,668 _,669 >(cumulus_client_consensus_aura::ImportQueueParams {670 block_import,671 client,672 create_inherent_data_providers: move |_, _| async move {673 let time = sp_timestamp::InherentDataProvider::from_system_time();674675 let slot =676 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(677 *time,678 slot_duration,679 );680681 Ok((slot, time))682 },683 registry: config.prometheus_registry(),684 spawner: &task_manager.spawn_essential_handle(),685 telemetry,686 })687 .map_err(Into::into)688}689690pub fn start_consensus<ExecutorDispatch, RuntimeApi, Runtime>(691 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,692 backend: Arc<FullBackend>,693 prometheus_registry: Option<&Registry>,694 telemetry: Option<TelemetryHandle>,695 task_manager: &TaskManager,696 relay_chain_interface: Arc<dyn RelayChainInterface>,697 transaction_pool: Arc<698 sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,699 >,700 sync_oracle: Arc<SyncingService<Block>>,701 keystore: KeystorePtr,702 overseer_handle: OverseerHandle,703 relay_chain_slot_duration: Duration,704 para_id: ParaId,705 collator_key: CollatorPair,706 announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,707) -> Result<(), sc_service::Error>708where709 ExecutorDispatch: NativeExecutionDispatch + 'static,710 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>711 + Send712 + Sync713 + 'static,714 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,715 Runtime: RuntimeInstance,716{717 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;718719 let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(720 task_manager.spawn_handle(),721 client.clone(),722 transaction_pool,723 prometheus_registry,724 telemetry.clone(),725 );726 let proposer = Proposer::new(proposer_factory);727728 let collator_service = CollatorService::new(729 client.clone(),730 Arc::new(task_manager.spawn_handle()),731 announce_block,732 client.clone(),733 );734735 let block_import = ParachainBlockImport::new(client.clone(), backend);736737 let params = BuildAuraConsensusParams {738 create_inherent_data_providers: move |_, ()| async move { Ok(()) },739 block_import,740 para_client: client,741 #[cfg(feature = "lookahead")]742 para_backend: backend,743 para_id,744 relay_client: relay_chain_interface,745 sync_oracle,746 keystore,747 slot_duration,748 proposer,749 collator_service,750 // With async-baking, we allowed to be both slower (longer authoring) and faster (multiple para blocks per relay block)751 authoring_duration: Duration::from_millis(500),752 overseer_handle,753 #[cfg(feature = "lookahead")]754 code_hash_provider: || {},755 collator_key,756 relay_chain_slot_duration,757 };758759 task_manager.spawn_essential_handle().spawn(760 "aura",761 None,762 run_aura::<_, AuraAuthorityPair, _, _, _, _, _, _, _>(params),763 );764 Ok(())765}766767fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(768 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,769 _: Arc<FullBackend>,770 config: &Configuration,771 _: Option<TelemetryHandle>,772 task_manager: &TaskManager,773) -> Result<sc_consensus::DefaultImportQueue<Block>, sc_service::Error>774where775 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>776 + Send777 + Sync778 + 'static,779 RuntimeApi::RuntimeApi:780 sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> + sp_api::ApiExt<Block>,781 ExecutorDispatch: NativeExecutionDispatch + 'static,782{783 Ok(sc_consensus_manual_seal::import_queue(784 Box::new(client),785 &task_manager.spawn_essential_handle(),786 config.prometheus_registry(),787 ))788}789790pub struct OtherPartial {791 pub telemetry: Option<Telemetry>,792 pub telemetry_worker_handle: Option<TelemetryWorkerHandle>,793 pub eth_filter_pool: Option<FilterPool>,794 pub eth_backend: Arc<fc_db::kv::Backend<Block>>,795}796797struct DefaultEthConfig<C>(PhantomData<C>);798impl<C> EthConfig<Block, C> for DefaultEthConfig<C>799where800 C: StorageProvider<Block, FullBackend> + Sync + Send + 'static,801{802 type EstimateGasAdapter = ();803 type RuntimeStorageOverride = SystemAccountId32StorageOverride<Block, C, FullBackend>;804}805806/// Builds a new development service. This service uses instant seal, and mocks807/// the parachain inherent808pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(809 config: Configuration,810 autoseal_interval: u64,811 autoseal_finalize_delay: Option<u64>,812 disable_autoseal_on_tx: bool,813) -> sc_service::error::Result<TaskManager>814where815 Runtime: RuntimeInstance + Send + Sync + 'static,816 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,817 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,818 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>819 + Send820 + Sync821 + 'static,822 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,823 ExecutorDispatch: NativeExecutionDispatch + 'static,824{825 use fc_consensus::FrontierBlockImport;826 use sc_consensus_manual_seal::{827 run_delayed_finalize, run_manual_seal, DelayedFinalizeParams, EngineCommand,828 ManualSealParams,829 };830831 let sc_service::PartialComponents {832 client,833 backend,834 mut task_manager,835 import_queue,836 keystore_container,837 select_chain: maybe_select_chain,838 transaction_pool,839 other:840 OtherPartial {841 telemetry,842 eth_filter_pool,843 eth_backend,844 telemetry_worker_handle: _,845 },846 } = new_partial::<Runtime, RuntimeApi, ExecutorDispatch, _>(847 &config,848 dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,849 )?;850 let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);851 let prometheus_registry = config.prometheus_registry().cloned();852853 let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =854 sc_service::build_network(sc_service::BuildNetworkParams {855 config: &config,856 net_config,857 client: client.clone(),858 transaction_pool: transaction_pool.clone(),859 spawn_handle: task_manager.spawn_handle(),860 import_queue,861 block_announce_validator_builder: None,862 warp_sync_params: None,863 })?;864865 let collator = config.role.is_authority();866867 let select_chain = maybe_select_chain;868869 if collator {870 let block_import = FrontierBlockImport::new(client.clone(), client.clone());871872 let env = sc_basic_authorship::ProposerFactory::new(873 task_manager.spawn_handle(),874 client.clone(),875 transaction_pool.clone(),876 prometheus_registry.as_ref(),877 telemetry.as_ref().map(|x| x.handle()),878 );879880 let transactions_commands_stream: Box<881 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,882 > = Box::new(883 transaction_pool884 .pool()885 .validated_pool()886 .import_notification_stream()887 .filter(move |_| futures::future::ready(!disable_autoseal_on_tx))888 .map(|_| EngineCommand::SealNewBlock {889 create_empty: true,890 finalize: false,891 parent_hash: None,892 sender: None,893 }),894 );895896 let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));897898 let idle_commands_stream: Box<899 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,900 > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {901 create_empty: true,902 finalize: false,903 parent_hash: None,904 sender: None,905 }));906907 let commands_stream = select(transactions_commands_stream, idle_commands_stream);908909 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;910 let client_set_aside_for_cidp = client.clone();911912 if let Some(delay_sec) = autoseal_finalize_delay {913 let spawn_handle = task_manager.spawn_handle();914915 task_manager.spawn_essential_handle().spawn_blocking(916 "finalization_task",917 Some("block-authoring"),918 run_delayed_finalize(DelayedFinalizeParams {919 client: client.clone(),920 delay_sec,921 spawn_handle,922 }),923 );924 }925926 task_manager.spawn_essential_handle().spawn_blocking(927 "authorship_task",928 Some("block-authoring"),929 run_manual_seal(ManualSealParams {930 block_import,931 env,932 client: client.clone(),933 pool: transaction_pool.clone(),934 commands_stream,935 select_chain: select_chain.clone(),936 consensus_data_provider: None,937 create_inherent_data_providers: move |block: Hash, ()| {938 let current_para_block = client_set_aside_for_cidp939 .number(block)940 .expect("Header lookup should succeed")941 .expect("Header passed in as parent should be present in backend.");942943 let client_for_xcm = client_set_aside_for_cidp.clone();944 async move {945 let time = sp_timestamp::InherentDataProvider::from_system_time();946947 let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {948 current_para_block,949 relay_offset: 1000,950 relay_blocks_per_para_block: 2,951 para_blocks_per_relay_epoch: 0,952 xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(953 &*client_for_xcm,954 block,955 Default::default(),956 Default::default(),957 ),958 relay_randomness_config: (),959 raw_downward_messages: vec![],960 raw_horizontal_messages: vec![],961 };962963 let slot =964 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(965 *time,966 slot_duration,967 );968969 Ok((time, slot, mocked_parachain))970 }971 },972 }),973 );974 }975976 #[cfg(feature = "pov-estimate")]977 let rpc_backend = backend.clone();978979 let runtime_id = config.chain_spec.runtime_id();980981 // Frontier982 let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));983 let fee_history_limit = 2048;984985 let eth_pubsub_notification_sinks: Arc<986 EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<Block>>,987 > = Default::default();988989 let overrides = overrides_handle(client.clone());990 let eth_block_data_cache = spawn_frontier_tasks(991 FrontierTaskParams {992 client: client.clone(),993 substrate_backend: backend.clone(),994 eth_filter_pool: eth_filter_pool.clone(),995 eth_backend: eth_backend.clone(),996 fee_history_limit,997 fee_history_cache: fee_history_cache.clone(),998 task_manager: &task_manager,999 prometheus_registry,1000 overrides: overrides.clone(),1001 sync_strategy: SyncStrategy::Normal,1002 },1003 sync_service.clone(),1004 eth_pubsub_notification_sinks.clone(),1005 );10061007 // Rpc1008 let rpc_builder = Box::new({1009 clone!(1010 client,1011 backend,1012 eth_backend,1013 eth_pubsub_notification_sinks,1014 fee_history_cache,1015 eth_block_data_cache,1016 overrides,1017 transaction_pool,1018 network,1019 sync_service,1020 );1021 move |deny_unsafe, subscription_task_executor: SubscriptionTaskExecutor| {1022 clone!(1023 backend,1024 eth_block_data_cache,1025 client,1026 eth_backend,1027 eth_filter_pool,1028 eth_pubsub_notification_sinks,1029 fee_history_cache,1030 eth_block_data_cache,1031 network,1032 runtime_id,1033 transaction_pool,1034 select_chain,1035 overrides,1036 );10371038 #[cfg(not(feature = "pov-estimate"))]1039 let _ = backend;10401041 let mut rpc_module = RpcModule::new(());10421043 let full_deps = FullDeps {1044 runtime_id,10451046 #[cfg(feature = "pov-estimate")]1047 exec_params: uc_rpc::pov_estimate::ExecutorParams {1048 wasm_method: config.wasm_method,1049 default_heap_pages: config.default_heap_pages,1050 max_runtime_instances: config.max_runtime_instances,1051 runtime_cache_size: config.runtime_cache_size,1052 },10531054 #[cfg(feature = "pov-estimate")]1055 backend,1056 // eth_backend,1057 deny_unsafe,1058 client: client.clone(),1059 pool: transaction_pool.clone(),1060 select_chain,1061 };10621063 create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_module, full_deps)?;10641065 let eth_deps = EthDeps {1066 client,1067 graph: transaction_pool.pool().clone(),1068 pool: transaction_pool,1069 is_authority: true,1070 network,1071 eth_backend,1072 // TODO: Unhardcode1073 max_past_logs: 10000,1074 fee_history_limit,1075 fee_history_cache,1076 eth_block_data_cache,1077 // TODO: Unhardcode1078 enable_dev_signer: false,1079 eth_filter_pool,1080 eth_pubsub_notification_sinks,1081 overrides,1082 sync: sync_service.clone(),1083 // We don't have any inherents except parachain built-ins, which we can't even extract from inside `run_aura`.1084 pending_create_inherent_data_providers: |_, ()| async move { Ok(()) },1085 };10861087 create_eth::<1088 _,1089 _,1090 _,1091 _,1092 _,1093 _,1094 DefaultEthConfig<FullClient<RuntimeApi, ExecutorDispatch>>,1095 >(1096 &mut rpc_module,1097 eth_deps,1098 subscription_task_executor.clone(),1099 )?;11001101 Ok(rpc_module)1102 }1103 });11041105 sc_service::spawn_tasks(sc_service::SpawnTasksParams {1106 network,1107 sync_service,1108 client,1109 keystore: keystore_container.keystore(),1110 task_manager: &mut task_manager,1111 transaction_pool,1112 rpc_builder,1113 backend,1114 system_rpc_tx,1115 config,1116 telemetry: None,1117 tx_handler_controller,1118 })?;11191120 network_starter.start_network();1121 Ok(task_manager)1122}11231124fn overrides_handle<C, BE>(client: Arc<C>) -> Arc<OverrideHandle<Block>>1125where1126 C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,1127 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,1128 C: Send + Sync + 'static,1129 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,1130 BE: Backend<Block> + 'static,1131 BE::State: StateBackend<BlakeTwo256>,1132{1133 let mut overrides_map = BTreeMap::new();1134 overrides_map.insert(1135 EthereumStorageSchema::V1,1136 Box::new(SchemaV1Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,1137 );1138 overrides_map.insert(1139 EthereumStorageSchema::V2,1140 Box::new(SchemaV2Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,1141 );1142 overrides_map.insert(1143 EthereumStorageSchema::V3,1144 Box::new(SchemaV3Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,1145 );11461147 Arc::new(OverrideHandle {1148 schemas: overrides_map,1149 fallback: Box::new(RuntimeApiStorageOverride::new(client)),1150 })1151}11521153pub struct FrontierTaskParams<'a, C, B> {1154 pub task_manager: &'a TaskManager,1155 pub client: Arc<C>,1156 pub substrate_backend: Arc<B>,1157 pub eth_backend: Arc<fc_db::kv::Backend<Block>>,1158 pub eth_filter_pool: Option<FilterPool>,1159 pub overrides: Arc<OverrideHandle<Block>>,1160 pub fee_history_limit: u64,1161 pub fee_history_cache: FeeHistoryCache,1162 pub sync_strategy: SyncStrategy,1163 pub prometheus_registry: Option<Registry>,1164}11651166pub fn spawn_frontier_tasks<C, B>(1167 params: FrontierTaskParams<C, B>,1168 sync: Arc<SyncingService<Block>>,1169 pubsub_notification_sinks: Arc<1170 EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<Block>>,1171 >,1172) -> Arc<EthBlockDataCacheTask<Block>>1173where1174 C: ProvideRuntimeApi<Block> + BlockOf,1175 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,1176 C: BlockchainEvents<Block> + StorageProvider<Block, B>,1177 C: Send + Sync + 'static,1178 C::Api: EthereumRuntimeRPCApi<Block>,1179 C::Api: BlockBuilder<Block>,1180 B: Backend<Block> + 'static,1181 B::State: StateBackend<BlakeTwo256>,1182{1183 let FrontierTaskParams {1184 task_manager,1185 client,1186 substrate_backend,1187 eth_backend,1188 eth_filter_pool,1189 overrides,1190 fee_history_limit,1191 fee_history_cache,1192 sync_strategy,1193 prometheus_registry,1194 } = params;1195 // Frontier offchain DB task. Essential.1196 // Maps emulated ethereum data to substrate native data.1197 params.task_manager.spawn_essential_handle().spawn(1198 "frontier-mapping-sync-worker",1199 Some("frontier"),1200 MappingSyncWorker::new(1201 client.import_notification_stream(),1202 Duration::new(6, 0),1203 client.clone(),1204 substrate_backend,1205 overrides.clone(),1206 eth_backend,1207 3,1208 0,1209 sync_strategy,1210 sync,1211 pubsub_notification_sinks,1212 )1213 .for_each(|()| futures::future::ready(())),1214 );12151216 // Frontier `EthFilterApi` maintenance.1217 // Manages the pool of user-created Filters.1218 if let Some(eth_filter_pool) = eth_filter_pool {1219 // Each filter is allowed to stay in the pool for 100 blocks.1220 const FILTER_RETAIN_THRESHOLD: u64 = 100;1221 params.task_manager.spawn_essential_handle().spawn(1222 "frontier-filter-pool",1223 Some("frontier"),1224 EthTask::filter_pool_task(client.clone(), eth_filter_pool, FILTER_RETAIN_THRESHOLD),1225 );1226 }12271228 // Spawn Frontier FeeHistory cache maintenance task.1229 params.task_manager.spawn_essential_handle().spawn(1230 "frontier-fee-history",1231 Some("frontier"),1232 EthTask::fee_history_task(1233 client,1234 overrides.clone(),1235 fee_history_cache,1236 fee_history_limit,1237 ),1238 );12391240 Arc::new(EthBlockDataCacheTask::new(1241 task_manager.spawn_handle(),1242 overrides,1243 50,1244 50,1245 prometheus_registry,1246 ))1247}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::{19 collections::BTreeMap,20 marker::PhantomData,21 pin::Pin,22 sync::{Arc, Mutex},23 time::Duration,24};2526use cumulus_client_cli::CollatorOptions;27use cumulus_client_collator::service::CollatorService;28#[cfg(not(feature = "lookahead"))]29use cumulus_client_consensus_aura::collators::basic::{30 run as run_aura, Params as BuildAuraConsensusParams,31};32#[cfg(feature = "lookahead")]33use cumulus_client_consensus_aura::collators::lookahead::{34 run as run_aura, Params as BuildAuraConsensusParams,35};36use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport;37use cumulus_client_consensus_proposer::Proposer;38use cumulus_client_network::RequireSecondedInBlockAnnounce;39use cumulus_client_service::{40 build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, DARecoveryProfile,41 StartRelayChainTasksParams,42};43use cumulus_primitives_core::ParaId;44use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};45use fc_mapping_sync::{kv::MappingSyncWorker, EthereumBlockNotificationSinks, SyncStrategy};46use fc_rpc::{47 frontier_backend_client::SystemAccountId32StorageOverride, EthBlockDataCacheTask, EthConfig,48 EthTask, OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override, SchemaV2Override,49 SchemaV3Override, StorageOverride,50};51use fc_rpc_core::types::{FeeHistoryCache, FilterPool};52use fp_rpc::EthereumRuntimeRPCApi;53use fp_storage::EthereumStorageSchema;54use futures::{55 stream::select,56 task::{Context, Poll},57 Stream, StreamExt,58};59use jsonrpsee::RpcModule;60use polkadot_service::CollatorPair;61use sc_client_api::{AuxStore, Backend, BlockOf, BlockchainEvents, StorageProvider};62use sc_consensus::ImportQueue;63use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch};64use sc_network::NetworkBlock;65use sc_network_sync::SyncingService;66use sc_rpc::SubscriptionTaskExecutor;67use sc_service::{Configuration, PartialComponents, TaskManager};68use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};69use serde::{Deserialize, Serialize};70use sp_api::{ProvideRuntimeApi, StateBackend};71use sp_block_builder::BlockBuilder;72use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};73use sp_consensus_aura::sr25519::AuthorityPair as AuraAuthorityPair;74use sp_keystore::KeystorePtr;75use sp_runtime::traits::BlakeTwo256;76use substrate_prometheus_endpoint::Registry;77use tokio::time::Interval;78use up_common::types::{opaque::*, Nonce};7980use crate::{81 chain_spec::RuntimeIdentification,82 rpc::{create_eth, create_full, EthDeps, FullDeps},83};8485/// Unique native executor instance.86#[cfg(feature = "unique-runtime")]87pub struct UniqueRuntimeExecutor;8889#[cfg(feature = "quartz-runtime")]90/// Quartz native executor instance.91pub struct QuartzRuntimeExecutor;9293/// Opal native executor instance.94pub struct OpalRuntimeExecutor;9596#[cfg(feature = "unique-runtime")]97impl NativeExecutionDispatch for UniqueRuntimeExecutor {98 /// Only enable the benchmarking host functions when we actually want to benchmark.99 #[cfg(feature = "runtime-benchmarks")]100 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;101 /// Otherwise we only use the default Substrate host functions.102 #[cfg(not(feature = "runtime-benchmarks"))]103 type ExtendHostFunctions = ();104105 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {106 unique_runtime::api::dispatch(method, data)107 }108109 fn native_version() -> sc_executor::NativeVersion {110 unique_runtime::native_version()111 }112}113114#[cfg(feature = "quartz-runtime")]115impl NativeExecutionDispatch for QuartzRuntimeExecutor {116 /// Only enable the benchmarking host functions when we actually want to benchmark.117 #[cfg(feature = "runtime-benchmarks")]118 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;119 /// Otherwise we only use the default Substrate host functions.120 #[cfg(not(feature = "runtime-benchmarks"))]121 type ExtendHostFunctions = ();122123 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {124 quartz_runtime::api::dispatch(method, data)125 }126127 fn native_version() -> sc_executor::NativeVersion {128 quartz_runtime::native_version()129 }130}131132impl NativeExecutionDispatch for OpalRuntimeExecutor {133 /// Only enable the benchmarking host functions when we actually want to benchmark.134 #[cfg(feature = "runtime-benchmarks")]135 type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;136 /// Otherwise we only use the default Substrate host functions.137 #[cfg(not(feature = "runtime-benchmarks"))]138 type ExtendHostFunctions = ();139140 fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {141 opal_runtime::api::dispatch(method, data)142 }143144 fn native_version() -> sc_executor::NativeVersion {145 opal_runtime::native_version()146 }147}148149pub struct AutosealInterval {150 interval: Interval,151}152153impl AutosealInterval {154 pub fn new(config: &Configuration, interval: u64) -> Self {155 let _tokio_runtime = config.tokio_handle.enter();156 let interval = tokio::time::interval(Duration::from_millis(interval));157158 Self { interval }159 }160}161162impl Stream for AutosealInterval {163 type Item = tokio::time::Instant;164165 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {166 self.interval.poll_tick(cx).map(Some)167 }168}169170pub fn open_frontier_backend<C: HeaderBackend<Block>>(171 client: Arc<C>,172 config: &Configuration,173) -> Result<Arc<fc_db::kv::Backend<Block>>, String> {174 let config_dir = config.base_path.config_dir(config.chain_spec.id());175 let database_dir = config_dir.join("frontier").join("db");176177 Ok(Arc::new(fc_db::kv::Backend::<Block>::new(178 client,179 &fc_db::kv::DatabaseSettings {180 source: fc_db::DatabaseSource::RocksDb {181 path: database_dir,182 cache_size: 0,183 },184 },185 )?))186}187188type FullClient<RuntimeApi, ExecutorDispatch> =189 sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;190type FullBackend = sc_service::TFullBackend<Block>;191type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;192type ParachainBlockImport<RuntimeApi, ExecutorDispatch> =193 TParachainBlockImport<Block, Arc<FullClient<RuntimeApi, ExecutorDispatch>>, FullBackend>;194195/// Generate a supertrait based on bounds, and blanket impl for it.196macro_rules! ez_bounds {197 ($vis:vis trait $name:ident$(<$($gen:ident $(: $($(+)? $bound:path)*)?),* $(,)?>)? $(:)? $($(+)? $super:path)* {}) => {198 $vis trait $name $(<$($gen $(: $($bound+)*)?,)*>)?: $($super +)* {}199 impl<T, $($($gen $(: $($bound+)*)?,)*)?> $name$(<$($gen,)*>)? for T200 where T: $($super +)* {}201 }202}203ez_bounds!(204 pub trait RuntimeApiDep<Runtime: RuntimeInstance>:205 sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>206 + sp_consensus_aura::AuraApi<Block, AuraId>207 + fp_rpc::EthereumRuntimeRPCApi<Block>208 + sp_session::SessionKeys<Block>209 + sp_block_builder::BlockBuilder<Block>210 + pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance>211 + sp_api::ApiExt<Block>212 + up_rpc::UniqueApi<Block, Runtime::CrossAccountId, AccountId>213 + app_promotion_rpc::AppPromotionApi<Block, BlockNumber, Runtime::CrossAccountId, AccountId>214 + up_pov_estimate_rpc::PovEstimateApi<Block>215 + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>216 + sp_api::Metadata<Block>217 + sp_offchain::OffchainWorkerApi<Block>218 + cumulus_primitives_core::CollectCollationInfo<Block>219 // Deprecated, not used.220 + fp_rpc::ConvertTransactionRuntimeApi<Block>221 {222 }223);224225/// Starts a `ServiceBuilder` for a full service.226///227/// Use this macro if you don't actually need the full service, but just the builder in order to228/// be able to perform chain operations.229#[allow(clippy::type_complexity)]230pub fn new_partial<Runtime, RuntimeApi, ExecutorDispatch, BIQ>(231 config: &Configuration,232 build_import_queue: BIQ,233) -> Result<234 PartialComponents<235 FullClient<RuntimeApi, ExecutorDispatch>,236 FullBackend,237 FullSelectChain,238 sc_consensus::DefaultImportQueue<Block>,239 sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,240 OtherPartial,241 >,242 sc_service::Error,243>244where245 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,246 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>247 + Send248 + Sync249 + 'static,250 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,251 Runtime: RuntimeInstance,252 ExecutorDispatch: NativeExecutionDispatch + 'static,253 BIQ: FnOnce(254 Arc<FullClient<RuntimeApi, ExecutorDispatch>>,255 Arc<FullBackend>,256 &Configuration,257 Option<TelemetryHandle>,258 &TaskManager,259 ) -> Result<sc_consensus::DefaultImportQueue<Block>, sc_service::Error>,260{261 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 = sc_service::new_native_or_wasm_executor(config);273274 let (client, backend, keystore_container, task_manager) =275 sc_service::new_full_parts::<Block, RuntimeApi, _>(276 config,277 telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),278 executor,279 )?;280 let client = Arc::new(client);281282 let telemetry_worker_handle = telemetry.as_ref().map(|(worker, _)| worker.handle());283284 let telemetry = telemetry.map(|(worker, telemetry)| {285 task_manager286 .spawn_handle()287 .spawn("telemetry", None, worker.run());288 telemetry289 });290291 let select_chain = sc_consensus::LongestChain::new(backend.clone());292293 let transaction_pool = sc_transaction_pool::BasicPool::new_full(294 config.transaction_pool.clone(),295 config.role.is_authority().into(),296 config.prometheus_registry(),297 task_manager.spawn_essential_handle(),298 client.clone(),299 );300301 let eth_filter_pool: Option<FilterPool> = Some(Arc::new(Mutex::new(BTreeMap::new())));302303 let eth_backend = open_frontier_backend(client.clone(), config)?;304305 let import_queue = build_import_queue(306 client.clone(),307 backend.clone(),308 config,309 telemetry.as_ref().map(|telemetry| telemetry.handle()),310 &task_manager,311 )?;312313 let params = PartialComponents {314 backend,315 client,316 import_queue,317 keystore_container,318 task_manager,319 transaction_pool,320 select_chain,321 other: OtherPartial {322 telemetry,323 eth_filter_pool,324 eth_backend,325 telemetry_worker_handle,326 },327 };328329 Ok(params)330}331332macro_rules! clone {333 ($($i:ident),* $(,)?) => {334 $(335 let $i = $i.clone();336 )*337 };338}339340/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.341///342/// This is the actual implementation that is abstract over the executor and the runtime api.343#[sc_tracing::logging::prefix_logs_with("Parachain")]344pub async fn start_node<Runtime, RuntimeApi, ExecutorDispatch>(345 parachain_config: Configuration,346 polkadot_config: Configuration,347 collator_options: CollatorOptions,348 para_id: ParaId,349 hwbench: Option<sc_sysinfo::HwBench>,350) -> sc_service::error::Result<(TaskManager, Arc<FullClient<RuntimeApi, ExecutorDispatch>>)>351where352 sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,353 Runtime: RuntimeInstance + Send + Sync + 'static,354 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,355 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,356 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>357 + Send358 + Sync359 + 'static,360 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,361 Runtime: RuntimeInstance,362 ExecutorDispatch: NativeExecutionDispatch + 'static,363{364 let parachain_config = prepare_node_config(parachain_config);365366 let params = new_partial::<Runtime, RuntimeApi, ExecutorDispatch, _>(367 ¶chain_config,368 parachain_build_import_queue,369 )?;370 let OtherPartial {371 mut telemetry,372 telemetry_worker_handle,373 eth_filter_pool,374 eth_backend,375 } = params.other;376 let net_config = sc_network::config::FullNetworkConfiguration::new(¶chain_config.network);377378 let client = params.client.clone();379 let backend = params.backend.clone();380 let mut task_manager = params.task_manager;381382 let (relay_chain_interface, collator_key) = build_relay_chain_interface(383 polkadot_config,384 ¶chain_config,385 telemetry_worker_handle,386 &mut task_manager,387 collator_options.clone(),388 hwbench.clone(),389 )390 .await391 .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?;392393 let block_announce_validator =394 RequireSecondedInBlockAnnounce::new(relay_chain_interface.clone(), para_id);395396 let validator = parachain_config.role.is_authority();397 let prometheus_registry = parachain_config.prometheus_registry().cloned();398 let transaction_pool = params.transaction_pool.clone();399 let import_queue_service = params.import_queue.service();400401 let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =402 sc_service::build_network(sc_service::BuildNetworkParams {403 config: ¶chain_config,404 net_config,405 client: client.clone(),406 transaction_pool: transaction_pool.clone(),407 spawn_handle: task_manager.spawn_handle(),408 import_queue: params.import_queue,409 block_announce_validator_builder: Some(Box::new(|_| {410 Box::new(block_announce_validator)411 })),412 warp_sync_params: None,413 })?;414415 let select_chain = params.select_chain.clone();416417 let runtime_id = parachain_config.chain_spec.runtime_id();418419 // Frontier420 let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));421 let fee_history_limit = 2048;422423 let eth_pubsub_notification_sinks: Arc<424 EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<Block>>,425 > = Default::default();426427 let overrides = overrides_handle(client.clone());428 let eth_block_data_cache = spawn_frontier_tasks(429 FrontierTaskParams {430 client: client.clone(),431 substrate_backend: backend.clone(),432 eth_filter_pool: eth_filter_pool.clone(),433 eth_backend: eth_backend.clone(),434 fee_history_limit,435 fee_history_cache: fee_history_cache.clone(),436 task_manager: &task_manager,437 prometheus_registry: prometheus_registry.clone(),438 overrides: overrides.clone(),439 sync_strategy: SyncStrategy::Parachain,440 },441 sync_service.clone(),442 eth_pubsub_notification_sinks.clone(),443 );444445 // Rpc446 let rpc_builder = Box::new({447 clone!(448 client,449 backend,450 eth_backend,451 eth_pubsub_notification_sinks,452 fee_history_cache,453 eth_block_data_cache,454 overrides,455 transaction_pool,456 network,457 sync_service,458 );459 move |deny_unsafe, subscription_task_executor: SubscriptionTaskExecutor| {460 clone!(461 backend,462 eth_block_data_cache,463 client,464 eth_backend,465 eth_filter_pool,466 eth_pubsub_notification_sinks,467 fee_history_cache,468 eth_block_data_cache,469 network,470 runtime_id,471 transaction_pool,472 select_chain,473 overrides,474 );475476 #[cfg(not(feature = "pov-estimate"))]477 let _ = backend;478479 let mut rpc_handle = RpcModule::new(());480481 let full_deps = FullDeps {482 client: client.clone(),483 runtime_id,484485 #[cfg(feature = "pov-estimate")]486 exec_params: uc_rpc::pov_estimate::ExecutorParams {487 wasm_method: parachain_config.wasm_method,488 default_heap_pages: parachain_config.default_heap_pages,489 max_runtime_instances: parachain_config.max_runtime_instances,490 runtime_cache_size: parachain_config.runtime_cache_size,491 },492493 #[cfg(feature = "pov-estimate")]494 backend,495496 deny_unsafe,497 pool: transaction_pool.clone(),498 select_chain,499 };500501 create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_handle, full_deps)?;502503 let eth_deps = EthDeps {504 client,505 graph: transaction_pool.pool().clone(),506 pool: transaction_pool,507 is_authority: validator,508 network,509 eth_backend,510 // TODO: Unhardcode511 max_past_logs: 10000,512 fee_history_limit,513 fee_history_cache,514 eth_block_data_cache,515 // TODO: Unhardcode516 enable_dev_signer: false,517 eth_filter_pool,518 eth_pubsub_notification_sinks,519 overrides,520 sync: sync_service.clone(),521 pending_create_inherent_data_providers: |_, ()| async move { Ok(()) },522 };523524 create_eth::<525 _,526 _,527 _,528 _,529 _,530 _,531 DefaultEthConfig<FullClient<RuntimeApi, ExecutorDispatch>>,532 >(533 &mut rpc_handle,534 eth_deps,535 subscription_task_executor.clone(),536 )?;537538 Ok(rpc_handle)539 }540 });541542 sc_service::spawn_tasks(sc_service::SpawnTasksParams {543 rpc_builder,544 client: client.clone(),545 transaction_pool: transaction_pool.clone(),546 task_manager: &mut task_manager,547 config: parachain_config,548 keystore: params.keystore_container.keystore(),549 backend: backend.clone(),550 network: network.clone(),551 sync_service: sync_service.clone(),552 system_rpc_tx,553 telemetry: telemetry.as_mut(),554 tx_handler_controller,555 })?;556557 if let Some(hwbench) = hwbench {558 sc_sysinfo::print_hwbench(&hwbench);559560 if let Some(ref mut telemetry) = telemetry {561 let telemetry_handle = telemetry.handle();562 task_manager.spawn_handle().spawn(563 "telemetry_hwbench",564 None,565 sc_sysinfo::initialize_hwbench_telemetry(telemetry_handle, hwbench),566 );567 }568 }569570 let announce_block = {571 let sync_service = sync_service.clone();572 Arc::new(Box::new(move |hash, data| {573 sync_service.announce_block(hash, data)574 }))575 };576577 let relay_chain_slot_duration = Duration::from_secs(6);578579 let overseer_handle = relay_chain_interface580 .overseer_handle()581 .map_err(|e| sc_service::Error::Application(Box::new(e)))?;582583 start_relay_chain_tasks(StartRelayChainTasksParams {584 client: client.clone(),585 announce_block: announce_block.clone(),586 para_id,587 relay_chain_interface: relay_chain_interface.clone(),588 task_manager: &mut task_manager,589 da_recovery_profile: if validator {590 DARecoveryProfile::Collator591 } else {592 DARecoveryProfile::FullNode593 },594 import_queue: import_queue_service,595 relay_chain_slot_duration,596 recovery_handle: Box::new(overseer_handle.clone()),597 sync_service: sync_service.clone(),598 })?;599600 if validator {601 start_consensus(602 client.clone(),603 backend.clone(),604 prometheus_registry.as_ref(),605 telemetry.as_ref().map(|t| t.handle()),606 &task_manager,607 relay_chain_interface.clone(),608 transaction_pool,609 sync_service.clone(),610 params.keystore_container.keystore(),611 overseer_handle,612 relay_chain_slot_duration,613 para_id,614 collator_key.expect("cli args do not allow this"),615 announce_block,616 )?;617 }618619 start_network.start_network();620621 Ok((task_manager, client))622}623624/// Build the import queue for the the parachain runtime.625pub fn parachain_build_import_queue<Runtime, RuntimeApi, ExecutorDispatch>(626 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,627 backend: Arc<FullBackend>,628 config: &Configuration,629 telemetry: Option<TelemetryHandle>,630 task_manager: &TaskManager,631) -> Result<sc_consensus::DefaultImportQueue<Block>, sc_service::Error>632where633 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>634 + Send635 + Sync636 + 'static,637 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,638 Runtime: RuntimeInstance,639 ExecutorDispatch: NativeExecutionDispatch + 'static,640{641 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;642643 let block_import = ParachainBlockImport::new(client.clone(), backend);644645 cumulus_client_consensus_aura::import_queue::<646 sp_consensus_aura::sr25519::AuthorityPair,647 _,648 _,649 _,650 _,651 _,652 >(cumulus_client_consensus_aura::ImportQueueParams {653 block_import,654 client,655 create_inherent_data_providers: move |_, _| async move {656 let time = sp_timestamp::InherentDataProvider::from_system_time();657658 let slot =659 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(660 *time,661 slot_duration,662 );663664 Ok((slot, time))665 },666 registry: config.prometheus_registry(),667 spawner: &task_manager.spawn_essential_handle(),668 telemetry,669 })670 .map_err(Into::into)671}672673pub fn start_consensus<ExecutorDispatch, RuntimeApi, Runtime>(674 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,675 backend: Arc<FullBackend>,676 prometheus_registry: Option<&Registry>,677 telemetry: Option<TelemetryHandle>,678 task_manager: &TaskManager,679 relay_chain_interface: Arc<dyn RelayChainInterface>,680 transaction_pool: Arc<681 sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,682 >,683 sync_oracle: Arc<SyncingService<Block>>,684 keystore: KeystorePtr,685 overseer_handle: OverseerHandle,686 relay_chain_slot_duration: Duration,687 para_id: ParaId,688 collator_key: CollatorPair,689 announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,690) -> Result<(), sc_service::Error>691where692 ExecutorDispatch: NativeExecutionDispatch + 'static,693 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>694 + Send695 + Sync696 + 'static,697 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,698 Runtime: RuntimeInstance,699{700 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;701702 let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(703 task_manager.spawn_handle(),704 client.clone(),705 transaction_pool,706 prometheus_registry,707 telemetry.clone(),708 );709 let proposer = Proposer::new(proposer_factory);710711 let collator_service = CollatorService::new(712 client.clone(),713 Arc::new(task_manager.spawn_handle()),714 announce_block,715 client.clone(),716 );717718 let block_import = ParachainBlockImport::new(client.clone(), backend);719720 let params = BuildAuraConsensusParams {721 create_inherent_data_providers: move |_, ()| async move { Ok(()) },722 block_import,723 para_client: client,724 #[cfg(feature = "lookahead")]725 para_backend: backend,726 para_id,727 relay_client: relay_chain_interface,728 sync_oracle,729 keystore,730 slot_duration,731 proposer,732 collator_service,733 // With async-baking, we allowed to be both slower (longer authoring) and faster (multiple para blocks per relay block)734 authoring_duration: Duration::from_millis(500),735 overseer_handle,736 #[cfg(feature = "lookahead")]737 code_hash_provider: || {},738 collator_key,739 relay_chain_slot_duration,740 };741742 task_manager.spawn_essential_handle().spawn(743 "aura",744 None,745 run_aura::<_, AuraAuthorityPair, _, _, _, _, _, _, _>(params),746 );747 Ok(())748}749750fn dev_build_import_queue<RuntimeApi, ExecutorDispatch>(751 client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,752 _: Arc<FullBackend>,753 config: &Configuration,754 _: Option<TelemetryHandle>,755 task_manager: &TaskManager,756) -> Result<sc_consensus::DefaultImportQueue<Block>, sc_service::Error>757where758 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>759 + Send760 + Sync761 + 'static,762 RuntimeApi::RuntimeApi:763 sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> + sp_api::ApiExt<Block>,764 ExecutorDispatch: NativeExecutionDispatch + 'static,765{766 Ok(sc_consensus_manual_seal::import_queue(767 Box::new(client),768 &task_manager.spawn_essential_handle(),769 config.prometheus_registry(),770 ))771}772773pub struct OtherPartial {774 pub telemetry: Option<Telemetry>,775 pub telemetry_worker_handle: Option<TelemetryWorkerHandle>,776 pub eth_filter_pool: Option<FilterPool>,777 pub eth_backend: Arc<fc_db::kv::Backend<Block>>,778}779780struct DefaultEthConfig<C>(PhantomData<C>);781impl<C> EthConfig<Block, C> for DefaultEthConfig<C>782where783 C: StorageProvider<Block, FullBackend> + Sync + Send + 'static,784{785 type EstimateGasAdapter = ();786 type RuntimeStorageOverride = SystemAccountId32StorageOverride<Block, C, FullBackend>;787}788789/// Builds a new development service. This service uses instant seal, and mocks790/// the parachain inherent791pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(792 config: Configuration,793 autoseal_interval: u64,794 autoseal_finalize_delay: Option<u64>,795 disable_autoseal_on_tx: bool,796) -> sc_service::error::Result<TaskManager>797where798 Runtime: RuntimeInstance + Send + Sync + 'static,799 <Runtime as RuntimeInstance>::CrossAccountId: Serialize,800 for<'de> <Runtime as RuntimeInstance>::CrossAccountId: Deserialize<'de>,801 RuntimeApi: sp_api::ConstructRuntimeApi<Block, FullClient<RuntimeApi, ExecutorDispatch>>802 + Send803 + Sync804 + 'static,805 RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,806 ExecutorDispatch: NativeExecutionDispatch + 'static,807{808 use fc_consensus::FrontierBlockImport;809 use sc_consensus_manual_seal::{810 run_delayed_finalize, run_manual_seal, DelayedFinalizeParams, EngineCommand,811 ManualSealParams,812 };813814 let sc_service::PartialComponents {815 client,816 backend,817 mut task_manager,818 import_queue,819 keystore_container,820 select_chain: maybe_select_chain,821 transaction_pool,822 other:823 OtherPartial {824 telemetry,825 eth_filter_pool,826 eth_backend,827 telemetry_worker_handle: _,828 },829 } = new_partial::<Runtime, RuntimeApi, ExecutorDispatch, _>(830 &config,831 dev_build_import_queue::<RuntimeApi, ExecutorDispatch>,832 )?;833 let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);834 let prometheus_registry = config.prometheus_registry().cloned();835836 let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =837 sc_service::build_network(sc_service::BuildNetworkParams {838 config: &config,839 net_config,840 client: client.clone(),841 transaction_pool: transaction_pool.clone(),842 spawn_handle: task_manager.spawn_handle(),843 import_queue,844 block_announce_validator_builder: None,845 warp_sync_params: None,846 })?;847848 let collator = config.role.is_authority();849850 let select_chain = maybe_select_chain;851852 if collator {853 let block_import = FrontierBlockImport::new(client.clone(), client.clone());854855 let env = sc_basic_authorship::ProposerFactory::new(856 task_manager.spawn_handle(),857 client.clone(),858 transaction_pool.clone(),859 prometheus_registry.as_ref(),860 telemetry.as_ref().map(|x| x.handle()),861 );862863 let transactions_commands_stream: Box<864 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,865 > = Box::new(866 transaction_pool867 .pool()868 .validated_pool()869 .import_notification_stream()870 .filter(move |_| futures::future::ready(!disable_autoseal_on_tx))871 .map(|_| EngineCommand::SealNewBlock {872 create_empty: true,873 finalize: false,874 parent_hash: None,875 sender: None,876 }),877 );878879 let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));880881 let idle_commands_stream: Box<882 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,883 > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {884 create_empty: true,885 finalize: false,886 parent_hash: None,887 sender: None,888 }));889890 let commands_stream = select(transactions_commands_stream, idle_commands_stream);891892 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;893 let client_set_aside_for_cidp = client.clone();894895 if let Some(delay_sec) = autoseal_finalize_delay {896 let spawn_handle = task_manager.spawn_handle();897898 task_manager.spawn_essential_handle().spawn_blocking(899 "finalization_task",900 Some("block-authoring"),901 run_delayed_finalize(DelayedFinalizeParams {902 client: client.clone(),903 delay_sec,904 spawn_handle,905 }),906 );907 }908909 task_manager.spawn_essential_handle().spawn_blocking(910 "authorship_task",911 Some("block-authoring"),912 run_manual_seal(ManualSealParams {913 block_import,914 env,915 client: client.clone(),916 pool: transaction_pool.clone(),917 commands_stream,918 select_chain: select_chain.clone(),919 consensus_data_provider: None,920 create_inherent_data_providers: move |block: Hash, ()| {921 let current_para_block = client_set_aside_for_cidp922 .number(block)923 .expect("Header lookup should succeed")924 .expect("Header passed in as parent should be present in backend.");925926 let client_for_xcm = client_set_aside_for_cidp.clone();927 async move {928 let time = sp_timestamp::InherentDataProvider::from_system_time();929930 let mocked_parachain = cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider {931 current_para_block,932 relay_offset: 1000,933 relay_blocks_per_para_block: 2,934 para_blocks_per_relay_epoch: 0,935 xcm_config: cumulus_primitives_parachain_inherent::MockXcmConfig::new(936 &*client_for_xcm,937 block,938 Default::default(),939 Default::default(),940 ),941 relay_randomness_config: (),942 raw_downward_messages: vec![],943 raw_horizontal_messages: vec![],944 };945946 let slot =947 sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(948 *time,949 slot_duration,950 );951952 Ok((time, slot, mocked_parachain))953 }954 },955 }),956 );957 }958959 #[cfg(feature = "pov-estimate")]960 let rpc_backend = backend.clone();961962 let runtime_id = config.chain_spec.runtime_id();963964 // Frontier965 let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));966 let fee_history_limit = 2048;967968 let eth_pubsub_notification_sinks: Arc<969 EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<Block>>,970 > = Default::default();971972 let overrides = overrides_handle(client.clone());973 let eth_block_data_cache = spawn_frontier_tasks(974 FrontierTaskParams {975 client: client.clone(),976 substrate_backend: backend.clone(),977 eth_filter_pool: eth_filter_pool.clone(),978 eth_backend: eth_backend.clone(),979 fee_history_limit,980 fee_history_cache: fee_history_cache.clone(),981 task_manager: &task_manager,982 prometheus_registry,983 overrides: overrides.clone(),984 sync_strategy: SyncStrategy::Normal,985 },986 sync_service.clone(),987 eth_pubsub_notification_sinks.clone(),988 );989990 // Rpc991 let rpc_builder = Box::new({992 clone!(993 client,994 backend,995 eth_backend,996 eth_pubsub_notification_sinks,997 fee_history_cache,998 eth_block_data_cache,999 overrides,1000 transaction_pool,1001 network,1002 sync_service,1003 );1004 move |deny_unsafe, subscription_task_executor: SubscriptionTaskExecutor| {1005 clone!(1006 backend,1007 eth_block_data_cache,1008 client,1009 eth_backend,1010 eth_filter_pool,1011 eth_pubsub_notification_sinks,1012 fee_history_cache,1013 eth_block_data_cache,1014 network,1015 runtime_id,1016 transaction_pool,1017 select_chain,1018 overrides,1019 );10201021 #[cfg(not(feature = "pov-estimate"))]1022 let _ = backend;10231024 let mut rpc_module = RpcModule::new(());10251026 let full_deps = FullDeps {1027 runtime_id,10281029 #[cfg(feature = "pov-estimate")]1030 exec_params: uc_rpc::pov_estimate::ExecutorParams {1031 wasm_method: config.wasm_method,1032 default_heap_pages: config.default_heap_pages,1033 max_runtime_instances: config.max_runtime_instances,1034 runtime_cache_size: config.runtime_cache_size,1035 },10361037 #[cfg(feature = "pov-estimate")]1038 backend,1039 // eth_backend,1040 deny_unsafe,1041 client: client.clone(),1042 pool: transaction_pool.clone(),1043 select_chain,1044 };10451046 create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_module, full_deps)?;10471048 let eth_deps = EthDeps {1049 client,1050 graph: transaction_pool.pool().clone(),1051 pool: transaction_pool,1052 is_authority: true,1053 network,1054 eth_backend,1055 // TODO: Unhardcode1056 max_past_logs: 10000,1057 fee_history_limit,1058 fee_history_cache,1059 eth_block_data_cache,1060 // TODO: Unhardcode1061 enable_dev_signer: false,1062 eth_filter_pool,1063 eth_pubsub_notification_sinks,1064 overrides,1065 sync: sync_service.clone(),1066 // We don't have any inherents except parachain built-ins, which we can't even extract from inside `run_aura`.1067 pending_create_inherent_data_providers: |_, ()| async move { Ok(()) },1068 };10691070 create_eth::<1071 _,1072 _,1073 _,1074 _,1075 _,1076 _,1077 DefaultEthConfig<FullClient<RuntimeApi, ExecutorDispatch>>,1078 >(1079 &mut rpc_module,1080 eth_deps,1081 subscription_task_executor.clone(),1082 )?;10831084 Ok(rpc_module)1085 }1086 });10871088 sc_service::spawn_tasks(sc_service::SpawnTasksParams {1089 network,1090 sync_service,1091 client,1092 keystore: keystore_container.keystore(),1093 task_manager: &mut task_manager,1094 transaction_pool,1095 rpc_builder,1096 backend,1097 system_rpc_tx,1098 config,1099 telemetry: None,1100 tx_handler_controller,1101 })?;11021103 network_starter.start_network();1104 Ok(task_manager)1105}11061107fn overrides_handle<C, BE>(client: Arc<C>) -> Arc<OverrideHandle<Block>>1108where1109 C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,1110 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,1111 C: Send + Sync + 'static,1112 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,1113 BE: Backend<Block> + 'static,1114 BE::State: StateBackend<BlakeTwo256>,1115{1116 let mut overrides_map = BTreeMap::new();1117 overrides_map.insert(1118 EthereumStorageSchema::V1,1119 Box::new(SchemaV1Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,1120 );1121 overrides_map.insert(1122 EthereumStorageSchema::V2,1123 Box::new(SchemaV2Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,1124 );1125 overrides_map.insert(1126 EthereumStorageSchema::V3,1127 Box::new(SchemaV3Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,1128 );11291130 Arc::new(OverrideHandle {1131 schemas: overrides_map,1132 fallback: Box::new(RuntimeApiStorageOverride::new(client)),1133 })1134}11351136pub struct FrontierTaskParams<'a, C, B> {1137 pub task_manager: &'a TaskManager,1138 pub client: Arc<C>,1139 pub substrate_backend: Arc<B>,1140 pub eth_backend: Arc<fc_db::kv::Backend<Block>>,1141 pub eth_filter_pool: Option<FilterPool>,1142 pub overrides: Arc<OverrideHandle<Block>>,1143 pub fee_history_limit: u64,1144 pub fee_history_cache: FeeHistoryCache,1145 pub sync_strategy: SyncStrategy,1146 pub prometheus_registry: Option<Registry>,1147}11481149pub fn spawn_frontier_tasks<C, B>(1150 params: FrontierTaskParams<C, B>,1151 sync: Arc<SyncingService<Block>>,1152 pubsub_notification_sinks: Arc<1153 EthereumBlockNotificationSinks<fc_mapping_sync::EthereumBlockNotification<Block>>,1154 >,1155) -> Arc<EthBlockDataCacheTask<Block>>1156where1157 C: ProvideRuntimeApi<Block> + BlockOf,1158 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,1159 C: BlockchainEvents<Block> + StorageProvider<Block, B>,1160 C: Send + Sync + 'static,1161 C::Api: EthereumRuntimeRPCApi<Block>,1162 C::Api: BlockBuilder<Block>,1163 B: Backend<Block> + 'static,1164 B::State: StateBackend<BlakeTwo256>,1165{1166 let FrontierTaskParams {1167 task_manager,1168 client,1169 substrate_backend,1170 eth_backend,1171 eth_filter_pool,1172 overrides,1173 fee_history_limit,1174 fee_history_cache,1175 sync_strategy,1176 prometheus_registry,1177 } = params;1178 // Frontier offchain DB task. Essential.1179 // Maps emulated ethereum data to substrate native data.1180 params.task_manager.spawn_essential_handle().spawn(1181 "frontier-mapping-sync-worker",1182 Some("frontier"),1183 MappingSyncWorker::new(1184 client.import_notification_stream(),1185 Duration::new(6, 0),1186 client.clone(),1187 substrate_backend,1188 overrides.clone(),1189 eth_backend,1190 3,1191 0,1192 sync_strategy,1193 sync,1194 pubsub_notification_sinks,1195 )1196 .for_each(|()| futures::future::ready(())),1197 );11981199 // Frontier `EthFilterApi` maintenance.1200 // Manages the pool of user-created Filters.1201 if let Some(eth_filter_pool) = eth_filter_pool {1202 // Each filter is allowed to stay in the pool for 100 blocks.1203 const FILTER_RETAIN_THRESHOLD: u64 = 100;1204 params.task_manager.spawn_essential_handle().spawn(1205 "frontier-filter-pool",1206 Some("frontier"),1207 EthTask::filter_pool_task(client.clone(), eth_filter_pool, FILTER_RETAIN_THRESHOLD),1208 );1209 }12101211 // Spawn Frontier FeeHistory cache maintenance task.1212 params.task_manager.spawn_essential_handle().spawn(1213 "frontier-fee-history",1214 Some("frontier"),1215 EthTask::fee_history_task(1216 client,1217 overrides.clone(),1218 fee_history_cache,1219 fee_history_limit,1220 ),1221 );12221223 Arc::new(EthBlockDataCacheTask::new(1224 task_manager.spawn_handle(),1225 overrides,1226 50,1227 50,1228 prometheus_registry,1229 ))1230}pallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/benchmarking.rs
+++ b/pallets/app-promotion/src/benchmarking.rs
@@ -109,7 +109,7 @@
}
#[benchmark]
- fn payout_stakers(b: Linear<0, 100>) -> Result<(), BenchmarkError> {
+ fn payout_stakers(b: Linear<1, 100>) -> Result<(), BenchmarkError> {
let pallet_admin = account::<T::AccountId>("admin", 1, SEED);
PromototionPallet::<T>::set_admin_address(
RawOrigin::Root.into(),
pallets/collator-selection/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/collator-selection/src/benchmarking.rs
+++ b/pallets/collator-selection/src/benchmarking.rs
@@ -171,7 +171,8 @@
// Both invulnerables and candidates count together against MaxCollators.
// Maybe try putting it in braces? 1 .. (T::MaxCollators::get() - 2)
#[benchmark]
- fn add_invulnerable<T>(b: Linear<1, MAX_COLLATORS>) -> Result<(), BenchmarkError> {
+ fn add_invulnerable<T>(b: Linear<2, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
+ let b = b - 1;
register_validators::<T>(b);
register_invulnerables::<T>(b);
@@ -268,7 +269,8 @@
// worst case is when we have all the max-candidate slots filled except one, and we fill that
// one.
#[benchmark]
- fn onboard(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
+ fn onboard(c: Linear<2, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
+ let c = c - 1;
register_validators::<T>(c);
register_candidates::<T>(c);
@@ -293,9 +295,7 @@
// worst case is the last candidate leaving.
#[benchmark]
- fn offboard(c: Linear<0, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
- let c = c + 1;
-
+ fn offboard(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
register_validators::<T>(c);
register_candidates::<T>(c);
@@ -317,8 +317,7 @@
// worst case is the last candidate leaving.
#[benchmark]
- fn release_license(c: Linear<0, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
- let c = c + 1;
+ fn release_license(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
let bond = balance_unit::<T>();
register_validators::<T>(c);
@@ -343,8 +342,7 @@
// worst case is the last candidate leaving.
#[benchmark]
- fn force_release_license(c: Linear<0, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
- let c = c + 1;
+ fn force_release_license(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
let bond = balance_unit::<T>();
register_validators::<T>(c);
@@ -400,12 +398,9 @@
// worst case for new session.
#[benchmark]
fn new_session(
- r: Linear<0, MAX_INVULNERABLES>,
- c: Linear<0, MAX_INVULNERABLES>,
+ r: Linear<1, MAX_INVULNERABLES>,
+ c: Linear<1, MAX_INVULNERABLES>,
) -> Result<(), BenchmarkError> {
- let r = r + 1;
- let c = c + 1;
-
frame_system::Pallet::<T>::set_block_number(0u32.into());
register_validators::<T>(c);
pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -17,9 +17,7 @@
use frame_benchmarking::v2::{account, benchmarks, BenchmarkError};
use pallet_common::{
bench_init,
- benchmarking::{
- create_collection_raw, load_is_admin_and_property_permissions, property_key, property_value,
- },
+ benchmarking::{create_collection_raw, property_key, property_value},
CommonCollectionOperations,
};
use sp_std::prelude::*;
@@ -334,49 +332,51 @@
Ok(())
}
+ // TODO:
#[benchmark]
fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
- bench_init! {
- owner: sub; collection: collection(owner);
- owner: cross_from_sub;
- };
+ // bench_init! {
+ // owner: sub; collection: collection(owner);
+ // owner: cross_from_sub;
+ // };
- let perms = (0..b)
- .map(|k| PropertyKeyPermission {
- key: property_key(k as usize),
- permission: PropertyPermission {
- mutable: false,
- collection_admin: true,
- token_owner: true,
- },
- })
- .collect::<Vec<_>>();
- <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- let props = (0..b)
- .map(|k| Property {
- key: property_key(k as usize),
- value: property_value(),
- })
- .collect::<Vec<_>>();
- let item = create_max_item(&collection, &owner, owner.clone())?;
+ // let perms = (0..b)
+ // .map(|k| PropertyKeyPermission {
+ // key: property_key(k as usize),
+ // permission: PropertyPermission {
+ // mutable: false,
+ // collection_admin: true,
+ // token_owner: true,
+ // },
+ // })
+ // .collect::<Vec<_>>();
+ // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
+ #[block]
+ {}
+ // let props = (0..b)
+ // .map(|k| Property {
+ // key: property_key(k as usize),
+ // value: property_value(),
+ // })
+ // .collect::<Vec<_>>();
+ // let item = create_max_item(&collection, &owner, owner.clone())?;
// let (is_collection_admin, property_permissions) =
// load_is_admin_and_property_permissions(&collection, &owner);
- todo!();
- #[block]
- {
- // let mut property_writer =
- // pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
+ // #[block]
+ // {
+ // let mut property_writer =
+ // pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);
- // property_writer.write_token_properties(
- // item,
- // props.into_iter(),
- // crate::erc::ERC721TokenEvent::TokenChanged {
- // token_id: item.into(),
- // }
- // .to_log(T::ContractAddress::get()),
- // )?;
- }
+ // property_writer.write_token_properties(
+ // item,
+ // props.into_iter(),
+ // crate::erc::ERC721TokenEvent::TokenChanged {
+ // token_id: item.into(),
+ // }
+ // .to_log(T::ContractAddress::get()),
+ // )?;
+ // }
Ok(())
}
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -490,35 +490,35 @@
Ok(())
}
+ // TODO:
#[benchmark]
fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
- bench_init! {
- owner: sub; collection: collection(owner);
- owner: cross_from_sub;
- };
+ // bench_init! {
+ // owner: sub; collection: collection(owner);
+ // owner: cross_from_sub;
+ // };
+
+ // let perms = (0..b)
+ // .map(|k| PropertyKeyPermission {
+ // key: property_key(k as usize),
+ // permission: PropertyPermission {
+ // mutable: false,
+ // collection_admin: true,
+ // token_owner: true,
+ // },
+ // })
+ // .collect::<Vec<_>>();
+ // <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
- let perms = (0..b)
- .map(|k| PropertyKeyPermission {
- key: property_key(k as usize),
- permission: PropertyPermission {
- mutable: false,
- collection_admin: true,
- token_owner: true,
- },
- })
- .collect::<Vec<_>>();
- <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
+ #[block]
+ {}
// let props = (0..b).map(|k| Property {
// key: property_key(k as usize),
// value: property_value(),
// }).collect::<Vec<_>>();
// let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;
- // let (is_collection_admin, property_permissions) = load_is_admin_and_property_permissions(&collection, &owner);
-
- #[block]
- {}
- todo!();
+ // let (is_collection_admin, property_permissions) = load_is_admin_and_property_permissions(&collection, &owner)
// let mut property_writer = pallet_common::collection_info_loaded_property_writer(
// &collection,
// is_collection_admin,