From 04eae615b584cbaf2bf987f18997ba8618005f8d Mon Sep 17 00:00:00 2001 From: Ashley Date: Wed, 29 Jan 2020 12:13:47 +0100 Subject: [PATCH] Update tokio to 0.2 again and remove `TaskExecutor`s (#786) * upgrade tokio again * Remove WrappedExecutor * switch to spawn_blocking --- polkadot/Cargo.lock | 61 ++++--------------- polkadot/availability-store/Cargo.toml | 2 +- polkadot/availability-store/src/lib.rs | 7 +-- polkadot/availability-store/src/worker.rs | 8 +-- polkadot/cli/Cargo.toml | 3 +- polkadot/cli/src/lib.rs | 36 ++++------- polkadot/collator/Cargo.toml | 4 +- polkadot/collator/src/lib.rs | 8 +-- polkadot/network/src/tests/validation.rs | 16 +++-- polkadot/service/Cargo.toml | 1 - polkadot/service/src/lib.rs | 24 ++------ polkadot/validation/Cargo.toml | 3 +- polkadot/validation/src/block_production.rs | 4 +- .../validation/src/validation_service/mod.rs | 20 +++--- 14 files changed, 63 insertions(+), 134 deletions(-) diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index b7697222cb..4311da019c 100644 --- a/polkadot/Cargo.lock +++ b/polkadot/Cargo.lock @@ -1384,15 +1384,6 @@ dependencies = [ "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "futures-timer" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "futures-timer" version = "2.0.2" @@ -1423,7 +1414,6 @@ name = "futures-util-preview" version = "0.3.0-alpha.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1548,7 +1538,7 @@ dependencies = [ "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1582,7 +1572,7 @@ dependencies = [ "indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-util 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1785,7 +1775,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "pin-project 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "tower-service 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3714,7 +3704,7 @@ dependencies = [ "sp-consensus 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sp-core 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sp-runtime 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", - "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3722,7 +3712,6 @@ name = "polkadot-cli" version = "0.7.19" dependencies = [ "browser-utils 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", - "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "polkadot-service 0.7.19", @@ -3736,7 +3725,7 @@ dependencies = [ "sp-core 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sp-runtime 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "structopt 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-futures 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3746,7 +3735,7 @@ name = "polkadot-collator" version = "0.7.19" dependencies = [ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-timer 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "polkadot-cli 0.7.19", @@ -3763,7 +3752,7 @@ dependencies = [ "sp-core 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sp-keyring 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sp-runtime 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", - "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3971,7 +3960,6 @@ name = "polkadot-service" version = "0.7.19" dependencies = [ "frame-system-rpc-runtime-api 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", - "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "kusama-runtime 0.7.19", @@ -4062,8 +4050,7 @@ dependencies = [ "sp-timestamp 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sp-transaction-pool 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "sp-trie 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", - "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4701,7 +4688,7 @@ dependencies = [ "sp-state-machine 0.8.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)", "structopt 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -6372,12 +6359,13 @@ dependencies = [ [[package]] name = "tokio" -version = "0.2.4" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -6419,16 +6407,6 @@ dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "tokio-executor" -version = "0.2.0-alpha.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "tokio-fs" version = "0.1.6" @@ -6489,16 +6467,6 @@ dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "tokio-sync" -version = "0.2.0-alpha.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "tokio-tcp" version = "0.1.3" @@ -6580,7 +6548,7 @@ dependencies = [ "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -7377,7 +7345,6 @@ dependencies = [ "checksum futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "86f148ef6b69f75bb610d4f9a2336d4fc88c4b5b67129d1a340dd0fd362efeec" "checksum futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9" "checksum futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "878f1d2fc31355fa02ed2372e741b0c17e58373341e6a122569b4623a14a7d33" -"checksum futures-timer 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7946248e9429ff093345d3e8fdf4eb0f9b2d79091611c9c14f744971a6f8be45" "checksum futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a1de7508b218029b0f01662ed8f61b1c964b3ae99d6f25462d0f55a595109df6" "checksum futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76" "checksum futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "5ce968633c17e5f97936bd2797b6e38fb56cf16a7422319f7ec2e30d3c470e8d" @@ -7770,18 +7737,16 @@ dependencies = [ "checksum tiny-keccak 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d8a021c69bb74a44ccedb824a046447e2c84a01df9e5c20779750acb38e11b2" "checksum tiny-keccak 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2953ca5148619bc99695c1274cb54c5275bbb913c6adad87e72eaf8db9787f69" "checksum tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" -"checksum tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bcced6bb623d4bff3739c176c415f13c418f426395c169c9c3cd9a492c715b16" +"checksum tokio 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "c1fc73332507b971a5010664991a441b5ee0de92017f5a0e8b00fd684573045b" "checksum tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" "checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f" "checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443" "checksum tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f27ee0e6db01c5f0b2973824547ce7e637b2ed79b891a9677b0de9bd532b6ac" -"checksum tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9ee9ceecf69145923834ea73f32ba40c790fd877b74a7817dd0b089f1eb9c7c8" "checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af" "checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" "checksum tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "c56391be9805bc80163151c0b9e5164ee64f4b0200962c346fea12773158f22d" "checksum tokio-rustls 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1df2fa53ac211c136832f530ccb081af9af891af22d685a9493e232c7a359bc2" "checksum tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d06554cce1ae4a50f42fba8023918afa931413aded705b560e29600ccf7c6d76" -"checksum tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "4f1aaeb685540f7407ea0e27f1c9757d258c7c6bf4e3eb19da6fc59b747239d2" "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" "checksum tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd2c6a3885302581f4401c82af70d792bb9df1700e7437b0aeb4ada94d5388c" "checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" diff --git a/polkadot/availability-store/Cargo.toml b/polkadot/availability-store/Cargo.toml index 06d01b8664..79eda5ac8c 100644 --- a/polkadot/availability-store/Cargo.toml +++ b/polkadot/availability-store/Cargo.toml @@ -12,7 +12,7 @@ parking_lot = "0.9.0" derive_more = "0.99" log = "0.4.8" futures = "0.3.1" -tokio = { version = "0.2.4", features = ["rt-core"] } +tokio = { version = "0.2.10", features = ["rt-core"] } exit-future = "0.2.0" codec = { package = "parity-scale-codec", version = "1.1.0", features = ["derive"] } sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } diff --git a/polkadot/availability-store/src/lib.rs b/polkadot/availability-store/src/lib.rs index d62eafae0d..7c0c219d7e 100644 --- a/polkadot/availability-store/src/lib.rs +++ b/polkadot/availability-store/src/lib.rs @@ -58,9 +58,6 @@ use worker::{ use store::{Store as InnerStore}; -/// Abstraction over an executor that lets you spawn tasks in the background. -pub(crate) type TaskExecutor = Arc; - const LOG_TARGET: &str = "availability"; /// Configuration for the availability store. @@ -197,7 +194,7 @@ impl Store { &self, wrapped_block_import: I, client: Arc

, - thread_pool: TaskExecutor, + spawner: impl Spawn, keystore: KeyStorePtr, ) -> ClientResult> where @@ -213,7 +210,7 @@ impl Store { self.inner.clone(), client, wrapped_block_import, - thread_pool, + spawner, keystore, to_worker, ); diff --git a/polkadot/availability-store/src/worker.rs b/polkadot/availability-store/src/worker.rs index 9621797d08..f83dc8fe2c 100644 --- a/polkadot/availability-store/src/worker.rs +++ b/polkadot/availability-store/src/worker.rs @@ -37,12 +37,12 @@ use polkadot_primitives::parachain::{ CandidateReceipt, ParachainHost, ValidatorId, ValidatorPair, AvailableMessages, BlockData, ErasureChunk, }; -use futures::{prelude::*, future::select, channel::{mpsc, oneshot}, task::SpawnExt}; +use futures::{prelude::*, future::select, channel::{mpsc, oneshot}, task::{Spawn, SpawnExt}}; use keystore::KeyStorePtr; use tokio::runtime::{Handle, Runtime as LocalRuntime}; -use crate::{LOG_TARGET, Data, TaskExecutor, ProvideGossipMessages, erasure_coding_topic}; +use crate::{LOG_TARGET, Data, ProvideGossipMessages, erasure_coding_topic}; use crate::store::Store; /// Errors that may occur. @@ -747,7 +747,7 @@ impl AvailabilityBlockImport { availability_store: Store, client: Arc

