Update the service to std futures (#4447)

* Switch service to futures03

* Fix tests

* Fix service test and cli

* Re-add Executor trait to SpawnTaskHandle

* Fix node-service

* Update babe

* Fix browser node

* Update aura

* Revert back to tokio-executor to fix runtime panic

* Add todo item

* Fix service tests again

* Timeout test futures

* Fix tests

* nits

* Fix service test

* Remove zstd patch

* Re-add futures01 to aura and babe tests as a dev-dep

* Change failing test to tee

* Fix node

* Upgrade tokio

* fix society

* Start switching grandpa to stable futures

* Revert "Start switching grandpa to stable futures"

This reverts commit 9c1976346237637effc07c13f7d0403daf5e71cf.

* Fix utils

* Revert substrate service test

* Revert gitlab

Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Ashley
2020-01-14 15:43:45 +01:00
committed by GitHub
parent 972be34e38
commit 3219be2508
24 changed files with 246 additions and 312 deletions
+1 -2
View File
@@ -25,7 +25,6 @@ crate-type = ["cdylib", "rlib"]
# third-party dependencies
codec = { package = "parity-scale-codec", version = "1.0.6" }
serde = { version = "1.0.102", features = ["derive"] }
futures01 = { package = "futures", version = "0.1.29" }
futures = { version = "0.3.1", features = ["compat"] }
hex-literal = "0.2.1"
jsonrpc-core = "14.0.3"
@@ -81,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" }
+13 -22
View File
@@ -15,7 +15,6 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
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<I, T, E>(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,37 +175,25 @@ where
T: AbstractService,
E: IntoExit,
{
use futures::{FutureExt, TryFutureExt, channel::oneshot, future::select, compat::Future01CompatExt};
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 service = service
.map_err(|err| error::Error::Service(err))
.compat();
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(())
}
}
+7 -6
View File
@@ -113,8 +113,8 @@ macro_rules! new_full_start {
macro_rules! new_full {
($config:expr, $with_startup_data: expr) => {{
use futures::{
stream::StreamExt,
future::{FutureExt, TryFutureExt},
prelude::*,
compat::Future01CompatExt
};
use sc_network::Event;
@@ -191,9 +191,8 @@ macro_rules! new_full {
service.keystore(),
dht_event_stream,
);
let future01_authority_discovery = authority_discovery.map(|x| Ok(x)).compat();
service.spawn_task(future01_authority_discovery);
service.spawn_task(authority_discovery);
}
// if the node isn't actively participating in consensus then it doesn't
@@ -223,7 +222,7 @@ macro_rules! new_full {
service.network(),
service.on_exit(),
service.spawn_task_handle(),
)?);
)?.compat().map(drop));
},
(true, false) => {
// start the full GRANDPA voter
@@ -239,7 +238,9 @@ macro_rules! new_full {
};
// the GRANDPA voter task is considered infallible, i.e.
// if it fails we take down the service with it.
service.spawn_essential_task(grandpa::run_grandpa_voter(grandpa_config)?);
service.spawn_essential_task(
grandpa::run_grandpa_voter(grandpa_config)?.compat().map(drop)
);
},
(_, true) => {
grandpa::setup_disabled_grandpa(