diff --git a/Cargo.lock b/Cargo.lock index f3160f7b22cb..d9fa60393da0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3698,7 +3698,6 @@ dependencies = [ name = "polkadot-service" version = "0.7.1" dependencies = [ - "exit-future 0.1.4 (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)", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index e2748dc1653c..6c8738afb0bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,10 +10,10 @@ build = "build.rs" edition = "2018" [dependencies] -cli = { package = "polkadot-cli", path = "cli" } +cli = { package = "polkadot-cli", path = "cli", default-features = false } futures = "0.3.1" -ctrlc = { version = "3.1.3", features = ["termination"] } -service = { package = "polkadot-service", path = "service" } +ctrlc = { version = "3.1.3", features = ["termination"], optional = true } +service = { package = "polkadot-service", path = "service", default-features = false } [build-dependencies] vergen = "3.0.4" @@ -47,3 +47,7 @@ maintenance = { status = "actively-developed" } [profile.release] # Polkadot runtime requires unwinding. panic = "unwind" + +[features] +default = ["rocksdb", "ctrlc"] +rocksdb = ["cli/rocksdb", "service/rocksdb"] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 2a2603e84b81..270aca0d8956 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -12,8 +12,9 @@ futures = { version = "0.3.1", features = ["compat"] } futures01 = { package = "futures", version = "0.1.29" } structopt = "0.3.4" cli = { package = "substrate-cli", git = "https://github.com/paritytech/substrate", branch = "ashley-update-exit-future" } -service = { package = "polkadot-service", path = "../service" } +service = { package = "polkadot-service", path = "../service", default-features = false } [features] -default = [ "wasmtime" ] +default = [ "wasmtime", "rocksdb" ] wasmtime = [ "cli/wasmtime" ] +rocksdb = [ "service/rocksdb" ] diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 780af01f2b23..8714909deb91 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -23,7 +23,7 @@ mod chain_spec; use chain_spec::ChainSpec; use futures::{Future, FutureExt, TryFutureExt, future::select, channel::oneshot, compat::Future01CompatExt}; -use tokio::runtime::Runtime; +pub use tokio::runtime::Runtime; use std::sync::Arc; use log::{info, error}; use structopt::StructOpt; @@ -37,8 +37,6 @@ pub use cli::{VersionInfo, IntoExit, NoCustom}; pub use cli::{display_role, error}; type BoxedFuture = Box + Send>; -/// Abstraction over an executor that lets you spawn tasks in the background. -pub type TaskExecutor = Arc + Send + Sync>; fn load_spec(id: &str) -> Result, String> { Ok(match ChainSpec::from(id) { @@ -62,7 +60,7 @@ pub trait Worker: IntoExit { fn configuration(&self) -> service::CustomConfiguration { Default::default() } /// Do work and schedule exit. - fn work(self, service: &S, executor: TaskExecutor) -> Self::Work + fn work(self, service: &S, executor: &Runtime) -> Self::Work where S: AbstractService, @@ -147,6 +145,7 @@ pub fn run(worker: W, version: cli::VersionInfo) -> error::Result<()> where cli::ParseAndPrepare::RevertChain(cmd) => cmd.run_with_builder::<(), _, _, _, _, _>(|config| Ok(service::new_chain_ops(config)?), load_spec), cli::ParseAndPrepare::CustomCommand(PolkadotSubCommands::ValidationWorker(args)) => { + #[cfg(not(target_os = "unknown"))] service::run_validation_worker(&args.mem_id)?; Ok(()) } @@ -168,32 +167,24 @@ fn run_until_exit( { let (exit_send, exit) = oneshot::channel(); - let executor = runtime.executor(); let informant = cli::informant::build(&service); - let future = select(exit, informant) - .map(|_| Ok(())) - .compat(); + let future = select(exit, informant); - executor.spawn(future); + let informant_handle = runtime.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, Arc::new(executor)); + let work = worker.work(&service, &runtime); let service = service .map_err(|err| error!("Error while running Service: {}", err)) .compat(); - let future = select(service, work) - .map(|_| Ok::<_, ()>(())) - .compat(); + let future = select(service, work);; let _ = runtime.block_on(future); let _ = exit_send.send(()); - use futures01::Future; - - // TODO [andre]: timeout this future substrate/#1318 - let _ = runtime.shutdown_on_idle().wait(); + let _ = runtime.block_on(informant_handle); Ok(()) } diff --git a/src/main.rs b/src/main.rs index 842f70cbe42a..17dee361102f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ #![warn(missing_docs)] -use cli::{AbstractService, VersionInfo, TaskExecutor}; +use cli::{AbstractService, VersionInfo, Runtime}; use futures::channel::oneshot; use futures::{future, FutureExt}; @@ -33,6 +33,7 @@ impl cli::IntoExit for Worker { let (exit_send, exit) = oneshot::channel(); let exit_send_cell = RefCell::new(Some(exit_send)); + #[cfg(not(target_os = "unknown"))] ctrlc::set_handler(move || { if let Some(exit_send) = exit_send_cell.try_borrow_mut().expect("signal handler not reentrant; qed").take() { exit_send.send(()).expect("Error sending exit notification"); @@ -45,7 +46,7 @@ impl cli::IntoExit for Worker { impl cli::Worker for Worker { type Work = ::Exit; - fn work(self, _: &S, _: TaskExecutor) -> Self::Work + fn work(self, _: &S, _: &Runtime) -> Self::Work where S: AbstractService,