, block_import: I, - thread_pool: TaskExecutor, + spawner: impl Spawn, keystore: KeyStorePtr, to_worker: mpsc::UnboundedSender, ) -> Self @@ -771,7 +771,7 @@ impl AvailabilityBlockImport { exit.clone() ).map(drop); - if let Err(_) = thread_pool.spawn(Box::new(prune_available)) { + if let Err(_) = spawner.spawn(prune_available) { error!(target: LOG_TARGET, "Failed to spawn availability pruning task"); exit_signal = None; } diff --git a/polkadot/cli/Cargo.toml b/polkadot/cli/Cargo.toml index f04bff080b..9eb82d2799 100644 --- a/polkadot/cli/Cargo.toml +++ b/polkadot/cli/Cargo.toml @@ -11,7 +11,6 @@ crate-type = ["cdylib", "rlib"] [dependencies] log = "0.4.8" futures = { version = "0.3.1", features = ["compat"] } -futures01 = { package = "futures", version = "0.1.29" } structopt = "=0.3.7" sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } @@ -23,7 +22,7 @@ sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "polk sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" } service = { package = "polkadot-service", path = "../service", default-features = false } -tokio = { version = "0.1.22", optional = true } +tokio = { version = "0.2.10", features = ["rt-threaded"], optional = true } wasm-bindgen = { version = "0.2.57", optional = true } wasm-bindgen-futures = { version = "0.4.7", optional = true } diff --git a/polkadot/cli/src/lib.rs b/polkadot/cli/src/lib.rs index 4657e3f31a..aebe61d6c8 100644 --- a/polkadot/cli/src/lib.rs +++ b/polkadot/cli/src/lib.rs @@ -24,9 +24,7 @@ mod chain_spec; mod browser; use chain_spec::ChainSpec; -use futures::{ - Future, FutureExt, TryFutureExt, future::select, channel::oneshot, compat::Compat, -}; +use futures::{Future, future::{select, Either}, channel::oneshot}; #[cfg(feature = "cli")] use tokio::runtime::Runtime; use log::info; @@ -35,7 +33,7 @@ use sp_api::ConstructRuntimeApi; pub use service::{ AbstractService, CustomConfiguration, ProvideRuntimeApi, CoreApi, ParachainHost, IsKusama, - WrappedExecutor, Block, self, RuntimeApiCollection, TFullClient + Block, self, RuntimeApiCollection, TFullClient }; pub use sc_cli::{VersionInfo, IntoExit, NoCustom, SharedParams}; @@ -172,8 +170,8 @@ where config.custom.authority_discovery_enabled = custom_args.authority_discovery_enabled; let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?; config.tasks_executor = { - let runtime_handle = runtime.executor(); - Some(Box::new(move |fut| { runtime_handle.spawn(Compat::new(fut.map(Ok))); })) + let runtime_handle = runtime.handle().clone(); + Some(Box::new(move |fut| { runtime_handle.spawn(fut); })) }; match config.roles { service::Roles::LIGHT => @@ -221,34 +219,22 @@ pub fn run_until_exit( ) -> error::Result<()> { let (exit_send, exit) = oneshot::channel(); - let executor = runtime.executor(); let informant = sc_cli::informant::build(&service); - let future = select(exit, informant) - .map(|_| Ok(())) - .compat(); - executor.spawn(future); + let handle = runtime.spawn(select(exit, informant)); // we eagerly drop the service so that the internal exit future is fired, // but we need to keep holding a reference to the global telemetry guard let _telemetry = service.telemetry(); - let service_res = { - let service = service - .map_err(|err| error::Error::Service(err)); - - let select = select(service, e) - .map(|_| Ok(())) - .compat(); - - runtime.block_on(select) - }; + let service_res = runtime.block_on(select(service, e)); let _ = exit_send.send(()); - use futures01::Future; - // TODO [andre]: timeout this future substrate/#1318 - let _ = runtime.shutdown_on_idle().wait(); + runtime.block_on(handle); - service_res + match service_res { + Either::Left((res, _)) => res.map_err(error::Error::Service), + Either::Right((_, _)) => Ok(()) + } } diff --git a/polkadot/collator/Cargo.toml b/polkadot/collator/Cargo.toml index cff210b84f..1da9d7145a 100644 --- a/polkadot/collator/Cargo.toml +++ b/polkadot/collator/Cargo.toml @@ -21,8 +21,8 @@ polkadot-network = { path = "../network" } polkadot-validation = { path = "../validation" } polkadot-service = { path = "../service" } log = "0.4.8" -tokio = "0.1.22" -futures-timer = "1.0" +tokio = "0.2.10" +futures-timer = "2.0" codec = { package = "parity-scale-codec", version = "1.1.0" } [dev-dependencies] diff --git a/polkadot/collator/src/lib.rs b/polkadot/collator/src/lib.rs index 28ef198a7e..de588e12ab 100644 --- a/polkadot/collator/src/lib.rs +++ b/polkadot/collator/src/lib.rs @@ -62,7 +62,7 @@ use polkadot_primitives::{ } }; use polkadot_cli::{ - ProvideRuntimeApi, AbstractService, ParachainHost, IsKusama, WrappedExecutor, + ProvideRuntimeApi, AbstractService, ParachainHost, IsKusama, service::{self, Roles, SelectChain} }; use polkadot_network::validation::{LeafWorkParams, ValidationNetwork}; @@ -308,7 +308,7 @@ fn run_collator_node( Extrinsic: service::Codec + Send + Sync + 'static, { let runtime = tokio::runtime::Runtime::new().map_err(|e| format!("{:?}", e))?; - let spawner = WrappedExecutor(service.spawn_task_handle()); + let spawner = service.spawn_task_handle(); let client = service.client(); let network = service.network(); @@ -427,7 +427,7 @@ fn run_collator_node( ); let exit = inner_exit_2.clone(); - tokio::spawn(future::select(res.boxed(), exit).map(drop).map(|_| Ok(())).compat()); + tokio::spawn(future::select(res.boxed(), exit)); }); } future::ok(()) @@ -450,7 +450,7 @@ fn run_collator_node( inner_exit.clone() ).map(drop); - tokio::spawn(future.map(|_| Ok(())).compat()); + tokio::spawn(future); } }.boxed(); diff --git a/polkadot/network/src/tests/validation.rs b/polkadot/network/src/tests/validation.rs index 7a26e81f07..57111d225f 100644 --- a/polkadot/network/src/tests/validation.rs +++ b/polkadot/network/src/tests/validation.rs @@ -42,13 +42,11 @@ use std::collections::HashMap; use std::sync::Arc; use std::pin::Pin; use std::task::{Poll, Context}; -use futures::{prelude::*, channel::mpsc, future::{select, Either}}; +use futures::{prelude::*, channel::mpsc, future::{select, Either}, task::Spawn}; use codec::Encode; use super::{TestContext, TestChainContext}; -type TaskExecutor = Arc; - #[derive(Clone, Copy)] struct NeverExit; @@ -321,19 +319,19 @@ impl ParachainHost for RuntimeApi { } } -type TestValidationNetwork = crate::validation::ValidationNetwork< +type TestValidationNetwork = crate::validation::ValidationNetwork< TestApi, NeverExit, - TaskExecutor, + SP, >; -struct Built { +struct Built { gossip: Pin>>, api_handle: Arc>, - networks: Vec, + networks: Vec>, } -fn build_network(n: usize, executor: TaskExecutor) -> Built { +fn build_network(n: usize, spawner: SP) -> Built { let (gossip_router, gossip_handle) = make_gossip(); let api_handle = Arc::new(Mutex::new(Default::default())); let runtime_api = Arc::new(TestApi { data: api_handle.clone() }); @@ -353,7 +351,7 @@ fn build_network(n: usize, executor: TaskExecutor) -> Built { message_val, NeverExit, runtime_api.clone(), - executor.clone(), + spawner.clone(), ) }); diff --git a/polkadot/service/Cargo.toml b/polkadot/service/Cargo.toml index 4c25341a79..f140fc13ce 100644 --- a/polkadot/service/Cargo.toml +++ b/polkadot/service/Cargo.toml @@ -10,7 +10,6 @@ serde = { version = "1.0.102", features = ["derive"] } lazy_static = "1.4.0" log = "0.4.8" futures = "0.3.1" -futures01 = { package = "futures", version = "0.1.29" } slog = "2.5.2" hex-literal = "0.2.1" av_store = { package = "polkadot-availability-store", path = "../availability-store" } diff --git a/polkadot/service/src/lib.rs b/polkadot/service/src/lib.rs index 5585734006..182b4e0e82 100644 --- a/polkadot/service/src/lib.rs +++ b/polkadot/service/src/lib.rs @@ -18,11 +18,7 @@ pub mod chain_spec; -use futures::{ - FutureExt, TryFutureExt, - task::{Spawn, SpawnError, FutureObj}, - compat::Future01CompatExt, -}; +use futures::{FutureExt, compat::Future01CompatExt}; use sc_client::LongestChain; use std::sync::Arc; use std::time::Duration; @@ -57,18 +53,6 @@ pub use codec::Codec; pub use polkadot_runtime; pub use kusama_runtime; -/// Wrap a futures01 executor as a futures03 spawn. -#[derive(Clone)] -pub struct WrappedExecutor(pub T); - -impl Spawn for WrappedExecutor - where T: futures01::future::Executor + Send + 'static>> -{ - fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> { - self.0.execute(Box::new(future.map(Ok).compat())) - .map_err(|_| SpawnError::shutdown()) - } -} /// Polkadot-specific configuration. pub struct CustomConfiguration { /// Set to `Some` with a collator `CollatorId` and desired parachain @@ -402,14 +386,14 @@ pub fn new_full(config: Configuration) gossip_validator, service.on_exit(), service.client(), - WrappedExecutor(service.spawn_task_handle()), + service.spawn_task_handle(), ); let (validation_service_handle, validation_service) = consensus::ServiceBuilder { client: client.clone(), network: validation_network.clone(), collators: validation_network, - task_executor: Arc::new(WrappedExecutor(service.spawn_task_handle())), + spawner: service.spawn_task_handle(), availability_store: availability_store.clone(), select_chain: select_chain.clone(), keystore: service.keystore(), @@ -433,7 +417,7 @@ pub fn new_full(config: Configuration) let block_import = availability_store.block_import( block_import, client.clone(), - Arc::new(WrappedExecutor(service.spawn_task_handle())), + service.spawn_task_handle(), service.keystore(), )?; diff --git a/polkadot/validation/Cargo.toml b/polkadot/validation/Cargo.toml index 2975bd5f51..8aea3fe045 100644 --- a/polkadot/validation/Cargo.toml +++ b/polkadot/validation/Cargo.toml @@ -8,11 +8,10 @@ edition = "2018" futures = "0.3.1" futures-timer = "2.0" parking_lot = "0.9.0" -tokio = { version = "0.2.4", features = ["rt-core"] } +tokio = { version = "0.2.10", features = ["rt-core", "blocking"] } derive_more = "0.14.1" log = "0.4.8" exit-future = "0.2.0" -tokio-executor = { version = "0.2.0-alpha.6", features = ["blocking"] } codec = { package = "parity-scale-codec", version = "1.1.0", default-features = false, features = ["derive"] } availability_store = { package = "polkadot-availability-store", path = "../availability-store" } parachain = { package = "polkadot-parachain", path = "../parachain" } diff --git a/polkadot/validation/src/block_production.rs b/polkadot/validation/src/block_production.rs index 6d4e736389..bedd83f789 100644 --- a/polkadot/validation/src/block_production.rs +++ b/polkadot/validation/src/block_production.rs @@ -222,11 +222,11 @@ impl consensus::Proposer for Proposer impl Stream + Send + Unpin { } /// A builder for the validation service. -pub struct ServiceBuilder { +pub struct ServiceBuilder { /// The underlying blockchain client. pub client: Arc

