Unverified Commit d2de6d8b authored by Ashley's avatar Ashley
Browse files

Revert cli tokio version to avoid libp2p panic

parent 0c5f24e0
......@@ -3532,7 +3532,7 @@ dependencies = [
"sc-network 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"sc-service 2.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-master)",
"structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.2.2 (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.55 (registry+https://github.com/rust-lang/crates.io-index)",
"wasm-bindgen-futures 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)",
]
......
......@@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
log = "0.4.8"
tokio = "0.2.1"
tokio = "0.1.22"
futures = { version = "0.3.1", features = ["compat"] }
futures01 = { package = "futures", version = "0.1.29" }
structopt = "0.3.4"
......
......@@ -24,8 +24,9 @@ mod chain_spec;
mod browser;
use chain_spec::ChainSpec;
use futures::{Future, future::select, channel::oneshot, compat::Future01CompatExt};
pub use tokio::runtime::Runtime;
use futures::{Future, FutureExt, TryFutureExt, future::select, channel::oneshot, compat::Future01CompatExt};
use tokio::runtime::Runtime;
use std::sync::Arc;
use log::{info, error};
use structopt::StructOpt;
......@@ -37,6 +38,10 @@ pub use service::{
pub use cli::{VersionInfo, IntoExit, NoCustom};
pub use cli::{display_role, error};
type BoxedFuture = Box<dyn futures01::Future<Item = (), Error = ()> + Send>;
/// Abstraction over an executor that lets you spawn tasks in the background.
pub type TaskExecutor = Arc<dyn futures01::future::Executor<BoxedFuture> + Send + Sync>;
fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
Ok(match ChainSpec::from(id) {
Some(spec) => Some(spec.load()?),
......@@ -59,7 +64,7 @@ pub trait Worker: IntoExit {
fn configuration(&self) -> service::CustomConfiguration { Default::default() }
/// Do work and schedule exit.
fn work<S, SC, B, CE>(self, service: &S, executor: &Runtime) -> Self::Work
fn work<S, SC, B, CE>(self, service: &S, executor: TaskExecutor) -> Self::Work
where S: AbstractService<Block = service::Block, RuntimeApi = service::RuntimeApi,
Backend = B, SelectChain = SC,
NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>,
......@@ -166,24 +171,32 @@ fn run_until_exit<T, SC, B, CE, W>(
{
let (exit_send, exit) = oneshot::channel();
let executor = runtime.executor();
let informant = cli::informant::build(&service);
let future = select(exit, informant);
let future = select(exit, informant)
.map(|_| Ok(()))
.compat();
let informant_handle = runtime.spawn(future);
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 work = worker.work(&service, &runtime);
let work = worker.work(&service, Arc::new(executor));
let service = service
.map_err(|err| error!("Error while running Service: {}", err))
.compat();
let future = select(service, work);
let future = select(service, work)
.map(|_| Ok::<_, ()>(()))
.compat();
let _ = runtime.block_on(future);
let _ = exit_send.send(());
let _ = runtime.block_on(informant_handle);
use futures01::Future;
// TODO [andre]: timeout this future substrate/#1318
let _ = runtime.shutdown_on_idle().wait();
Ok(())
}
......@@ -18,7 +18,7 @@
#![warn(missing_docs)]
use cli::{AbstractService, VersionInfo, Runtime};
use cli::{AbstractService, VersionInfo, TaskExecutor};
use futures::channel::oneshot;
use futures::{future, FutureExt};
......@@ -46,7 +46,7 @@ impl cli::IntoExit for Worker {
impl cli::Worker for Worker {
type Work = <Self as cli::IntoExit>::Exit;
fn work<S, SC, B, CE>(self, _: &S, _: &Runtime) -> Self::Work
fn work<S, SC, B, CE>(self, _: &S, _: TaskExecutor) -> Self::Work
where S: AbstractService<Block = service::Block, RuntimeApi = service::RuntimeApi,
Backend = B, SelectChain = SC,
NetworkSpecialization = service::PolkadotProtocol, CallExecutor = CE>,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment