diff --git a/Cargo.lock b/Cargo.lock index 40e99c676461d..4d19541afca28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3076,7 +3076,7 @@ dependencies = [ "structopt 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-build-script-utils 2.0.0", "tempfile 3.1.0 (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.4 (registry+https://github.com/rust-lang/crates.io-index)", "vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-futures 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3216,7 +3216,6 @@ name = "node-template" version = "2.0.0" dependencies = [ "ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "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)", "node-template-runtime 2.0.0", @@ -3240,7 +3239,7 @@ dependencies = [ "sp-runtime 2.0.0", "sp-transaction-pool 2.0.0", "substrate-build-script-utils 2.0.0", - "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "trie-root 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -7213,6 +7212,7 @@ 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/bin/node-template/Cargo.toml b/bin/node-template/Cargo.toml index aaaae647cf564..0333e887ec4b8 100644 --- a/bin/node-template/Cargo.toml +++ b/bin/node-template/Cargo.toml @@ -11,10 +11,9 @@ path = "src/main.rs" [dependencies] futures = "0.3.1" -futures01 = { package = "futures", version = "0.1.29" } ctrlc = { version = "3.1.3", features = ["termination"] } log = "0.4.8" -tokio = "0.1.22" +tokio = { version = "0.2", features = ["rt-threaded"] } parking_lot = "0.9.0" codec = { package = "parity-scale-codec", version = "1.0.0" } trie-root = "0.15.2" diff --git a/bin/node-template/src/cli.rs b/bin/node-template/src/cli.rs index 98fa330fdb915..44764e5c9db41 100644 --- a/bin/node-template/src/cli.rs +++ b/bin/node-template/src/cli.rs @@ -1,5 +1,5 @@ use crate::service; -use futures::{future::{select, Map}, FutureExt, TryFutureExt, channel::oneshot}; +use futures::{future::{select, Map, Either}, FutureExt, channel::oneshot}; use std::cell::RefCell; use tokio::runtime::Runtime; pub use sc_cli::{VersionInfo, IntoExit, error}; @@ -75,33 +75,23 @@ where let informant = informant::build(&service); - let future = select(exit, informant) - .map(|_| Ok(())) - .compat(); - - runtime.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 exit = e.into_exit(); - let select = select(service, exit) - .map(|_| Ok(())) - .compat(); - runtime.block_on(select) - }; + let exit = e.into_exit(); + let service_res = runtime.block_on(select(service, exit)); let _ = exit_send.send(()); - // TODO [andre]: timeout this future #1318 - - use futures01::Future; + runtime.block_on(handle); - let _ = runtime.shutdown_on_idle().wait(); - - service_res + match service_res { + Either::Left((res, _)) => res.map_err(error::Error::Service), + Either::Right((_, _)) => Ok(()) + } } // handles ctrl-c diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 4f12775cc48fb..ec54f5b374873 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -80,7 +80,7 @@ node-primitives = { version = "2.0.0", path = "../primitives" } node-executor = { version = "2.0.0", path = "../executor" } # CLI-specific dependencies -tokio = { version = "0.1.22", optional = true } +tokio = { version = "0.2", features = ["rt-threaded"], optional = true } sc-cli = { version = "2.0.0", optional = true, path = "../../../client/cli" } ctrlc = { version = "3.1.3", features = ["termination"], optional = true } node-transaction-factory = { version = "2.0.0", optional = true, path = "../transaction-factory" } diff --git a/bin/node/cli/src/cli.rs b/bin/node/cli/src/cli.rs index 823a4cc15b577..7a4321802cf36 100644 --- a/bin/node/cli/src/cli.rs +++ b/bin/node/cli/src/cli.rs @@ -15,7 +15,6 @@ // along with Substrate. If not, see . pub use sc_cli::VersionInfo; -use tokio::prelude::Future; use tokio::runtime::{Builder as RuntimeBuilder, Runtime}; use sc_cli::{IntoExit, NoCustom, SharedParams, ImportParams, error}; use sc_service::{AbstractService, Roles as ServiceRoles, Configuration}; @@ -25,6 +24,7 @@ use sc_cli::{display_role, parse_and_prepare, GetSharedParams, ParseAndPrepare}; use crate::{service, ChainSpec, load_spec}; use crate::factory_impl::FactoryState; use node_transaction_factory::RuntimeAdapter; +use futures::{channel::oneshot, future::{select, Either}}; /// Custom subcommands. #[derive(Clone, Debug, StructOpt)] @@ -105,7 +105,10 @@ pub fn run(args: I, exit: E, version: sc_cli::VersionInfo) -> error::Re info!("Chain specification: {}", config.chain_spec.name()); info!("Node name: {}", config.name); info!("Roles: {}", display_role(&config)); - let runtime = RuntimeBuilder::new().name_prefix("main-tokio-").build() + let runtime = RuntimeBuilder::new() + .thread_name("main-tokio-") + .threaded_scheduler() + .build() .map_err(|e| format!("{:?}", e))?; match config.roles { ServiceRoles::LIGHT => run_until_exit( @@ -172,34 +175,25 @@ where T: AbstractService, E: IntoExit, { - use futures::{FutureExt, TryFutureExt, channel::oneshot, future::select}; - let (exit_send, exit) = oneshot::channel(); let informant = sc_cli::informant::build(&service); - let future = select(informant, exit) - .map(|_| Ok(())) - .compat(); - - runtime.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 exit = e.into_exit(); - let select = select(service, exit) - .map(|_| Ok(())) - .compat(); - runtime.block_on(select) - }; + let exit = e.into_exit(); + let service_res = runtime.block_on(select(service, exit)); let _ = exit_send.send(()); - // TODO [andre]: timeout this future #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/client/cli/Cargo.toml b/client/cli/Cargo.toml index a61f80d67dd00..b653f982e6694 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -16,7 +16,7 @@ time = "0.1.42" ansi_term = "0.12.1" lazy_static = "1.4.0" app_dirs = "1.2.1" -tokio = "0.2.1" +tokio = "0.2" futures = "0.3.1" fdlimit = "0.1.1" serde_json = "1.0.41"