, /// A handle to the network object used to communicate. @@ -126,7 +126,7 @@ pub struct ServiceBuilder { /// A handle to the collator pool we are using. pub collators: C, /// A handle to a background executor. - pub task_executor: TaskExecutor, + pub spawner: SP, /// A handle to the availability store. pub availability_store: AvailabilityStore, /// A chain selector for determining active leaves in the block-DAG. @@ -137,7 +137,7 @@ pub struct ServiceBuilder { pub max_block_data_size: Option, } -impl ServiceBuilder where +impl ServiceBuilder where C: Collators + Send + Sync + Unpin + 'static, C::Collation: Send + Unpin + 'static, P: BlockchainEvents + BlockBody, @@ -150,6 +150,7 @@ impl ServiceBuilder where N::TableRouter: Send + 'static, N::BuildTableRouter: Send + Unpin + 'static, SC: SelectChain + 'static, + SP: Spawn + Send + 'static, // Rust bug: https://github.com/rust-lang/rust/issues/24159 sp_api::StateBackendFor: sp_api::StateBackend>, { @@ -171,7 +172,7 @@ impl ServiceBuilder where client: self.client.clone(), network: self.network, collators: self.collators, - handle: self.task_executor, + spawner: self.spawner, availability_store: self.availability_store, live_instances: HashMap::new(), }; @@ -247,15 +248,15 @@ fn signing_key(validators: &[ValidatorId], keystore: &KeyStorePtr) -> Option { +pub(crate) struct ParachainValidationInstances { /// The client instance. client: Arc

