From 8b9325e5d1b5d89eda37005c63cf6dab94cb729e Mon Sep 17 00:00:00 2001 From: timotree3 Date: Fri, 27 Sep 2019 15:12:58 -0400 Subject: [PATCH] core: Rewrite `await!(future)` to `future.await` This resolves #1723 by migrating away from the old syntax The other change this commit makes is removing `#![feature(await_macro)]` invocations --- conductor_api/src/lib.rs | 2 +- core/src/action.rs | 1 - core/src/agent/actions/commit.rs | 5 +- core/src/agent/chain_store.rs | 1 - core/src/dht/actions/hold.rs | 2 +- core/src/dht/dht_reducers.rs | 1 - core/src/instance.rs | 18 +++---- core/src/lib.rs | 2 +- core/src/link_tests.rs | 1 - core/src/network/actions/custom_send.rs | 5 +- .../network/actions/get_validation_package.rs | 5 +- .../src/network/actions/initialize_network.rs | 14 +++--- core/src/network/actions/publish.rs | 5 +- .../network/actions/publish_header_entry.rs | 5 +- core/src/network/actions/query.rs | 5 +- core/src/network/actions/shutdown.rs | 2 +- core/src/network/handler/lists.rs | 1 - core/src/network/reducers/init.rs | 1 - core/src/network/reducers/publish.rs | 1 - .../network/reducers/publish_header_entry.rs | 1 - .../actions/build_validation_package.rs | 5 +- .../src/nucleus/actions/call_zome_function.rs | 5 +- core/src/nucleus/actions/initialize.rs | 16 +++--- core/src/nucleus/actions/mod.rs | 1 - .../actions/run_validation_callback.rs | 5 +- core/src/nucleus/ribosome/api/call.rs | 1 - core/src/nucleus/ribosome/api/capabilities.rs | 1 - core/src/nucleus/ribosome/api/commit.rs | 1 - core/src/nucleus/ribosome/api/crypto.rs | 1 - core/src/nucleus/ribosome/api/get_entry.rs | 1 - core/src/nucleus/ribosome/api/link_entries.rs | 1 - core/src/nucleus/ribosome/api/meta.rs | 1 - core/src/nucleus/ribosome/callback/init.rs | 1 - core/src/nucleus/ribosome/callback/mod.rs | 1 - core/src/nucleus/state.rs | 1 - core/src/nucleus/validation/agent_entry.rs | 5 +- core/src/nucleus/validation/app_entry.rs | 2 +- core/src/nucleus/validation/link_entry.rs | 2 +- core/src/nucleus/validation/mod.rs | 49 +++++++++---------- core/src/nucleus/validation/remove_entry.rs | 2 +- core/src/workflows/application.rs | 21 ++++---- core/src/workflows/author_entry.rs | 49 +++++++++---------- core/src/workflows/get_entry_result.rs | 20 +++----- core/src/workflows/get_link_result.rs | 6 +-- core/src/workflows/get_links_count.rs | 6 +-- core/src/workflows/hold_entry.rs | 9 ++-- core/src/workflows/hold_entry_remove.rs | 34 +++++++------ core/src/workflows/hold_entry_update.rs | 13 ++--- core/src/workflows/hold_link.rs | 17 ++++--- core/src/workflows/mod.rs | 17 +++---- core/src/workflows/remove_link.rs | 17 ++++--- .../respond_validation_package_request.rs | 9 ++-- 52 files changed, 187 insertions(+), 211 deletions(-) diff --git a/conductor_api/src/lib.rs b/conductor_api/src/lib.rs index 1fb4cf3f4d..2e70d37580 100644 --- a/conductor_api/src/lib.rs +++ b/conductor_api/src/lib.rs @@ -2,7 +2,7 @@ //! Arc::new(Mutex::new(SimplePersister::new(file_system.clone()))), //! file_system.clone(), -#![feature(try_trait, async_await, await_macro)] +#![feature(try_trait, async_await)] #![warn(unused_extern_crates)] /// Holochain Conductor API /// diff --git a/core/src/action.rs b/core/src/action.rs index 2bf6e67e99..239d4f3ee9 100644 --- a/core/src/action.rs +++ b/core/src/action.rs @@ -414,5 +414,4 @@ pub mod tests { assert_ne!(calculate_hash(&aw1), calculate_hash(&aw2)); } - } diff --git a/core/src/agent/actions/commit.rs b/core/src/agent/actions/commit.rs index 3ba434d716..aec70b7fb2 100644 --- a/core/src/agent/actions/commit.rs +++ b/core/src/agent/actions/commit.rs @@ -25,10 +25,11 @@ pub async fn commit_entry( vec![], ))); dispatch_action(context.action_channel(), action_wrapper.clone()); - await!(CommitFuture { + CommitFuture { context: context.clone(), action: action_wrapper, - }) + } + .await } /// CommitFuture resolves to ActionResponse diff --git a/core/src/agent/chain_store.rs b/core/src/agent/chain_store.rs index f3ed48096c..ddb8885b60 100644 --- a/core/src/agent/chain_store.rs +++ b/core/src/agent/chain_store.rs @@ -875,5 +875,4 @@ pub mod tests { assert_eq!(set.matches("src/bar/baz/foo.rs"), vec![2, 3]); // *.rs no longer matches, due to '/' separators assert_eq!(set.matches("foo.rs"), vec![0, 3]); // but, any number of leading '/' are matched by a '**/...' } - } diff --git a/core/src/dht/actions/hold.rs b/core/src/dht/actions/hold.rs index 143a66f3bb..2f801eca86 100644 --- a/core/src/dht/actions/hold.rs +++ b/core/src/dht/actions/hold.rs @@ -16,7 +16,7 @@ pub async fn hold_entry( let address = entry_wh.entry.address(); let action_wrapper = ActionWrapper::new(Action::Hold(entry_wh.to_owned())); dispatch_action(context.action_channel(), action_wrapper.clone()); - await!(HoldEntryFuture { context, address }) + HoldEntryFuture { context, address }.await } pub struct HoldEntryFuture { diff --git a/core/src/dht/dht_reducers.rs b/core/src/dht/dht_reducers.rs index 8682527700..437216f8a6 100644 --- a/core/src/dht/dht_reducers.rs +++ b/core/src/dht/dht_reducers.rs @@ -432,5 +432,4 @@ pub mod tests { assert_eq!(&entry, &result_entry,); } - } diff --git a/core/src/instance.rs b/core/src/instance.rs index fa59c1974f..98fd237058 100644 --- a/core/src/instance.rs +++ b/core/src/instance.rs @@ -100,15 +100,10 @@ impl Instance { context: Arc, ) -> HcResult> { let context = self.inner_setup(context); - context.block_on( - async { - await!(initialize_chain(dna.clone(), &context))?; - await!(initialize_network_with_spoofed_dna( - spoofed_dna_address, - &context - )) - }, - )?; + context.block_on(async { + initialize_chain(dna.clone(), &context).await?; + initialize_network_with_spoofed_dna(spoofed_dna_address, &context).await + })?; Ok(context) } @@ -339,10 +334,11 @@ impl Instance { #[allow(clippy::needless_lifetimes)] pub async fn shutdown_network(&self) -> HcResult<()> { - await!(network::actions::shutdown::shutdown( + network::actions::shutdown::shutdown( self.state.clone(), self.action_channel.as_ref().unwrap().clone(), - )) + ) + .await } } diff --git a/core/src/lib.rs b/core/src/lib.rs index fc5ad58ae8..5d2c52d7f3 100755 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,5 +1,5 @@ //! The library implementing the holochain pattern of validation rules + local source chain + DHT -#![feature(arbitrary_self_types, async_await, await_macro)] +#![feature(arbitrary_self_types, async_await)] #![warn(unused_extern_crates)] #[macro_use] extern crate serde_derive; diff --git a/core/src/link_tests.rs b/core/src/link_tests.rs index 0ca5fde9ad..e27d3e6c58 100644 --- a/core/src/link_tests.rs +++ b/core/src/link_tests.rs @@ -114,5 +114,4 @@ pub mod tests { _ => false, }); } - } diff --git a/core/src/network/actions/custom_send.rs b/core/src/network/actions/custom_send.rs index 41ae4c92b6..18965bb046 100644 --- a/core/src/network/actions/custom_send.rs +++ b/core/src/network/actions/custom_send.rs @@ -40,10 +40,11 @@ pub async fn custom_send( }) .expect("Could not spawn thread for custom_send timeout"); - await!(SendResponseFuture { + SendResponseFuture { context: context.clone(), id, - }) + } + .await } /// SendResponseFuture waits for a result to show up in NetworkState::custom_direct_message_replys diff --git a/core/src/network/actions/get_validation_package.rs b/core/src/network/actions/get_validation_package.rs index bb11d81878..b37474f069 100644 --- a/core/src/network/actions/get_validation_package.rs +++ b/core/src/network/actions/get_validation_package.rs @@ -26,10 +26,11 @@ pub async fn get_validation_package( let entry_address = header.entry_address().clone(); let action_wrapper = ActionWrapper::new(Action::GetValidationPackage(header)); dispatch_action(context.action_channel(), action_wrapper.clone()); - await!(GetValidationPackageFuture { + GetValidationPackageFuture { context: context.clone(), address: entry_address, - }) + } + .await } /// GetValidationPackageFuture resolves to an Option diff --git a/core/src/network/actions/initialize_network.rs b/core/src/network/actions/initialize_network.rs index c10a26313f..583e9b849f 100644 --- a/core/src/network/actions/initialize_network.rs +++ b/core/src/network/actions/initialize_network.rs @@ -12,7 +12,7 @@ use std::{pin::Pin, sync::Arc}; /// Creates a network proxy object and stores DNA and agent hash in the network state. pub async fn initialize_network(context: &Arc) -> HcResult<()> { - let (dna_address, agent_id) = await!(get_dna_and_agent(context))?; + let (dna_address, agent_id) = get_dna_and_agent(context).await?; let handler = create_handler(&context, dna_address.to_string()); let network_settings = NetworkSettings { p2p_config: context.p2p_config.clone(), @@ -23,9 +23,10 @@ pub async fn initialize_network(context: &Arc) -> HcResult<()> { let action_wrapper = ActionWrapper::new(Action::InitNetwork(network_settings)); dispatch_action(context.action_channel(), action_wrapper.clone()); - await!(InitNetworkFuture { + InitNetworkFuture { context: context.clone(), - })?; + } + .await?; Ok(()) } @@ -35,7 +36,7 @@ pub async fn initialize_network_with_spoofed_dna( dna_address: Address, context: &Arc, ) -> HcResult<()> { - let (_, agent_id) = await!(get_dna_and_agent(context))?; + let (_, agent_id) = get_dna_and_agent(context).await?; let handler = create_handler(&context, dna_address.to_string()); let network_settings = NetworkSettings { p2p_config: context.p2p_config.clone(), @@ -46,9 +47,10 @@ pub async fn initialize_network_with_spoofed_dna( let action_wrapper = ActionWrapper::new(Action::InitNetwork(network_settings)); dispatch_action(context.action_channel(), action_wrapper.clone()); - await!(InitNetworkFuture { + InitNetworkFuture { context: context.clone(), - }) + } + .await } pub struct InitNetworkFuture { diff --git a/core/src/network/actions/publish.rs b/core/src/network/actions/publish.rs index 0db8e71f0f..ece0943c01 100644 --- a/core/src/network/actions/publish.rs +++ b/core/src/network/actions/publish.rs @@ -17,10 +17,11 @@ use std::{pin::Pin, sync::Arc}; pub async fn publish(address: Address, context: &Arc) -> HcResult
{ let action_wrapper = ActionWrapper::new(Action::Publish(address)); dispatch_action(context.action_channel(), action_wrapper.clone()); - await!(PublishFuture { + PublishFuture { context: context.clone(), action: action_wrapper, - }) + } + .await } /// PublishFuture resolves to ActionResponse diff --git a/core/src/network/actions/publish_header_entry.rs b/core/src/network/actions/publish_header_entry.rs index 388f826714..6a54413924 100644 --- a/core/src/network/actions/publish_header_entry.rs +++ b/core/src/network/actions/publish_header_entry.rs @@ -14,10 +14,11 @@ use std::{pin::Pin, sync::Arc}; pub async fn publish_header_entry(address: Address, context: &Arc) -> HcResult
{ let action_wrapper = ActionWrapper::new(Action::PublishHeaderEntry(address)); dispatch_action(context.action_channel(), action_wrapper.clone()); - await!(PublishHeaderEntryFuture { + PublishHeaderEntryFuture { context: context.clone(), action: action_wrapper, - }) + } + .await } /// PublishFuture resolves to ActionResponse diff --git a/core/src/network/actions/query.rs b/core/src/network/actions/query.rs index 01de926d99..c6ecde0246 100644 --- a/core/src/network/actions/query.rs +++ b/core/src/network/actions/query.rs @@ -78,10 +78,11 @@ pub async fn query( }) .expect("Could not spawn thread for get timeout"); - await!(QueryFuture { + QueryFuture { context: context.clone(), key: key.clone(), - }) + } + .await } /// GetEntryFuture resolves to a HcResult. diff --git a/core/src/network/actions/shutdown.rs b/core/src/network/actions/shutdown.rs index 5a6a4c6e9d..acd1ad0ed4 100644 --- a/core/src/network/actions/shutdown.rs +++ b/core/src/network/actions/shutdown.rs @@ -23,7 +23,7 @@ pub async fn shutdown( if state.read().unwrap().network().initialized().is_ok() { let action_wrapper = ActionWrapper::new(Action::ShutdownNetwork); dispatch_action(&action_channel, action_wrapper.clone()); - await!(ShutdownFuture { state }) + ShutdownFuture { state }.await } else { Err(HolochainError::ErrorGeneric( "Tried to shutdown network that was never initialized".to_string(), diff --git a/core/src/network/handler/lists.rs b/core/src/network/handler/lists.rs index 972a24e837..b0d1ca11f8 100644 --- a/core/src/network/handler/lists.rs +++ b/core/src/network/handler/lists.rs @@ -183,5 +183,4 @@ pub mod tests { get_all_aspect_addresses(&chain_header.address(), context.clone()).is_ok() })); } - } diff --git a/core/src/network/reducers/init.rs b/core/src/network/reducers/init.rs index 9218f7e2e2..fa5b081d56 100644 --- a/core/src/network/reducers/init.rs +++ b/core/src/network/reducers/init.rs @@ -106,5 +106,4 @@ pub mod test { assert_eq!(result, ()); } - } diff --git a/core/src/network/reducers/publish.rs b/core/src/network/reducers/publish.rs index f1c5f4a7ad..ab4e8198ab 100644 --- a/core/src/network/reducers/publish.rs +++ b/core/src/network/reducers/publish.rs @@ -201,5 +201,4 @@ mod tests { store.reduce(action_wrapper); } - } diff --git a/core/src/network/reducers/publish_header_entry.rs b/core/src/network/reducers/publish_header_entry.rs index 97132d763c..37942f3576 100644 --- a/core/src/network/reducers/publish_header_entry.rs +++ b/core/src/network/reducers/publish_header_entry.rs @@ -106,5 +106,4 @@ mod tests { store.reduce(action_wrapper); } - } diff --git a/core/src/nucleus/actions/build_validation_package.rs b/core/src/nucleus/actions/build_validation_package.rs index 6e87cac3fe..3e2f553507 100644 --- a/core/src/nucleus/actions/build_validation_package.rs +++ b/core/src/nucleus/actions/build_validation_package.rs @@ -177,11 +177,12 @@ pub async fn build_validation_package<'a>( .expect("Could not spawn thread for build_validation_package"); } - await!(ValidationPackageFuture { + ValidationPackageFuture { context: context.clone(), key: id, error: None, - }) + } + .await } // given a slice of headers return the entries for those marked public diff --git a/core/src/nucleus/actions/call_zome_function.rs b/core/src/nucleus/actions/call_zome_function.rs index 9e4bef2244..ccae444c56 100644 --- a/core/src/nucleus/actions/call_zome_function.rs +++ b/core/src/nucleus/actions/call_zome_function.rs @@ -125,10 +125,11 @@ pub async fn call_zome_function( zome_call ); - await!(CallResultFuture { + CallResultFuture { context: context.clone(), zome_call, - }) + } + .await } /// validates that a given zome function call specifies a correct zome function and capability grant diff --git a/core/src/nucleus/actions/initialize.rs b/core/src/nucleus/actions/initialize.rs index 3dc716cc1e..00295b0310 100644 --- a/core/src/nucleus/actions/initialize.rs +++ b/core/src/nucleus/actions/initialize.rs @@ -79,7 +79,7 @@ pub async fn initialize_chain( // Commit DNA to chain let dna_entry = Entry::Dna(Box::new(dna.clone())); - let dna_commit = await!(commit_entry(dna_entry, None, &context_clone)); + let dna_commit = commit_entry(dna_entry, None, &context_clone).await; if dna_commit.is_err() { let error = dna_commit.err().unwrap(); dispatch_error_result(&context_clone, error.clone()); @@ -91,7 +91,7 @@ pub async fn initialize_chain( // Commit AgentId to chain let agent_id_entry = Entry::AgentId(context_clone.agent_id.clone()); - let agent_id_commit = await!(commit_entry(agent_id_entry, None, &context_clone)); + let agent_id_commit = commit_entry(agent_id_entry, None, &context_clone).await; // Let initialization fail if AgentId could not be committed. // Currently this cannot happen since ToEntry for Agent always creates @@ -139,11 +139,8 @@ pub async fn initialize_chain( } let grant = maybe_public_cap_grant_entry.ok().unwrap(); - let public_cap_grant_commit = await!(commit_entry( - Entry::CapTokenGrant(grant.clone()), - None, - &context_clone - )); + let public_cap_grant_commit = + commit_entry(Entry::CapTokenGrant(grant.clone()), None, &context_clone).await; // Let initialization fail if Public Grant could not be committed. match public_cap_grant_commit { @@ -178,10 +175,11 @@ pub async fn initialize_chain( ))) .expect("Action channel not usable in initialize_chain()"); - await!(InitializationFuture { + InitializationFuture { context: context.clone(), created_at: Instant::now(), - }) + } + .await } /// InitializationFuture resolves to an Ok(NucleusStatus) or an Err(String). diff --git a/core/src/nucleus/actions/mod.rs b/core/src/nucleus/actions/mod.rs index 91ca949f8c..b3941ca04d 100644 --- a/core/src/nucleus/actions/mod.rs +++ b/core/src/nucleus/actions/mod.rs @@ -135,5 +135,4 @@ pub mod tests { let (instance, _context) = instance(None); assert!(instance.state().nucleus().has_initialized()); } - } diff --git a/core/src/nucleus/actions/run_validation_callback.rs b/core/src/nucleus/actions/run_validation_callback.rs index 0e082fdcfd..783678e04a 100644 --- a/core/src/nucleus/actions/run_validation_callback.rs +++ b/core/src/nucleus/actions/run_validation_callback.rs @@ -62,10 +62,11 @@ pub async fn run_validation_callback( }) .expect("Could not spawn thread for validation callback"); - await!(ValidationCallbackFuture { + ValidationCallbackFuture { context: context.clone(), key: (id, address), - }) + } + .await } /// ValidationFuture resolves to an Ok(ActionWrapper) or an Err(error_message:String). diff --git a/core/src/nucleus/ribosome/api/call.rs b/core/src/nucleus/ribosome/api/call.rs index 505f534a83..7a073423f0 100644 --- a/core/src/nucleus/ribosome/api/call.rs +++ b/core/src/nucleus/ribosome/api/call.rs @@ -538,5 +538,4 @@ pub mod tests { ); assert!(check_capability(context.clone(), &zome_call)); } - } diff --git a/core/src/nucleus/ribosome/api/capabilities.rs b/core/src/nucleus/ribosome/api/capabilities.rs index e105de1752..a0ea9bb054 100644 --- a/core/src/nucleus/ribosome/api/capabilities.rs +++ b/core/src/nucleus/ribosome/api/capabilities.rs @@ -133,5 +133,4 @@ pub mod tests { ), ); } - } diff --git a/core/src/nucleus/ribosome/api/commit.rs b/core/src/nucleus/ribosome/api/commit.rs index 14a65747ab..809b35de33 100644 --- a/core/src/nucleus/ribosome/api/commit.rs +++ b/core/src/nucleus/ribosome/api/commit.rs @@ -96,5 +96,4 @@ pub mod tests { ), ); } - } diff --git a/core/src/nucleus/ribosome/api/crypto.rs b/core/src/nucleus/ribosome/api/crypto.rs index b58b66df9b..8ad15fb00f 100644 --- a/core/src/nucleus/ribosome/api/crypto.rs +++ b/core/src/nucleus/ribosome/api/crypto.rs @@ -76,5 +76,4 @@ mod test_super { call_result, ); } - } diff --git a/core/src/nucleus/ribosome/api/get_entry.rs b/core/src/nucleus/ribosome/api/get_entry.rs index f61f5ac30f..1986d5b279 100644 --- a/core/src/nucleus/ribosome/api/get_entry.rs +++ b/core/src/nucleus/ribosome/api/get_entry.rs @@ -309,5 +309,4 @@ pub mod tests { // call_result, // ); } - } diff --git a/core/src/nucleus/ribosome/api/link_entries.rs b/core/src/nucleus/ribosome/api/link_entries.rs index 0df3a0c002..366d1d9d87 100644 --- a/core/src/nucleus/ribosome/api/link_entries.rs +++ b/core/src/nucleus/ribosome/api/link_entries.rs @@ -238,5 +238,4 @@ pub mod tests { assert_ne!(result1, result2); } - } diff --git a/core/src/nucleus/ribosome/api/meta.rs b/core/src/nucleus/ribosome/api/meta.rs index ffe460555e..d39953ea0d 100644 --- a/core/src/nucleus/ribosome/api/meta.rs +++ b/core/src/nucleus/ribosome/api/meta.rs @@ -65,5 +65,4 @@ mod test_super { call_result, ); } - } diff --git a/core/src/nucleus/ribosome/callback/init.rs b/core/src/nucleus/ribosome/callback/init.rs index 067e81ae1c..1d1256966f 100644 --- a/core/src/nucleus/ribosome/callback/init.rs +++ b/core/src/nucleus/ribosome/callback/init.rs @@ -75,5 +75,4 @@ pub mod tests { error ); } - } diff --git a/core/src/nucleus/ribosome/callback/mod.rs b/core/src/nucleus/ribosome/callback/mod.rs index 95dcf18600..cbce50980a 100644 --- a/core/src/nucleus/ribosome/callback/mod.rs +++ b/core/src/nucleus/ribosome/callback/mod.rs @@ -346,5 +346,4 @@ pub mod tests { assert_eq!(output, Callback::from_index(input)); } } - } diff --git a/core/src/nucleus/state.rs b/core/src/nucleus/state.rs index 0fb4a429dd..c59d6e23bf 100644 --- a/core/src/nucleus/state.rs +++ b/core/src/nucleus/state.rs @@ -215,5 +215,4 @@ pub mod tests { pub fn test_nucleus_state() -> NucleusState { NucleusState::new() } - } diff --git a/core/src/nucleus/validation/agent_entry.rs b/core/src/nucleus/validation/agent_entry.rs index eeaa61c4d1..78c6952f1b 100644 --- a/core/src/nucleus/validation/agent_entry.rs +++ b/core/src/nucleus/validation/agent_entry.rs @@ -36,12 +36,13 @@ pub async fn validate_agent_entry( log_debug!(context, "Validating agent entry with args: {:?}", params); - let results = await!(future::join_all(dna.zomes.iter().map(|(zome_name, _)| { + let results = future::join_all(dna.zomes.iter().map(|(zome_name, _)| { let call = CallbackFnCall::new(&zome_name, "__hdk_validate_agent_entry", params.clone()); // Need to return a boxed future for it to work with join_all // https://users.rust-lang.org/t/the-trait-unpin-is-not-implemented-for-genfuture-error-when-using-join-all/23612/2 run_validation_callback(entry.address(), call, &context).boxed() - }))); + })) + .await; let errors: Vec = results .iter() diff --git a/core/src/nucleus/validation/app_entry.rs b/core/src/nucleus/validation/app_entry.rs index 051ca76a6b..f109f9afb5 100644 --- a/core/src/nucleus/validation/app_entry.rs +++ b/core/src/nucleus/validation/app_entry.rs @@ -43,5 +43,5 @@ pub async fn validate_app_entry( }; let call = CallbackFnCall::new(&zome_name, "__hdk_validate_app_entry", params); - await!(run_validation_callback(entry.address(), call, &context)) + run_validation_callback(entry.address(), call, &context).await } diff --git a/core/src/nucleus/validation/link_entry.rs b/core/src/nucleus/validation/link_entry.rs index d6da36de57..6278d3b98d 100644 --- a/core/src/nucleus/validation/link_entry.rs +++ b/core/src/nucleus/validation/link_entry.rs @@ -116,5 +116,5 @@ pub async fn validate_link_entry( params, ); - await!(run_validation_callback(address, call, context)) + run_validation_callback(address, call, context).await } diff --git a/core/src/nucleus/validation/mod.rs b/core/src/nucleus/validation/mod.rs index ba15fa783e..7d4eda406c 100644 --- a/core/src/nucleus/validation/mod.rs +++ b/core/src/nucleus/validation/mod.rs @@ -86,42 +86,37 @@ pub async fn validate_entry( // TODO: Specify when DNA can be commited as an update and how to implement validation of DNA entries then. EntryType::Dna => Ok(()), - EntryType::App(app_entry_type) => await!(app_entry::validate_app_entry( - entry.clone(), - app_entry_type.clone(), - context, - link, - validation_data - )), + EntryType::App(app_entry_type) => { + app_entry::validate_app_entry( + entry.clone(), + app_entry_type.clone(), + context, + link, + validation_data, + ) + .await + } - EntryType::LinkAdd => await!(link_entry::validate_link_entry( - entry.clone(), - validation_data, - context - )), + EntryType::LinkAdd => { + link_entry::validate_link_entry(entry.clone(), validation_data, context).await + } - EntryType::LinkRemove => await!(link_entry::validate_link_entry( - entry.clone(), - validation_data, - context - )), + EntryType::LinkRemove => { + link_entry::validate_link_entry(entry.clone(), validation_data, context).await + } // Deletion entries are not validated currently and always valid // TODO: Specify how Deletion can be commited to chain. - EntryType::Deletion => await!(remove_entry::validate_remove_entry( - entry.clone(), - validation_data, - context - )), + EntryType::Deletion => { + remove_entry::validate_remove_entry(entry.clone(), validation_data, context).await + } // a grant should always be private, so it should always pass EntryType::CapTokenGrant => Ok(()), - EntryType::AgentId => await!(agent_entry::validate_agent_entry( - entry.clone(), - validation_data, - context, - )), + EntryType::AgentId => { + agent_entry::validate_agent_entry(entry.clone(), validation_data, context).await + } // chain headers always pass for now. In future this should check that the entry is valid EntryType::ChainHeader => Ok(()), diff --git a/core/src/nucleus/validation/remove_entry.rs b/core/src/nucleus/validation/remove_entry.rs index 8c4014594e..c5bd06e850 100644 --- a/core/src/nucleus/validation/remove_entry.rs +++ b/core/src/nucleus/validation/remove_entry.rs @@ -45,5 +45,5 @@ pub async fn validate_remove_entry( }; let call = CallbackFnCall::new(&zome_name, "__hdk_validate_app_entry", params); - await!(run_validation_callback(entry.address(), call, context)) + run_validation_callback(entry.address(), call, context).await } diff --git a/core/src/workflows/application.rs b/core/src/workflows/application.rs index 676301b278..44040ca22c 100644 --- a/core/src/workflows/application.rs +++ b/core/src/workflows/application.rs @@ -25,33 +25,36 @@ pub async fn initialize( let dna = dna.ok_or(HolochainError::DnaMissing)?; // 2. Initialize the local chain if not already - let first_initialization = match await!(get_dna_and_agent(&instance_context)) { + let first_initialization = match get_dna_and_agent(&instance_context).await { Ok(_) => false, Err(err) => { log_debug!(context, "dna/initialize: No DNA and agent in chain so assuming uninitialized: {:?}", err ); - await!(initialize_chain(dna.clone(), &instance_context))?; - log_debug!(context, "dna/initialize: Initializing new chain from given DNA..."); + initialize_chain(dna.clone(), &instance_context).await?; + log_debug!( + context, + "dna/initialize: Initializing new chain from given DNA..." + ); true } }; // 3. Initialize the network - await!(initialize_network(&instance_context))?; + initialize_network(&instance_context).await?; if first_initialization { - // 4. (first initialization only) Publish the agent entry and headers of the agent and DNA entries. - await!(publish(context.agent_id.address(), &context))?; + // 4. (first initialization only) Publish the agent entry and headers of the agent and DNA entries. + publish(context.agent_id.address(), &context).await?; let dna_entry = Entry::Dna(Box::new(dna.clone())); - await!(publish_header_entry(dna_entry.address(), &context))?; + publish_header_entry(dna_entry.address(), &context).await?; let agent_id_entry = Entry::AgentId(context.agent_id.clone()); - await!(publish_header_entry(agent_id_entry.address(), &context))?; + publish_header_entry(agent_id_entry.address(), &context).await?; // 5. (first initialization only) Call the init callbacks in the zomes - await!(call_init(dna, &instance_context))?; + call_init(dna, &instance_context).await?; } Ok(instance_context) } diff --git a/core/src/workflows/author_entry.rs b/core/src/workflows/author_entry.rs index a2ff9afbf4..4f8d5356f6 100644 --- a/core/src/workflows/author_entry.rs +++ b/core/src/workflows/author_entry.rs @@ -46,11 +46,7 @@ pub async fn author_entry<'a>( } // 1. Build the context needed for validation of the entry - let validation_package = await!(build_validation_package( - &entry, - context.clone(), - provenances - ))?; + let validation_package = build_validation_package(&entry, context.clone(), provenances).await?; let validation_data = ValidationData { package: validation_package, lifecycle: EntryLifecycle::Chain, @@ -61,12 +57,13 @@ pub async fn author_entry<'a>( "workflow/authoring_entry/{}: validating...", address ); - await!(validate_entry( + validate_entry( entry.clone(), maybe_link_update_delete.clone(), validation_data, - &context - ))?; + &context, + ) + .await?; log_debug!(context, "worflow/authoring_entry {}: is valid!", address); // 3. Commit the entry @@ -74,11 +71,7 @@ pub async fn author_entry<'a>( "workflow/authoring_entry/{}: committing...", address ); - let addr = await!(commit_entry( - entry.clone(), - maybe_link_update_delete, - &context - ))?; + let addr = commit_entry(entry.clone(), maybe_link_update_delete, &context).await?; log_debug!(context, "workflow/authoring_entry/{}: committed", address); // 4. Publish the valid entry to DHT. This will call Hold to itself @@ -87,23 +80,29 @@ pub async fn author_entry<'a>( "workflow/authoring_entry/{}: publishing...", address ); - await!(publish(entry.address(), &context))?; - log_debug!(context, - "workflow/authoring_entry/{}: published!", - address - ); + publish(entry.address(), &context).await?; + log_debug!(context, "workflow/authoring_entry/{}: published!", address); } else { - log_debug!(context, - "workflow/authoring_entry/{}: entry is private, no publishing", - address + log_debug!( + context, + "workflow/authoring_entry/{}: entry is private, no publishing", + address ); } // 5. Publish the header for all types (including private entries) - log_debug!(context, "debug/workflow/authoring_entry/{}: publishing header...", address); - await!(publish_header_entry(entry.address(), &context))?; - log_debug!(context, "debug/workflow/authoring_entry/{}: header published!", address); - + log_debug!( + context, + "debug/workflow/authoring_entry/{}: publishing header...", + address + ); + publish_header_entry(entry.address(), &context).await?; + log_debug!( + context, + "debug/workflow/authoring_entry/{}: header published!", + address + ); + Ok(CommitEntryResult::new(addr)) } diff --git a/core/src/workflows/get_entry_result.rs b/core/src/workflows/get_entry_result.rs index 3eb5e02beb..52ae763cab 100644 --- a/core/src/workflows/get_entry_result.rs +++ b/core/src/workflows/get_entry_result.rs @@ -26,11 +26,9 @@ pub async fn get_entry_with_meta_workflow<'a>( let method = QueryMethod::Entry(address.clone()); // 2. No result, so try on the network if let None = maybe_entry_with_meta { - let response = await!(network::actions::query::query( - context.clone(), - method.clone(), - timeout.clone(), - ))?; + let response = + network::actions::query::query(context.clone(), method.clone(), timeout.clone()) + .await?; match response { NetworkQueryResult::Entry(maybe_entry) => Ok(maybe_entry), _ => Err(HolochainError::ErrorGeneric( @@ -54,11 +52,12 @@ pub async fn get_entry_with_meta_workflow<'a>( headers, })), Err(_) => { - let response = await!(network::actions::query::query( + let response = network::actions::query::query( context.clone(), method.clone(), timeout.clone(), - ))?; + ) + .await?; match response { NetworkQueryResult::Entry(maybe_entry) => Ok(maybe_entry), _ => Err(HolochainError::ErrorGeneric( @@ -84,11 +83,8 @@ pub async fn get_entry_result_workflow<'a>( let address = maybe_address.unwrap(); maybe_address = None; // Try to get entry - let maybe_entry_with_meta_and_headers = await!(get_entry_with_meta_workflow( - context, - &address, - &args.options.timeout - ))?; + let maybe_entry_with_meta_and_headers = + get_entry_with_meta_workflow(context, &address, &args.options.timeout).await?; // Entry found if let Some(entry_with_meta_and_headers) = maybe_entry_with_meta_and_headers { diff --git a/core/src/workflows/get_link_result.rs b/core/src/workflows/get_link_result.rs index 9e44e07de1..4ac9e18394 100644 --- a/core/src/workflows/get_link_result.rs +++ b/core/src/workflows/get_link_result.rs @@ -20,11 +20,7 @@ pub async fn get_link_result_workflow<'a>( headers: link_args.options.headers, }; let method = QueryMethod::Link(link_args.clone(), GetLinksNetworkQuery::Links(config)); - let response = await!(query( - context.clone(), - method, - link_args.options.timeout.clone() - ))?; + let response = query(context.clone(), method, link_args.options.timeout.clone()).await?; let links_result = match response { NetworkQueryResult::Links(query, _, _) => Ok(query), diff --git a/core/src/workflows/get_links_count.rs b/core/src/workflows/get_links_count.rs index f8931a5ecc..3fc24646a2 100644 --- a/core/src/workflows/get_links_count.rs +++ b/core/src/workflows/get_links_count.rs @@ -15,11 +15,7 @@ pub async fn get_link_result_count_workflow<'a>( link_args: &'a GetLinksArgs, ) -> Result { let method = QueryMethod::Link(link_args.clone(), GetLinksNetworkQuery::Count); - let response = await!(query( - context.clone(), - method, - link_args.options.timeout.clone() - ))?; + let response = query(context.clone(), method, link_args.options.timeout.clone()).await?; let links_result = match response { NetworkQueryResult::Links(link_result, _, _) => Ok(link_result), diff --git a/core/src/workflows/hold_entry.rs b/core/src/workflows/hold_entry.rs index 1624acca56..8385a3fe7b 100644 --- a/core/src/workflows/hold_entry.rs +++ b/core/src/workflows/hold_entry.rs @@ -25,7 +25,8 @@ pub async fn hold_entry_workflow( context: Arc, ) -> Result<(), HolochainError> { // 1. Get hold of validation package - let maybe_validation_package = await!(validation_package(&entry_with_header, context.clone())) + let maybe_validation_package = validation_package(&entry_with_header, context.clone()) + .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; log_debug!(context, "workflow/hold_entry: {}", message); @@ -59,12 +60,12 @@ pub async fn hold_entry_workflow( }; // 3. Validate the entry - await!(validate_entry( + validate_entry( entry_with_header.entry.clone(), None, validation_data, &context - )) + ).await .map_err(|err| { if let ValidationError::UnresolvedDependencies(dependencies) = &err { log_debug!(context, "workflow/hold_entry: {} could not be validated due to unresolved dependencies and will be tried later. List of missing dependencies: {:?}", @@ -93,7 +94,7 @@ pub async fn hold_entry_workflow( ); // 3. If valid store the entry in the local DHT shard - await!(hold_entry(entry_with_header, context.clone()))?; + hold_entry(entry_with_header, context.clone()).await?; log_debug!(context, "workflow/hold_entry: HOLDING: {}", diff --git a/core/src/workflows/hold_entry_remove.rs b/core/src/workflows/hold_entry_remove.rs index 3ec89d0f01..a2e55c1a10 100644 --- a/core/src/workflows/hold_entry_remove.rs +++ b/core/src/workflows/hold_entry_remove.rs @@ -23,19 +23,20 @@ pub async fn hold_remove_workflow( context: Arc, ) -> Result<(), HolochainError> { // 1. Get hold of validation package - let maybe_validation_package = await!(validation_package(entry_with_header, context.clone())) + let maybe_validation_package = validation_package(entry_with_header, context.clone()) + .await .map_err(|err| { - let message = "Could not get validation package from source! -> Add to pending..."; - log_debug!(context, "workflow/hold_remove: {}", message); - log_debug!(context, "workflow/hold_remove: Error was: {:?}", err); - add_pending_validation( - entry_with_header.to_owned(), - Vec::new(), - ValidatingWorkflow::RemoveEntry, - context.clone(), - ); - HolochainError::ValidationPending - })?; + let message = "Could not get validation package from source! -> Add to pending..."; + log_debug!(context, "workflow/hold_remove: {}", message); + log_debug!(context, "workflow/hold_remove: Error was: {:?}", err); + add_pending_validation( + entry_with_header.to_owned(), + Vec::new(), + ValidatingWorkflow::RemoveEntry, + context.clone(), + ); + HolochainError::ValidationPending + })?; let validation_package = maybe_validation_package .ok_or_else(|| "Could not get validation package from source".to_string())?; @@ -46,12 +47,12 @@ pub async fn hold_remove_workflow( }; // 3. Validate the entry - await!(validate_entry( + validate_entry( entry_with_header.entry.clone(), None, validation_data, &context - )) + ).await .map_err(|err| { if let ValidationError::UnresolvedDependencies(dependencies) = &err { log_debug!(context, "workflow/hold_remove: Entry removal could not be validated due to unresolved dependencies and will be tried later. List of missing dependencies: {:?}", dependencies); @@ -76,9 +77,10 @@ pub async fn hold_remove_workflow( let deleted_entry_address = deletion_entry.clone().deleted_entry_address(); // 3. If valid store the entry in the local DHT shard - await!(remove_entry( + remove_entry( &context.clone(), deleted_entry_address, entry_with_header.entry.address().clone(), - )) + ) + .await } diff --git a/core/src/workflows/hold_entry_update.rs b/core/src/workflows/hold_entry_update.rs index ad079ab5c8..ea259800d3 100644 --- a/core/src/workflows/hold_entry_update.rs +++ b/core/src/workflows/hold_entry_update.rs @@ -24,7 +24,8 @@ pub async fn hold_update_workflow( let EntryWithHeader { entry, header } = entry_with_header; // 1. Get hold of validation package - let maybe_validation_package = await!(validation_package(&entry_with_header, context.clone())) + let maybe_validation_package = validation_package(&entry_with_header, context.clone()) + .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; log_debug!(context, "workflow/hold_update: {}", message); @@ -52,12 +53,12 @@ pub async fn hold_update_workflow( }; // 3. Validate the entry - await!(validate_entry( + validate_entry( entry.clone(), Some(link.clone()), validation_data, &context - )) + ).await .map_err(|err| { if let ValidationError::UnresolvedDependencies(dependencies) = &err { log_debug!(context, "workflow/hold_update: Entry update could not be validated due to unresolved dependencies and will be tried later. List of missing dependencies: {:?}", dependencies); @@ -79,11 +80,7 @@ pub async fn hold_update_workflow( })?; // 3. If valid store the entry in the local DHT shard - await!(update_entry( - &context.clone(), - link, - entry.address().clone() - ))?; + update_entry(&context.clone(), link, entry.address().clone()).await?; Ok(()) } diff --git a/core/src/workflows/hold_link.rs b/core/src/workflows/hold_link.rs index d991e6540f..db29d5452f 100644 --- a/core/src/workflows/hold_link.rs +++ b/core/src/workflows/hold_link.rs @@ -32,7 +32,8 @@ pub async fn hold_link_workflow( log_debug!(context, "workflow/hold_link: {:?}", link); log_debug!(context, "workflow/hold_link: getting validation package..."); // 1. Get hold of validation package - let maybe_validation_package = await!(validation_package(&entry_with_header, context.clone())) + let maybe_validation_package = validation_package(&entry_with_header, context.clone()) + .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; log_debug!(context, "workflow/hold_link: {}", message); @@ -66,12 +67,12 @@ pub async fn hold_link_workflow( // 3. Validate the entry log_debug!(context, "workflow/hold_link: validate..."); - await!(validate_entry( + validate_entry( entry_with_header.entry.clone(), None, validation_data, &context - )) + ).await .map_err(|err| { if let ValidationError::UnresolvedDependencies(dependencies) = &err { log_debug!(context, "workflow/hold_link: Link could not be validated due to unresolved dependencies and will be tried later. List of missing dependencies: {:?}", dependencies); @@ -94,12 +95,16 @@ pub async fn hold_link_workflow( log_debug!(context, "workflow/hold_link: is valid!"); // 3. If valid store the entry in the local DHT shard - await!(add_link(&link_add, &context))?; + add_link(&link_add, &context).await?; log_debug!(context, "workflow/hold_link: added! {:?}", link); //4. store link_add entry so we have all we need to respond to get links queries without any other network look-up - await!(hold_entry_workflow(&entry_with_header, context.clone()))?; - log_debug!(context, "workflow/hold_entry: added! {:?}", entry_with_header); + hold_entry_workflow(&entry_with_header, context.clone()).await?; + log_debug!( + context, + "workflow/hold_entry: added! {:?}", + entry_with_header + ); //5. Link has been added to EAV and LinkAdd Entry has been stored on the dht Ok(()) diff --git a/core/src/workflows/mod.rs b/core/src/workflows/mod.rs index 4a58f84667..9107b7e9da 100644 --- a/core/src/workflows/mod.rs +++ b/core/src/workflows/mod.rs @@ -69,11 +69,12 @@ async fn try_make_local_validation_package( if overlapping_provenance.is_some() { // We authored this entry, so lets build the validation package here and now: - await!(build_validation_package( + build_validation_package( &entry_with_header.entry, context.clone(), entry_with_header.header.provenances(), - )) + ) + .await } else { Err(HolochainError::ErrorGeneric(String::from( "Can't create validation package locally", @@ -91,16 +92,12 @@ async fn validation_package( context: Arc, ) -> Result, HolochainError> { // 1. Try to construct it locally: - if let Ok(package) = await!(try_make_local_validation_package( - &entry_with_header, - context.clone() - )) { + if let Ok(package) = + try_make_local_validation_package(&entry_with_header, context.clone()).await + { Ok(Some(package)) } else { // If that is not possible, get the validation package from source - await!(get_validation_package( - entry_with_header.header.clone(), - &context - )) + get_validation_package(entry_with_header.header.clone(), &context).await } } diff --git a/core/src/workflows/remove_link.rs b/core/src/workflows/remove_link.rs index d3f018c9c3..550e684054 100644 --- a/core/src/workflows/remove_link.rs +++ b/core/src/workflows/remove_link.rs @@ -35,7 +35,8 @@ pub async fn remove_link_workflow( log_debug!(context, "workflow/remove_link: getting validation package..." ); - let maybe_validation_package = await!(validation_package(&entry_with_header, context.clone())) + let maybe_validation_package = validation_package(&entry_with_header, context.clone()) + .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; log_debug!(context, "workflow/remove_link: {}", message); @@ -61,12 +62,12 @@ pub async fn remove_link_workflow( // 3. Validate the entry log_debug!(context, "workflow/remove_link: validate..."); - await!(validate_entry( + validate_entry( entry_with_header.entry.clone(), None, validation_data, &context - )) + ).await .map_err(|err| { if let ValidationError::UnresolvedDependencies(dependencies) = &err { log_debug!(context, "workflow/remove_link: Link could not be validated due to unresolved dependencies and will be tried later. List of missing dependencies: {:?}", dependencies); @@ -90,12 +91,16 @@ pub async fn remove_link_workflow( log_debug!(context, "workflow/remove_link: is valid!"); // 3. If valid store remove the entry in the local DHT shard - await!(remove_link(&entry_with_header.entry, &context))?; + remove_link(&entry_with_header.entry, &context).await?; log_debug!(context, "workflow/remove_link: added! {:?}", link); //4. store link_remove entry so we have all we need to respond to get links queries without any other network look-up``` - await!(hold_entry_workflow(&entry_with_header, context.clone()))?; - log_debug!(context, "workflow/hold_entry: added! {:?}", entry_with_header); + hold_entry_workflow(&entry_with_header, context.clone()).await?; + log_debug!( + context, + "workflow/hold_entry: added! {:?}", + entry_with_header + ); Ok(()) } diff --git a/core/src/workflows/respond_validation_package_request.rs b/core/src/workflows/respond_validation_package_request.rs index d6fdd7ba63..6b6eaa9051 100644 --- a/core/src/workflows/respond_validation_package_request.rs +++ b/core/src/workflows/respond_validation_package_request.rs @@ -21,12 +21,9 @@ pub async fn respond_validation_package_request( ) { let maybe_validation_package = match get_entry_from_agent_chain(&context, &requested_entry_address) { - Ok(Some(entry)) => await!(build_validation_package( - &entry, - context.clone(), - provenances - )) - .ok(), + Ok(Some(entry)) => build_validation_package(&entry, context.clone(), provenances) + .await + .ok(), _ => None, };