diff --git a/Cargo.lock b/Cargo.lock index 4c74549d08b99..0ea53a0aa78f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9814,7 +9814,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59" dependencies = [ "cfg-if 0.1.10", - "rand 0.7.3", + "rand 0.3.23", "static_assertions", ] diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index 1c22b388af78e..e61dd86418825 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -131,7 +131,7 @@ pub fn run() -> sc_cli::Result<()> { match config.role { Role::Light => service::new_light(config), _ => service::new_full(config), - } + }.map_err(sc_cli::Error::Service) }) } } diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 3b7d56c2dbbc5..5c84f4cab7d61 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -36,7 +36,7 @@ crate-type = ["cdylib", "rlib"] # third-party dependencies codec = { package = "parity-scale-codec", version = "1.3.6" } serde = { version = "1.0.102", features = ["derive"] } -futures = { version = "0.3.1", features = ["compat"] } +futures = { version = "0.3.9", features = ["compat"] } hex-literal = "0.3.1" log = "0.4.8" rand = "0.7.2" diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index ed3aff88c75de..fcb8b6f0085e0 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -76,7 +76,7 @@ pub fn run() -> Result<()> { match config.role { Role::Light => service::new_light(config), _ => service::new_full(config), - } + }.map_err(sc_cli::Error::Service) }) } Some(Subcommand::Inspect(cmd)) => { diff --git a/client/cli/src/runner.rs b/client/cli/src/runner.rs index 9836471fb9fa2..74ac9e5bc7f62 100644 --- a/client/cli/src/runner.rs +++ b/client/cli/src/runner.rs @@ -27,17 +27,19 @@ use log::info; use sc_service::{Configuration, TaskType, TaskManager}; use sp_utils::metrics::{TOKIO_THREADS_ALIVE, TOKIO_THREADS_TOTAL}; use std::marker::PhantomData; +use sc_service::Error as ServiceError; +use crate::error::Error as CliError; #[cfg(target_family = "unix")] -async fn main(func: F) -> std::result::Result<(), Box> +async fn main(func: F) -> std::result::Result<(), E> where F: Future> + future::FusedFuture, - E: 'static + std::error::Error, + E: std::error::Error + Send + Sync + 'static + From, { use tokio::signal::unix::{signal, SignalKind}; - let mut stream_int = signal(SignalKind::interrupt())?; - let mut stream_term = signal(SignalKind::terminate())?; + let mut stream_int = signal(SignalKind::interrupt()).map_err(ServiceError::Io)?; + let mut stream_term = signal(SignalKind::terminate()).map_err(ServiceError::Io)?; let t1 = stream_int.recv().fuse(); let t2 = stream_term.recv().fuse(); @@ -55,10 +57,10 @@ where } #[cfg(not(unix))] -async fn main(func: F) -> std::result::Result<(), Box> +async fn main(func: F) -> std::result::Result<(), E> where F: Future> + future::FusedFuture, - E: 'static + std::error::Error, + E: std::error::Error + Send + Sync + 'static + From, { use tokio::signal::ctrl_c; @@ -90,19 +92,19 @@ pub fn build_runtime() -> std::result::Result( +fn run_until_exit( mut tokio_runtime: tokio::runtime::Runtime, - future: FUT, + future: F, task_manager: TaskManager, -) -> Result<()> +) -> std::result::Result<(), E> where - FUT: Future> + future::Future, - ERR: 'static + std::error::Error, + F: Future> + future::Future, + E: std::error::Error + Send + Sync + 'static + From, { let f = future.fuse(); pin_mut!(f); - tokio_runtime.block_on(main(f)).map_err(|e| e.to_string())?; + tokio_runtime.block_on(main(f))?; tokio_runtime.block_on(task_manager.clean_shutdown()); Ok(()) @@ -172,32 +174,43 @@ impl Runner { /// A helper function that runs a node with tokio and stops if the process receives the signal /// `SIGTERM` or `SIGINT`. - pub fn run_node_until_exit>>( + pub fn run_node_until_exit( mut self, initialize: impl FnOnce(Configuration) -> F, - ) -> Result<()> { + ) -> std::result::Result<(), E> + where + F: Future>, + E: std::error::Error + Send + Sync + 'static + From, + { self.print_node_infos(); let mut task_manager = self.tokio_runtime.block_on(initialize(self.config))?; let res = self.tokio_runtime.block_on(main(task_manager.future().fuse())); self.tokio_runtime.block_on(task_manager.clean_shutdown()); - res.map_err(|e| e.to_string().into()) + Ok(res?) } /// A helper function that runs a command with the configuration of this node. - pub fn sync_run(self, runner: impl FnOnce(Configuration) -> Result<()>) -> Result<()> { + pub fn sync_run( + self, + runner: impl FnOnce(Configuration) -> std::result::Result<(), E> + ) -> std::result::Result<(), E> + where + E: std::error::Error + Send + Sync + 'static + From, + { runner(self.config) } /// A helper function that runs a future with tokio and stops if the process receives /// the signal `SIGTERM` or `SIGINT`. - pub fn async_run( - self, runner: impl FnOnce(Configuration) -> Result<(FUT, TaskManager)>, - ) -> Result<()> + pub fn async_run( + self, runner: impl FnOnce(Configuration) -> std::result::Result<(F, TaskManager), E>, + ) -> std::result::Result<(), E> where - FUT: Future>, + F: Future>, + E: std::error::Error + Send + Sync + 'static + From + From, { let (future, task_manager) = runner(self.config)?; - run_until_exit(self.tokio_runtime, future, task_manager) + run_until_exit::<_, E>(self.tokio_runtime, future, task_manager) } /// Get an immutable reference to the node Configuration