, /// The backing network handle. network: N, /// Parachain collators. collators: C, - /// handle to remote task executor - handle: TaskExecutor, + /// handle to spawner + spawner: SP, /// Store for extrinsic data. availability_store: AvailabilityStore, /// Live agreements. Maps relay chain parent hashes to attestation @@ -263,7 +264,7 @@ pub(crate) struct ParachainValidationInstances { live_instances: HashMap>, } -impl ParachainValidationInstances where +impl ParachainValidationInstances where C: Collators + Send + Unpin + 'static, N: Network, P: ProvideRuntimeApi + HeaderBackend + BlockBody + Send + Sync + 'static, @@ -271,6 +272,7 @@ impl ParachainValidationInstances where C::Collation: Send + Unpin + 'static, N::TableRouter: Send + 'static, N::BuildTableRouter: Unpin + Send + 'static, + SP: Spawn + Send + 'static, // Rust bug: https://github.com/rust-lang/rust/issues/24159 sp_api::StateBackendFor: sp_api::StateBackend>, { @@ -448,7 +450,7 @@ impl ParachainValidationInstances where let cancellable_work = select(exit, router).map(drop); // spawn onto thread pool. - if self.handle.spawn(cancellable_work).is_err() { + if self.spawner.spawn(cancellable_work).is_err() { error!("Failed to spawn cancellable work task"); } }