From e0d574e1387fbd535c3a98461394517d1a6f841f Mon Sep 17 00:00:00 2001 From: Austin Abell Date: Mon, 29 Jun 2020 20:03:06 -0400 Subject: [PATCH] Update async-std runtime setup (#526) * Update async-std runtime setup * Update ctrl-c handler setup --- blockchain/beacon/src/drand_api/api.rs | 24 +++++++++++------------ blockchain/beacon/src/drand_api/common.rs | 12 ++++++------ forest/src/cli/mod.rs | 5 ++--- forest/src/daemon.rs | 12 ++++++------ forest/src/main.rs | 7 ++++--- forest/src/subcommand.rs | 7 ++----- 6 files changed, 32 insertions(+), 35 deletions(-) diff --git a/blockchain/beacon/src/drand_api/api.rs b/blockchain/beacon/src/drand_api/api.rs index 3bd43fca305c..e23732c010ed 100644 --- a/blockchain/beacon/src/drand_api/api.rs +++ b/blockchain/beacon/src/drand_api/api.rs @@ -1,4 +1,4 @@ -// This file is generated by rust-protobuf 2.15.0. Do not edit +// This file is generated by rust-protobuf 2.15.1. Do not edit // @generated // https://github.com/rust-lang/rust-clippy/issues/702 @@ -25,7 +25,7 @@ use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; /// Generated files are compatible only with the same version /// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_15_0; +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_15_1; #[derive(PartialEq,Clone,Default)] pub struct PublicRandRequest { @@ -125,7 +125,7 @@ impl ::protobuf::Message for PublicRandRequest { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -389,7 +389,7 @@ impl ::protobuf::Message for PublicRandResponse { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -585,7 +585,7 @@ impl ::protobuf::Message for PrivateRandRequest { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -763,7 +763,7 @@ impl ::protobuf::Message for PrivateRandResponse { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -998,7 +998,7 @@ impl ::protobuf::Message for ECIES { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -1136,7 +1136,7 @@ impl ::protobuf::Message for DistKeyRequest { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -1293,7 +1293,7 @@ impl ::protobuf::Message for DistKeyResponse { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -1419,7 +1419,7 @@ impl ::protobuf::Message for HomeRequest { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -1576,7 +1576,7 @@ impl ::protobuf::Message for HomeResponse { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -1804,7 +1804,7 @@ impl ::protobuf::Message for Node { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } diff --git a/blockchain/beacon/src/drand_api/common.rs b/blockchain/beacon/src/drand_api/common.rs index 53130f7af417..90513c7021f9 100644 --- a/blockchain/beacon/src/drand_api/common.rs +++ b/blockchain/beacon/src/drand_api/common.rs @@ -1,4 +1,4 @@ -// This file is generated by rust-protobuf 2.15.0. Do not edit +// This file is generated by rust-protobuf 2.15.1. Do not edit // @generated // https://github.com/rust-lang/rust-clippy/issues/702 @@ -25,7 +25,7 @@ use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; /// Generated files are compatible only with the same version /// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_15_0; +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_15_1; #[derive(PartialEq,Clone,Default)] pub struct Empty { @@ -95,7 +95,7 @@ impl ::protobuf::Message for Empty { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -317,7 +317,7 @@ impl ::protobuf::Message for Identity { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -686,7 +686,7 @@ impl ::protobuf::Message for GroupPacket { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -848,7 +848,7 @@ impl ::protobuf::Message for GroupRequest { fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } diff --git a/forest/src/cli/mod.rs b/forest/src/cli/mod.rs index a35336fe8e56..34e3a1874d4d 100644 --- a/forest/src/cli/mod.rs +++ b/forest/src/cli/mod.rs @@ -7,7 +7,6 @@ mod genesis; pub use self::config::Config; pub(super) use self::genesis::initialize_genesis; -use async_std::task; use std::cell::RefCell; use std::io; use std::process; @@ -80,7 +79,7 @@ impl DaemonOpts { } /// Blocks current thread until ctrl-c is received -pub(super) fn block_until_sigint() { +pub(super) async fn block_until_sigint() { let (ctrlc_send, ctrlc_oneshot) = futures::channel::oneshot::channel(); let ctrlc_send_c = RefCell::new(Some(ctrlc_send)); @@ -99,5 +98,5 @@ pub(super) fn block_until_sigint() { }) .expect("Error setting Ctrl-C handler"); - task::block_on(ctrlc_oneshot).unwrap(); + ctrlc_oneshot.await.unwrap(); } diff --git a/forest/src/daemon.rs b/forest/src/daemon.rs index 822274791525..8825690eb540 100644 --- a/forest/src/daemon.rs +++ b/forest/src/daemon.rs @@ -15,7 +15,7 @@ use std::sync::Arc; use utils::write_to_file; /// Starts daemon process -pub(super) fn start(config: Config) { +pub(super) async fn start(config: Config) { info!("Starting Forest daemon"); let net_keypair = get_keypair(&format!("{}{}", &config.data_dir, "/libp2p/keypair")) .unwrap_or_else(|| { @@ -80,12 +80,12 @@ pub(super) fn start(config: Config) { }); // Block until ctrl-c is hit - block_until_sigint(); + block_until_sigint().await; - // Drop threads - drop(rpc_thread); - drop(p2p_thread); - drop(sync_thread); + // Cancel all async services + rpc_thread.cancel().await; + p2p_thread.cancel().await; + sync_thread.cancel().await; info!("Forest finish shutdown"); } diff --git a/forest/src/main.rs b/forest/src/main.rs index 45ab09a7a02a..e0db1d7d4ff8 100644 --- a/forest/src/main.rs +++ b/forest/src/main.rs @@ -10,7 +10,8 @@ mod subcommand; use cli::CLI; use structopt::StructOpt; -fn main() { +#[async_std::main] +async fn main() { logger::setup_logger(); // Capture CLI inputs @@ -18,9 +19,9 @@ fn main() { CLI { daemon_opts, cmd: None, - } => daemon::start(daemon_opts.to_config().unwrap()), + } => daemon::start(daemon_opts.to_config().unwrap()).await, CLI { cmd: Some(command), .. - } => subcommand::process(command), + } => subcommand::process(command).await, } } diff --git a/forest/src/subcommand.rs b/forest/src/subcommand.rs index abe047165c09..87cc1f40f442 100644 --- a/forest/src/subcommand.rs +++ b/forest/src/subcommand.rs @@ -3,7 +3,6 @@ use super::cli::Subcommand; use super::paramfetch::{get_params_default, SectorSizeOpt}; -use async_std::task; use fil_types::SectorSize; /// Converts a human readable string to a u64 size. @@ -27,7 +26,7 @@ fn ram_to_int(size: &str) -> Result { } /// Process CLI subcommand -pub(super) fn process(command: Subcommand) { +pub(super) async fn process(command: Subcommand) { match command { Subcommand::FetchParams { params_size, @@ -48,9 +47,7 @@ pub(super) fn process(command: Subcommand) { ); }; - task::block_on(async { - get_params_default(sizes, verbose).await.unwrap(); - }); + get_params_default(sizes, verbose).await.unwrap(); } } }