From a19fb8e4bf86662e5199b34febe6cec14b385193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Fri, 17 Jan 2020 15:17:46 +0000 Subject: [PATCH] Revert "Instantiate environment with asynchronous API (#768)" This reverts commit 989db4b81a59582f3f41f83b0eb7fc0917f0bcb5. --- Cargo.lock | 5 ++--- cli/Cargo.toml | 2 +- cli/src/lib.rs | 30 ++++++++++++++++++++++-------- collator/Cargo.toml | 2 +- collator/src/lib.rs | 6 +++--- service/src/lib.rs | 5 +++-- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b58ed3192d92..a612cab2c221 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3761,7 +3761,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.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.22 (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)", ] @@ -3788,7 +3788,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.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -6397,7 +6397,6 @@ 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)", ] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 79fb893feaeb..99da5f42be57 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -23,7 +23,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.2", features = ["rt-threaded"], optional = true } +tokio = { version = "0.1.22", optional = true } wasm-bindgen = { version = "0.2.57", optional = true } wasm-bindgen-futures = { version = "0.4.7", optional = true } diff --git a/cli/src/lib.rs b/cli/src/lib.rs index a18b1a8934b2..93460654b5ff 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -24,7 +24,9 @@ mod chain_spec; mod browser; use chain_spec::ChainSpec; -use futures::{Future, future::{select, Either}, channel::oneshot}; +use futures::{ + Future, FutureExt, TryFutureExt, future::select, channel::oneshot, +}; #[cfg(feature = "cli")] use tokio::runtime::Runtime; use log::info; @@ -215,22 +217,34 @@ 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(); - let handle = runtime.spawn(select(exit, informant)); + executor.spawn(future); // 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 = runtime.block_on(select(service, e)); + 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 _ = exit_send.send(()); - runtime.block_on(handle); + use futures01::Future; + // TODO [andre]: timeout this future substrate/#1318 + let _ = runtime.shutdown_on_idle().wait(); - match service_res { - Either::Left((res, _)) => res.map_err(error::Error::Service), - Either::Right((_, _)) => Ok(()) - } + service_res } diff --git a/collator/Cargo.toml b/collator/Cargo.toml index d0bc02069899..de937a700043 100644 --- a/collator/Cargo.toml +++ b/collator/Cargo.toml @@ -21,7 +21,7 @@ polkadot-network = { path = "../network" } polkadot-validation = { path = "../validation" } polkadot-service = { path = "../service" } log = "0.4.8" -tokio = "0.2" +tokio = "0.1.22" futures-timer = "1.0" codec = { package = "parity-scale-codec", version = "1.1.0" } diff --git a/collator/src/lib.rs b/collator/src/lib.rs index 8666765b66b7..afcb4e75b8bd 100644 --- a/collator/src/lib.rs +++ b/collator/src/lib.rs @@ -425,7 +425,7 @@ fn run_collator_node( ); let exit = inner_exit_2.clone(); - tokio::spawn(future::select(res.boxed(), exit).map(drop)); + tokio::spawn(future::select(res.boxed(), exit).map(drop).map(|_| Ok(())).compat()); }) }); @@ -449,11 +449,11 @@ fn run_collator_node( inner_exit.clone() ).map(drop); - tokio::spawn(future); + tokio::spawn(future.map(|_| Ok(())).compat()); future::ready(()) }); - service.spawn_essential_task(work); + service.spawn_essential_task(work.map(|_| Ok::<_, ()>(())).compat()); polkadot_cli::run_until_exit(runtime, service, exit) } diff --git a/service/src/lib.rs b/service/src/lib.rs index 51a00d8a0ecb..c89aca1b12b6 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -467,6 +467,7 @@ pub fn new_full(config: Configuration) service.keystore(), dht_event_stream, ); + service.spawn_task(authority_discovery); } } @@ -509,8 +510,8 @@ pub fn new_full(config: Configuration) }; service.spawn_essential_task( - grandpa::run_grandpa_voter(grandpa_config)?.compat().map(drop) - ); + grandpa::run_grandpa_voter(grandpa_config)?.compat().map(|_| ()) + ) } else { grandpa::setup_disabled_grandpa( service.client(),