From 9b65a47d8a3ca651c855d2735d2dd8c71cbc66d0 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Thu, 6 Jun 2024 14:53:20 +0200 Subject: [PATCH] apply template and fix build --- Cargo.lock | 138 +++++++------------------- Cargo.toml | 14 +-- node/Cargo.toml | 2 +- node/src/cli.rs | 5 - node/src/command.rs | 40 ++++---- node/src/rpc.rs | 4 +- node/src/service.rs | 229 +++++++++++++++++++++----------------------- 7 files changed, 168 insertions(+), 264 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e372e4..d3b4781 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2202,7 +2202,7 @@ dependencies = [ "async-trait", "cumulus-primitives-core", "futures 0.3.30", - "jsonrpsee-core 0.22.5", + "jsonrpsee-core", "parity-scale-codec", "polkadot-overseer", "sc-client-api", @@ -2267,7 +2267,7 @@ dependencies = [ "either", "futures 0.3.30", "futures-timer", - "jsonrpsee 0.22.5", + "jsonrpsee", "parity-scale-codec", "pin-project", "polkadot-overseer", @@ -2843,7 +2843,7 @@ dependencies = [ "encointer-balances-tx-payment-rpc-runtime-api", "encointer-primitives", "encointer-rpc", - "jsonrpsee 0.22.5", + "jsonrpsee", "log", "pallet-transaction-payment", "pallet-transaction-payment-rpc", @@ -2912,7 +2912,7 @@ dependencies = [ "frame-benchmarking-cli", "futures 0.3.30", "hex-literal", - "jsonrpsee 0.20.3", + "jsonrpsee", "log", "nix 0.24.3", "pallet-encointer-bazaar-rpc", @@ -3089,9 +3089,9 @@ version = "10.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ada8935fc7557fa1a43ffdb096e6f709c61be31e75bef6a5a1d16da8958b7cf2" dependencies = [ - "jsonrpsee 0.22.5", - "jsonrpsee-core 0.22.5", - "jsonrpsee-types 0.22.5", + "jsonrpsee", + "jsonrpsee-core", + "jsonrpsee-types", "thiserror", ] @@ -4661,28 +4661,16 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "jsonrpsee" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "affdc52f7596ccb2d7645231fc6163bb314630c989b64998f3699a28b4d5d4dc" -dependencies = [ - "jsonrpsee-core 0.20.3", - "jsonrpsee-server 0.20.3", - "jsonrpsee-types 0.20.3", - "tokio", -] - [[package]] name = "jsonrpsee" version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfdb12a2381ea5b2e68c3469ec604a007b367778cdb14d09612c8069ebd616ad" dependencies = [ - "jsonrpsee-core 0.22.5", + "jsonrpsee-core", "jsonrpsee-proc-macros", - "jsonrpsee-server 0.22.5", - "jsonrpsee-types 0.22.5", + "jsonrpsee-server", + "jsonrpsee-types", "jsonrpsee-ws-client", "tokio", "tracing", @@ -4696,7 +4684,7 @@ checksum = "4978087a58c3ab02efc5b07c5e5e2803024536106fd5506f558db172c889b3aa" dependencies = [ "futures-util", "http", - "jsonrpsee-core 0.22.5", + "jsonrpsee-core", "pin-project", "rustls-native-certs 0.7.0", "rustls-pki-types", @@ -4709,29 +4697,6 @@ dependencies = [ "url", ] -[[package]] -name = "jsonrpsee-core" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da2327ba8df2fdbd5e897e2b5ed25ce7f299d345b9736b6828814c3dbd1fd47b" -dependencies = [ - "anyhow", - "async-trait", - "beef", - "futures-util", - "hyper", - "jsonrpsee-types 0.20.3", - "parking_lot 0.12.1", - "rand 0.8.5", - "rustc-hash", - "serde", - "serde_json", - "soketto", - "thiserror", - "tokio", - "tracing", -] - [[package]] name = "jsonrpsee-core" version = "0.22.5" @@ -4744,7 +4709,7 @@ dependencies = [ "futures-timer", "futures-util", "hyper", - "jsonrpsee-types 0.22.5", + "jsonrpsee-types", "parking_lot 0.12.1", "pin-project", "rand 0.8.5", @@ -4770,29 +4735,6 @@ dependencies = [ "syn 2.0.58", ] -[[package]] -name = "jsonrpsee-server" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c39a00449c9ef3f50b84fc00fc4acba20ef8f559f07902244abf4c15c5ab9c" -dependencies = [ - "futures-util", - "http", - "hyper", - "jsonrpsee-core 0.20.3", - "jsonrpsee-types 0.20.3", - "route-recognizer", - "serde", - "serde_json", - "soketto", - "thiserror", - "tokio", - "tokio-stream", - "tokio-util", - "tower", - "tracing", -] - [[package]] name = "jsonrpsee-server" version = "0.22.5" @@ -4802,8 +4744,8 @@ dependencies = [ "futures-util", "http", "hyper", - "jsonrpsee-core 0.22.5", - "jsonrpsee-types 0.22.5", + "jsonrpsee-core", + "jsonrpsee-types", "pin-project", "route-recognizer", "serde", @@ -4817,20 +4759,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "jsonrpsee-types" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be0be325642e850ed0bdff426674d2e66b2b7117c9be23a7caef68a2902b7d9" -dependencies = [ - "anyhow", - "beef", - "serde", - "serde_json", - "thiserror", - "tracing", -] - [[package]] name = "jsonrpsee-types" version = "0.22.5" @@ -4852,8 +4780,8 @@ checksum = "58b9db2dfd5bb1194b0ce921504df9ceae210a345bc2f6c5a61432089bbab070" dependencies = [ "http", "jsonrpsee-client-transport", - "jsonrpsee-core 0.22.5", - "jsonrpsee-types 0.22.5", + "jsonrpsee-core", + "jsonrpsee-types", "url", ] @@ -5876,7 +5804,7 @@ version = "33.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70db3d6f4fdfd688a4f995f5eb3ee9764b766a01f4a4789fa5469a02d213ee12" dependencies = [ - "jsonrpsee 0.22.5", + "jsonrpsee", "parity-scale-codec", "serde", "sp-api", @@ -6972,7 +6900,7 @@ checksum = "e6708371cce80e0ad74bfb8e304c923188cd832025dfccf0120c8fa426380f02" dependencies = [ "encointer-primitives", "encointer-rpc", - "jsonrpsee 0.22.5", + "jsonrpsee", "log", "pallet-encointer-bazaar-rpc-runtime-api", "parity-scale-codec", @@ -7032,7 +6960,7 @@ checksum = "dd49db775ff5ac1886dc7dc96fab9be575f1d4b5e348e481a0849c44f73d0aaf" dependencies = [ "encointer-primitives", "encointer-rpc", - "jsonrpsee 0.22.5", + "jsonrpsee", "log", "pallet-encointer-ceremonies-rpc-runtime-api", "parity-scale-codec", @@ -7086,7 +7014,7 @@ checksum = "283b028e0f072cf1fb0963ec1a1fc6a6f85c039d8687a0a04795a689752f5a64" dependencies = [ "encointer-primitives", "encointer-rpc", - "jsonrpsee 0.22.5", + "jsonrpsee", "log", "pallet-encointer-communities-rpc-runtime-api", "parity-scale-codec", @@ -7839,7 +7767,7 @@ version = "35.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46ba896951ef39011e27d0a91b565520636f926f01b1c912a411146af079ef5e" dependencies = [ - "jsonrpsee 0.22.5", + "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", "sp-api", @@ -9131,7 +9059,7 @@ version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b791f93e89c38bafc894e9364c27a85b8d5696a9280f95f22c39a601cae4e6c8" dependencies = [ - "jsonrpsee 0.22.5", + "jsonrpsee", "mmr-rpc", "pallet-transaction-payment-rpc", "polkadot-primitives", @@ -11070,7 +10998,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd3bd3762945244a50e7e64aa9302405ba3d225a807872a4f99e8250e5ec4e60" dependencies = [ "futures 0.3.30", - "jsonrpsee 0.22.5", + "jsonrpsee", "sc-consensus-babe", "sc-consensus-epochs", "sc-rpc-api", @@ -11131,7 +11059,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7db1d87a1107de282b3208e25370c1f54dcfc9f0c12bdea52fad127df4929c63" dependencies = [ "futures 0.3.30", - "jsonrpsee 0.22.5", + "jsonrpsee", "log", "parity-scale-codec", "parking_lot 0.12.1", @@ -11211,7 +11139,7 @@ checksum = "5c587c6b017281f2029a7901de1e2f6f85ee8b365e9d15b159a5c44450fc71f6" dependencies = [ "finality-grandpa", "futures 0.3.30", - "jsonrpsee 0.22.5", + "jsonrpsee", "log", "parity-scale-codec", "sc-client-api", @@ -11621,7 +11549,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3af3898afc9e63bfda6bbb75a20bb66a4b3de0bc077eb1b67d94b04f69b984" dependencies = [ "futures 0.3.30", - "jsonrpsee 0.22.5", + "jsonrpsee", "log", "parity-scale-codec", "parking_lot 0.12.1", @@ -11653,7 +11581,7 @@ version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2656a0da9ce809fb31dc0517b7e0a4185001785154b59cd9546566f1db8df346" dependencies = [ - "jsonrpsee 0.22.5", + "jsonrpsee", "parity-scale-codec", "sc-chain-spec", "sc-mixnet", @@ -11678,7 +11606,7 @@ dependencies = [ "governor", "http", "hyper", - "jsonrpsee 0.22.5", + "jsonrpsee", "log", "serde_json", "substrate-prometheus-endpoint", @@ -11697,7 +11625,7 @@ dependencies = [ "futures 0.3.30", "futures-util", "hex", - "jsonrpsee 0.22.5", + "jsonrpsee", "log", "parity-scale-codec", "parking_lot 0.12.1", @@ -11731,7 +11659,7 @@ dependencies = [ "exit-future", "futures 0.3.30", "futures-timer", - "jsonrpsee 0.22.5", + "jsonrpsee", "log", "parity-scale-codec", "parking_lot 0.12.1", @@ -11817,7 +11745,7 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "910d78b0ea4778a639a9d1345d4e5ce27721ed0d717635aded1bb6c522044bb2" dependencies = [ - "jsonrpsee 0.22.5", + "jsonrpsee", "parity-scale-codec", "sc-chain-spec", "sc-client-api", @@ -13687,7 +13615,7 @@ checksum = "d19975c2965833aed97064cd34975ed5bc0390e4436c84b381874c8abce43712" dependencies = [ "frame-system-rpc-runtime-api", "futures 0.3.30", - "jsonrpsee 0.22.5", + "jsonrpsee", "log", "parity-scale-codec", "sc-rpc-api", @@ -13729,7 +13657,7 @@ version = "32.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "538029eeb26c9ab3f5f8677d696336f92ee536918f4e7ba7fcad1d08ad31ca6b" dependencies = [ - "jsonrpsee 0.22.5", + "jsonrpsee", "parity-scale-codec", "sc-client-api", "sc-rpc-api", diff --git a/Cargo.toml b/Cargo.toml index 3151829..50d0c1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,17 +10,17 @@ panic = "unwind" [workspace.dependencies] assert_cmd = "2.0" async-trait = "0.1.74" -clap = { version = "4.4.14", features = ["derive"] } +clap = { version = "4.5.3", features = ["derive"] } color-print = "0.3.4" parity-scale-codec = { version = "3.6", default-features = false, features = ["derive"] } futures = { version = "0.3.28", features = ["compat"] } hex-literal = "0.4.1" -jsonrpsee = { version = "0.20.3", features = ["server"] } -log = { version = "0.4.20", default-features = false } +jsonrpsee = { version = "0.22.5", features = ["server"] } +log = { version = "0.4.21", default-features = false } nix = "0.24" -scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } -serde = { version = "1.0.195", default-features = false, features = ["derive"] } -serde_json = { version = "1.0.111", features = ["arbitrary_precision"] } +scale-info = { version = "2.11.1", default-features = false, features = ["derive"] } +serde = { version = "1.0.197", default-features = false, features = ["derive"] } +serde_json = { version = "1.0.114", features = ["arbitrary_precision"] } smallvec = "1.11.2" tempfile = "3.8.1" @@ -59,7 +59,6 @@ cumulus-primitives-timestamp = { version = "0.12.0", default-features = false } cumulus-primitives-utility = { version = "0.12.0", default-features = false } frame-benchmarking = { version = "33.0.0", default-features = false } frame-executive = { version = "33.0.0", default-features = false } -frame-rpc-system = { version = "33.0.0", package = "substrate-frame-rpc-system" } frame-support = { version = "33.0.0", default-features = false } frame-system = { version = "33.0.0", default-features = false } frame-system-benchmarking = { version = "33.0.0", default-features = false } @@ -142,6 +141,7 @@ sp-keyring = "36.0.0" sp-keystore = "0.38.0" sp-timestamp = "31.0.0" substrate-build-script-utils = "11.0.0" +substrate-frame-rpc-system = "33.0.0" substrate-prometheus-endpoint = "0.17.0" # ### only while debugging/developping diff --git a/node/Cargo.toml b/node/Cargo.toml index dd19073..062b7cc 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -75,9 +75,9 @@ sp-transaction-pool = { workspace = true, features = ["std"] } substrate-prometheus-endpoint = { workspace = true } # RPC related dependencies -frame-rpc-system = { workspace = true } pallet-transaction-payment-rpc = { workspace = true } sc-transaction-pool-api = { workspace = true } +substrate-frame-rpc-system = { workspace = true } # Polkadot dependencies polkadot-cli = { workspace = true } diff --git a/node/src/cli.rs b/node/src/cli.rs index 73ef996..cffbfbc 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -37,11 +37,6 @@ pub enum Subcommand { /// The pallet benchmarking moved to the `pallet` sub-command. #[command(subcommand)] Benchmark(frame_benchmarking_cli::BenchmarkCmd), - - /// Try-runtime has migrated to a standalone - /// [CLI](). The subcommand exists as a stub and - /// deprecation notice. It will be removed entirely some time after Janurary 2024. - TryRuntime, } const AFTER_HELP_EXAMPLE: &str = color_print::cstr!( diff --git a/node/src/command.rs b/node/src/command.rs index 42b3038..8c2e752 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -16,10 +16,11 @@ use crate::{ chain_spec, - chain_spec::{ChainSpec, GenesisKeys, RelayChain}, + chain_spec::{ChainSpec as EncointerChainSpec, GenesisKeys, RelayChain}, cli::{Cli, RelayChainCli, Subcommand}, service::new_partial, }; +use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions; use cumulus_primitives_core::ParaId; use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; use log::info; @@ -28,15 +29,17 @@ use sc_cli::{ CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, Result, SharedParams, SubstrateCli, }; -use sc_service::config::{BasePath, PrometheusConfig}; -use sp_runtime::traits::AccountIdConversion; +use sc_service::{ + config::{BasePath, PrometheusConfig}, + ChainSpec, +}; use std::net::SocketAddr; // If we don't skipp here, each cmd expands to 5 lines. I think we have better overview like this. #[rustfmt::skip] fn load_spec( id: &str, -) -> std::result::Result, String> { +) -> std::result::Result, String> { Ok(match id { // live configs (hard coded genesis state. genesis will always be shell for a live system) "encointer-rococo" => Box::new(chain_spec::encointer_rococo()?), @@ -74,7 +77,7 @@ fn load_spec( "" => return Err("No chain-spec specified".into()), path => { - let chain_spec = ChainSpec::from_json_file(path.into())?; + let chain_spec = EncointerChainSpec::from_json_file(path.into())?; Box::new(chain_spec) }, }) @@ -111,7 +114,7 @@ impl SubstrateCli for Cli { 2017 } - fn load_spec(&self, id: &str) -> std::result::Result, String> { + fn load_spec(&self, id: &str) -> std::result::Result, String> { load_spec(id) } } @@ -147,7 +150,7 @@ impl SubstrateCli for RelayChainCli { 2017 } - fn load_spec(&self, id: &str) -> std::result::Result, String> { + fn load_spec(&self, id: &str) -> std::result::Result, String> { polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id) } } @@ -211,7 +214,7 @@ pub fn run() -> Result<()> { &polkadot_cli, config.tokio_handle.clone(), ) - .map_err(|err| format!("Relay chain argument error: {}", err))?; + .map_err(|err| format!("Relay chain argument error: {}", err))?; cmd.run(config, polkadot_config) }) @@ -237,7 +240,7 @@ pub fn run() -> Result<()> { match cmd { BenchmarkCmd::Pallet(cmd) => if cfg!(feature = "runtime-benchmarks") { - runner.sync_run(|config| cmd.run::(config)) + runner.sync_run(|config| cmd.run_with_spec::, ReclaimHostFunctions>(Some(config.chain_spec))) } else { Err("Benchmarking wasn't enabled when building the node. \ You can enable it with `--features runtime-benchmarks`." @@ -254,7 +257,7 @@ pub fn run() -> Result<()> { to enable storage benchmarks." .into(), ) - .into()), + .into()), #[cfg(feature = "runtime-benchmarks")] BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { let partials = new_partial(&config)?; @@ -270,7 +273,6 @@ pub fn run() -> Result<()> { _ => Err("Benchmarking sub-command unsupported".into()), } }, - Some(Subcommand::TryRuntime) => Err("The `try-runtime` subcommand has been migrated to a standalone CLI (https://github.com/paritytech/try-runtime-cli). It is no longer being maintained here and will be removed entirely some time after January 2024. Please remove this subcommand from your runtime and use the standalone CLI.".into()), None => { let runner = cli.create_runner(&cli.run.normalize())?; let collator_options = cli.run.collator_options(); @@ -294,17 +296,11 @@ pub fn run() -> Result<()> { let id = ParaId::from(para_id); - let parachain_account = - AccountIdConversion::::into_account_truncating( - &id, - ); - let tokio_handle = config.tokio_handle.clone(); let polkadot_config = SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle) .map_err(|err| format!("Relay chain argument error: {}", err))?; - info!("Parachain Account: {parachain_account}"); info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" }); crate::service::start_parachain_node( @@ -314,9 +310,9 @@ pub fn run() -> Result<()> { id, hwbench, ) - .await - .map(|r| r.0) - .map_err(Into::into) + .await + .map(|r| r.0) + .map_err(Into::into) }) }, } @@ -367,7 +363,7 @@ impl CliConfiguration for RelayChainCli { fn prometheus_config( &self, default_listen_port: u16, - chain_spec: &Box, + chain_spec: &Box, ) -> Result> { self.base.base.prometheus_config(default_listen_port, chain_spec) } @@ -437,7 +433,7 @@ impl CliConfiguration for RelayChainCli { fn telemetry_endpoints( &self, - chain_spec: &Box, + chain_spec: &Box, ) -> Result> { self.base.base.telemetry_endpoints(chain_spec) } diff --git a/node/src/rpc.rs b/node/src/rpc.rs index 28ec6ef..46ea3cb 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -45,7 +45,7 @@ where + Sync + 'static, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, - C::Api: frame_rpc_system::AccountNonceApi, + C::Api: substrate_frame_rpc_system::AccountNonceApi, C::Api: BlockBuilder, P: TransactionPool + Sync + Send + 'static, C::Api: pallet_encointer_ceremonies_rpc_runtime_api::CeremoniesApi, @@ -62,11 +62,11 @@ where >::OffchainStorage: 'static, // added by encointer { use encointer_balances_tx_payment_rpc::{BalancesTxPaymentApiServer, BalancesTxPaymentRpc}; - use frame_rpc_system::{System, SystemApiServer}; use pallet_encointer_bazaar_rpc::{BazaarApiServer, BazaarRpc}; use pallet_encointer_ceremonies_rpc::{CeremoniesApiServer, CeremoniesRpc}; use pallet_encointer_communities_rpc::{CommunitiesApiServer, CommunitiesRpc}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; + use substrate_frame_rpc_system::{System, SystemApiServer}; let mut module = RpcExtension::new(()); let FullDeps { client, pool, backend, offchain_indexing_enabled, deny_unsafe } = deps; diff --git a/node/src/service.rs b/node/src/service.rs index 7497351..fd2ea20 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -14,7 +14,8 @@ use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImpo use cumulus_client_consensus_proposer::Proposer; use cumulus_client_service::{ build_network, build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, - BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, StartRelayChainTasksParams, + BuildNetworkParams, CollatorSybilResistance, DARecoveryProfile, ParachainHostFunctions, + StartRelayChainTasksParams, }; use cumulus_primitives_core::{relay_chain::CollatorPair, ParaId}; use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface}; @@ -32,8 +33,7 @@ use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sp_keystore::KeystorePtr; use substrate_prometheus_endpoint::Registry; -type ParachainExecutor = - WasmExecutor<(sp_io::SubstrateHostFunctions, frame_benchmarking::benchmarking::HostFunctions)>; +type ParachainExecutor = WasmExecutor; type ParachainClient = TFullClient; @@ -71,7 +71,7 @@ pub fn new_partial(config: &Configuration) -> Result .default_heap_pages .map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| HeapAllocStrategy::Static { extra_pages: h as _ }); - let executor = WasmExecutor::builder() + let executor = ParachainExecutor::builder() .with_execution_method(config.wasm_method) .with_onchain_heap_alloc_strategy(heap_pages) .with_offchain_heap_alloc_strategy(heap_pages) @@ -80,10 +80,11 @@ pub fn new_partial(config: &Configuration) -> Result .build(); let (client, backend, keystore_container, task_manager) = - sc_service::new_full_parts::( + sc_service::new_full_parts_record_import::( config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), executor, + true, )?; let client = Arc::new(client); @@ -110,7 +111,7 @@ pub fn new_partial(config: &Configuration) -> Result config, telemetry.as_ref().map(|telemetry| telemetry.handle()), &task_manager, - )?; + ); Ok(PartialComponents { backend, @@ -124,11 +125,100 @@ pub fn new_partial(config: &Configuration) -> Result }) } +/// Build the import queue for the parachain runtime. +fn build_import_queue( + client: Arc, + block_import: ParachainBlockImport, + config: &Configuration, + telemetry: Option, + task_manager: &TaskManager, +) -> sc_consensus::DefaultImportQueue { + cumulus_client_consensus_aura::equivocation_import_queue::fully_verifying_import_queue::< + sp_consensus_aura::sr25519::AuthorityPair, + _, + _, + _, + _, + >( + client, + block_import, + move |_, _| async move { + let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); + Ok(timestamp) + }, + &task_manager.spawn_essential_handle(), + config.prometheus_registry(), + telemetry, + ) +} + +fn start_consensus( + client: Arc, + block_import: ParachainBlockImport, + prometheus_registry: Option<&Registry>, + telemetry: Option, + task_manager: &TaskManager, + relay_chain_interface: Arc, + transaction_pool: Arc>, + sync_oracle: Arc>, + keystore: KeystorePtr, + relay_chain_slot_duration: Duration, + para_id: ParaId, + collator_key: CollatorPair, + overseer_handle: OverseerHandle, + announce_block: Arc>) + Send + Sync>, +) -> Result<(), sc_service::Error> { + use cumulus_client_consensus_aura::collators::basic::{ + self as basic_aura, Params as BasicAuraParams, + }; + + let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( + task_manager.spawn_handle(), + client.clone(), + transaction_pool, + prometheus_registry, + telemetry.clone(), + ); + + let proposer = Proposer::new(proposer_factory); + + let collator_service = CollatorService::new( + client.clone(), + Arc::new(task_manager.spawn_handle()), + announce_block, + client.clone(), + ); + + let params = BasicAuraParams { + create_inherent_data_providers: move |_, ()| async move { Ok(()) }, + block_import, + para_client: client, + relay_client: relay_chain_interface, + sync_oracle, + keystore, + collator_key, + para_id, + overseer_handle, + relay_chain_slot_duration, + proposer, + collator_service, + // Very limited proposal time. + authoring_duration: Duration::from_millis(500), + collation_request_receiver: None, + }; + + let fut = + basic_aura::run::( + params, + ); + task_manager.spawn_essential_handle().spawn("aura", None, fut); + + Ok(()) +} + /// Start a node with the given parachain `Configuration` and relay chain `Configuration`. -/// -/// This is the actual implementation that is abstract over the executor and the runtime api. #[sc_tracing::logging::prefix_logs_with("Parachain")] -async fn start_node_impl( +pub async fn start_parachain_node( parachain_config: Configuration, polkadot_config: Configuration, collator_options: CollatorOptions, @@ -139,7 +229,11 @@ async fn start_node_impl( let params = new_partial(¶chain_config)?; let (block_import, mut telemetry, telemetry_worker_handle) = params.other; - let net_config = sc_network::config::FullNetworkConfiguration::new(¶chain_config.network); + let net_config = sc_network::config::FullNetworkConfiguration::< + _, + _, + sc_network::NetworkWorker, + >::new(¶chain_config.network); let client = params.client.clone(); let backend = params.backend.clone(); @@ -161,6 +255,8 @@ async fn start_node_impl( let transaction_pool = params.transaction_pool.clone(); let import_queue_service = params.import_queue.service(); + // NOTE: because we use Aura here explicitly, we can use `CollatorSybilResistance::Resistant` + // when starting the network. let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = build_network(BuildNetworkParams { parachain_config: ¶chain_config, @@ -188,7 +284,7 @@ async fn start_node_impl( transaction_pool: Some(OffchainTransactionPoolFactory::new( transaction_pool.clone(), )), - network_provider: network.clone(), + network_provider: Arc::new(network.clone()), is_validator: parachain_config.role.is_authority(), enable_http_requests: false, custom_extensions: move |_| vec![], @@ -309,114 +405,3 @@ async fn start_node_impl( Ok((task_manager, client)) } - -/// Build the import queue for the parachain runtime. -fn build_import_queue( - client: Arc, - block_import: ParachainBlockImport, - config: &Configuration, - telemetry: Option, - task_manager: &TaskManager, -) -> Result, sc_service::Error> { - let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; - - Ok(cumulus_client_consensus_aura::equivocation_import_queue::fully_verifying_import_queue::< - sp_consensus_aura::sr25519::AuthorityPair, - _, - _, - _, - _, - >( - client, - block_import, - move |_, _| async move { - let timestamp = sp_timestamp::InherentDataProvider::from_system_time(); - Ok(timestamp) - }, - slot_duration, - &task_manager.spawn_essential_handle(), - config.prometheus_registry(), - telemetry, - )) -} - -fn start_consensus( - client: Arc, - block_import: ParachainBlockImport, - prometheus_registry: Option<&Registry>, - telemetry: Option, - task_manager: &TaskManager, - relay_chain_interface: Arc, - transaction_pool: Arc>, - sync_oracle: Arc>, - keystore: KeystorePtr, - relay_chain_slot_duration: Duration, - para_id: ParaId, - collator_key: CollatorPair, - overseer_handle: OverseerHandle, - announce_block: Arc>) + Send + Sync>, -) -> Result<(), sc_service::Error> { - use cumulus_client_consensus_aura::collators::basic::{ - self as basic_aura, Params as BasicAuraParams, - }; - - // NOTE: because we use Aura here explicitly, we can use `CollatorSybilResistance::Resistant` - // when starting the network. - - let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; - - let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( - task_manager.spawn_handle(), - client.clone(), - transaction_pool, - prometheus_registry, - telemetry.clone(), - ); - - let proposer = Proposer::new(proposer_factory); - - let collator_service = CollatorService::new( - client.clone(), - Arc::new(task_manager.spawn_handle()), - announce_block, - client.clone(), - ); - - let params = BasicAuraParams { - create_inherent_data_providers: move |_, ()| async move { Ok(()) }, - block_import, - para_client: client, - relay_client: relay_chain_interface, - sync_oracle, - keystore, - collator_key, - para_id, - overseer_handle, - slot_duration, - relay_chain_slot_duration, - proposer, - collator_service, - // Very limited proposal time. - authoring_duration: Duration::from_millis(500), - collation_request_receiver: None, - }; - - let fut = - basic_aura::run::( - params, - ); - task_manager.spawn_essential_handle().spawn("aura", None, fut); - - Ok(()) -} - -/// Start a parachain node. -pub async fn start_parachain_node( - parachain_config: Configuration, - polkadot_config: Configuration, - collator_options: CollatorOptions, - para_id: ParaId, - hwbench: Option, -) -> sc_service::error::Result<(TaskManager, Arc)> { - start_node_impl(parachain_config, polkadot_config, collator_options, para_id, hwbench).await -}