Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 1c75ee8

Browse files
committed
replace task executor with tokio handler
paritytech/substrate#9737
1 parent 664d000 commit 1c75ee8

File tree

3 files changed

+49
-50
lines changed

3 files changed

+49
-50
lines changed

polkadot-parachains/src/command.rs

+33-37
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use crate::{
1818
chain_spec,
1919
cli::{Cli, RelayChainCli, Subcommand},
2020
service::{
21-
StatemineRuntimeExecutor, StatemintRuntimeExecutor, WestmintRuntimeExecutor, new_partial,
22-
RococoParachainRuntimeExecutor, ShellRuntimeExecutor, Block,
21+
new_partial, Block, RococoParachainRuntimeExecutor, ShellRuntimeExecutor,
22+
StatemineRuntimeExecutor, StatemintRuntimeExecutor, WestmintRuntimeExecutor,
2323
},
2424
};
2525
use codec::Encode;
@@ -28,8 +28,8 @@ use cumulus_primitives_core::ParaId;
2828
use log::info;
2929
use polkadot_parachain::primitives::AccountIdConversion;
3030
use sc_cli::{
31-
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
32-
NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
31+
build_runtime, ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams,
32+
KeystoreParams, NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
3333
};
3434
use sc_service::config::{BasePath, PrometheusConfig};
3535
use sp_core::hexdisplay::HexDisplay;
@@ -327,7 +327,7 @@ pub fn run() -> Result<()> {
327327
let polkadot_config = SubstrateCli::create_configuration(
328328
&polkadot_cli,
329329
&polkadot_cli,
330-
config.task_executor.clone(),
330+
config.tokio_handle.clone(),
331331
)
332332
.map_err(|err| format!("Relay chain argument error: {}", err))?;
333333

@@ -423,10 +423,13 @@ pub fn run() -> Result<()> {
423423
generate_genesis_block(&config.chain_spec).map_err(|e| format!("{:?}", e))?;
424424
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
425425

426-
let task_executor = config.task_executor.clone();
427-
let polkadot_config =
428-
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, task_executor)
429-
.map_err(|err| format!("Relay chain argument error: {}", err))?;
426+
let tokio_runtime = build_runtime()?;
427+
let polkadot_config = SubstrateCli::create_configuration(
428+
&polkadot_cli,
429+
&polkadot_cli,
430+
tokio_runtime.handle().clone(),
431+
)
432+
.map_err(|err| format!("Relay chain argument error: {}", err))?;
430433

431434
info!("Parachain id: {:?}", id);
432435
info!("Parachain Account: {}", parachain_account);
@@ -441,32 +444,29 @@ pub fn run() -> Result<()> {
441444
);
442445

443446
if config.chain_spec.is_statemint() {
444-
crate::service::start_statemint_node::<statemint_runtime::RuntimeApi, StatemintRuntimeExecutor>(
445-
config,
446-
polkadot_config,
447-
id,
448-
)
449-
.await
450-
.map(|r| r.0)
451-
.map_err(Into::into)
447+
crate::service::start_statemint_node::<
448+
statemint_runtime::RuntimeApi,
449+
StatemintRuntimeExecutor,
450+
>(config, polkadot_config, id)
451+
.await
452+
.map(|r| r.0)
453+
.map_err(Into::into)
452454
} else if config.chain_spec.is_statemine() {
453-
crate::service::start_statemint_node::<statemine_runtime::RuntimeApi, StatemineRuntimeExecutor>(
454-
config,
455-
polkadot_config,
456-
id,
457-
)
458-
.await
459-
.map(|r| r.0)
460-
.map_err(Into::into)
455+
crate::service::start_statemint_node::<
456+
statemine_runtime::RuntimeApi,
457+
StatemineRuntimeExecutor,
458+
>(config, polkadot_config, id)
459+
.await
460+
.map(|r| r.0)
461+
.map_err(Into::into)
461462
} else if config.chain_spec.is_westmint() {
462-
crate::service::start_statemint_node::<westmint_runtime::RuntimeApi, WestmintRuntimeExecutor>(
463-
config,
464-
polkadot_config,
465-
id,
466-
)
467-
.await
468-
.map(|r| r.0)
469-
.map_err(Into::into)
463+
crate::service::start_statemint_node::<
464+
westmint_runtime::RuntimeApi,
465+
WestmintRuntimeExecutor,
466+
>(config, polkadot_config, id)
467+
.await
468+
.map(|r| r.0)
469+
.map_err(Into::into)
470470
} else if config.chain_spec.is_shell() {
471471
crate::service::start_shell_node(config, polkadot_config, id)
472472
.await
@@ -575,10 +575,6 @@ impl CliConfiguration<Self> for RelayChainCli {
575575
self.base.base.rpc_ws_max_connections()
576576
}
577577

578-
fn rpc_http_threads(&self) -> Result<Option<usize>> {
579-
self.base.base.rpc_http_threads()
580-
}
581-
582578
fn rpc_cors(&self, is_dev: bool) -> Result<Option<Vec<String>>> {
583579
self.base.base.rpc_cors(is_dev)
584580
}

test/service/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ codec = { package = "parity-scale-codec", version = "2.0.0" }
99
rand = "0.7.3"
1010
serde = { version = "1.0.101", features = ["derive"] }
1111
async-trait = "0.1.42"
12+
tokio = "1.10.0"
1213

1314
# Substrate
1415
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" }

test/service/src/lib.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use sc_service::{
3838
OffchainWorkerConfig, PruningMode, TransactionStorageMode, WasmExecutionMethod,
3939
},
4040
BasePath, ChainSpec, Configuration, Error as ServiceError, PartialComponents, Role,
41-
RpcHandlers, TFullBackend, TFullClient, TaskExecutor, TaskManager,
41+
RpcHandlers, TFullBackend, TFullClient, TaskManager,
4242
};
4343
use sp_arithmetic::traits::SaturatedConversion;
4444
use sp_blockchain::HeaderBackend;
@@ -375,7 +375,7 @@ enum Consensus {
375375
/// A builder to create a [`TestNode`].
376376
pub struct TestNodeBuilder {
377377
para_id: ParaId,
378-
task_executor: TaskExecutor,
378+
tokio_handle: tokio::runtime::Handle,
379379
key: Sr25519Keyring,
380380
collator_key: Option<CollatorPair>,
381381
parachain_nodes: Vec<MultiaddrWithPeerId>,
@@ -391,13 +391,13 @@ impl TestNodeBuilder {
391391
/// Create a new instance of `Self`.
392392
///
393393
/// `para_id` - The parachain id this node is running for.
394-
/// `task_executor` - The task executor to use.
394+
/// `tokio_handle` - The tokio handler to use.
395395
/// `key` - The key that will be used to generate the name and that will be passed as `dev_seed`.
396-
pub fn new(para_id: ParaId, task_executor: TaskExecutor, key: Sr25519Keyring) -> Self {
396+
pub fn new(para_id: ParaId, tokio_handle: tokio::runtime::Handle, key: Sr25519Keyring) -> Self {
397397
TestNodeBuilder {
398398
key,
399399
para_id,
400-
task_executor,
400+
tokio_handle,
401401
collator_key: None,
402402
parachain_nodes: Vec::new(),
403403
parachain_nodes_exclusive: false,
@@ -503,7 +503,7 @@ impl TestNodeBuilder {
503503
let parachain_config = node_config(
504504
self.storage_update_func_parachain
505505
.unwrap_or_else(|| Box::new(|| ())),
506-
self.task_executor.clone(),
506+
self.tokio_handle.clone(),
507507
self.key.clone(),
508508
self.parachain_nodes,
509509
self.parachain_nodes_exclusive,
@@ -514,7 +514,7 @@ impl TestNodeBuilder {
514514
let mut relay_chain_config = polkadot_test_service::node_config(
515515
self.storage_update_func_relay_chain
516516
.unwrap_or_else(|| Box::new(|| ())),
517-
self.task_executor,
517+
self.tokio_handle,
518518
self.key,
519519
self.relay_chain_nodes,
520520
false,
@@ -557,7 +557,7 @@ impl TestNodeBuilder {
557557
/// adjustments to the runtime genesis.
558558
pub fn node_config(
559559
storage_update_func: impl Fn(),
560-
task_executor: TaskExecutor,
560+
tokio_handle: tokio::runtime::Handle,
561561
key: Sr25519Keyring,
562562
nodes: Vec<MultiaddrWithPeerId>,
563563
nodes_exlusive: bool,
@@ -609,7 +609,7 @@ pub fn node_config(
609609
impl_name: "cumulus-test-node".to_string(),
610610
impl_version: "0.1".to_string(),
611611
role,
612-
task_executor,
612+
tokio_handle,
613613
transaction_pool: Default::default(),
614614
network: network_config,
615615
keystore: KeystoreConfig::InMemory,
@@ -637,7 +637,6 @@ pub fn node_config(
637637
rpc_ws: None,
638638
rpc_ipc: None,
639639
rpc_ws_max_connections: None,
640-
rpc_http_threads: None,
641640
rpc_cors: None,
642641
rpc_methods: Default::default(),
643642
rpc_max_payload: None,
@@ -686,7 +685,10 @@ impl TestNode {
686685
let call = frame_system::Call::set_code { code: validation };
687686

688687
self.send_extrinsic(
689-
runtime::SudoCall::sudo_unchecked_weight { call: Box::new(call.into()), weight: 1_000 },
688+
runtime::SudoCall::sudo_unchecked_weight {
689+
call: Box::new(call.into()),
690+
weight: 1_000,
691+
},
690692
Sr25519Keyring::Alice,
691693
)
692694
.await
@@ -747,13 +749,13 @@ pub fn construct_extrinsic(
747749
/// This is essentially a wrapper around
748750
/// [`run_validator_node`](polkadot_test_service::run_validator_node).
749751
pub fn run_relay_chain_validator_node(
750-
task_executor: TaskExecutor,
752+
tokio_handle: tokio::runtime::Handle,
751753
key: Sr25519Keyring,
752754
storage_update_func: impl Fn(),
753755
boot_nodes: Vec<MultiaddrWithPeerId>,
754756
) -> polkadot_test_service::PolkadotTestNode {
755757
polkadot_test_service::run_validator_node(
756-
task_executor,
758+
tokio_handle,
757759
key,
758760
storage_update_func,
759761
boot_nodes,

0 commit comments

Comments
 (0)