From 98ea160253756c593d21e9e1f87a1669025f34e9 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Mon, 11 Nov 2019 12:18:50 +1100 Subject: [PATCH 01/79] Add incomplete work on chain-pair, discontinuing for now. --- crates/core/src/action.rs | 6 +-- crates/core/src/agent/state.rs | 10 ++--- crates/core/src/consistency.rs | 4 +- crates/core/src/network/entry_with_header.rs | 43 ------------------- crates/core/src/network/mod.rs | 2 +- .../network/reducers/publish_header_entry.rs | 4 +- 6 files changed, 13 insertions(+), 56 deletions(-) delete mode 100644 crates/core/src/network/entry_with_header.rs diff --git a/crates/core/src/action.rs b/crates/core/src/action.rs index 239d4f3ee9..15a12b13f9 100644 --- a/crates/core/src/action.rs +++ b/crates/core/src/action.rs @@ -3,7 +3,7 @@ use crate::{ network::{ direct_message::DirectMessage, entry_aspect::EntryAspect, - entry_with_header::EntryWithHeader, + chain_pair::ChainPair, query::{GetLinksNetworkQuery, NetworkQueryResult}, state::NetworkState, }, @@ -113,14 +113,14 @@ pub enum Action { // ------------- /// Adds an entry to the local DHT shard. /// Does not validate, assumes entry is valid. - Hold(EntryWithHeader), + Hold(ChainPair), /// Adds a link to the local DHT shard's meta/EAV storage /// Does not validate, assumes link is valid. AddLink(LinkData), //action for updating crudstatus - CrudStatus((EntryWithHeader, CrudStatus)), + CrudStatus((ChainPair, CrudStatus)), //Removes a link for the local DHT RemoveLink(Entry), diff --git a/crates/core/src/agent/state.rs b/crates/core/src/agent/state.rs index a6f31cbc83..4734248087 100644 --- a/crates/core/src/agent/state.rs +++ b/crates/core/src/agent/state.rs @@ -1,7 +1,7 @@ use crate::{ action::{Action, ActionWrapper, AgentReduceFn}, agent::chain_store::{ChainStore, ChainStoreIterator}, - network::entry_with_header::EntryWithHeader, + network::chain_pair::ChainPair, state::State, }; use holochain_persistence_api::cas::content::{Address, AddressableContent, Content}; @@ -29,8 +29,8 @@ use std::{ }; /// The state-slice for the Agent. -/// Holds the agent's source chain and keys. -#[derive(Clone, Debug, PartialEq)] +///   qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq1 s the agent's source chain and keys. +#[derive(Clone, Debug, PartialEq)] pub struct AgentState { /// every action and the result of that action // @TODO this will blow up memory, implement as some kind of dropping/FIFO with a limit? @@ -219,11 +219,11 @@ pub fn create_new_chain_header( pub fn create_entry_with_header_for_header( root_state: &StateWrapper, chain_header: ChainHeader, -) -> Result { +) -> Result { let entry = Entry::ChainHeader(chain_header); let header = create_new_chain_header(&entry, &root_state.agent(), &root_state, &None, &Vec::new())?; - Ok(EntryWithHeader { entry, header }) + ChainPair::new(header, entry) } /// Do a Commit Action against an agent state. diff --git a/crates/core/src/consistency.rs b/crates/core/src/consistency.rs index 1a020ad3d4..ccb7eaeafd 100644 --- a/crates/core/src/consistency.rs +++ b/crates/core/src/consistency.rs @@ -1,6 +1,6 @@ use crate::{ action::Action, context::Context, entry::CanPublish, - network::entry_with_header::EntryWithHeader, nucleus::ZomeFnCall, + network::chain_pair::ChainPair, nucleus::ZomeFnCall, }; use holochain_core_types::{agent::AgentId, entry::Entry, link::link_data::LinkData}; use holochain_persistence_api::cas::content::{Address, AddressableContent}; @@ -161,7 +161,7 @@ impl ConsistencyModel { None }) } - Action::Hold(EntryWithHeader { entry, .. }) => { + Action::Hold(ChainPair(.., header)) => { Some(ConsistencySignal::new_terminal(Hold(entry.address()))) } Action::UpdateEntry((old, new)) => Some(ConsistencySignal::new_terminal( diff --git a/crates/core/src/network/entry_with_header.rs b/crates/core/src/network/entry_with_header.rs deleted file mode 100644 index 34a80041cf..0000000000 --- a/crates/core/src/network/entry_with_header.rs +++ /dev/null @@ -1,43 +0,0 @@ -use crate::{ - agent::find_chain_header, - state::{State, StateWrapper}, -}; -use holochain_core_types::{chain_header::ChainHeader, entry::Entry, error::HolochainError}; -use holochain_persistence_api::cas::content::Address; -use std::convert::TryInto; - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct EntryWithHeader { - pub entry: Entry, - pub header: ChainHeader, -} - -impl EntryWithHeader { - pub fn new(entry: Entry, header: ChainHeader) -> EntryWithHeader { - EntryWithHeader { entry, header } - } -} - -fn fetch_entry_from_cas(address: &Address, state: &State) -> Result { - let json = state - .agent() - .chain_store() - .content_storage() - .read()? - .fetch(address)? - .ok_or_else(|| HolochainError::from("Entry not found"))?; - let s: Entry = json.try_into()?; - Ok(s) -} - -pub fn fetch_entry_with_header( - address: &Address, - state: &State, -) -> Result { - let entry = fetch_entry_from_cas(address, state)?; - - let header = find_chain_header(&entry, &StateWrapper::from(state.clone())) - .ok_or_else(|| HolochainError::from("No header found for entry"))?; - - Ok(EntryWithHeader::new(entry, header)) -} diff --git a/crates/core/src/network/mod.rs b/crates/core/src/network/mod.rs index 40bb6b0caf..0f402b871a 100644 --- a/crates/core/src/network/mod.rs +++ b/crates/core/src/network/mod.rs @@ -1,6 +1,6 @@ pub mod actions; pub mod direct_message; -pub mod entry_with_header; +pub mod chain_pair; pub mod handler; pub mod reducers; pub mod state; diff --git a/crates/core/src/network/reducers/publish_header_entry.rs b/crates/core/src/network/reducers/publish_header_entry.rs index 381bc4f482..2e4e076cfa 100644 --- a/crates/core/src/network/reducers/publish_header_entry.rs +++ b/crates/core/src/network/reducers/publish_header_entry.rs @@ -4,7 +4,7 @@ use crate::{ network::{ actions::ActionResponse, entry_aspect::EntryAspect, - entry_with_header::{fetch_entry_with_header, EntryWithHeader}, + entry_with_header::{fetch_entry_with_header, ChainPair}, reducers::{publish::entry_data_to_entry_aspect_data, send}, state::NetworkState, }, @@ -26,7 +26,7 @@ fn publish_header( root_state: &State, chain_header: ChainHeader, ) -> Result<(), HolochainError> { - let EntryWithHeader { entry, header } = + let chain_pair = create_entry_with_header_for_header(&StateWrapper::from(root_state.clone()), chain_header)?; send( network_state, From c5be66395c9853be4ece4ff3d2d2ea3af48e014a Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Mon, 18 Nov 2019 17:29:21 +1100 Subject: [PATCH 02/79] Add more work, still incomplete --- crates/core/src/agent/state.rs | 4 +- crates/core/src/dht/actions/hold.rs | 8 ++-- crates/core/src/dht/dht_reducers.rs | 4 +- crates/core/src/dht/dht_store.rs | 20 ++++++---- crates/core/src/network/handler/store.rs | 37 +++++++++++-------- .../nucleus/actions/add_pending_validation.rs | 6 +-- .../src/scheduled_jobs/pending_validations.rs | 2 +- crates/core/src/workflows/hold_entry.rs | 6 +-- crates/core/src/workflows/mod.rs | 20 +++++----- 9 files changed, 59 insertions(+), 48 deletions(-) diff --git a/crates/core/src/agent/state.rs b/crates/core/src/agent/state.rs index 4734248087..dd09d46f6a 100644 --- a/crates/core/src/agent/state.rs +++ b/crates/core/src/agent/state.rs @@ -29,8 +29,8 @@ use std::{ }; /// The state-slice for the Agent. -///   qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq1 s the agent's source chain and keys. -#[derive(Clone, Debug, PartialEq)] +/// Hold's the agent's source chain and keys. +#[derive(Clone, Debug, PartialEq)]q pub struct AgentState { /// every action and the result of that action // @TODO this will blow up memory, implement as some kind of dropping/FIFO with a limit? diff --git a/crates/core/src/dht/actions/hold.rs b/crates/core/src/dht/actions/hold.rs index 57684dbc7b..2076aabd24 100644 --- a/crates/core/src/dht/actions/hold.rs +++ b/crates/core/src/dht/actions/hold.rs @@ -2,7 +2,7 @@ use crate::{ action::{Action, ActionWrapper}, context::Context, instance::dispatch_action, - network::entry_with_header::EntryWithHeader, + network::chain_pair::ChainPair, }; use futures::{future::Future, task::Poll}; use holochain_core_types::error::HolochainError; @@ -10,11 +10,11 @@ use holochain_persistence_api::cas::content::{Address, AddressableContent}; use std::{pin::Pin, sync::Arc}; pub async fn hold_entry( - entry_wh: &EntryWithHeader, + chain_pair: &ChainPair, context: Arc, ) -> Result { - let address = entry_wh.entry.address(); - let action_wrapper = ActionWrapper::new(Action::Hold(entry_wh.to_owned())); + let address = chain_pair.entry.address(); + let action_wrapper = ActionWrapper::new(Action::Hold(chain_pair.to_owned())); dispatch_action(context.action_channel(), action_wrapper.clone()); HoldEntryFuture { context, address }.await } diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 04e285923a..80892eea95 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -3,7 +3,7 @@ use crate::{ action::{Action, ActionWrapper}, dht::dht_store::DhtStore, - network::entry_with_header::EntryWithHeader, + network::chain_pair::ChainPair, }; use std::sync::Arc; @@ -67,7 +67,7 @@ pub(crate) fn reduce_hold_entry( old_store: &DhtStore, action_wrapper: &ActionWrapper, ) -> Option { - let EntryWithHeader { entry, header } = unwrap_to!(action_wrapper.action() => Action::Hold); + let chain_pair { entry, header } = unwrap_to!(action_wrapper.action() => Action::Hold); let mut new_store = (*old_store).clone(); match reduce_store_entry_inner(&mut new_store, &entry) { Ok(()) => { diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index d370561c3d..eee6bfd611 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -217,14 +217,18 @@ impl DhtStore { entry: &Entry, header: &ChainHeader, ) -> Result<(), HolochainError> { - let eavi = EntityAttributeValueIndex::new( - &entry.address(), - &Attribute::EntryHeader, - &header.address(), - )?; - self.content_storage().write().unwrap().add(header)?; - self.meta_storage().write().unwrap().add_eavi(&eavi)?; - Ok(()) + if let Ok(chain_pair) = ChainPair::new(header, entry) { + let eavi = EntityAttributeValueIndex::new( + &entry.address(), + &Attribute::EntryHeader, + &header.address(), + )?; + self.content_storage().write().unwrap().add(header)?; + self.meta_storage().write().unwrap().add_eavi(&eavi)?; + Ok(()) + } else { + Err(_) + } } pub fn mark_entry_as_held(&mut self, entry: &Entry) { diff --git a/crates/core/src/network/handler/store.rs b/crates/core/src/network/handler/store.rs index 3652c90881..ce587db1b5 100644 --- a/crates/core/src/network/handler/store.rs +++ b/crates/core/src/network/handler/store.rs @@ -1,6 +1,6 @@ use crate::{ context::Context, - network::{entry_aspect::EntryAspect, entry_with_header::EntryWithHeader}, + network::{entry_aspect::EntryAspect, chain_pair::ChainPair}, workflows::{ hold_entry::hold_entry_workflow, hold_entry_remove::hold_remove_workflow, hold_entry_update::hold_update_workflow, hold_link::hold_link_workflow, @@ -25,20 +25,27 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc) { context, "net/handle: handle_store: Got EntryAspect::Content. processing..." ); - let entry_with_header = EntryWithHeader { entry, header }; - thread::Builder::new() - .name(format!( - "store_entry_content/{}", - ProcessUniqueId::new().to_string() - )) - .spawn(move || { - if let Err(err) = context - .block_on(hold_entry_workflow(&entry_with_header, context.clone())) - { - log_error!(context, "net/dht: {}", err); - } - }) - .expect("Could not spawn thread for storing EntryAspect::Content"); + + if let Ok(chain_pair) = ChainPair::new(header, entry) { + thread::Builder::new() + .name(format!( + "store_entry_content/{}", + ProcessUniqueId::new().to_string() + )) + .spawn(move || { + if let Err(err) = context + .block_on(hold_entry_workflow(&chain_pair, context.clone())) + { + log_error!(context, "net/dht: {}", err); + } + }) + .expect("Could not spawn thread for storing EntryAspect::Content"); + + } else if Err(err) { + log_error!(context, "net/handle: handle_store: Got EntryAspect::Content with non-matching entry and header", err) + } else { + unreachable!() + } } EntryAspect::Header(header) => { panic!(format!("unimplemented store aspect Header: {:?}", header)); diff --git a/crates/core/src/nucleus/actions/add_pending_validation.rs b/crates/core/src/nucleus/actions/add_pending_validation.rs index 854b722f6e..adddf85127 100644 --- a/crates/core/src/nucleus/actions/add_pending_validation.rs +++ b/crates/core/src/nucleus/actions/add_pending_validation.rs @@ -2,14 +2,14 @@ use crate::{ action::{Action, ActionWrapper}, context::Context, instance::dispatch_action, - network::entry_with_header::EntryWithHeader, + network::chain_pair::ChainPair, scheduled_jobs::pending_validations::{PendingValidationStruct, ValidatingWorkflow}, }; use holochain_persistence_api::cas::content::Address; use std::sync::Arc; pub fn add_pending_validation( - entry_with_header: EntryWithHeader, + chain_pair: ChainPair, dependencies: Vec
, workflow: ValidatingWorkflow, context: Arc, @@ -18,7 +18,7 @@ pub fn add_pending_validation( context.action_channel(), ActionWrapper::new(Action::AddPendingValidation(Arc::new( PendingValidationStruct { - entry_with_header, + chain_pair, dependencies, workflow, }, diff --git a/crates/core/src/scheduled_jobs/pending_validations.rs b/crates/core/src/scheduled_jobs/pending_validations.rs index b86ebae0f2..4207ff4b98 100644 --- a/crates/core/src/scheduled_jobs/pending_validations.rs +++ b/crates/core/src/scheduled_jobs/pending_validations.rs @@ -68,7 +68,7 @@ impl fmt::Display for ValidatingWorkflow { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, DefaultJson)] pub struct PendingValidationStruct { - pub entry_with_header: EntryWithHeader, + pub chain_pair: ChainPair, pub dependencies: Vec
, pub workflow: ValidatingWorkflow, } diff --git a/crates/core/src/workflows/hold_entry.rs b/crates/core/src/workflows/hold_entry.rs index 399122ed8c..fa9719e52f 100644 --- a/crates/core/src/workflows/hold_entry.rs +++ b/crates/core/src/workflows/hold_entry.rs @@ -1,7 +1,7 @@ use crate::{ context::Context, dht::actions::hold::hold_entry, - network::entry_with_header::EntryWithHeader, + network::chain_pair::ChainPair, nucleus::{ actions::add_pending_validation::add_pending_validation, validation::validate_entry, }, @@ -21,11 +21,11 @@ use holochain_persistence_api::cas::content::AddressableContent; use std::sync::Arc; pub async fn hold_entry_workflow( - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, context: Arc, ) -> Result<(), HolochainError> { // 1. Get hold of validation package - let maybe_validation_package = validation_package(&entry_with_header, context.clone()) + let maybe_validation_package = validation_package(&chain_pair, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 9107b7e9da..088c087c16 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -36,11 +36,11 @@ use std::sync::Arc; /// Checks the DNA's validation package definition for the given entry type. /// Fails if this entry type needs more than just the header for validation. async fn try_make_local_validation_package( - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, context: Arc, ) -> Result { - let entry = &entry_with_header.entry; - let entry_header = &entry_with_header.header; + let entry = &chain_pair.entry(); + let entry_header = &chain_pair.header(); let validation_package_definition = get_validation_package_definition(entry, context.clone()) .and_then(|callback_result| match callback_result { @@ -61,8 +61,8 @@ async fn try_make_local_validation_package( _ => { let agent = context.state()?.agent().get_agent()?; - let overlapping_provenance = entry_with_header - .header + let overlapping_provenance = chain_pair + .header() .provenances() .iter() .find(|p| p.source() == agent.address()); @@ -70,9 +70,9 @@ 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: build_validation_package( - &entry_with_header.entry, + &chain_pair.entry(), context.clone(), - entry_with_header.header.provenances(), + chain_pair.header().provenances(), ) .await } else { @@ -88,16 +88,16 @@ async fn try_make_local_validation_package( /// First tries to create it locally and if that fails will try to get the /// validation package from the source. async fn validation_package( - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, context: Arc, ) -> Result, HolochainError> { // 1. Try to construct it locally: if let Ok(package) = - try_make_local_validation_package(&entry_with_header, context.clone()).await + try_make_local_validation_package(&chain_pair, context.clone()).await { Ok(Some(package)) } else { // If that is not possible, get the validation package from source - get_validation_package(entry_with_header.header.clone(), &context).await + get_validation_package(chain_pair.header().clone(), &context).await } } From 2a2aa67f891eeac64a46e482d994101397252a34 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Mon, 18 Nov 2019 20:01:40 +1100 Subject: [PATCH 03/79] More work on reworking entry_with_header and EntryWithHeader and dependent code to use chain_pair and ChainPair, add custom error variant HeaderEntryMismatch, fixing some format errors --- crates/conductor_lib/src/config.rs | 4 +- crates/conductor_lib/src/error.rs | 1 - crates/conductor_lib/src/holochain.rs | 2 +- crates/conductor_lib/src/keystore.rs | 1 - crates/core/src/agent/state.rs | 6 +- crates/core/src/consistency.rs | 2 +- crates/core/src/dht/dht_reducers.rs | 17 +++--- crates/core/src/dht/dht_store.rs | 29 ++++++---- crates/core/src/network/handler/mod.rs | 57 ++++++++++++------- .../reducers/add_pending_validation.rs | 14 ++--- .../src/scheduled_jobs/pending_validations.rs | 18 +++--- crates/core/src/workflows/hold_entry.rs | 2 +- crates/core/src/workflows/mod.rs | 2 +- crates/core_types/src/bits_n_pieces.rs | 1 - crates/core_types/src/chain_header.rs | 1 - crates/core_types/src/eav/eavi.rs | 1 - crates/core_types/src/entry/entry_type.rs | 1 - crates/core_types/src/error/mod.rs | 16 +++++- crates/dpki/src/keypair.rs | 1 - crates/dpki/src/password_encryption.rs | 1 - crates/hdk/tests/links.rs | 2 +- crates/hdk/tests/misc.rs | 7 ++- .../src/dht/bbdht/dynamodb/account/mod.rs | 1 - .../src/dht/bbdht/dynamodb/api/agent/read.rs | 1 - .../src/dht/bbdht/dynamodb/api/agent/write.rs | 1 - .../src/dht/bbdht/dynamodb/api/item/read.rs | 1 - .../src/dht/bbdht/dynamodb/api/item/write.rs | 1 - .../dht/bbdht/dynamodb/api/table/create.rs | 1 - .../dht/bbdht/dynamodb/api/table/delete.rs | 1 - .../dht/bbdht/dynamodb/api/table/describe.rs | 1 - .../src/dht/bbdht/dynamodb/api/table/exist.rs | 1 - .../src/dht/bbdht/dynamodb/client/mod.rs | 1 - .../src/dht/bbdht/dynamodb/schema/mod.rs | 1 - .../src/workflow/from_client/bootstrap.rs | 1 - .../src/workflow/from_client/leave_space.rs | 1 - crates/wasm_utils/src/memory/allocation.rs | 1 - crates/wasm_utils/src/memory/read.rs | 1 - crates/wasm_utils/src/memory/ribosome.rs | 1 - crates/wasm_utils/src/memory/stack.rs | 1 - 39 files changed, 108 insertions(+), 95 deletions(-) diff --git a/crates/conductor_lib/src/config.rs b/crates/conductor_lib/src/config.rs index 58e538caf9..d6e3668d15 100644 --- a/crates/conductor_lib/src/config.rs +++ b/crates/conductor_lib/src/config.rs @@ -1376,7 +1376,9 @@ pub mod tests { path = "app3_spec_storage" {} - "#, bridges) + "#, + bridges + ) } #[test] diff --git a/crates/conductor_lib/src/error.rs b/crates/conductor_lib/src/error.rs index 2c64e4dfa3..04f82f0760 100644 --- a/crates/conductor_lib/src/error.rs +++ b/crates/conductor_lib/src/error.rs @@ -123,5 +123,4 @@ pub mod tests { HolochainInstanceError::from(HolochainError::DnaMissing), ); } - } diff --git a/crates/conductor_lib/src/holochain.rs b/crates/conductor_lib/src/holochain.rs index 8bdfbcab64..277a020007 100644 --- a/crates/conductor_lib/src/holochain.rs +++ b/crates/conductor_lib/src/holochain.rs @@ -365,7 +365,7 @@ mod tests { #[test] fn can_instantiate() { - let mut dna = create_arbitrary_test_dna();; + let mut dna = create_arbitrary_test_dna(); dna.name = "TestApp".to_string(); let (context, _test_logger, _) = test_context("bob"); let result = Holochain::new(dna.clone(), context.clone()); diff --git a/crates/conductor_lib/src/keystore.rs b/crates/conductor_lib/src/keystore.rs index 7e58b7322c..2971bfd90d 100644 --- a/crates/conductor_lib/src/keystore.rs +++ b/crates/conductor_lib/src/keystore.rs @@ -834,5 +834,4 @@ pub mod tests { "VX4j1zRvIT7FojcTsqJJfu81NU1bUgiKxqWZOl/bCR4=".to_string() ); } - } diff --git a/crates/core/src/agent/state.rs b/crates/core/src/agent/state.rs index dd09d46f6a..594409913e 100644 --- a/crates/core/src/agent/state.rs +++ b/crates/core/src/agent/state.rs @@ -30,7 +30,7 @@ use std::{ /// The state-slice for the Agent. /// Hold's the agent's source chain and keys. -#[derive(Clone, Debug, PartialEq)]q +#[derive(Clone, Debug, PartialEq)] pub struct AgentState { /// every action and the result of that action // @TODO this will blow up memory, implement as some kind of dropping/FIFO with a limit? @@ -213,10 +213,10 @@ pub fn create_new_chain_header( )) } -/// Create an entry-with-header for a header. +/// Creates a `ChainPair` for a `ChainHeader`. /// Since published headers are treated as entries, the header must also /// have its own header! -pub fn create_entry_with_header_for_header( +pub fn create_chain_pair_for_header( root_state: &StateWrapper, chain_header: ChainHeader, ) -> Result { diff --git a/crates/core/src/consistency.rs b/crates/core/src/consistency.rs index ccb7eaeafd..42f6f27b31 100644 --- a/crates/core/src/consistency.rs +++ b/crates/core/src/consistency.rs @@ -178,7 +178,7 @@ impl ConsistencyModel { )), Action::AddPendingValidation(validation) => { - let address = validation.entry_with_header.entry.address(); + let address = validation.chain_pair.entry.address(); Some(ConsistencySignal::new_pending( AddPendingValidation(address.clone()), Source, diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 80892eea95..ba09d806dd 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -164,7 +164,7 @@ pub mod tests { dht_store::create_get_links_eavi_query, }, instance::tests::test_context, - network::entry_with_header::EntryWithHeader, + network::chain_pair::ChainPair, state::test_store, }; use holochain_core_types::{ @@ -185,13 +185,10 @@ pub mod tests { let storage = &store.dht().content_storage().clone(); let sys_entry = test_sys_entry(); - let entry_wh = EntryWithHeader { - entry: sys_entry.clone(), - header: test_chain_header(), - }; + let chain_pair = ChainPair::new(test_chain_header(), sys_entry.clone()); let new_dht_store = - reduce_hold_entry(&store.dht(), &ActionWrapper::new(Action::Hold(entry_wh))) + reduce_hold_entry(&store.dht(), &ActionWrapper::new(Action::Hold(chain_pair))) .expect("there should be a new store for committing a sys entry"); assert_eq!( @@ -416,11 +413,11 @@ pub mod tests { let store = test_store(context.clone()); let entry = test_entry(); - let entry_wh = EntryWithHeader { - entry: entry.clone(), + let chain_pair = ChainPair::new( header: test_chain_header(), - }; - let action_wrapper = ActionWrapper::new(Action::Hold(entry_wh.clone())); + entry: entry.clone(), + ); + let action_wrapper = ActionWrapper::new(Action::Hold(chain_pair.clone())); store.reduce(action_wrapper); diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index eee6bfd611..36da14e0bd 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -217,17 +217,24 @@ impl DhtStore { entry: &Entry, header: &ChainHeader, ) -> Result<(), HolochainError> { - if let Ok(chain_pair) = ChainPair::new(header, entry) { - let eavi = EntityAttributeValueIndex::new( - &entry.address(), - &Attribute::EntryHeader, - &header.address(), - )?; - self.content_storage().write().unwrap().add(header)?; - self.meta_storage().write().unwrap().add_eavi(&eavi)?; - Ok(()) - } else { - Err(_) + match ChainPair::new(header, entry) { + Ok(_chain_pair) => { + let eavi = EntityAttributeValueIndex::new( + &entry.address(), + &Attribute::EntryHeader, + &header.address(), + )?; + self.content_storage().write().unwrap().add(header)?; + self.meta_storage().write().unwrap().add_eavi(&eavi)?; + Ok(()) + Err(header_entry_mismatch as HeaderEntryMismatch(.., err_msg)) => { + let add_err_msg = format!( + "Tried to add entry {} and header {} to the CAS and EAV, respectively", + entry, header, + ); + err_msg = concat!(err_msg, add_err_msg); + Err(HeaderEntryMismatch(.., err_msg) + } } } diff --git a/crates/core/src/network/handler/mod.rs b/crates/core/src/network/handler/mod.rs index f83af2eeaf..c25cbffc69 100644 --- a/crates/core/src/network/handler/mod.rs +++ b/crates/core/src/network/handler/mod.rs @@ -1,4 +1,4 @@ -use crate::agent::state::create_entry_with_header_for_header; +use crate::agent::state::create_chain_pair_for_header; use holochain_logging::prelude::*; pub mod fetch; pub mod lists; @@ -11,8 +11,8 @@ use crate::{ entry::CanPublish, network::{ direct_message::DirectMessage, + chain_pair::ChainPair, entry_aspect::EntryAspect, - entry_with_header::EntryWithHeader, handler::{ fetch::*, lists::{handle_get_authoring_list, handle_get_gossip_list}, @@ -302,19 +302,34 @@ fn get_content_aspect( }); // If we have found a header for the requested entry in the chain... - let maybe_entry_with_header = match maybe_chain_header { - Some((header, true)) => Some(create_entry_with_header_for_header(&*state, header)?), + let maybe_chain_pair = match maybe_chain_header { + Some((header, true)) => Some(create_chain_pair_for_header(&*state, header)?), Some((header, false)) => { // ... we can just get the content from the chain CAS - Some(EntryWithHeader { - entry: get_entry_from_cas( - &state.agent().chain_store().content_storage(), - header.entry_address(), - )? - .expect("Could not find entry in chain CAS, but header is chain"), - header, - }) - } + match get_entry_from_cas( + &state.agent().chain_store().content_storage(), + header.entry_address(), + ) { + Ok(Some(entry)) => {Some(ChainPair::new(header, entry))}, + Ok(None) => { + let err_message = format!( + "net/fetch/get_content_aspect: no entry associated with address {} could be + found in the CAS, but the header {} is in the chain", + entry, header + ); + log_error!(context, "{}", err_message); + return HolochainError::ErrorGeneric(err_message); + }, + Err(err) => { + let err_message = format!( + "net/fetch/get_content_aspect: got an error while trying to get an entry associated with the address {}from the CAS. The header {} is in the chain. Error: {:?}", + entry, header, err + ); + log_error!(context, "{}", err_message); + return HolochainError::ErrorGeneric(err_message); + }, + } + }, None => { // ... but if we didn't author that entry, let's see if we have it in the DHT cas: if let Some(entry) = get_entry_from_cas(&state.dht().content_storage(), entry_address)? @@ -333,10 +348,10 @@ fn get_content_aspect( // TODO: this is just taking the first header.. // We should actually transform all headers into EntryAspect::Headers and just the first one // into an EntryAspect content (What about ordering? Using the headers timestamp?) - Some(EntryWithHeader { + Some(ChainPair::new( + headers[0].clone(), entry, - header: headers[0].clone(), - }) + )) } else { debug!( "GET CONTENT ASPECT: entry found in cas, but then couldn't find a header" @@ -350,17 +365,17 @@ fn get_content_aspect( } }; - let entry_with_header = maybe_entry_with_header.ok_or(HolochainError::EntryNotFoundLocally)?; + let chain_pair = maybe_chain_pair.ok_or(HolochainError::EntryNotFoundLocally)?; - let _ = entry_with_header - .entry + let _ = chain_pair + .entry() .entry_type() .can_publish(&context) .ok_or(HolochainError::EntryIsPrivate)?; Ok(EntryAspect::Content( - entry_with_header.entry, - entry_with_header.header, + chain_pair.entry(), + chain_pair.header(), )) } diff --git a/crates/core/src/nucleus/reducers/add_pending_validation.rs b/crates/core/src/nucleus/reducers/add_pending_validation.rs index 457595e3e9..f337bd6851 100644 --- a/crates/core/src/nucleus/reducers/add_pending_validation.rs +++ b/crates/core/src/nucleus/reducers/add_pending_validation.rs @@ -17,7 +17,7 @@ pub fn reduce_add_pending_validation( ) { let action = action_wrapper.action(); let pending = unwrap_to!(action => Action::AddPendingValidation); - let address = pending.entry_with_header.entry.address(); + let address = pending.chain_pair.entry().address(); let workflow = pending.workflow.clone(); state.pending_validations.insert( PendingValidationKey::new(address, workflow), @@ -30,7 +30,7 @@ pub mod tests { use super::*; use crate::{ instance::tests::test_context, - network::entry_with_header::EntryWithHeader, + network::chain_pair::ChainPair, nucleus::state::{tests::test_nucleus_state, PendingValidationKey}, scheduled_jobs::pending_validations::{PendingValidationStruct, ValidatingWorkflow}, state::test_store, @@ -46,14 +46,14 @@ pub mod tests { let root_state = test_store(context); let entry = Entry::App("package_entry".into(), RawString::from("test value").into()); - let entry_with_header = EntryWithHeader { - entry: entry.clone(), - header: test_chain_header(), - }; + let chain_pair = ChainPair::new( + test_chain_header(), + entry.clone() + ); let action_wrapper = ActionWrapper::new(Action::AddPendingValidation(Arc::new( PendingValidationStruct { - entry_with_header, + chain_pair, dependencies: Vec::new(), workflow: ValidatingWorkflow::HoldEntry, }, diff --git a/crates/core/src/scheduled_jobs/pending_validations.rs b/crates/core/src/scheduled_jobs/pending_validations.rs index 4207ff4b98..9b7fb88e12 100644 --- a/crates/core/src/scheduled_jobs/pending_validations.rs +++ b/crates/core/src/scheduled_jobs/pending_validations.rs @@ -1,6 +1,6 @@ use crate::{ context::Context, - network::entry_with_header::EntryWithHeader, + network::chain_pair::ChainPair, nucleus::actions::remove_pending_validation::remove_pending_validation, workflows::{hold_entry::hold_entry_workflow, hold_link::hold_link_workflow}, }; @@ -82,29 +82,29 @@ fn retry_validation(pending: PendingValidation, context: Arc) { .spawn(move || { let result = match pending.workflow { ValidatingWorkflow::HoldLink => context.block_on(hold_link_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::HoldEntry => context.block_on(hold_entry_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::RemoveLink => context.block_on(remove_link_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::UpdateEntry => context.block_on(hold_update_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::RemoveEntry => context.block_on(hold_remove_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), }; if Err(HolochainError::ValidationPending) != result { remove_pending_validation( - pending.entry_with_header.entry.address(), + pending.chain_pair.entry().address(), pending.workflow.clone(), &context, ); @@ -125,8 +125,8 @@ pub fn run_pending_validations(context: Arc) { log_debug!( context, "scheduled_jobs/run_pending_validations: found pending validation for {}: {}", - pending.entry_with_header.entry.entry_type(), - pending.entry_with_header.entry.address() + pending.chain_pair.entry().entry_type(), + pending.chain_pair.entry().address() ); retry_validation(pending.clone(), context.clone()); }); diff --git a/crates/core/src/workflows/hold_entry.rs b/crates/core/src/workflows/hold_entry.rs index fa9719e52f..fa4e5f01fe 100644 --- a/crates/core/src/workflows/hold_entry.rs +++ b/crates/core/src/workflows/hold_entry.rs @@ -32,7 +32,7 @@ pub async fn hold_entry_workflow( log_debug!(context, "workflow/hold_entry: {}", message); log_debug!(context, "workflow/hold_entry: Error was: {:?}", err); add_pending_validation( - entry_with_header.to_owned(), + chain_pair.to_owned(), Vec::new(), ValidatingWorkflow::HoldEntry, context.clone(), diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 088c087c16..46f212e63f 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -14,7 +14,7 @@ pub mod respond_validation_package_request; use crate::{ context::Context, network::{ - actions::get_validation_package::get_validation_package, entry_with_header::EntryWithHeader, + actions::get_validation_package::get_validation_package, chain_pair::ChainPair, }, nucleus::{ actions::build_validation_package::build_validation_package, diff --git a/crates/core_types/src/bits_n_pieces.rs b/crates/core_types/src/bits_n_pieces.rs index 126385c430..4d142a5c1e 100644 --- a/crates/core_types/src/bits_n_pieces.rs +++ b/crates/core_types/src/bits_n_pieces.rs @@ -123,5 +123,4 @@ pub mod tests { ), ); } - } diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index ed90405c85..29f18efb36 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -402,5 +402,4 @@ pub mod tests { .address(), ); } - } diff --git a/crates/core_types/src/eav/eavi.rs b/crates/core_types/src/eav/eavi.rs index 6d93da6d32..627b3a1556 100644 --- a/crates/core_types/src/eav/eavi.rs +++ b/crates/core_types/src/eav/eavi.rs @@ -432,5 +432,4 @@ pub mod tests { ) .is_err()); } - } diff --git a/crates/core_types/src/entry/entry_type.rs b/crates/core_types/src/entry/entry_type.rs index 715f65dbd3..b64e2f4059 100644 --- a/crates/core_types/src/entry/entry_type.rs +++ b/crates/core_types/src/entry/entry_type.rs @@ -252,5 +252,4 @@ pub mod tests { assert_eq!(type_str, &String::from(variant),); } } - } diff --git a/crates/core_types/src/error/mod.rs b/crates/core_types/src/error/mod.rs index 8080c9fb46..d4dfa61d09 100644 --- a/crates/core_types/src/error/mod.rs +++ b/crates/core_types/src/error/mod.rs @@ -7,6 +7,8 @@ mod ribosome_error; use self::HolochainError::*; pub use self::{dna_error::*, ribosome_error::*}; use futures::channel::oneshot::Canceled as FutureCanceled; +use holochain_core_types::{chain_header::ChainHeader, entry::Entry}; +use holochain_persistence_api::cas::content::Address; use holochain_json_api::{ error::{JsonError, JsonResult}, json::*, @@ -115,6 +117,7 @@ pub enum HolochainError { InitializationFailed(String), LifecycleError(String), DnaHashMismatch(HashString, HashString), + HeaderEntryMismatch(String, Address, Entry, ChainHeader, Address, Entry), EntryNotFoundLocally, EntryIsPrivate, List(Vec), @@ -162,6 +165,18 @@ impl fmt::Display for HolochainError { "Provided DNA hash does not match actual DNA hash! {} != {}", hash1, hash2 ), + HeaderEntryMismatch( + header_entry_address, + header_entry, + header, + entry_address, + entry, + err_msg. + ) => write!( + "Header/Entry mismatch. The address {} of the entry {} in the + header {} does not match the address {} of the entry {}. {}", + header_entry_address, header_entry, header, entry_address, entry, err_msg + ) EntryNotFoundLocally => write!(f, "The requested entry could not be found locally"), EntryIsPrivate => write!( f, @@ -447,5 +462,4 @@ mod tests { .to_string(), ); } - } diff --git a/crates/dpki/src/keypair.rs b/crates/dpki/src/keypair.rs index a15d4b0d5a..d45995a5c0 100755 --- a/crates/dpki/src/keypair.rs +++ b/crates/dpki/src/keypair.rs @@ -324,5 +324,4 @@ mod tests { let succeeded = sign_keys.verify(&mut message, &mut signature); assert!(!succeeded); } - } diff --git a/crates/dpki/src/password_encryption.rs b/crates/dpki/src/password_encryption.rs index 9c0f993ce7..95c89af290 100644 --- a/crates/dpki/src/password_encryption.rs +++ b/crates/dpki/src/password_encryption.rs @@ -212,5 +212,4 @@ pub(crate) mod tests { .unwrap(); assert!(hashed_password_c.compare(&mut hashed_password_b) == 0); } - } diff --git a/crates/hdk/tests/links.rs b/crates/hdk/tests/links.rs index 3c23ba83f7..818c1a5d7c 100644 --- a/crates/hdk/tests/links.rs +++ b/crates/hdk/tests/links.rs @@ -254,7 +254,7 @@ pub fn test_links_with_immediate_timeout() { let result = make_test_call(&mut hc, "my_entries_immediate_timeout", r#"{}"#); let expected_result: ZomeApiResult<()> = serde_json::from_str::>(&result.clone().unwrap().to_string()).unwrap(); - let zome_internal_error = generate_zome_internal_error(String::from(r#""Timeout""#));; + let zome_internal_error = generate_zome_internal_error(String::from(r#""Timeout""#)); assert_zome_internal_errors_equivalent(&expected_result.unwrap_err(), &zome_internal_error); } diff --git a/crates/hdk/tests/misc.rs b/crates/hdk/tests/misc.rs index 20a27a5aef..d345375991 100755 --- a/crates/hdk/tests/misc.rs +++ b/crates/hdk/tests/misc.rs @@ -460,7 +460,10 @@ fn show_env() { let dna = hc.context().unwrap().get_dna().unwrap(); let dna_address_string = dna.address().to_string(); let dna_address = dna_address_string.as_str(); - let format = format!(r#"{{"Ok":{{"dna_name":"TestApp","dna_address":"{}","agent_id":"{{\"nick\":\"show_env\",\"pub_sign_key\":\"HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i\"}}","agent_address":"HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i","cap_request":{{"cap_token":"QmSbEonVd9pmUxQqAS87a6CkdMPUsrjYLshW9eYz3wJkZ1","provenance":["HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i","FxhnQJzPu+TPqJHCtT2e5CNMky2YnnLXtABMJyNhx5SyztyeuKU/zxS4a1e8uKdPYT5N0ldCcLgpITeHfB7dAg=="]}},"properties":"{{}}"}}}}"#,dna_address); + let format = format!( + r#"{{"Ok":{{"dna_name":"TestApp","dna_address":"{}","agent_id":"{{\"nick\":\"show_env\",\"pub_sign_key\":\"HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i\"}}","agent_address":"HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i","cap_request":{{"cap_token":"QmSbEonVd9pmUxQqAS87a6CkdMPUsrjYLshW9eYz3wJkZ1","provenance":["HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i","FxhnQJzPu+TPqJHCtT2e5CNMky2YnnLXtABMJyNhx5SyztyeuKU/zxS4a1e8uKdPYT5N0ldCcLgpITeHfB7dAg=="]}},"properties":"{{}}"}}}}"#, + dna_address + ); let json_result = Ok(JsonString::from_json(&format)); let result = make_test_call(&mut hc, "show_env", r#"{}"#); @@ -481,7 +484,7 @@ fn test_signal() { recieved_signal == &UserSignal { name: String::from("test-signal"), - arguments: JsonString::from(r#"{"message":"test message"}"#) + arguments: JsonString::from(r#"{"message":"test message"}"#), } } _ => false, diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/account/mod.rs b/crates/sim1h/src/dht/bbdht/dynamodb/account/mod.rs index f0847cfa30..726d6e595b 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/account/mod.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/account/mod.rs @@ -44,5 +44,4 @@ pub mod tests { // fail to describe limits assert!(describe_limits(&log_context, &bad_client).is_err()); } - } diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/read.rs b/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/read.rs index 99dd5a3822..05060c1dea 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/read.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/read.rs @@ -96,5 +96,4 @@ pub mod tests { } } } - } diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/write.rs b/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/write.rs index 7daa2c38f2..314b2b2a78 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/write.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/write.rs @@ -76,5 +76,4 @@ pub mod tests { // touch agent assert!(touch_agent(&log_context, &local_client, &table_name, &agent_id).is_ok()); } - } diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/api/item/read.rs b/crates/sim1h/src/dht/bbdht/dynamodb/api/item/read.rs index 61990c2e57..aa6ab20dcc 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/api/item/read.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/api/item/read.rs @@ -76,5 +76,4 @@ pub mod tests { // get_item_by_address(&local_client, &table_name, &content.address()) // ); } - } diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/api/item/write.rs b/crates/sim1h/src/dht/bbdht/dynamodb/api/item/write.rs index 5e97a78b39..300f92fc8f 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/api/item/write.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/api/item/write.rs @@ -195,5 +195,4 @@ pub mod tests { assert!(ensure_content(&log_context, &local_client, &table_name, &content).is_ok()); } } - } diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/api/table/create.rs b/crates/sim1h/src/dht/bbdht/dynamodb/api/table/create.rs index bf7ca871da..3f63529096 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/api/table/create.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/api/table/create.rs @@ -248,5 +248,4 @@ pub mod test { assert!(ensure_cas_table(&log_context, &local_client, &table_name).is_ok()); } } - } diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/api/table/delete.rs b/crates/sim1h/src/dht/bbdht/dynamodb/api/table/delete.rs index fbb20e55d5..555243f03e 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/api/table/delete.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/api/table/delete.rs @@ -72,5 +72,4 @@ pub mod test { assert!(!table_exists(&log_context, &local_client, &table_name) .expect("could not check that the table exists")); } - } diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/api/table/describe.rs b/crates/sim1h/src/dht/bbdht/dynamodb/api/table/describe.rs index f38516aecd..6795a29e85 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/api/table/describe.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/api/table/describe.rs @@ -98,5 +98,4 @@ pub mod test { describe_table(&log_context, &local_client, &table_name), ); } - } diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/api/table/exist.rs b/crates/sim1h/src/dht/bbdht/dynamodb/api/table/exist.rs index e1836ac169..eb5f6acbb0 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/api/table/exist.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/api/table/exist.rs @@ -107,5 +107,4 @@ pub mod tests { assert!(!table_exists(&log_context, &local_client, &table_name) .expect("could not check if table exists")); } - } diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/client/mod.rs b/crates/sim1h/src/dht/bbdht/dynamodb/client/mod.rs index 6e1813289a..be22e03ea1 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/client/mod.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/client/mod.rs @@ -34,5 +34,4 @@ pub mod test { tracer(&log_context, "smoke test"); client(Region::SaEast1); } - } diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/schema/mod.rs b/crates/sim1h/src/dht/bbdht/dynamodb/schema/mod.rs index 781be65124..2d4170db15 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/schema/mod.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/schema/mod.rs @@ -122,5 +122,4 @@ pub mod test { result, ); } - } diff --git a/crates/sim1h/src/workflow/from_client/bootstrap.rs b/crates/sim1h/src/workflow/from_client/bootstrap.rs index d0c9cc7b84..18a5e3405a 100644 --- a/crates/sim1h/src/workflow/from_client/bootstrap.rs +++ b/crates/sim1h/src/workflow/from_client/bootstrap.rs @@ -62,5 +62,4 @@ pub mod tests { } }; } - } diff --git a/crates/sim1h/src/workflow/from_client/leave_space.rs b/crates/sim1h/src/workflow/from_client/leave_space.rs index 5c5de8ff01..9a1ebc2ca4 100644 --- a/crates/sim1h/src/workflow/from_client/leave_space.rs +++ b/crates/sim1h/src/workflow/from_client/leave_space.rs @@ -45,5 +45,4 @@ pub mod tests { } } } - } diff --git a/crates/wasm_utils/src/memory/allocation.rs b/crates/wasm_utils/src/memory/allocation.rs index 3bf38ec0e6..723ba88501 100644 --- a/crates/wasm_utils/src/memory/allocation.rs +++ b/crates/wasm_utils/src/memory/allocation.rs @@ -261,5 +261,4 @@ pub mod tests { .length(), ); } - } diff --git a/crates/wasm_utils/src/memory/read.rs b/crates/wasm_utils/src/memory/read.rs index fcc092f6d5..825e24cd7e 100644 --- a/crates/wasm_utils/src/memory/read.rs +++ b/crates/wasm_utils/src/memory/read.rs @@ -29,5 +29,4 @@ pub mod tests { assert_eq!(s, WasmAllocation::read_str_raw(ptr as *mut c_char),); } - } diff --git a/crates/wasm_utils/src/memory/ribosome.rs b/crates/wasm_utils/src/memory/ribosome.rs index daf2dcbc1c..816c8ce013 100644 --- a/crates/wasm_utils/src/memory/ribosome.rs +++ b/crates/wasm_utils/src/memory/ribosome.rs @@ -332,5 +332,4 @@ pub mod tests { return_code_for_allocation_result(Ok(allocation)), ); } - } diff --git a/crates/wasm_utils/src/memory/stack.rs b/crates/wasm_utils/src/memory/stack.rs index a78536f043..4211f342b3 100644 --- a/crates/wasm_utils/src/memory/stack.rs +++ b/crates/wasm_utils/src/memory/stack.rs @@ -266,5 +266,4 @@ pub mod memory_tests { }), ); } - } From 09f5ece109dcad9a630678410d9c4a3bae1336e1 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Tue, 19 Nov 2019 15:01:49 +1100 Subject: [PATCH 04/79] Fix formatting errors and some logical errors --- crates/core/src/action.rs | 2 +- crates/core/src/agent/state.rs | 2 +- crates/core/src/consistency.rs | 4 +-- crates/core/src/dht/dht_reducers.rs | 5 +-- crates/core/src/dht/dht_store.rs | 18 ++++++---- crates/core/src/network/handler/mod.rs | 15 ++++---- crates/core/src/network/handler/store.rs | 7 ++-- crates/core/src/network/mod.rs | 2 +- .../reducers/add_pending_validation.rs | 5 +-- .../src/nucleus/ribosome/api/get_links.rs | 4 +-- crates/core/src/nucleus/ribosome/api/sign.rs | 7 +++- .../nucleus/ribosome/api/verify_signature.rs | 12 +++++-- .../src/scheduled_jobs/pending_validations.rs | 35 ++++++++----------- crates/core/src/workflows/mod.rs | 8 ++--- crates/core_types/src/error/mod.rs | 8 ++--- 15 files changed, 66 insertions(+), 68 deletions(-) diff --git a/crates/core/src/action.rs b/crates/core/src/action.rs index 15a12b13f9..2e99d4df5b 100644 --- a/crates/core/src/action.rs +++ b/crates/core/src/action.rs @@ -1,9 +1,9 @@ use crate::{ agent::state::AgentState, network::{ + chain_pair::ChainPair, direct_message::DirectMessage, entry_aspect::EntryAspect, - chain_pair::ChainPair, query::{GetLinksNetworkQuery, NetworkQueryResult}, state::NetworkState, }, diff --git a/crates/core/src/agent/state.rs b/crates/core/src/agent/state.rs index 594409913e..f681d0495c 100644 --- a/crates/core/src/agent/state.rs +++ b/crates/core/src/agent/state.rs @@ -30,7 +30,7 @@ use std::{ /// The state-slice for the Agent. /// Hold's the agent's source chain and keys. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub struct AgentState { /// every action and the result of that action // @TODO this will blow up memory, implement as some kind of dropping/FIFO with a limit? diff --git a/crates/core/src/consistency.rs b/crates/core/src/consistency.rs index 42f6f27b31..67ab3b4c29 100644 --- a/crates/core/src/consistency.rs +++ b/crates/core/src/consistency.rs @@ -1,6 +1,6 @@ use crate::{ - action::Action, context::Context, entry::CanPublish, - network::chain_pair::ChainPair, nucleus::ZomeFnCall, + action::Action, context::Context, entry::CanPublish, network::chain_pair::ChainPair, + nucleus::ZomeFnCall, }; use holochain_core_types::{agent::AgentId, entry::Entry, link::link_data::LinkData}; use holochain_persistence_api::cas::content::{Address, AddressableContent}; diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index ba09d806dd..1933fa3ca6 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -413,10 +413,7 @@ pub mod tests { let store = test_store(context.clone()); let entry = test_entry(); - let chain_pair = ChainPair::new( - header: test_chain_header(), - entry: entry.clone(), - ); + let chain_pair = ChainPair::new(test_chain_header(), entry.clone()); let action_wrapper = ActionWrapper::new(Action::Hold(chain_pair.clone())); store.reduce(action_wrapper); diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index 36da14e0bd..54111377ed 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -227,14 +227,18 @@ impl DhtStore { self.content_storage().write().unwrap().add(header)?; self.meta_storage().write().unwrap().add_eavi(&eavi)?; Ok(()) - Err(header_entry_mismatch as HeaderEntryMismatch(.., err_msg)) => { - let add_err_msg = format!( - "Tried to add entry {} and header {} to the CAS and EAV, respectively", - entry, header, - ); - err_msg = concat!(err_msg, add_err_msg); - Err(HeaderEntryMismatch(.., err_msg) } + Err(err) => match err { + HolochainError::HeaderEntryMismatch(err_msg, ..) => { + let add_err_msg = format!( + "Tried to add entry {} and header {} to the CAS and EAV, respectively", + entry, header, + ); + err_msg = concat!(err_msg, add_err_msg); + Err(HolochainError::HeaderEntryMismatch(err_msg, ..)) + } + _ => unreachable!(), + }, } } diff --git a/crates/core/src/network/handler/mod.rs b/crates/core/src/network/handler/mod.rs index c25cbffc69..b99de16fa0 100644 --- a/crates/core/src/network/handler/mod.rs +++ b/crates/core/src/network/handler/mod.rs @@ -10,8 +10,8 @@ use crate::{ context::Context, entry::CanPublish, network::{ - direct_message::DirectMessage, chain_pair::ChainPair, + direct_message::DirectMessage, entry_aspect::EntryAspect, handler::{ fetch::*, @@ -310,7 +310,7 @@ fn get_content_aspect( &state.agent().chain_store().content_storage(), header.entry_address(), ) { - Ok(Some(entry)) => {Some(ChainPair::new(header, entry))}, + Ok(Some(entry)) => Some(ChainPair::new(header, entry)), Ok(None) => { let err_message = format!( "net/fetch/get_content_aspect: no entry associated with address {} could be @@ -319,7 +319,7 @@ fn get_content_aspect( ); log_error!(context, "{}", err_message); return HolochainError::ErrorGeneric(err_message); - }, + } Err(err) => { let err_message = format!( "net/fetch/get_content_aspect: got an error while trying to get an entry associated with the address {}from the CAS. The header {} is in the chain. Error: {:?}", @@ -327,9 +327,9 @@ fn get_content_aspect( ); log_error!(context, "{}", err_message); return HolochainError::ErrorGeneric(err_message); - }, + } } - }, + } None => { // ... but if we didn't author that entry, let's see if we have it in the DHT cas: if let Some(entry) = get_entry_from_cas(&state.dht().content_storage(), entry_address)? @@ -348,10 +348,7 @@ fn get_content_aspect( // TODO: this is just taking the first header.. // We should actually transform all headers into EntryAspect::Headers and just the first one // into an EntryAspect content (What about ordering? Using the headers timestamp?) - Some(ChainPair::new( - headers[0].clone(), - entry, - )) + Some(ChainPair::new(headers[0].clone(), entry)) } else { debug!( "GET CONTENT ASPECT: entry found in cas, but then couldn't find a header" diff --git a/crates/core/src/network/handler/store.rs b/crates/core/src/network/handler/store.rs index ce587db1b5..1eb9c8d0ae 100644 --- a/crates/core/src/network/handler/store.rs +++ b/crates/core/src/network/handler/store.rs @@ -1,6 +1,6 @@ use crate::{ context::Context, - network::{entry_aspect::EntryAspect, chain_pair::ChainPair}, + network::{chain_pair::ChainPair, entry_aspect::EntryAspect}, workflows::{ hold_entry::hold_entry_workflow, hold_entry_remove::hold_remove_workflow, hold_entry_update::hold_update_workflow, hold_link::hold_link_workflow, @@ -33,14 +33,13 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc) { ProcessUniqueId::new().to_string() )) .spawn(move || { - if let Err(err) = context - .block_on(hold_entry_workflow(&chain_pair, context.clone())) + if let Err(err) = + context.block_on(hold_entry_workflow(&chain_pair, context.clone())) { log_error!(context, "net/dht: {}", err); } }) .expect("Could not spawn thread for storing EntryAspect::Content"); - } else if Err(err) { log_error!(context, "net/handle: handle_store: Got EntryAspect::Content with non-matching entry and header", err) } else { diff --git a/crates/core/src/network/mod.rs b/crates/core/src/network/mod.rs index 0f402b871a..be916c7727 100644 --- a/crates/core/src/network/mod.rs +++ b/crates/core/src/network/mod.rs @@ -1,6 +1,6 @@ pub mod actions; -pub mod direct_message; pub mod chain_pair; +pub mod direct_message; pub mod handler; pub mod reducers; pub mod state; diff --git a/crates/core/src/nucleus/reducers/add_pending_validation.rs b/crates/core/src/nucleus/reducers/add_pending_validation.rs index f337bd6851..8f43439ecf 100644 --- a/crates/core/src/nucleus/reducers/add_pending_validation.rs +++ b/crates/core/src/nucleus/reducers/add_pending_validation.rs @@ -46,10 +46,7 @@ pub mod tests { let root_state = test_store(context); let entry = Entry::App("package_entry".into(), RawString::from("test value").into()); - let chain_pair = ChainPair::new( - test_chain_header(), - entry.clone() - ); + let chain_pair = ChainPair::new(test_chain_header(), entry.clone()); let action_wrapper = ActionWrapper::new(Action::AddPendingValidation(Arc::new( PendingValidationStruct { diff --git a/crates/core/src/nucleus/ribosome/api/get_links.rs b/crates/core/src/nucleus/ribosome/api/get_links.rs index 669b3e8f5b..3fe64f47fd 100644 --- a/crates/core/src/nucleus/ribosome/api/get_links.rs +++ b/crates/core/src/nucleus/ribosome/api/get_links.rs @@ -193,7 +193,7 @@ pub mod tests { ); let expected_2 = JsonString::from_json( &(format!( - r#"{{"ok":true,"value":"{{\"links\":[{{\"address\":\"{}\",\"headers\":[],\"tag\":\"{}\",\"status\":\"live\"}},{{\"address\":\"{}\",\"headers\":[],\"tag\":\"{}\",\"status\":\"live\"}}]}}","error":"null"}}"#, + r#"{{"ok":true,"value":"{{\"links\":[{{\"address\":\"{}\",\"headers\":[],\"tag\":\"{}\",\"status\":\"live\"}},{{\"address\":\"{}\",\"headers\":[],\"tag\":\"{}\",\"status\":\"live\"}}]}}","error":"null"}}"#, entry_addresses[2], "test-tag", entry_addresses[1], "test-tag", ) + "\u{0}"), ); @@ -316,7 +316,7 @@ pub mod tests { ); let expected_2 = JsonString::from_json( &(format!( - r#"{{"ok":true,"value":"{{\"links\":[{{\"address\":\"{}\",\"headers\":[],\"tag\":\"{}\",\"status\":\"live\"}},{{\"address\":\"{}\",\"headers\":[],\"tag\":\"{}\",\"status\":\"live\"}}]}}","error":"null"}}"#, + r#"{{"ok":true,"value":"{{\"links\":[{{\"address\":\"{}\",\"headers\":[],\"tag\":\"{}\",\"status\":\"live\"}},{{\"address\":\"{}\",\"headers\":[],\"tag\":\"{}\",\"status\":\"live\"}}]}}","error":"null"}}"#, entry_addresses[2], "test-tag2", entry_addresses[1], "test-tag1", ) + "\u{0}"), ); diff --git a/crates/core/src/nucleus/ribosome/api/sign.rs b/crates/core/src/nucleus/ribosome/api/sign.rs index 6164ce7404..4765cec73d 100644 --- a/crates/core/src/nucleus/ribosome/api/sign.rs +++ b/crates/core/src/nucleus/ribosome/api/sign.rs @@ -69,7 +69,12 @@ mod test_super { .as_bytes() .to_vec(), ); - assert_eq!(JsonString::from_json(r#"{"ok":true,"value":"xoEEoLF1yWM4VBNtjEwrfM/iVzjuAxxbkOyBWi0LV0+1CAH/PCs9MErnbmFeZRtQNtw7+SmVrm7Irac4lZsaDA==","error":"null"}"#), call_result,); + assert_eq!( + JsonString::from_json( + r#"{"ok":true,"value":"xoEEoLF1yWM4VBNtjEwrfM/iVzjuAxxbkOyBWi0LV0+1CAH/PCs9MErnbmFeZRtQNtw7+SmVrm7Irac4lZsaDA==","error":"null"}"# + ), + call_result, + ); } #[test] diff --git a/crates/core/src/nucleus/ribosome/api/verify_signature.rs b/crates/core/src/nucleus/ribosome/api/verify_signature.rs index 5fe8932eee..d8d21674c0 100644 --- a/crates/core/src/nucleus/ribosome/api/verify_signature.rs +++ b/crates/core/src/nucleus/ribosome/api/verify_signature.rs @@ -56,9 +56,17 @@ mod test_super { ZomeApiFunction::Crypto.as_str(), r#"{ "payload": "this is data", "method":"Sign" }"#.as_bytes().to_vec(), ); - assert_eq!(JsonString::from_json(r#"{"ok":true,"value":"xoEEoLF1yWM4VBNtjEwrfM/iVzjuAxxbkOyBWi0LV0+1CAH/PCs9MErnbmFeZRtQNtw7+SmVrm7Irac4lZsaDA==","error":"null"}"#), call_result,); + assert_eq!( + JsonString::from_json( + r#"{"ok":true,"value":"xoEEoLF1yWM4VBNtjEwrfM/iVzjuAxxbkOyBWi0LV0+1CAH/PCs9MErnbmFeZRtQNtw7+SmVrm7Irac4lZsaDA==","error":"null"}"# + ), + call_result, + ); - let args = format!(r#"{{ "provenance": ["{}","xoEEoLF1yWM4VBNtjEwrfM/iVzjuAxxbkOyBWi0LV0+1CAH/PCs9MErnbmFeZRtQNtw7+SmVrm7Irac4lZsaDA=="], "payload": "this is data" }}"#,context.agent_id.address()); + let args = format!( + r#"{{ "provenance": ["{}","xoEEoLF1yWM4VBNtjEwrfM/iVzjuAxxbkOyBWi0LV0+1CAH/PCs9MErnbmFeZRtQNtw7+SmVrm7Irac4lZsaDA=="], "payload": "this is data" }}"#, + context.agent_id.address() + ); let (call_result, _) = test_zome_api_function( ZomeApiFunction::VerifySignature.as_str(), args.as_bytes().to_vec(), diff --git a/crates/core/src/scheduled_jobs/pending_validations.rs b/crates/core/src/scheduled_jobs/pending_validations.rs index 9b7fb88e12..6982974104 100644 --- a/crates/core/src/scheduled_jobs/pending_validations.rs +++ b/crates/core/src/scheduled_jobs/pending_validations.rs @@ -81,26 +81,21 @@ fn retry_validation(pending: PendingValidation, context: Arc) { )) .spawn(move || { let result = match pending.workflow { - ValidatingWorkflow::HoldLink => context.block_on(hold_link_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::HoldEntry => context.block_on(hold_entry_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::RemoveLink => context.block_on(remove_link_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::UpdateEntry => context.block_on(hold_update_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::RemoveEntry => context.block_on(hold_remove_workflow( - &pending.chain_pair, - context.clone(), - )), + ValidatingWorkflow::HoldLink => { + context.block_on(hold_link_workflow(&pending.chain_pair, context.clone())) + } + ValidatingWorkflow::HoldEntry => { + context.block_on(hold_entry_workflow(&pending.chain_pair, context.clone())) + } + ValidatingWorkflow::RemoveLink => { + context.block_on(remove_link_workflow(&pending.chain_pair, context.clone())) + } + ValidatingWorkflow::UpdateEntry => { + context.block_on(hold_update_workflow(&pending.chain_pair, context.clone())) + } + ValidatingWorkflow::RemoveEntry => { + context.block_on(hold_remove_workflow(&pending.chain_pair, context.clone())) + } }; if Err(HolochainError::ValidationPending) != result { remove_pending_validation( diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 46f212e63f..c206f51f99 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -13,9 +13,7 @@ pub mod respond_validation_package_request; use crate::{ context::Context, - network::{ - actions::get_validation_package::get_validation_package, chain_pair::ChainPair, - }, + network::{actions::get_validation_package::get_validation_package, chain_pair::ChainPair}, nucleus::{ actions::build_validation_package::build_validation_package, ribosome::callback::{ @@ -92,9 +90,7 @@ async fn validation_package( context: Arc, ) -> Result, HolochainError> { // 1. Try to construct it locally: - if let Ok(package) = - try_make_local_validation_package(&chain_pair, context.clone()).await - { + if let Ok(package) = try_make_local_validation_package(&chain_pair, context.clone()).await { Ok(Some(package)) } else { // If that is not possible, get the validation package from source diff --git a/crates/core_types/src/error/mod.rs b/crates/core_types/src/error/mod.rs index d4dfa61d09..e24d80afe2 100644 --- a/crates/core_types/src/error/mod.rs +++ b/crates/core_types/src/error/mod.rs @@ -8,13 +8,12 @@ use self::HolochainError::*; pub use self::{dna_error::*, ribosome_error::*}; use futures::channel::oneshot::Canceled as FutureCanceled; use holochain_core_types::{chain_header::ChainHeader, entry::Entry}; -use holochain_persistence_api::cas::content::Address; use holochain_json_api::{ error::{JsonError, JsonResult}, json::*, }; use holochain_locksmith::LocksmithError; -use holochain_persistence_api::{error::PersistenceError, hash::HashString}; +use holochain_persistence_api::{cas::content::Address, error::PersistenceError, hash::HashString}; use lib3h_crypto_api::CryptoError; use serde_json::Error as SerdeError; @@ -166,17 +165,18 @@ impl fmt::Display for HolochainError { hash1, hash2 ), HeaderEntryMismatch( + err_msg, header_entry_address, header_entry, header, entry_address, entry, - err_msg. ) => write!( + f, "Header/Entry mismatch. The address {} of the entry {} in the header {} does not match the address {} of the entry {}. {}", header_entry_address, header_entry, header, entry_address, entry, err_msg - ) + ), EntryNotFoundLocally => write!(f, "The requested entry could not be found locally"), EntryIsPrivate => write!( f, From 57d9ed2ba1e9ea4f4ac4d7f509b83977a8da9e2f Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Tue, 19 Nov 2019 17:40:26 +1100 Subject: [PATCH 05/79] Add work on implementing Display for HeaderEntryMismatch: several errors introduced due to unimplemented traits Ord and Display for contained types --- crates/core_types/src/chain_header.rs | 8 +++++++- crates/core_types/src/lib.rs | 1 + crates/core_types/src/link/link_list.rs | 9 +++++++++ crates/core_types/src/link/mod.rs | 9 +++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index 29f18efb36..955edb3971 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -19,7 +19,8 @@ use holochain_json_api::{ json::JsonString, }; -use std::convert::TryInto; +use std::{convert::TryInto, fmt}; + /// ChainHeader of a source chain "Item" /// The address of the ChainHeader is used as the Item's key in the source chain hash table @@ -47,6 +48,11 @@ pub struct ChainHeader { timestamp: Iso8601, } +impl fmt::Display for ChainHeader { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + + } +} impl PartialEq for ChainHeader { fn eq(&self, other: &ChainHeader) -> bool { self.address() == other.address() diff --git a/crates/core_types/src/lib.rs b/crates/core_types/src/lib.rs index fee0d99f4d..fa509a1a4b 100644 --- a/crates/core_types/src/lib.rs +++ b/crates/core_types/src/lib.rs @@ -50,6 +50,7 @@ pub mod agent; pub mod bits_n_pieces; pub mod chain_migrate; pub mod dna; +pub mod dump_vec; pub mod hdk_version; pub mod link; pub mod network; diff --git a/crates/core_types/src/link/link_list.rs b/crates/core_types/src/link/link_list.rs index eb421f3682..9dfb46a736 100644 --- a/crates/core_types/src/link/link_list.rs +++ b/crates/core_types/src/link/link_list.rs @@ -1,5 +1,7 @@ use crate::link::Link; use holochain_json_api::{error::JsonError, json::JsonString}; +use std::fmt; +use dump_vec::DumpVec; //------------------------------------------------------------------------------------------------- // LinkList @@ -21,3 +23,10 @@ impl LinkList { &self.links } } + +impl fmt::Display for LinkList { + fn fmt(&self, f: &mut fmt::formatter) -> fmt::Result { + let dump_vec_links = DumpVec(*self.links); + write!(f, "Link list: {}", dump_vec_links) + } +} diff --git a/crates/core_types/src/link/mod.rs b/crates/core_types/src/link/mod.rs index 7295eaf6aa..64d5435ce8 100644 --- a/crates/core_types/src/link/mod.rs +++ b/crates/core_types/src/link/mod.rs @@ -17,6 +17,7 @@ use entry::Entry; use holochain_persistence_api::cas::content::AddressableContent; use link::link_data::LinkData; use regex::Regex; +use std::fmt; type LinkType = String; type LinkTag = String; @@ -29,6 +30,14 @@ pub struct Link { tag: LinkTag, } +impl fmt::Display for Link { + fn fmt(&self, f: &mut fmt::formatter) -> fmt::Result { + write!(f, "Link: \nbase: {}\ntarget: {}\nlink_type: {}\ntag: {}", + self.0, self.1, self.2, self.3 + ) + } +} + impl Link { pub fn new(base: &Address, target: &Address, link_type: &str, tag: &str) -> Self { Link { From 4cf1b5660cf859df04dbb50142a4c67a507b3648 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Tue, 19 Nov 2019 17:50:42 +1100 Subject: [PATCH 06/79] Don't deref self --- crates/core_types/src/link/link_list.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core_types/src/link/link_list.rs b/crates/core_types/src/link/link_list.rs index 9dfb46a736..020da45e25 100644 --- a/crates/core_types/src/link/link_list.rs +++ b/crates/core_types/src/link/link_list.rs @@ -26,7 +26,7 @@ impl LinkList { impl fmt::Display for LinkList { fn fmt(&self, f: &mut fmt::formatter) -> fmt::Result { - let dump_vec_links = DumpVec(*self.links); + let dump_vec_links = DumpVec(self.links); write!(f, "Link list: {}", dump_vec_links) } } From ee46a2d001b046f9b00bfc3c101b30a4167412b9 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Tue, 19 Nov 2019 18:27:27 +1100 Subject: [PATCH 07/79] Add fixes. --- crates/core_types/src/chain_header.rs | 7 +------ crates/core_types/src/error/mod.rs | 12 ++++-------- crates/core_types/src/error/ribosome_error.rs | 2 ++ crates/core_types/src/lib.rs | 1 - crates/core_types/src/link/link_list.rs | 9 --------- crates/core_types/src/link/mod.rs | 9 --------- crates/sim2h/src/lib.rs | 2 +- 7 files changed, 8 insertions(+), 34 deletions(-) diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index 955edb3971..01938ce6d2 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -19,7 +19,7 @@ use holochain_json_api::{ json::JsonString, }; -use std::{convert::TryInto, fmt}; +use std::{convert::TryInto}; /// ChainHeader of a source chain "Item" @@ -48,11 +48,6 @@ pub struct ChainHeader { timestamp: Iso8601, } -impl fmt::Display for ChainHeader { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - - } -} impl PartialEq for ChainHeader { fn eq(&self, other: &ChainHeader) -> bool { self.address() == other.address() diff --git a/crates/core_types/src/error/mod.rs b/crates/core_types/src/error/mod.rs index e24d80afe2..79130676d3 100644 --- a/crates/core_types/src/error/mod.rs +++ b/crates/core_types/src/error/mod.rs @@ -7,7 +7,6 @@ mod ribosome_error; use self::HolochainError::*; pub use self::{dna_error::*, ribosome_error::*}; use futures::channel::oneshot::Canceled as FutureCanceled; -use holochain_core_types::{chain_header::ChainHeader, entry::Entry}; use holochain_json_api::{ error::{JsonError, JsonResult}, json::*, @@ -116,7 +115,7 @@ pub enum HolochainError { InitializationFailed(String), LifecycleError(String), DnaHashMismatch(HashString, HashString), - HeaderEntryMismatch(String, Address, Entry, ChainHeader, Address, Entry), + HeaderEntryMismatch(String, Address, Address), EntryNotFoundLocally, EntryIsPrivate, List(Vec), @@ -167,15 +166,12 @@ impl fmt::Display for HolochainError { HeaderEntryMismatch( err_msg, header_entry_address, - header_entry, - header, entry_address, - entry, ) => write!( f, - "Header/Entry mismatch. The address {} of the entry {} in the - header {} does not match the address {} of the entry {}. {}", - header_entry_address, header_entry, header, entry_address, entry, err_msg + "Header/Entry mismatch. The address {} of the entry in the + header does not match the address {} of the entry. {}", + header_entry_address, entry_address, err_msg ), EntryNotFoundLocally => write!(f, "The requested entry could not be found locally"), EntryIsPrivate => write!( diff --git a/crates/core_types/src/error/ribosome_error.rs b/crates/core_types/src/error/ribosome_error.rs index daf478ca3a..1061a0f840 100644 --- a/crates/core_types/src/error/ribosome_error.rs +++ b/crates/core_types/src/error/ribosome_error.rs @@ -206,6 +206,8 @@ impl From for RibosomeErrorCode { HolochainError::InitializationFailed(_) => RibosomeErrorCode::Unspecified, HolochainError::LifecycleError(_) => RibosomeErrorCode::Unspecified, HolochainError::DnaHashMismatch(_, _) => RibosomeErrorCode::Unspecified, + HolochainError::HeaderEntryMismatch(_, _, _) => + RibosomeErrorCode::Unspecified, HolochainError::EntryNotFoundLocally => RibosomeErrorCode::Unspecified, HolochainError::EntryIsPrivate => RibosomeErrorCode::Unspecified, HolochainError::List(_) => RibosomeErrorCode::Unspecified, diff --git a/crates/core_types/src/lib.rs b/crates/core_types/src/lib.rs index fa509a1a4b..fee0d99f4d 100644 --- a/crates/core_types/src/lib.rs +++ b/crates/core_types/src/lib.rs @@ -50,7 +50,6 @@ pub mod agent; pub mod bits_n_pieces; pub mod chain_migrate; pub mod dna; -pub mod dump_vec; pub mod hdk_version; pub mod link; pub mod network; diff --git a/crates/core_types/src/link/link_list.rs b/crates/core_types/src/link/link_list.rs index 020da45e25..eb421f3682 100644 --- a/crates/core_types/src/link/link_list.rs +++ b/crates/core_types/src/link/link_list.rs @@ -1,7 +1,5 @@ use crate::link::Link; use holochain_json_api::{error::JsonError, json::JsonString}; -use std::fmt; -use dump_vec::DumpVec; //------------------------------------------------------------------------------------------------- // LinkList @@ -23,10 +21,3 @@ impl LinkList { &self.links } } - -impl fmt::Display for LinkList { - fn fmt(&self, f: &mut fmt::formatter) -> fmt::Result { - let dump_vec_links = DumpVec(self.links); - write!(f, "Link list: {}", dump_vec_links) - } -} diff --git a/crates/core_types/src/link/mod.rs b/crates/core_types/src/link/mod.rs index 64d5435ce8..7295eaf6aa 100644 --- a/crates/core_types/src/link/mod.rs +++ b/crates/core_types/src/link/mod.rs @@ -17,7 +17,6 @@ use entry::Entry; use holochain_persistence_api::cas::content::AddressableContent; use link::link_data::LinkData; use regex::Regex; -use std::fmt; type LinkType = String; type LinkTag = String; @@ -30,14 +29,6 @@ pub struct Link { tag: LinkTag, } -impl fmt::Display for Link { - fn fmt(&self, f: &mut fmt::formatter) -> fmt::Result { - write!(f, "Link: \nbase: {}\ntarget: {}\nlink_type: {}\ntag: {}", - self.0, self.1, self.2, self.3 - ) - } -} - impl Link { pub fn new(base: &Address, target: &Address, link_type: &str, tag: &str) -> Self { Link { diff --git a/crates/sim2h/src/lib.rs b/crates/sim2h/src/lib.rs index b7852c8540..8e0b4f49e8 100644 --- a/crates/sim2h/src/lib.rs +++ b/crates/sim2h/src/lib.rs @@ -532,7 +532,7 @@ impl Sim2h { } else { debug!("Got FetchEntry result with request id {} - this is for gossiping to agent with incomplete data", fetch_result.request_id); let to_agent_id = AgentPubKey::from(fetch_result.request_id); - let maybe_url = self.lookup_joined(space_address, &to_agent_id);; + let maybe_url = self.lookup_joined(space_address, &to_agent_id); if maybe_url.is_none() { error!("Got FetchEntryResult with request id that is not a known agent id. I guess we lost that agent before we could deliver missing aspects."); return Ok(()) From ac42df21506bb5a4fe448b5b771d9601b0641faf Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Wed, 20 Nov 2019 15:16:09 +1100 Subject: [PATCH 08/79] Fix errors, e.g. with handling errors when creating a chain pair --- crates/core/src/consistency.rs | 2 +- crates/core/src/dht/actions/hold.rs | 2 +- crates/core/src/network/handler/mod.rs | 12 +- crates/core/src/network/handler/store.rs | 164 +++++++++++------- crates/core/src/network/reducers/publish.rs | 58 +++---- .../network/reducers/publish_header_entry.rs | 13 +- .../reducers/add_pending_validation.rs | 2 +- .../reducers/remove_pending_validation.rs | 11 +- crates/core/src/nucleus/validation/mod.rs | 18 +- crates/core/src/workflows/hold_entry.rs | 20 +-- .../core/src/workflows/hold_entry_remove.rs | 18 +- .../core/src/workflows/hold_entry_update.rs | 15 +- crates/core/src/workflows/hold_link.rs | 29 ++-- crates/core/src/workflows/remove_link.rs | 22 +-- 14 files changed, 212 insertions(+), 174 deletions(-) diff --git a/crates/core/src/consistency.rs b/crates/core/src/consistency.rs index 67ab3b4c29..704cbd2524 100644 --- a/crates/core/src/consistency.rs +++ b/crates/core/src/consistency.rs @@ -178,7 +178,7 @@ impl ConsistencyModel { )), Action::AddPendingValidation(validation) => { - let address = validation.chain_pair.entry.address(); + let address = validation.chain_pair.entry().address(); Some(ConsistencySignal::new_pending( AddPendingValidation(address.clone()), Source, diff --git a/crates/core/src/dht/actions/hold.rs b/crates/core/src/dht/actions/hold.rs index 2076aabd24..a131555ab8 100644 --- a/crates/core/src/dht/actions/hold.rs +++ b/crates/core/src/dht/actions/hold.rs @@ -13,7 +13,7 @@ pub async fn hold_entry( chain_pair: &ChainPair, context: Arc, ) -> Result { - let address = chain_pair.entry.address(); + let address = chain_pair.entry().address(); let action_wrapper = ActionWrapper::new(Action::Hold(chain_pair.to_owned())); dispatch_action(context.action_channel(), action_wrapper.clone()); HoldEntryFuture { context, address }.await diff --git a/crates/core/src/network/handler/mod.rs b/crates/core/src/network/handler/mod.rs index b99de16fa0..177b07021b 100644 --- a/crates/core/src/network/handler/mod.rs +++ b/crates/core/src/network/handler/mod.rs @@ -306,16 +306,20 @@ fn get_content_aspect( Some((header, true)) => Some(create_chain_pair_for_header(&*state, header)?), Some((header, false)) => { // ... we can just get the content from the chain CAS + let header_entry_address = header.entry_address(); + let match get_entry_from_cas( &state.agent().chain_store().content_storage(), - header.entry_address(), + header_entry_address, ) { Ok(Some(entry)) => Some(ChainPair::new(header, entry)), Ok(None) => { let err_message = format!( - "net/fetch/get_content_aspect: no entry associated with address {} could be - found in the CAS, but the header {} is in the chain", - entry, header + "net/fetch/get_content_aspect: no entry associated + with the entry address {} in the header {} could + be found in the CAS, but the header is in the + chain", + header_entry_address, header ); log_error!(context, "{}", err_message); return HolochainError::ErrorGeneric(err_message); diff --git a/crates/core/src/network/handler/store.rs b/crates/core/src/network/handler/store.rs index 1eb9c8d0ae..a2200bc0dd 100644 --- a/crates/core/src/network/handler/store.rs +++ b/crates/core/src/network/handler/store.rs @@ -7,7 +7,7 @@ use crate::{ remove_link::remove_link_workflow, }, }; -use holochain_core_types::entry::{deletion_entry::DeletionEntry, Entry}; +use holochain_core_types::{entry::{deletion_entry::DeletionEntry, Entry}, error::HolochainError}; use holochain_json_api::json::JsonString; use holochain_persistence_api::cas::content::AddressableContent; use lib3h_protocol::data_types::StoreEntryAspectData; @@ -26,8 +26,9 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc) { "net/handle: handle_store: Got EntryAspect::Content. processing..." ); - if let Ok(chain_pair) = ChainPair::new(header, entry) { - thread::Builder::new() + match ChainPair::new(header, entry) { + Ok(chain_pair) => { + thread::Builder::new() .name(format!( "store_entry_content/{}", ProcessUniqueId::new().to_string() @@ -40,10 +41,10 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc) { } }) .expect("Could not spawn thread for storing EntryAspect::Content"); - } else if Err(err) { - log_error!(context, "net/handle: handle_store: Got EntryAspect::Content with non-matching entry and header", err) - } else { - unreachable!() + }, + Err(err) => { + log_error!(context, "net/handle: handle_store: Got EntryAspect::Content with non-matching entry {:#?} and header {:#?}", err, entry, header) + } } } EntryAspect::Header(header) => { @@ -59,20 +60,27 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc) { log_error!(context, "net/handle: handle_store: Got EntryAspect::LinkAdd with non-matching LinkData and ChainHeader! Hash of content in header does not match content! Ignoring."); return; } - let entry_with_header = EntryWithHeader { entry, header }; - thread::Builder::new() - .name(format!( - "store_link_entry/{}", - ProcessUniqueId::new().to_string() - )) - .spawn(move || { - if let Err(error) = context - .block_on(hold_link_workflow(&entry_with_header, context.clone())) - { - log_error!(context, "net/dht: {}", error); - } - }) - .expect("Could not spawn thread for storing EntryAspect::LinkAdd"); + match ChainPair::new(header, entry) { + Ok(chain_pair) => { + thread::Builder::new() + .name(format!( + "store_link_entry/{}", + ProcessUniqueId::new().to_string() + )) + .spawn(move || { + if let Err(error) = context + .block_on(hold_link_workflow(&chain_pair, context.clone())) + { + log_error!(context, "net/dht: {}", error); + } + }) + .expect("Could not spawn thread for storing EntryAspect::LinkAdd"); + }, + Err(error) => { + log_error!(context, "net/handle: handle_store: Could not create a ChainPair for EntryAspect::LinkAdd in order to store it. Error:\n{}\nEntry:\n{:#?}\nHeader:{:#?}", error, entry, header) + } + } + } EntryAspect::LinkRemove((link_data, links_to_remove), header) => { log_debug!( @@ -80,40 +88,59 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc) { "net/handle: handle_store: Got EntryAspect::LinkRemove. processing...", ); let entry = Entry::LinkRemove((link_data, links_to_remove)); - let entry_with_header = EntryWithHeader { entry, header }; - thread::Builder::new() - .name(format!( - "store_link_remove/{}", - ProcessUniqueId::new().to_string() - )) - .spawn(move || { - if let Err(error) = context - .block_on(remove_link_workflow(&entry_with_header, context.clone())) - { - log_error!(context, "net/dht: {}", error) - } - }) - .expect("Could not spawn thread for storing EntryAspect::LinkRemove"); + match ChainPair::new(header, entry) { + Ok(chain_pair) => { + thread::Builder::new() + .name(format!( + "store_link_remove/{}", + ProcessUniqueId::new().to_string() + )) + .spawn(move || { + if let Err(error) = context + .block_on(remove_link_workflow(&chain_pair, context.clone())) + { + log_error!(context, "net/dht: {}", error) + } + }) + .expect("Could not spawn thread for storing EntryAspect::LinkRemove"); + }, + Err(error) => { + log_error!(context, "net/handle: handle_store: + Couldn't not create a ChainPair in order to store the + entry and header for EntryAspect::LinkRemove. Error:\n + {}\nEntry:\n{:#?}\nHeader:\n{:#?}", + error, entry, header) + } + } } EntryAspect::Update(entry, header) => { log_debug!( context, "net/handle: handle_store: Got EntryAspect::Update. processing..." ); - let entry_with_header = EntryWithHeader { entry, header }; - thread::Builder::new() - .name(format!( - "store_update/{}", - ProcessUniqueId::new().to_string() - )) - .spawn(move || { - if let Err(error) = context - .block_on(hold_update_workflow(&entry_with_header, context.clone())) - { - log_error!(context, "net/dht: {}", error) - } - }) - .expect("Could not spawn thread for storing EntryAspect::Update"); + match ChainPair::new(header, entry) { + Ok(chain_pair) => { + thread::Builder::new() + .name(format!( + "store_update/{}", + ProcessUniqueId::new().to_string() + )) + .spawn(move || { + if let Err(error) = context + .block_on(hold_update_workflow(&chain_pair, context.clone())) + { + log_error!(context, "net/dht: {}", error) + } + }) + .expect("Could not spawn thread for storing EntryAspect::Update"); + }, + Err(error) => { + log_error!(context, "net/handle: handle_store: Could not create ChainPair in order to store EntryAspect::Update, header: {:#?}, entry: {:#?}. Error: {}. Error: {}", + header, entry, error) + } + } else if Err(error) { + log_error!(context, "net/handle: failed processing EntryAspect::Update while trying to create a chain pair, with error: {}. The entry is {}, and header is {}", error, entry, header) + }; } EntryAspect::Deletion(header) => { log_debug!( @@ -130,20 +157,30 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc) { }; let entry = Entry::Deletion(DeletionEntry::new(deleted_entry_address)); - let entry_with_header = EntryWithHeader { entry, header }; - thread::Builder::new() - .name(format!( - "store_deletion/{}", - ProcessUniqueId::new().to_string() - )) - .spawn(move || { - if let Err(error) = context - .block_on(hold_remove_workflow(&entry_with_header, context.clone())) - { - log_error!(context, "net/handle_store: {}", error) - } - }) - .expect("Could not spawn thread for storing EntryAspect::Deletion"); + match ChainPair::new(header, entry) { + Ok(chain_pair) => { + thread::Builder::new() + .name(format!( + "store_deletion/{}", + ProcessUniqueId::new().to_string() + )) + .spawn(move || { + if let Err(error) = context + .block_on(hold_remove_workflow(&chain_pair, context.clone())) + { + log_error!(context, "net/handle_store: {}", error) + } + }) + .expect("Could not spawn thread for storing EntryAspect::Deletion"); + }, + Err(err) => { + log_error!(context, "net/handle: handle_store: Could + not create ChainPair in order to store + EntryAspect::Deletion. Entry:\n{:#?}\n. The entry in + the attempted chain pair is a deletion entry, and the + header is:\n{:#?}\nError: {}", entry, header, err) + }, + } } } } else { @@ -156,6 +193,7 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc) { } /* +// If reintroducing this, update entry_with_header to chain_pair /// The network requests us to store meta information (links/CRUD/etc) for an /// entry that we hold. pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index 5bd4874949..2ee221b0c1 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -3,7 +3,7 @@ use crate::{ network::{ actions::ActionResponse, entry_aspect::EntryAspect, - entry_with_header::{fetch_entry_with_header, EntryWithHeader}, + chain_pair::{fetch_chain_pair, ChainPair}, reducers::send, state::NetworkState, }, @@ -39,7 +39,7 @@ pub fn entry_data_to_entry_aspect_data(ea: &EntryAspect) -> EntryAspectData { /// Send to network a PublishDhtData message fn publish_entry( network_state: &mut NetworkState, - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, ) -> Result<(), HolochainError> { send( network_state, @@ -47,10 +47,10 @@ fn publish_entry( space_address: network_state.dna_address.clone().unwrap().into(), provider_agent_id: network_state.agent_id.clone().unwrap().into(), entry: EntryData { - entry_address: entry_with_header.entry.address().clone().into(), + entry_address: chain_pair.entry().address().clone().into(), aspect_list: vec![entry_data_to_entry_aspect_data(&EntryAspect::Content( - entry_with_header.entry.clone(), - entry_with_header.header.clone(), + chain_pair.entry().clone(), + chain_pair.header().clone(), ))], }, }), @@ -62,16 +62,16 @@ fn publish_update_delete_meta( network_state: &mut NetworkState, orig_entry_address: Address, crud_status: CrudStatus, - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, ) -> Result<(), HolochainError> { // publish crud-status let aspect = match crud_status { CrudStatus::Modified => EntryAspect::Update( - entry_with_header.entry.clone(), - entry_with_header.header.clone(), + chain_pair.entry().clone(), + chain_pair.header().clone(), ), - CrudStatus::Deleted => EntryAspect::Deletion(entry_with_header.header.clone()), + CrudStatus::Deleted => EntryAspect::Deletion(chain_pair.header().clone()), crud => { return Err(HolochainError::ErrorGeneric(format!( "Unexpeced CRUD variant {:?}", @@ -96,27 +96,27 @@ fn publish_update_delete_meta( Ok(()) } -/// Send to network a PublishMeta message holding a link metadata to `entry_with_header` +/// Send to network a PublishMeta message holding a link metadata to `chain_pair` fn publish_link_meta( network_state: &mut NetworkState, - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, ) -> Result<(), HolochainError> { - let (base, aspect) = match entry_with_header.entry.clone() { + let (base, aspect) = match chain_pair.entry().clone() { Entry::LinkAdd(link_data) => ( link_data.link().base().clone(), - EntryAspect::LinkAdd(link_data, entry_with_header.header.clone()), + EntryAspect::LinkAdd(link_data, chain_pair.header().clone()), ), Entry::LinkRemove((link_data, links_to_remove)) => ( link_data.link().base().clone(), EntryAspect::LinkRemove( (link_data, links_to_remove), - entry_with_header.header.clone(), + chain_pair.header().clone(), ), ), _ => { return Err(HolochainError::ErrorGeneric(format!( "Received bad entry type. Expected Entry::LinkAdd/Remove received {:?}", - entry_with_header.entry, + chain_pair.entry(), ))); } }; @@ -140,39 +140,39 @@ fn reduce_publish_inner( ) -> Result<(), HolochainError> { network_state.initialized()?; - let entry_with_header = fetch_entry_with_header(&address, root_state)?; + let chain_pair = fetch_chain_pair(&address, root_state)?; - match entry_with_header.entry.entry_type() { - EntryType::AgentId => publish_entry(network_state, &entry_with_header), - EntryType::App(_) => publish_entry(network_state, &entry_with_header).and_then(|_| { - match entry_with_header.header.link_update_delete() { + match chain_pair.entry().entry_type() { + EntryType::AgentId => publish_entry(network_state, &chain_pair), + EntryType::App(_) => publish_entry(network_state, &chain_pair).and_then(|_| { + match chain_pair.header().link_update_delete() { Some(modified_entry) => publish_update_delete_meta( network_state, modified_entry, CrudStatus::Modified, - &entry_with_header.clone(), + &chain_pair.clone(), ), None => Ok(()), } }), - EntryType::LinkAdd => publish_entry(network_state, &entry_with_header) - .and_then(|_| publish_link_meta(network_state, &entry_with_header)), - EntryType::LinkRemove => publish_entry(network_state, &entry_with_header) - .and_then(|_| publish_link_meta(network_state, &entry_with_header)), - EntryType::Deletion => publish_entry(network_state, &entry_with_header).and_then(|_| { - match entry_with_header.header.link_update_delete() { + EntryType::LinkAdd => publish_entry(network_state, &chain_pair) + .and_then(|_| publish_link_meta(network_state, &chain_pair)), + EntryType::LinkRemove => publish_entry(network_state, &chain_pair) + .and_then(|_| publish_link_meta(network_state, &chain_pair)), + EntryType::Deletion => publish_entry(network_state, &chain_pair).and_then(|_| { + match chain_pair.header().link_update_delete() { Some(modified_entry) => publish_update_delete_meta( network_state, modified_entry, CrudStatus::Deleted, - &entry_with_header.clone(), + &chain_pair.clone(), ), None => Ok(()), } }), _ => Err(HolochainError::NotImplemented(format!( "reduce_publish_inner not implemented for {}", - entry_with_header.entry.entry_type() + chain_pair.entry().entry_type() ))), } } diff --git a/crates/core/src/network/reducers/publish_header_entry.rs b/crates/core/src/network/reducers/publish_header_entry.rs index 2e4e076cfa..5d5cea72ef 100644 --- a/crates/core/src/network/reducers/publish_header_entry.rs +++ b/crates/core/src/network/reducers/publish_header_entry.rs @@ -1,10 +1,10 @@ use crate::{ action::ActionWrapper, - agent::state::create_entry_with_header_for_header, + agent::state::create_chain_pair_for_header, network::{ actions::ActionResponse, entry_aspect::EntryAspect, - entry_with_header::{fetch_entry_with_header, ChainPair}, + chain_pair::fetch_chain_pair, reducers::{publish::entry_data_to_entry_aspect_data, send}, state::NetworkState, }, @@ -27,7 +27,8 @@ fn publish_header( chain_header: ChainHeader, ) -> Result<(), HolochainError> { let chain_pair = - create_entry_with_header_for_header(&StateWrapper::from(root_state.clone()), chain_header)?; + create_chain_pair_for_header(&StateWrapper::from(root_state.clone()), chain_header)?; + let entry = chain_pair.entry(); send( network_state, Lib3hClientProtocol::PublishEntry(ProvidedEntryData { @@ -37,7 +38,7 @@ fn publish_header( entry_address: entry.address().clone().into(), aspect_list: vec![entry_data_to_entry_aspect_data(&EntryAspect::Content( entry.clone(), - header, + chain_pair.header(), ))], }, }), @@ -50,8 +51,8 @@ fn reduce_publish_header_entry_inner( address: &Address, ) -> Result<(), HolochainError> { network_state.initialized()?; - let entry_with_header = fetch_entry_with_header(&address, root_state)?; - publish_header(network_state, root_state, entry_with_header.header) + let chain_pair = fetch_chain_pair(&address, root_state)?; + publish_header(network_state, root_state, chain_pair.header()) } pub fn reduce_publish_header_entry( diff --git a/crates/core/src/nucleus/reducers/add_pending_validation.rs b/crates/core/src/nucleus/reducers/add_pending_validation.rs index 8f43439ecf..343472a72d 100644 --- a/crates/core/src/nucleus/reducers/add_pending_validation.rs +++ b/crates/core/src/nucleus/reducers/add_pending_validation.rs @@ -6,7 +6,7 @@ use crate::{ use holochain_persistence_api::cas::content::AddressableContent; /// Reduce AddPendingValidation Action. -/// Inserts boxed EntryWithHeader and dependencies into state, referenced with +/// Inserts boxed ChainPair and dependencies into state, referenced with /// the entry's address. #[allow(unknown_lints)] #[allow(clippy::needless_pass_by_value)] diff --git a/crates/core/src/nucleus/reducers/remove_pending_validation.rs b/crates/core/src/nucleus/reducers/remove_pending_validation.rs index e1195606da..9c729bc5dd 100644 --- a/crates/core/src/nucleus/reducers/remove_pending_validation.rs +++ b/crates/core/src/nucleus/reducers/remove_pending_validation.rs @@ -5,7 +5,7 @@ use crate::{ }; /// Reduce RemovePendingValidation Action. -/// Removes boxed EntryWithHeader and dependencies from state, referenced with +/// Removes boxed ChainPair and dependencies from state, referenced with /// the entry's address. /// Corresponds to a prior AddPendingValidation Action. #[allow(unknown_lints)] @@ -27,7 +27,7 @@ pub mod tests { use super::*; use crate::{ instance::tests::test_context, - network::entry_with_header::EntryWithHeader, + network::chain_pair::ChainPair, nucleus::{ reducers::add_pending_validation::reduce_add_pending_validation, state::tests::test_nucleus_state, @@ -47,14 +47,11 @@ pub mod tests { let state = test_store(context); let entry = Entry::App("package_entry".into(), RawString::from("test value").into()); - let entry_with_header = EntryWithHeader { - entry: entry.clone(), - header: test_chain_header(), - }; + let chain_pair = ChainPair::new(test_chain_header(), entry.clone()); let action_wrapper = ActionWrapper::new(Action::AddPendingValidation(Arc::new( PendingValidationStruct { - entry_with_header, + chain_pair, dependencies: Vec::new(), workflow: ValidatingWorkflow::HoldEntry, }, diff --git a/crates/core/src/nucleus/validation/mod.rs b/crates/core/src/nucleus/validation/mod.rs index aa1c95bbd5..8e653e24e8 100644 --- a/crates/core/src/nucleus/validation/mod.rs +++ b/crates/core/src/nucleus/validation/mod.rs @@ -135,12 +135,12 @@ pub fn entry_to_validation_data( match entry { Entry::App(_, _) => maybe_link_update_delete .map(|link_update| { - get_entry_with_header(context.clone(), &link_update) - .map(|entry_with_header| { + get_chain_pair(context.clone(), &link_update) + .map(|chain_pair| { Ok(EntryValidationData::Modify { - old_entry: entry_with_header.0.entry.clone(), + old_entry: chain_pair.0.entry.clone(), new_entry: entry.clone(), - old_entry_header: entry_with_header.1.clone(), + old_entry_header: chain_pair.1.clone(), validation_data: validation_data.clone(), }) }) @@ -158,11 +158,11 @@ pub fn entry_to_validation_data( }), Entry::Deletion(deletion_entry) => { let deletion_address = deletion_entry.clone().deleted_entry_address(); - get_entry_with_header(context.clone(), &deletion_address) - .map(|entry_with_header| { + get_chain_pair(context.clone(), &deletion_address) + .map(|chain_pair| { Ok(EntryValidationData::Delete { - old_entry: entry_with_header.0.entry.clone(), - old_entry_header: entry_with_header.1.clone(), + old_entry: chain_pair.0.entry.clone(), + old_entry_header: chain_pair.1.clone(), validation_data: validation_data.clone(), }) }) @@ -182,7 +182,7 @@ pub fn entry_to_validation_data( } } -fn get_entry_with_header( +fn get_chain_pair( context: Arc, address: &Address, ) -> Result<(EntryWithMeta, ChainHeader), HolochainError> { diff --git a/crates/core/src/workflows/hold_entry.rs b/crates/core/src/workflows/hold_entry.rs index fa4e5f01fe..051c3c206f 100644 --- a/crates/core/src/workflows/hold_entry.rs +++ b/crates/core/src/workflows/hold_entry.rs @@ -44,7 +44,7 @@ pub async fn hold_entry_workflow( let message = "Source did respond to request but did not deliver validation package! (Empty response) This is weird! Let's try this again later -> Add to pending"; log_debug!(context, "workflow/hold_entry: {}", message); add_pending_validation( - entry_with_header.to_owned(), + chain_pair.to_owned(), Vec::new(), ValidatingWorkflow::HoldEntry, context.clone(), @@ -61,7 +61,7 @@ pub async fn hold_entry_workflow( // 3. Validate the entry validate_entry( - entry_with_header.entry.clone(), + chain_pair.entry().clone(), None, validation_data, &context @@ -69,11 +69,11 @@ pub async fn hold_entry_workflow( .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: {:?}", - entry_with_header.entry.address(), + chain_pair.entry().address(), dependencies, ); add_pending_validation( - entry_with_header.to_owned(), + chain_pair.to_owned(), dependencies.clone(), ValidatingWorkflow::HoldEntry, context.clone(), @@ -81,7 +81,7 @@ pub async fn hold_entry_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_entry: Entry {} is NOT valid! Validation error: {:?}", - entry_with_header.entry.address(), + chain_pair.entry().address(), err, ); HolochainError::from(err) @@ -91,16 +91,16 @@ pub async fn hold_entry_workflow( log_debug!( context, "workflow/hold_entry: is valid! {}", - entry_with_header.entry.address() + chain_pair.entry().address() ); // 3. If valid store the entry in the local DHT shard - hold_entry(entry_with_header, context.clone()).await?; + hold_entry(chain_pair, context.clone()).await?; log_debug!( context, "workflow/hold_entry: HOLDING: {}", - entry_with_header.entry.address() + chain_pair.entry().address() ); Ok(()) @@ -150,10 +150,10 @@ pub mod tests { let header = agent1_state .get_most_recent_header_for_entry(&entry) .expect("There must be a header in the author's source chain after commit"); - let entry_with_header = EntryWithHeader { entry, header }; + let chain_pair = ChainPair::new(header, entry)?; // Call hold_entry_workflow on victim DHT node - let result = context2.block_on(hold_entry_workflow(&entry_with_header, &context2)); + let result = context2.block_on(hold_entry_workflow(&chain_pair, &context2)); // ... and expect validation to fail with message defined in test WAT: assert!(result.is_err()); diff --git a/crates/core/src/workflows/hold_entry_remove.rs b/crates/core/src/workflows/hold_entry_remove.rs index a2e55c1a10..7fbba4a08a 100644 --- a/crates/core/src/workflows/hold_entry_remove.rs +++ b/crates/core/src/workflows/hold_entry_remove.rs @@ -1,6 +1,6 @@ use crate::{ context::Context, dht::actions::remove_entry::remove_entry, - network::entry_with_header::EntryWithHeader, nucleus::validation::validate_entry, + network::chain_pair::ChainPair, nucleus::validation::validate_entry, }; use crate::{ @@ -19,18 +19,18 @@ use holochain_persistence_api::cas::content::AddressableContent; use std::sync::Arc; pub async fn hold_remove_workflow( - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, context: Arc, ) -> Result<(), HolochainError> { // 1. Get hold of validation package - let maybe_validation_package = validation_package(entry_with_header, context.clone()) + let maybe_validation_package = validation_package(chain_pair, 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(), + chain_pair.to_owned(), Vec::new(), ValidatingWorkflow::RemoveEntry, context.clone(), @@ -48,7 +48,7 @@ pub async fn hold_remove_workflow( // 3. Validate the entry validate_entry( - entry_with_header.entry.clone(), + chain_pair.entry().clone(), None, validation_data, &context @@ -57,7 +57,7 @@ pub async fn hold_remove_workflow( 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); add_pending_validation( - entry_with_header.to_owned(), + chain_pair.to_owned(), dependencies.clone(), ValidatingWorkflow::RemoveEntry, context.clone(), @@ -65,7 +65,7 @@ pub async fn hold_remove_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_remove: Entry removal {:?} is NOT valid! Validation error: {:?}", - entry_with_header.entry, + chain_pair.entry(), err, ); HolochainError::from(err) @@ -73,14 +73,14 @@ pub async fn hold_remove_workflow( })?; - let deletion_entry = unwrap_to!(entry_with_header.entry => Entry::Deletion); + let deletion_entry = unwrap_to!(chain_pair.entry() => Entry::Deletion); let deleted_entry_address = deletion_entry.clone().deleted_entry_address(); // 3. If valid store the entry in the local DHT shard remove_entry( &context.clone(), deleted_entry_address, - entry_with_header.entry.address().clone(), + chain_pair.entry().address().clone(), ) .await } diff --git a/crates/core/src/workflows/hold_entry_update.rs b/crates/core/src/workflows/hold_entry_update.rs index ea259800d3..63e9ff1a00 100644 --- a/crates/core/src/workflows/hold_entry_update.rs +++ b/crates/core/src/workflows/hold_entry_update.rs @@ -1,6 +1,6 @@ use crate::{ context::Context, dht::actions::update_entry::update_entry, - network::entry_with_header::EntryWithHeader, nucleus::validation::validate_entry, + network::chain_pair::ChainPair, nucleus::validation::validate_entry, }; use holochain_persistence_api::cas::content::AddressableContent; @@ -18,20 +18,21 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn hold_update_workflow( - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, context: Arc, ) -> Result<(), HolochainError> { - let EntryWithHeader { entry, header } = entry_with_header; + let header = chain_pair.header(); + let entry = chain_pair.entry(); // 1. Get hold of validation package - let maybe_validation_package = validation_package(&entry_with_header, context.clone()) + let maybe_validation_package = validation_package(&chain_pair, 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); log_debug!(context, "workflow/hold_update: Error was: {:?}", err); add_pending_validation( - entry_with_header.to_owned(), + chain_pair.to_owned(), Vec::new(), ValidatingWorkflow::UpdateEntry, context.clone(), @@ -63,7 +64,7 @@ pub async fn hold_update_workflow( 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); add_pending_validation( - entry_with_header.to_owned(), + chain_pair.to_owned(), dependencies.clone(), ValidatingWorkflow::UpdateEntry, context.clone(), @@ -71,7 +72,7 @@ pub async fn hold_update_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_update: Entry update {:?} is NOT valid! Validation error: {:?}", - entry_with_header.entry, + entry, err, ); HolochainError::from(err) diff --git a/crates/core/src/workflows/hold_link.rs b/crates/core/src/workflows/hold_link.rs index 23abb3bc2c..31ff63dad6 100644 --- a/crates/core/src/workflows/hold_link.rs +++ b/crates/core/src/workflows/hold_link.rs @@ -1,6 +1,6 @@ use crate::{ context::Context, dht::actions::add_link::add_link, - network::entry_with_header::EntryWithHeader, nucleus::validation::validate_entry, + network::chain_pair::ChainPair, nucleus::validation::validate_entry, }; use crate::{ @@ -18,10 +18,10 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn hold_link_workflow( - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, context: Arc, ) -> Result<(), HolochainError> { - let link_add = match &entry_with_header.entry { + let link_add = match &chain_pair.entry() { Entry::LinkAdd(link_add) => link_add, _ => Err(HolochainError::ErrorGeneric( "hold_link_workflow expects entry to be an Entry::LinkAdd".to_string(), @@ -32,14 +32,14 @@ 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 = validation_package(&entry_with_header, context.clone()) + let maybe_validation_package = validation_package(&chain_pair, 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); log_debug!(context, "workflow/hold_link: Error was: {:?}", err); add_pending_validation( - entry_with_header.to_owned(), + chain_pair.to_owned(), Vec::new(), ValidatingWorkflow::HoldLink, context.clone(), @@ -50,7 +50,7 @@ pub async fn hold_link_workflow( let message = "Source did respond to request but did not deliver validation package! (Empty response) This is weird! Let's try this again later -> Add to pending"; log_debug!(context, "workflow/hold_link: {}", message); add_pending_validation( - entry_with_header.to_owned(), + chain_pair.to_owned(), Vec::new(), ValidatingWorkflow::HoldLink, context.clone(), @@ -68,7 +68,7 @@ pub async fn hold_link_workflow( // 3. Validate the entry log_debug!(context, "workflow/hold_link: validate..."); validate_entry( - entry_with_header.entry.clone(), + chain_pair.entry().clone(), None, validation_data, &context @@ -77,7 +77,7 @@ pub async fn hold_link_workflow( 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); add_pending_validation( - entry_with_header.to_owned(), + chain_pair.to_owned(), dependencies.clone(), ValidatingWorkflow::HoldLink, context.clone(), @@ -85,7 +85,7 @@ pub async fn hold_link_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_link: Link {:?} is NOT valid! Validation error: {:?}", - entry_with_header.entry, + chain_pair.entry(), err, ); HolochainError::from(err) @@ -99,11 +99,11 @@ pub async fn hold_link_workflow( 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 - hold_entry_workflow(&entry_with_header, context.clone()).await?; + hold_entry_workflow(&chain_pair, context.clone()).await?; log_debug!( context, "workflow/hold_entry: added! {:?}", - entry_with_header + chain_pair ); //5. Link has been added to EAV and LinkAdd Entry has been stored on the dht @@ -168,13 +168,10 @@ pub mod tests { let header = agent1_state .get_most_recent_header_for_entry(&link_entry) .expect("There must be a header in the author's source chain after commit"); - let entry_with_header = EntryWithHeader { - entry: link_entry, - header, - }; + let chain_pair = ChainPair::new(header, link_entry); // Call hold_entry_workflow on victim DHT node - let result = context2.block_on(hold_link_workflow(&entry_with_header, context2.clone())); + let result = context2.block_on(hold_link_workflow(&chain_pair, context2.clone())); // ... and expect validation to fail with message defined in test WAT: assert!(result.is_err()); diff --git a/crates/core/src/workflows/remove_link.rs b/crates/core/src/workflows/remove_link.rs index b92e75747c..8d4062425e 100644 --- a/crates/core/src/workflows/remove_link.rs +++ b/crates/core/src/workflows/remove_link.rs @@ -1,6 +1,6 @@ use crate::{ context::Context, dht::actions::remove_link::remove_link, - network::entry_with_header::EntryWithHeader, nucleus::validation::validate_entry, + network::chain_pair::ChainPair, nucleus::validation::validate_entry, workflows::hold_entry::hold_entry_workflow, }; @@ -19,10 +19,10 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn remove_link_workflow( - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, context: Arc, ) -> Result<(), HolochainError> { - let link_remove = match &entry_with_header.entry { + let link_remove = match &chain_pair.entry() { Entry::LinkRemove((link_remove, _)) => link_remove, _ => Err(HolochainError::ErrorGeneric( "remove_link_workflow expects entry to be an Entry::LinkRemove".to_string(), @@ -36,14 +36,14 @@ pub async fn remove_link_workflow( context, "workflow/remove_link: getting validation package..." ); - let maybe_validation_package = validation_package(&entry_with_header, context.clone()) + let maybe_validation_package = validation_package(&chain_pair, 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); log_debug!(context, "workflow/remove_link: Error was: {:?}", err); add_pending_validation( - entry_with_header.to_owned(), + chain_pair.to_owned(), Vec::new(), ValidatingWorkflow::RemoveLink, context.clone(), @@ -64,7 +64,7 @@ pub async fn remove_link_workflow( // 3. Validate the entry log_debug!(context, "workflow/remove_link: validate..."); validate_entry( - entry_with_header.entry.clone(), + chain_pair.entry().clone(), None, validation_data, &context @@ -73,7 +73,7 @@ pub async fn remove_link_workflow( 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); add_pending_validation( - entry_with_header.to_owned(), + chain_pair.to_owned(), dependencies.clone(), ValidatingWorkflow::HoldLink, context.clone(), @@ -81,7 +81,7 @@ pub async fn remove_link_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/remove_link: Link {:?} is NOT valid! Validation error: {:?}", - entry_with_header.entry, + chain_pair.entry(), err, ); HolochainError::from(err) @@ -92,15 +92,15 @@ 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 - remove_link(&entry_with_header.entry, &context).await?; + remove_link(&chain_pair.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``` - hold_entry_workflow(&entry_with_header, context.clone()).await?; + hold_entry_workflow(&chain_pair, context.clone()).await?; log_debug!( context, "workflow/hold_entry: added! {:?}", - entry_with_header + chain_pair ); Ok(()) From 8b25845779ec8c0646966f1c314e61ee37168920 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Thu, 21 Nov 2019 14:43:09 +1100 Subject: [PATCH 09/79] track chain_pair.rs, commit --- crates/core/src/network/chain_pair.rs | 69 +++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 crates/core/src/network/chain_pair.rs diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs new file mode 100644 index 0000000000..b51064cc2e --- /dev/null +++ b/crates/core/src/network/chain_pair.rs @@ -0,0 +1,69 @@ +use crate::{ + agent::find_chain_header, + state::{State, StateWrapper}, +}; +use holochain_core_types::{chain_header::ChainHeader, entry::Entry, error::HolochainError}; +use holochain_persistence_api::cas::content::Address; +use std::convert::TryInto; + +/// A `ChainPair` cannot be constructed unless the entry address in the +/// `ChainHeader` that is within the `ChainPair` is the same as the address +/// of the `Entry` that is also within the `ChainPair`. +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct ChainPair(ChainHeader, Entry); + +impl ChainPair { + pub fn new(header: ChainHeader, entry: Entry) -> Result { + let header_entry = header.entry(); + let header_entry_address = header_entry.address(); + let entry_address = entry.address(); + if header_entry_address == entry_address { + Ok(ChainPair(header, entry)) + } else { + Err(HolochainError::HeaderEntryMismatch( + "Tried to create a ChainPair, but got a mismatch with the header's entry address {} and the entry's address {}.", + header_entry_address, + entry_address, + )) + } + } + + pub fn header(&self) -> ChainHeader { + self.0.clone() + } + + pub fn entry(&self) -> Entry { + self.1.clone() + } + + pub fn fetch_chain_pair(address: &Address, state: &State) -> Result { + let entry = fetch_entry_from_cas(address, state)?; + + let header = + find_chain_header(&entry, &StateWrapper::from(state.clone())).ok_or_else(|| { + HolochainError::from( + "No header found for entry {}with address {}", + entry, + address, + ) + })?; + + ChainPair::new(entry, header) + } +} + +fn fetch_entry_from_cas(address: &Address, state: &State) -> Result { + let json = state + .agent() + .chain_store() + .content_storage() + .read()? + .fetch(address)? + .ok_or_else(|| { + HolochainError::from("Entry with address {} could not be found.", address) + })?; +HeaderEntryMismatch(String, Address, Address), + HeaderEntryMismatch(String, Address, Address), + let s: Entry = json.try_into()?; + Ok(s) +} From ec2b4c39b2a05aed95aa0a8ca00ca6705794c4eb Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Thu, 21 Nov 2019 18:11:37 +1100 Subject: [PATCH 10/79] Save work --- crates/core/src/network/entry_with_header.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/core/src/network/entry_with_header.rs b/crates/core/src/network/entry_with_header.rs index f59d8a6569..5dd1a0fdcb 100644 --- a/crates/core/src/network/entry_with_header.rs +++ b/crates/core/src/network/entry_with_header.rs @@ -31,10 +31,10 @@ impl EntryWithHeader { } } -pub fn fetch_entry_with_header( +pub fn fetch_chain_pair( address: &Address, state: &State, -) -> Result { +) -> Result { let entry = state .agent() .chain_store() From 88cf4869454b06004ac393c175992d7518fdbc17 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Thu, 21 Nov 2019 18:30:59 +1100 Subject: [PATCH 11/79] Re-add chain_pair.rs with revisions from upstream, delete entry_with_header.rs. --- crates/core/src/network/chain_pair.rs | 34 +++++--------- crates/core/src/network/entry_with_header.rs | 48 -------------------- 2 files changed, 12 insertions(+), 70 deletions(-) delete mode 100644 crates/core/src/network/entry_with_header.rs diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index b51064cc2e..39f0ce5ecc 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -1,5 +1,6 @@ use crate::{ agent::find_chain_header, + content_store::GetContent, state::{State, StateWrapper}, }; use holochain_core_types::{chain_header::ChainHeader, entry::Entry, error::HolochainError}; @@ -36,34 +37,23 @@ impl ChainPair { self.1.clone() } - pub fn fetch_chain_pair(address: &Address, state: &State) -> Result { - let entry = fetch_entry_from_cas(address, state)?; + pub fn fetch_chain_pair( + address: &Address, + state: &State + ) -> Result { + let entry = state + .agent() + .chain_store() + .get(address)? + .ok_or_else(|| HolochainError::from("Entry not found"))?; let header = find_chain_header(&entry, &StateWrapper::from(state.clone())).ok_or_else(|| { HolochainError::from( - "No header found for entry {}with address {}", - entry, - address, + "No header found for the address {}. Entry:\n{:#?}\n", + address, entry ) })?; - ChainPair::new(entry, header) } } - -fn fetch_entry_from_cas(address: &Address, state: &State) -> Result { - let json = state - .agent() - .chain_store() - .content_storage() - .read()? - .fetch(address)? - .ok_or_else(|| { - HolochainError::from("Entry with address {} could not be found.", address) - })?; -HeaderEntryMismatch(String, Address, Address), - HeaderEntryMismatch(String, Address, Address), - let s: Entry = json.try_into()?; - Ok(s) -} diff --git a/crates/core/src/network/entry_with_header.rs b/crates/core/src/network/entry_with_header.rs deleted file mode 100644 index 5dd1a0fdcb..0000000000 --- a/crates/core/src/network/entry_with_header.rs +++ /dev/null @@ -1,48 +0,0 @@ -use crate::{ - agent::find_chain_header, - content_store::GetContent, - state::{State, StateWrapper}, -}; -use holochain_core_types::{chain_header::ChainHeader, entry::Entry, error::HolochainError}; -use holochain_persistence_api::cas::content::{Address, AddressableContent}; - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct EntryWithHeader { - pub entry: Entry, - pub header: ChainHeader, -} - -impl EntryWithHeader { - pub fn new(entry: Entry, header: ChainHeader) -> EntryWithHeader { - EntryWithHeader { entry, header } - } - - pub fn try_from_entry_and_header( - entry: Entry, - header: ChainHeader, - ) -> Result { - if entry.address() != *header.entry_address() { - Err(HolochainError::ValidationFailed(String::from( - "Entry/Header mismatch", - ))) - } else { - Ok(EntryWithHeader::new(entry, header)) - } - } -} - -pub fn fetch_chain_pair( - address: &Address, - state: &State, -) -> Result { - let entry = state - .agent() - .chain_store() - .get(address)? - .ok_or_else(|| HolochainError::from("Entry not found"))?; - - let header = find_chain_header(&entry, &StateWrapper::from(state.clone())) - .ok_or_else(|| HolochainError::from("No header found for entry"))?; - - Ok(EntryWithHeader::new(entry, header)) -} From 9ca847d0be8e41d12479d91af64ca1f058e28679 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Fri, 22 Nov 2019 17:38:45 +1100 Subject: [PATCH 12/79] use try_from_header_and_entry and remove new for ChainPair. Add fixes. Use a convenience function, try_validate_from_entry_and_header --- crates/core/src/agent/state.rs | 2 +- crates/core/src/dht/dht_reducers.rs | 5 +- crates/core/src/dht/dht_store.rs | 16 +-- crates/core/src/network/chain_pair.rs | 34 ++++-- crates/core/src/network/handler/mod.rs | 22 ++-- crates/core/src/network/reducers/publish.rs | 31 ++--- .../network/reducers/publish_header_entry.rs | 2 +- .../reducers/add_pending_validation.rs | 2 +- .../reducers/queue_zome_function_call.rs | 2 +- .../reducers/remove_pending_validation.rs | 2 +- .../src/scheduled_jobs/pending_validations.rs | 109 +++++++++++++----- crates/core/src/workflows/hold_entry.rs | 2 +- .../core/src/workflows/hold_entry_remove.rs | 4 +- .../core/src/workflows/hold_entry_update.rs | 4 +- crates/core/src/workflows/hold_link.rs | 12 +- crates/core/src/workflows/remove_link.rs | 11 +- crates/core_types/src/chain_header.rs | 3 +- crates/core_types/src/error/mod.rs | 6 +- crates/core_types/src/error/ribosome_error.rs | 3 +- crates/hdk/tests/links.rs | 2 +- crates/hdk/tests/misc.rs | 7 +- crates/metrics/src/logger.rs | 1 - crates/metrics/src/metrics.rs | 1 - crates/metrics/src/stats.rs | 1 - crates/trycp_server/src/main.rs | 2 +- 25 files changed, 171 insertions(+), 115 deletions(-) diff --git a/crates/core/src/agent/state.rs b/crates/core/src/agent/state.rs index 5693a2cedc..9ce7b86790 100644 --- a/crates/core/src/agent/state.rs +++ b/crates/core/src/agent/state.rs @@ -217,7 +217,7 @@ pub fn create_chain_pair_for_header( let entry = Entry::ChainHeader(chain_header); let header = create_new_chain_header(&entry, &root_state.agent(), &root_state, &None, &Vec::new())?; - ChainPair::new(header, entry) + ChainPair::try_from_header_and_entry(header, entry) } /// Do a Commit Action against an agent state. diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index f605f5e6d2..1d0542ae35 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -225,7 +225,8 @@ pub mod tests { // test_entry is not sys so should do nothing let sys_entry = test_sys_entry(); - let chain_pair = ChainPair::new(test_chain_header(), sys_entry.clone()); + let chain_pair = + ChainPair::try_from_header_and_entry(test_chain_header(), sys_entry.clone())?; let new_dht_store = reduce_hold_entry(&store.dht(), &ActionWrapper::new(Action::Hold(chain_pair))) @@ -443,7 +444,7 @@ pub mod tests { let store = test_store(context.clone()); let entry = test_entry(); - let chain_pair = ChainPair::new(test_chain_header(), entry.clone()); + let chain_pair = ChainPair::try_from_header_and_entry(test_chain_header(), entry.clone())?; let action_wrapper = ActionWrapper::new(Action::Hold(chain_pair.clone())); store.reduce(action_wrapper); diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index 47260dc6bb..842130218c 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -228,16 +228,16 @@ impl DhtStore { entry: &Entry, header: &ChainHeader, ) -> Result<(), HolochainError> { - match ChainPair::new(header, entry) { + match ChainPair::try_from_header_and_entry(header, entry) { Ok(_chain_pair) => { let eavi = EntityAttributeValueIndex::new( - &entry.address(), - &Attribute::EntryHeader, - &header.address(), - )?; - self.add(header)?; - self.meta_storage.write().unwrap().add_eavi(&eavi)?; - Ok(()) + &entry.address(), + &Attribute::EntryHeader, + &header.address(), + )?; + self.add(header)?; + self.meta_storage.write().unwrap().add_eavi(&eavi)?; + Ok(()) } Err(err) => match err { HolochainError::HeaderEntryMismatch(err_msg, ..) => { diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index 39f0ce5ecc..3d80a9c61a 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -4,8 +4,7 @@ use crate::{ state::{State, StateWrapper}, }; use holochain_core_types::{chain_header::ChainHeader, entry::Entry, error::HolochainError}; -use holochain_persistence_api::cas::content::Address; -use std::convert::TryInto; +use holochain_persistence_api::cas::content::{Address, AddressableContent}; /// A `ChainPair` cannot be constructed unless the entry address in the /// `ChainHeader` that is within the `ChainPair` is the same as the address @@ -14,21 +13,33 @@ use std::convert::TryInto; pub struct ChainPair(ChainHeader, Entry); impl ChainPair { - pub fn new(header: ChainHeader, entry: Entry) -> Result { - let header_entry = header.entry(); - let header_entry_address = header_entry.address(); + // It seems best to not have a new method, since stylistically it is expected to return Self, whereas constructing could fail. + pub fn try_from_header_and_entry( + header: ChainHeader, + entry: Entry, + ) -> Result { + let header_entry_address = *header.entry_address(); let entry_address = entry.address(); if header_entry_address == entry_address { Ok(ChainPair(header, entry)) } else { Err(HolochainError::HeaderEntryMismatch( - "Tried to create a ChainPair, but got a mismatch with the header's entry address {} and the entry's address {}.", - header_entry_address, - entry_address, + "Tried to create a ChainPair, but got a mismatch with the header's entry address {} and the entry's address {}. Header:\n{:#?}\nEntry:{:#?}", + header_entry_address, entry_address, header, entry )) } } + // Convenience function for returning a custom error in the context of validation. + pub fn try_validate_from_entry_and_header( + entry: Entry, + header: ChainHeader, + entry_aspect: EntryAspect, + ) -> Result { + ChainPair::try_from_header_and_entry(header, entry) + .map_err(|e| HolochainError::ValidationFailed(String::from(e))) + } + pub fn header(&self) -> ChainHeader { self.0.clone() } @@ -49,11 +60,12 @@ impl ChainPair { let header = find_chain_header(&entry, &StateWrapper::from(state.clone())).ok_or_else(|| { - HolochainError::from( - "No header found for the address {}. Entry:\n{:#?}\n", + let error_msg = format!( + "No header found for the address:\n{}\nEntry:\n{:#?}\n", address, entry ) + HolochainError::from(error_msg) })?; - ChainPair::new(entry, header) + ChainPair::try_from_header_and_entry(header, entry) } } diff --git a/crates/core/src/network/handler/mod.rs b/crates/core/src/network/handler/mod.rs index 091d1b98a8..b0fca665d4 100644 --- a/crates/core/src/network/handler/mod.rs +++ b/crates/core/src/network/handler/mod.rs @@ -1,4 +1,4 @@ -use crate::agent::state::create_chain_pair_for_header, content_store::GetContent; +use crate::{agent::state::create_chain_pair_for_header, content_store::GetContent}; use holochain_logging::prelude::*; pub mod fetch; pub mod lists; @@ -306,14 +306,14 @@ fn get_content_aspect( Some((header, false)) => { // ... we can just get the content from the chain CAS let entry = state - .agent() - .chain_store() - .get(&header.entry_address())? - .expect("Could not find entry in chain CAS, but header is chain"); - match ChainPair::new(header, entry) { - Ok(chain_pair) => Some(chain_pair), - Err(error) => return Err(error) - } + .agent() + .chain_store() + .get(&header.entry_address())? + .expect("Could not find entry in chain CAS, but header is chain"); + match ChainPair::try_from_header_and_entry(header, entry) { + Ok(chain_pair) => Some(chain_pair), + Err(error) => return Err(error), + } } None => { // ... but if we didn't author that entry, let's see if we have it in the DHT cas: @@ -332,11 +332,11 @@ fn get_content_aspect( // TODO: this is just taking the first header.. // We should actually transform all headers into EntryAspect::Headers and just the first one // into an EntryAspect content (What about ordering? Using the headers timestamp?) - match ChainPair::new(headers[0].clone(), entry) { + match ChainPair::try_from_header_and_entry(headers[0].clone(), entry) { Ok(chain_pair) => Some(chain_pair), Err(error) => { log_error!(context, "{}", error); - Err(error) + None }, } } else { diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index 2ee221b0c1..539c1aa700 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -2,8 +2,8 @@ use crate::{ action::ActionWrapper, network::{ actions::ActionResponse, - entry_aspect::EntryAspect, chain_pair::{fetch_chain_pair, ChainPair}, + entry_aspect::EntryAspect, reducers::send, state::NetworkState, }, @@ -69,7 +69,7 @@ fn publish_update_delete_meta( let aspect = match crud_status { CrudStatus::Modified => EntryAspect::Update( chain_pair.entry().clone(), - chain_pair.header().clone(), + chain_pair.header().clone() ), CrudStatus::Deleted => EntryAspect::Deletion(chain_pair.header().clone()), crud => { @@ -110,8 +110,7 @@ fn publish_link_meta( link_data.link().base().clone(), EntryAspect::LinkRemove( (link_data, links_to_remove), - chain_pair.header().clone(), - ), + chain_pair.header().clone()), ), _ => { return Err(HolochainError::ErrorGeneric(format!( @@ -144,17 +143,19 @@ fn reduce_publish_inner( match chain_pair.entry().entry_type() { EntryType::AgentId => publish_entry(network_state, &chain_pair), - EntryType::App(_) => publish_entry(network_state, &chain_pair).and_then(|_| { - match chain_pair.header().link_update_delete() { - Some(modified_entry) => publish_update_delete_meta( - network_state, - modified_entry, - CrudStatus::Modified, - &chain_pair.clone(), - ), - None => Ok(()), - } - }), + EntryType::App(_) => { + publish_entry(network_state, &chain_pair).and_then(|_| { + match chain_pair.header().link_update_delete() { + Some(modified_entry) => publish_update_delete_meta( + network_state, + modified_entry, + CrudStatus::Modified, + &chain_pair.clone(), + ), + None => Ok(()), + } + }) + }, EntryType::LinkAdd => publish_entry(network_state, &chain_pair) .and_then(|_| publish_link_meta(network_state, &chain_pair)), EntryType::LinkRemove => publish_entry(network_state, &chain_pair) diff --git a/crates/core/src/network/reducers/publish_header_entry.rs b/crates/core/src/network/reducers/publish_header_entry.rs index 5d5cea72ef..8b334b80d0 100644 --- a/crates/core/src/network/reducers/publish_header_entry.rs +++ b/crates/core/src/network/reducers/publish_header_entry.rs @@ -3,8 +3,8 @@ use crate::{ agent::state::create_chain_pair_for_header, network::{ actions::ActionResponse, - entry_aspect::EntryAspect, chain_pair::fetch_chain_pair, + entry_aspect::EntryAspect, reducers::{publish::entry_data_to_entry_aspect_data, send}, state::NetworkState, }, diff --git a/crates/core/src/nucleus/reducers/add_pending_validation.rs b/crates/core/src/nucleus/reducers/add_pending_validation.rs index 343472a72d..44147fe5be 100644 --- a/crates/core/src/nucleus/reducers/add_pending_validation.rs +++ b/crates/core/src/nucleus/reducers/add_pending_validation.rs @@ -46,7 +46,7 @@ pub mod tests { let root_state = test_store(context); let entry = Entry::App("package_entry".into(), RawString::from("test value").into()); - let chain_pair = ChainPair::new(test_chain_header(), entry.clone()); + let chain_pair = ChainPair::try_from_header_and_entry(test_chain_header(), entry.clone())?; let action_wrapper = ActionWrapper::new(Action::AddPendingValidation(Arc::new( PendingValidationStruct { diff --git a/crates/core/src/nucleus/reducers/queue_zome_function_call.rs b/crates/core/src/nucleus/reducers/queue_zome_function_call.rs index 216d98227e..26f9fd212a 100644 --- a/crates/core/src/nucleus/reducers/queue_zome_function_call.rs +++ b/crates/core/src/nucleus/reducers/queue_zome_function_call.rs @@ -5,7 +5,7 @@ use crate::{ }; /// Reduce AddPendingValidation Action. -/// Inserts boxed EntryWithHeader and dependencies into state, referenced with +/// Inserts boxed ChainPair and dependencies into state, referenced with /// the entry's address. #[allow(unknown_lints)] #[allow(clippy::needless_pass_by_value)] diff --git a/crates/core/src/nucleus/reducers/remove_pending_validation.rs b/crates/core/src/nucleus/reducers/remove_pending_validation.rs index 9c729bc5dd..70916d7a81 100644 --- a/crates/core/src/nucleus/reducers/remove_pending_validation.rs +++ b/crates/core/src/nucleus/reducers/remove_pending_validation.rs @@ -47,7 +47,7 @@ pub mod tests { let state = test_store(context); let entry = Entry::App("package_entry".into(), RawString::from("test value").into()); - let chain_pair = ChainPair::new(test_chain_header(), entry.clone()); + let chain_pair = ChainPair::try_from_header_and_entry(test_chain_header(), entry.clone())?; let action_wrapper = ActionWrapper::new(Action::AddPendingValidation(Arc::new( PendingValidationStruct { diff --git a/crates/core/src/scheduled_jobs/pending_validations.rs b/crates/core/src/scheduled_jobs/pending_validations.rs index f8209a533d..5a9a4fc60d 100644 --- a/crates/core/src/scheduled_jobs/pending_validations.rs +++ b/crates/core/src/scheduled_jobs/pending_validations.rs @@ -15,7 +15,7 @@ use holochain_core_types::{ network::entry_aspect::EntryAspect, }; use holochain_json_api::{error::JsonError, json::JsonString}; -use holochain_persistence_api::cas::content::Address; +use holochain_persistence_api::cas::content::{Address, AddressableContent}; use std::{convert::TryFrom, fmt, sync::Arc}; pub type PendingValidation = Arc; @@ -90,31 +90,80 @@ impl TryFrom for PendingValidationStruct { type Error = HolochainError; fn try_from(aspect: EntryAspect) -> Result { match aspect { - EntryAspect::Content(entry, header) => Ok(PendingValidationStruct::new( - ChainPair::try_from_chain_pair(entry, header)?, - ValidatingWorkflow::HoldEntry, - )), + EntryAspect::Content(entry, header) => { + match try_validate_from_entry_and_header(entry, header) { + Ok(chain_pair) => { + Ok(PendingValidationStruct::new( + chain_pair, + ValidatingWorkflow::HoldEntry, + )), + Err(error) => { + let error_msg = format!( + "Tried to process EntryAspect::Content(entry, header)\n + where entry is:\n{#:?}\nHeader:\n{#:?}\nError:{}", + entry, header, error + ); + Err(HolochainError::ValidationFailed(String::from(error_msg))) + }, + } + } + }, EntryAspect::Header(_header) => Err(HolochainError::NotImplemented(String::from( "EntryAspect::Header", ))), EntryAspect::LinkAdd(link_data, header) => { - let entry = Entry::LinkAdd(link_data); - Ok(PendingValidationStruct::new( - EntryWithHeader::try_from_entry_and_header(entry, header)?, - ValidatingWorkflow::HoldLink, - )) + let entry = Entry::LinkAdd(link_data);LinkAdd; + // TODO: These match statements could be refactored as there + // is a lot of repetition. + match try_validate_from_entry_and_header(entry, header) { + Ok(chain_pair) => Ok(PendingValidationStruct::new( + chain_pair, + ValidatingWorkflow::HoldLink, + )), + Err(error) => { + let error_msg = format!( + "Tried to process EntryAspect::LinkAdd:\n{}", error + ); + Err(HolochainError::ValidationFailed(String::from(error_msg))) + }, + } } EntryAspect::LinkRemove((link_data, links_to_remove), header) => { let entry = Entry::LinkRemove((link_data, links_to_remove)); - Ok(PendingValidationStruct::new( - EntryWithHeader::try_from_entry_and_header(entry, header)?, - ValidatingWorkflow::RemoveLink, - )) - } - EntryAspect::Update(entry, header) => Ok(PendingValidationStruct::new( - EntryWithHeader::try_from_entry_and_header(entry, header)?, - ValidatingWorkflow::UpdateEntry, - )), + match try_validate_from_entry_and_header(entry, header) { + Ok(chain_pair) => Ok(PendingValidationStruct::new( + chain_pair, + ValidatingWorkflow::RemoveLink, + )), + Err(error) => { + let error_msg = format!( + "Tried to process\n + EntryAspect::LinkRemove((link_data, links_to_remove), + \nheader: {}. entry:\n{#:?}\nheader:\nlink_data:\n + {#:?}\nlinks_to_remove:\n{:#?}\nGot error:\n{}", + entry, header, link_data, links_to_remove, error + ); + Err(HolochainError::ValidationFailed(String::from(error_msg))) + }, + } + }, + EntryAspect::Update(entry, header) => { + match try_validate_from_entry_and_header(entry, header) { + Ok(chain_pair) => Ok(PendingValidationStruct::new( + chain_pair, + ValidatingWorkflow::UpdateEntry, + )), + Err(error) => { + let error_msg = format!( + "Tried to process\n + EntryAspect::Update(entry, header),\n + entry:\n{#:?}\nheader:\n{:#?}\nGot error:\n{}", + entry, header, link_data, links_to_remove, error + ); + Err(HolochainError::ValidationFailed(String::from(error_msg))) + }, + } + }, EntryAspect::Deletion(header) => { // reconstruct the deletion entry from the header. let deleted_entry_address = header.link_update_delete().ok_or_else(|| { @@ -124,11 +173,19 @@ impl TryFrom for PendingValidationStruct { })?; let entry = Entry::Deletion(DeletionEntry::new(deleted_entry_address)); - Ok(PendingValidationStruct::new( - EntryWithHeader::try_from_entry_and_header(entry, header)?, - ValidatingWorkflow::RemoveEntry, - )) - } + match ChainPair::try_validate_from_entry_and_header(entry, header) => { + Ok(chain_pair) => {Ok(PendingValidationStruct::new( + chain_pair, + ValidatingWorkflow::RemoveEntry, + ))}, + Err(error) => { + HolochainError::ValidationFailed( + "Tried to process EntryAspect::Deletion(header)\n + where header is:\n{#:?}\nGot error:\n{}", + header, error + )}, + } + }, } } } @@ -145,8 +202,8 @@ pub fn run_pending_validations(context: Arc) { log_debug!( context, "scheduled_jobs/run_pending_validations: found pending validation for {}: {}", - pending.entry_with_header.entry.entry_type(), - pending.entry_with_header.entry.address() + pending.chain_pair.entry().entry_type(), + pending.chain_pair.entry().address() ); retry_validation(pending.clone(), context.clone()); }); diff --git a/crates/core/src/workflows/hold_entry.rs b/crates/core/src/workflows/hold_entry.rs index 051c3c206f..61706c0fee 100644 --- a/crates/core/src/workflows/hold_entry.rs +++ b/crates/core/src/workflows/hold_entry.rs @@ -150,7 +150,7 @@ pub mod tests { let header = agent1_state .get_most_recent_header_for_entry(&entry) .expect("There must be a header in the author's source chain after commit"); - let chain_pair = ChainPair::new(header, entry)?; + let chain_pair = ChainPair::try_from_header_and_entry(header, entry)?; // Call hold_entry_workflow on victim DHT node let result = context2.block_on(hold_entry_workflow(&chain_pair, &context2)); diff --git a/crates/core/src/workflows/hold_entry_remove.rs b/crates/core/src/workflows/hold_entry_remove.rs index 7fbba4a08a..62246cd20a 100644 --- a/crates/core/src/workflows/hold_entry_remove.rs +++ b/crates/core/src/workflows/hold_entry_remove.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::remove_entry::remove_entry, - network::chain_pair::ChainPair, nucleus::validation::validate_entry, + context::Context, dht::actions::remove_entry::remove_entry, network::chain_pair::ChainPair, + nucleus::validation::validate_entry, }; use crate::{ diff --git a/crates/core/src/workflows/hold_entry_update.rs b/crates/core/src/workflows/hold_entry_update.rs index 63e9ff1a00..ca3f91aca5 100644 --- a/crates/core/src/workflows/hold_entry_update.rs +++ b/crates/core/src/workflows/hold_entry_update.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::update_entry::update_entry, - network::chain_pair::ChainPair, nucleus::validation::validate_entry, + context::Context, dht::actions::update_entry::update_entry, network::chain_pair::ChainPair, + nucleus::validation::validate_entry, }; use holochain_persistence_api::cas::content::AddressableContent; diff --git a/crates/core/src/workflows/hold_link.rs b/crates/core/src/workflows/hold_link.rs index 31ff63dad6..0c1026ddbd 100644 --- a/crates/core/src/workflows/hold_link.rs +++ b/crates/core/src/workflows/hold_link.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::add_link::add_link, - network::chain_pair::ChainPair, nucleus::validation::validate_entry, + context::Context, dht::actions::add_link::add_link, network::chain_pair::ChainPair, + nucleus::validation::validate_entry, }; use crate::{ @@ -100,11 +100,7 @@ pub async fn hold_link_workflow( //4. store link_add entry so we have all we need to respond to get links queries without any other network look-up hold_entry_workflow(&chain_pair, context.clone()).await?; - log_debug!( - context, - "workflow/hold_entry: added! {:?}", - chain_pair - ); + log_debug!(context, "workflow/hold_entry: added! {:?}", chain_pair); //5. Link has been added to EAV and LinkAdd Entry has been stored on the dht Ok(()) @@ -168,7 +164,7 @@ pub mod tests { let header = agent1_state .get_most_recent_header_for_entry(&link_entry) .expect("There must be a header in the author's source chain after commit"); - let chain_pair = ChainPair::new(header, link_entry); + let chain_pair = ChainPair::try_from_entry_and_header(header, link_entry); // Call hold_entry_workflow on victim DHT node let result = context2.block_on(hold_link_workflow(&chain_pair, context2.clone())); diff --git a/crates/core/src/workflows/remove_link.rs b/crates/core/src/workflows/remove_link.rs index 8d4062425e..c83dcac403 100644 --- a/crates/core/src/workflows/remove_link.rs +++ b/crates/core/src/workflows/remove_link.rs @@ -1,7 +1,6 @@ use crate::{ - context::Context, dht::actions::remove_link::remove_link, - network::chain_pair::ChainPair, nucleus::validation::validate_entry, - workflows::hold_entry::hold_entry_workflow, + context::Context, dht::actions::remove_link::remove_link, network::chain_pair::ChainPair, + nucleus::validation::validate_entry, workflows::hold_entry::hold_entry_workflow, }; use crate::{ @@ -97,11 +96,7 @@ pub async fn remove_link_workflow( //4. store link_remove entry so we have all we need to respond to get links queries without any other network look-up``` hold_entry_workflow(&chain_pair, context.clone()).await?; - log_debug!( - context, - "workflow/hold_entry: added! {:?}", - chain_pair - ); + log_debug!(context, "workflow/hold_entry: added! {:?}", chain_pair); Ok(()) } diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index 01938ce6d2..29f18efb36 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -19,8 +19,7 @@ use holochain_json_api::{ json::JsonString, }; -use std::{convert::TryInto}; - +use std::convert::TryInto; /// ChainHeader of a source chain "Item" /// The address of the ChainHeader is used as the Item's key in the source chain hash table diff --git a/crates/core_types/src/error/mod.rs b/crates/core_types/src/error/mod.rs index 79130676d3..c6cb2f5240 100644 --- a/crates/core_types/src/error/mod.rs +++ b/crates/core_types/src/error/mod.rs @@ -163,11 +163,7 @@ impl fmt::Display for HolochainError { "Provided DNA hash does not match actual DNA hash! {} != {}", hash1, hash2 ), - HeaderEntryMismatch( - err_msg, - header_entry_address, - entry_address, - ) => write!( + HeaderEntryMismatch(err_msg, header_entry_address, entry_address) => write!( f, "Header/Entry mismatch. The address {} of the entry in the header does not match the address {} of the entry. {}", diff --git a/crates/core_types/src/error/ribosome_error.rs b/crates/core_types/src/error/ribosome_error.rs index 1061a0f840..76cba8c03a 100644 --- a/crates/core_types/src/error/ribosome_error.rs +++ b/crates/core_types/src/error/ribosome_error.rs @@ -206,8 +206,7 @@ impl From for RibosomeErrorCode { HolochainError::InitializationFailed(_) => RibosomeErrorCode::Unspecified, HolochainError::LifecycleError(_) => RibosomeErrorCode::Unspecified, HolochainError::DnaHashMismatch(_, _) => RibosomeErrorCode::Unspecified, - HolochainError::HeaderEntryMismatch(_, _, _) => - RibosomeErrorCode::Unspecified, + HolochainError::HeaderEntryMismatch(_, _, _) => RibosomeErrorCode::Unspecified, HolochainError::EntryNotFoundLocally => RibosomeErrorCode::Unspecified, HolochainError::EntryIsPrivate => RibosomeErrorCode::Unspecified, HolochainError::List(_) => RibosomeErrorCode::Unspecified, diff --git a/crates/hdk/tests/links.rs b/crates/hdk/tests/links.rs index e1acd48302..410a95d637 100644 --- a/crates/hdk/tests/links.rs +++ b/crates/hdk/tests/links.rs @@ -252,7 +252,7 @@ pub fn test_links_with_immediate_timeout() { &result.clone().expect("err result").to_string(), ) .expect("bad deserialize"); - let zome_internal_error = generate_zome_internal_error(String::from(r#""Timeout""#));; + let zome_internal_error = generate_zome_internal_error(String::from(r#""Timeout""#)); assert_zome_internal_errors_equivalent(&expected_result.unwrap_err(), &zome_internal_error); } diff --git a/crates/hdk/tests/misc.rs b/crates/hdk/tests/misc.rs index 739f4c992f..5710c8b302 100755 --- a/crates/hdk/tests/misc.rs +++ b/crates/hdk/tests/misc.rs @@ -460,7 +460,10 @@ fn show_env() { let dna = hc.context().unwrap().get_dna().unwrap(); let dna_address_string = dna.address().to_string(); let dna_address = dna_address_string.as_str(); - let format = format!(r#"{{"Ok":{{"dna_name":"TestApp","dna_address":"{}","agent_id":"{{\"nick\":\"show_env\",\"pub_sign_key\":\"HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i\"}}","agent_address":"HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i","cap_request":{{"cap_token":"QmaT1nbEQn8KsMJ32nvBZUHHEtzrP32duzwPr5Es7H5zEW","provenance":["HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i","FxhnQJzPu+TPqJHCtT2e5CNMky2YnnLXtABMJyNhx5SyztyeuKU/zxS4a1e8uKdPYT5N0ldCcLgpITeHfB7dAg=="]}},"properties":"{{}}"}}}}"#,dna_address); + let format = format!( + r#"{{"Ok":{{"dna_name":"TestApp","dna_address":"{}","agent_id":"{{\"nick\":\"show_env\",\"pub_sign_key\":\"HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i\"}}","agent_address":"HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i","cap_request":{{"cap_token":"QmaT1nbEQn8KsMJ32nvBZUHHEtzrP32duzwPr5Es7H5zEW","provenance":["HcSCIBgTFMzn8vz5ogz5eW87h9nf5eqpdsJOKJ47ZRDopz74HihmraGXio74e6i","FxhnQJzPu+TPqJHCtT2e5CNMky2YnnLXtABMJyNhx5SyztyeuKU/zxS4a1e8uKdPYT5N0ldCcLgpITeHfB7dAg=="]}},"properties":"{{}}"}}}}"#, + dna_address + ); let json_result = Ok(JsonString::from_json(&format)); let result = make_test_call(&mut hc, "show_env", r#"{}"#); @@ -497,7 +500,7 @@ fn test_signal() { recieved_signal == &UserSignal { name: String::from("test-signal"), - arguments: JsonString::from(r#"{"message":"test message"}"#) + arguments: JsonString::from(r#"{"message":"test message"}"#), } } _ => false, diff --git a/crates/metrics/src/logger.rs b/crates/metrics/src/logger.rs index 1bfa46f8af..766576861e 100644 --- a/crates/metrics/src/logger.rs +++ b/crates/metrics/src/logger.rs @@ -130,5 +130,4 @@ mod tests { assert_eq!("sim2h_worker.tick.latency", metric.name); assert_eq!(123.0, metric.value); } - } diff --git a/crates/metrics/src/metrics.rs b/crates/metrics/src/metrics.rs index 2cf63b19b0..098277cfc5 100644 --- a/crates/metrics/src/metrics.rs +++ b/crates/metrics/src/metrics.rs @@ -106,5 +106,4 @@ mod test { assert!(ret) } - } diff --git a/crates/metrics/src/stats.rs b/crates/metrics/src/stats.rs index d29f5b8215..fde64240ab 100644 --- a/crates/metrics/src/stats.rs +++ b/crates/metrics/src/stats.rs @@ -196,5 +196,4 @@ mod tests { assert_eq!(size_stats.min(), 1.0); assert_eq!(size_stats.max(), 100.0); } - } diff --git a/crates/trycp_server/src/main.rs b/crates/trycp_server/src/main.rs index 4289f07d1d..a26c0b3f2b 100755 --- a/crates/trycp_server/src/main.rs +++ b/crates/trycp_server/src/main.rs @@ -380,7 +380,7 @@ fn main() { let mut conductor = Command::new("holochain") .args(&["-c", &config_path]) - .env("RUST_BACKTRACE","full") + .env("RUST_BACKTRACE", "full") .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() From 9dcf231e00a6c45d389a0df1c712c8bf7d99bfaa Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 23 Nov 2019 20:45:09 +1100 Subject: [PATCH 13/79] Fixing errors. Noticed that retry_validations was missing so added manually from develop, but I should pull upstream develop --- crates/core/src/dht/dht_reducers.rs | 1 - crates/core/src/dht/dht_store.rs | 6 +- crates/core/src/network/chain_pair.rs | 6 +- crates/core/src/network/handler/store.rs | 1 - .../src/scheduled_jobs/pending_validations.rs | 104 +++++++++++++----- crates/core_types/src/error/mod.rs | 8 +- 6 files changed, 89 insertions(+), 37 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 1d0542ae35..4dcc545abb 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -3,7 +3,6 @@ use crate::{ action::{Action, ActionWrapper}, dht::dht_store::DhtStore, - network::chain_pair::ChainPair, }; use std::sync::Arc; diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index 842130218c..2c883796c7 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -240,13 +240,13 @@ impl DhtStore { Ok(()) } Err(err) => match err { - HolochainError::HeaderEntryMismatch(err_msg, ..) => { + HolochainError::HeaderEntryMismatch(err_msg, header_entry_address, entry_address) => { let add_err_msg = format!( - "Tried to add entry {} and header {} to the CAS and EAV, respectively", + "Tried to add entry:\n{:#?}\nand header:\n{:#?}\nto the CAS and EAV, respectively", entry, header, ); err_msg = concat!(err_msg, add_err_msg); - Err(HolochainError::HeaderEntryMismatch(err_msg, ..)) + Err(HolochainError::HeaderEntryMismatch(err_msg, header_entry_address, entry_address)) } }, } diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index 3d80a9c61a..dea5fc861b 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -23,9 +23,9 @@ impl ChainPair { if header_entry_address == entry_address { Ok(ChainPair(header, entry)) } else { + let error_msg = format!("Tried to create a ChainPair, but got a mismatch with the header's entry address and the entry's address. Header:\n{:#?}\nEntry:{:#?}", header, entry); Err(HolochainError::HeaderEntryMismatch( - "Tried to create a ChainPair, but got a mismatch with the header's entry address {} and the entry's address {}. Header:\n{:#?}\nEntry:{:#?}", - header_entry_address, entry_address, header, entry + error_msg, header_entry_address, entry_address )) } } @@ -63,7 +63,7 @@ impl ChainPair { let error_msg = format!( "No header found for the address:\n{}\nEntry:\n{:#?}\n", address, entry - ) + ); HolochainError::from(error_msg) })?; ChainPair::try_from_header_and_entry(header, entry) diff --git a/crates/core/src/network/handler/store.rs b/crates/core/src/network/handler/store.rs index 457a69b110..43361ee140 100644 --- a/crates/core/src/network/handler/store.rs +++ b/crates/core/src/network/handler/store.rs @@ -1,7 +1,6 @@ use crate::{ context::Context, dht::actions::queue_holding_workflow::dispatch_queue_holding_workflow, - network::{chain_pair::ChainPair, entry_aspect::EntryAspect}, scheduled_jobs::pending_validations::PendingValidationStruct, }; use holochain_core_types::network::entry_aspect::EntryAspect; diff --git a/crates/core/src/scheduled_jobs/pending_validations.rs b/crates/core/src/scheduled_jobs/pending_validations.rs index 5a9a4fc60d..c0d2d3c2de 100644 --- a/crates/core/src/scheduled_jobs/pending_validations.rs +++ b/crates/core/src/scheduled_jobs/pending_validations.rs @@ -1,15 +1,9 @@ use crate::{ context::Context, network::chain_pair::ChainPair, - nucleus::actions::remove_pending_validation::remove_pending_validation, - workflows::{hold_entry::hold_entry_workflow, hold_link::hold_link_workflow}, }; use holochain_core_types::error::HolochainError; -use crate::workflows::{ - hold_entry_remove::hold_remove_workflow, hold_entry_update::hold_update_workflow, - remove_link::remove_link_workflow, -}; use holochain_core_types::{ entry::{deletion_entry::DeletionEntry, Entry}, network::entry_aspect::EntryAspect, @@ -91,31 +85,35 @@ impl TryFrom for PendingValidationStruct { fn try_from(aspect: EntryAspect) -> Result { match aspect { EntryAspect::Content(entry, header) => { - match try_validate_from_entry_and_header(entry, header) { + match ChainPair::try_validate_from_entry_and_header( + entry, + header, + EntryAspect::Content(entry, header) + ) { Ok(chain_pair) => { Ok(PendingValidationStruct::new( chain_pair, ValidatingWorkflow::HoldEntry, - )), - Err(error) => { - let error_msg = format!( - "Tried to process EntryAspect::Content(entry, header)\n - where entry is:\n{#:?}\nHeader:\n{#:?}\nError:{}", - entry, header, error - ); - Err(HolochainError::ValidationFailed(String::from(error_msg))) - }, + )) + } + Err(error) => { + let error_msg = format!( + "Tried to process EntryAspect::Content(entry, header)\n + where entry is:\n{#:?}\nHeader:\n{#:?}\nError:{}", + entry, header, error + ); + Err(HolochainError::ValidationFailed(String::from(error_msg))) } } }, EntryAspect::Header(_header) => Err(HolochainError::NotImplemented(String::from( "EntryAspect::Header", ))), - EntryAspect::LinkAdd(link_data, header) => { + ea @ EntryAspect::LinkAdd(link_data, header) => { let entry = Entry::LinkAdd(link_data);LinkAdd; // TODO: These match statements could be refactored as there // is a lot of repetition. - match try_validate_from_entry_and_header(entry, header) { + match ChainPair::try_validate_from_entry_and_header(entry, header, ea) { Ok(chain_pair) => Ok(PendingValidationStruct::new( chain_pair, ValidatingWorkflow::HoldLink, @@ -128,9 +126,13 @@ impl TryFrom for PendingValidationStruct { }, } } - EntryAspect::LinkRemove((link_data, links_to_remove), header) => { + ea @ EntryAspect::LinkRemove((link_data, links_to_remove), header) => { let entry = Entry::LinkRemove((link_data, links_to_remove)); - match try_validate_from_entry_and_header(entry, header) { + match ChainPair::try_validate_from_entry_and_header( + entry, + header, + ea + ) { Ok(chain_pair) => Ok(PendingValidationStruct::new( chain_pair, ValidatingWorkflow::RemoveLink, @@ -148,7 +150,11 @@ impl TryFrom for PendingValidationStruct { } }, EntryAspect::Update(entry, header) => { - match try_validate_from_entry_and_header(entry, header) { + match ChainPair::try_validate_from_entry_and_header( + entry, + header, + EntryAspect::Update(entry, header) + ) { Ok(chain_pair) => Ok(PendingValidationStruct::new( chain_pair, ValidatingWorkflow::UpdateEntry, @@ -173,23 +179,67 @@ impl TryFrom for PendingValidationStruct { })?; let entry = Entry::Deletion(DeletionEntry::new(deleted_entry_address)); - match ChainPair::try_validate_from_entry_and_header(entry, header) => { - Ok(chain_pair) => {Ok(PendingValidationStruct::new( + match ChainPair::ChainPair::try_validate_from_entry_and_header( + entry, + header, + EntryAspect::Deletion(header) + ) => { + Ok(chain_pair) => Ok(PendingValidationStruct::new( chain_pair, ValidatingWorkflow::RemoveEntry, - ))}, - Err(error) => { - HolochainError::ValidationFailed( + )), + Err(error) => HolochainError::ValidationFailed( "Tried to process EntryAspect::Deletion(header)\n where header is:\n{#:?}\nGot error:\n{}", header, error - )}, + ), } }, } } } + +fn retry_validation(pending: PendingValidation, context: Arc) { + thread::Builder::new() + .name(format!( + "retry_validation/{}", + ProcessUniqueId::new().to_string() + )) + .spawn(move || { + let result = match pending.workflow { + ValidatingWorkflow::HoldLink => context.block_on(hold_link_workflow( + &pending.entry_with_header, + context.clone(), + )), + ValidatingWorkflow::HoldEntry => context.block_on(hold_entry_workflow( + &pending.entry_with_header, + context.clone(), + )), + ValidatingWorkflow::RemoveLink => context.block_on(remove_link_workflow( + &pending.entry_with_header, + context.clone(), + )), + ValidatingWorkflow::UpdateEntry => context.block_on(hold_update_workflow( + &pending.entry_with_header, + context.clone(), + )), + ValidatingWorkflow::RemoveEntry => context.block_on(hold_remove_workflow( + &pending.entry_with_header, + context.clone(), + )), + }; + if Err(HolochainError::ValidationPending) != result { + remove_pending_validation( + pending.entry_with_header.entry.address(), + pending.workflow.clone(), + &context, + ); + } + }) + .expect("Could not spawn thread for retry_validation"); +} + pub fn run_pending_validations(context: Arc) { let pending_validations = context .state() diff --git a/crates/core_types/src/error/mod.rs b/crates/core_types/src/error/mod.rs index c6cb2f5240..7bc8f0b319 100644 --- a/crates/core_types/src/error/mod.rs +++ b/crates/core_types/src/error/mod.rs @@ -163,9 +163,13 @@ impl fmt::Display for HolochainError { "Provided DNA hash does not match actual DNA hash! {} != {}", hash1, hash2 ), - HeaderEntryMismatch(err_msg, header_entry_address, entry_address) => write!( + HeaderEntryMismatch( + err_msg, + header_entry_address, + entry_address, + ) => write!( f, - "Header/Entry mismatch. The address {} of the entry in the + "Header/Entry mismatch. The entry address {} in the header does not match the address {} of the entry. {}", header_entry_address, entry_address, err_msg ), From 85c9d845840d7142eacb690f909536f41bac9310 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 23 Nov 2019 21:25:32 +1100 Subject: [PATCH 14/79] Fixes, use try_validate_from_entry_and_header to reduce boilerplate --- crates/core/src/network/chain_pair.rs | 26 +++- .../src/scheduled_jobs/pending_validations.rs | 131 ++++++------------ 2 files changed, 62 insertions(+), 95 deletions(-) diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index dea5fc861b..1ea5db19c0 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -1,9 +1,15 @@ use crate::{ agent::find_chain_header, content_store::GetContent, + scheduled_jobs::{PendingValidationStruct, ValidatingWorkflow}, state::{State, StateWrapper}, }; -use holochain_core_types::{chain_header::ChainHeader, entry::Entry, error::HolochainError}; +use holochain_core_types::{ + chain_header::ChainHeader, + entry::Entry, + error::HolochainError, + network::entry_aspect::EntryAspect, +}; use holochain_persistence_api::cas::content::{Address, AddressableContent}; /// A `ChainPair` cannot be constructed unless the entry address in the @@ -35,9 +41,21 @@ impl ChainPair { entry: Entry, header: ChainHeader, entry_aspect: EntryAspect, - ) -> Result { - ChainPair::try_from_header_and_entry(header, entry) - .map_err(|e| HolochainError::ValidationFailed(String::from(e))) + validating_workflow: ValidatingWorkflow, + ) -> Result { + match ChainPair::try_from_header_and_entry(header, entry) { + Ok(chain_pair) => { + Ok(PendingValidationStruct::new( + chain_pair, + validating_workflow, + )), + }, + Err(error) => { + let add_err_msg = format!("Tried to process {#:?}", entry_aspect); + let error = format!("{}, {}", error, add_err_msg); + HolochainError::ValidationFailed(String::from(error)) + }, + } } pub fn header(&self) -> ChainHeader { diff --git a/crates/core/src/scheduled_jobs/pending_validations.rs b/crates/core/src/scheduled_jobs/pending_validations.rs index c0d2d3c2de..c7b2993757 100644 --- a/crates/core/src/scheduled_jobs/pending_validations.rs +++ b/crates/core/src/scheduled_jobs/pending_validations.rs @@ -1,9 +1,16 @@ use crate::{ context::Context, network::chain_pair::ChainPair, + nucleus::actions::remove_pending_validation::remove_pending_validation, + workflows::{hold_entry::hold_entry_workflow, hold_link::hold_link_workflow}, }; use holochain_core_types::error::HolochainError; +use crate::workflows::{ + hold_entry_remove::hold_remove_workflow, hold_entry_update::hold_update_workflow, + remove_link::remove_link_workflow, +}; + use holochain_core_types::{ entry::{deletion_entry::DeletionEntry, Entry}, network::entry_aspect::EntryAspect, @@ -57,7 +64,7 @@ impl fmt::Display for ValidatingWorkflow { ValidatingWorkflow::HoldEntry => write!(f, "HoldEntryWorkflow"), ValidatingWorkflow::HoldLink => write!(f, "HoldLinkWorkflow"), ValidatingWorkflow::RemoveLink => write!(f, "RemoveLinkWorkflow"), - ValidatingWorkflow::UpdateEntry => write!(f, "UpdateEntryWorkflow"), + ValidatingWorkflow::UpdateEntry => write!(f, "UpdateEntryWorkflow"),try_vali ValidatingWorkflow::RemoveEntry => write!(f, "RemoveEntryWorkflow"), } } @@ -84,93 +91,44 @@ impl TryFrom for PendingValidationStruct { type Error = HolochainError; fn try_from(aspect: EntryAspect) -> Result { match aspect { - EntryAspect::Content(entry, header) => { - match ChainPair::try_validate_from_entry_and_header( + ea @ EntryAspect::Content(entry, header) => { + ChainPair::try_validate_from_entry_and_header( entry, header, - EntryAspect::Content(entry, header) - ) { - Ok(chain_pair) => { - Ok(PendingValidationStruct::new( - chain_pair, - ValidatingWorkflow::HoldEntry, - )) - } - Err(error) => { - let error_msg = format!( - "Tried to process EntryAspect::Content(entry, header)\n - where entry is:\n{#:?}\nHeader:\n{#:?}\nError:{}", - entry, header, error - ); - Err(HolochainError::ValidationFailed(String::from(error_msg))) - } - } + ea, + ValidatingWorkflow::HoldEntry, + ) }, EntryAspect::Header(_header) => Err(HolochainError::NotImplemented(String::from( "EntryAspect::Header", ))), ea @ EntryAspect::LinkAdd(link_data, header) => { - let entry = Entry::LinkAdd(link_data);LinkAdd; - // TODO: These match statements could be refactored as there - // is a lot of repetition. - match ChainPair::try_validate_from_entry_and_header(entry, header, ea) { - Ok(chain_pair) => Ok(PendingValidationStruct::new( - chain_pair, - ValidatingWorkflow::HoldLink, - )), - Err(error) => { - let error_msg = format!( - "Tried to process EntryAspect::LinkAdd:\n{}", error - ); - Err(HolochainError::ValidationFailed(String::from(error_msg))) - }, - } + let entry = Entry::LinkAdd(link_data); + ChainPair::try_validate_from_entry_and_header( + entry, + header, + ea, + ValidatingWorkflow::HoldLink, + ) } ea @ EntryAspect::LinkRemove((link_data, links_to_remove), header) => { let entry = Entry::LinkRemove((link_data, links_to_remove)); - match ChainPair::try_validate_from_entry_and_header( + ChainPair::try_validate_from_entry_and_header( entry, header, - ea - ) { - Ok(chain_pair) => Ok(PendingValidationStruct::new( - chain_pair, - ValidatingWorkflow::RemoveLink, - )), - Err(error) => { - let error_msg = format!( - "Tried to process\n - EntryAspect::LinkRemove((link_data, links_to_remove), - \nheader: {}. entry:\n{#:?}\nheader:\nlink_data:\n - {#:?}\nlinks_to_remove:\n{:#?}\nGot error:\n{}", - entry, header, link_data, links_to_remove, error - ); - Err(HolochainError::ValidationFailed(String::from(error_msg))) - }, - } + ea, + ValidatingWorkflow::RemoveLink, + ) }, - EntryAspect::Update(entry, header) => { - match ChainPair::try_validate_from_entry_and_header( + ea @ EntryAspect::Update(entry, header) => { + ChainPair::try_validate_from_entry_and_header( entry, header, - EntryAspect::Update(entry, header) - ) { - Ok(chain_pair) => Ok(PendingValidationStruct::new( - chain_pair, - ValidatingWorkflow::UpdateEntry, - )), - Err(error) => { - let error_msg = format!( - "Tried to process\n - EntryAspect::Update(entry, header),\n - entry:\n{#:?}\nheader:\n{:#?}\nGot error:\n{}", - entry, header, link_data, links_to_remove, error - ); - Err(HolochainError::ValidationFailed(String::from(error_msg))) - }, - } + ea, + ValidatingWorkflow::UpdateEntry, + ) }, - EntryAspect::Deletion(header) => { + ea @ EntryAspect::Deletion(header) => { // reconstruct the deletion entry from the header. let deleted_entry_address = header.link_update_delete().ok_or_else(|| { HolochainError::ValidationFailed(String::from( @@ -179,21 +137,12 @@ impl TryFrom for PendingValidationStruct { })?; let entry = Entry::Deletion(DeletionEntry::new(deleted_entry_address)); - match ChainPair::ChainPair::try_validate_from_entry_and_header( + ChainPair::try_validate_from_entry_and_header( entry, header, - EntryAspect::Deletion(header) - ) => { - Ok(chain_pair) => Ok(PendingValidationStruct::new( - chain_pair, - ValidatingWorkflow::RemoveEntry, - )), - Err(error) => HolochainError::ValidationFailed( - "Tried to process EntryAspect::Deletion(header)\n - where header is:\n{#:?}\nGot error:\n{}", - header, error - ), - } + ea, + ValidatingWorkflow::RemoveEntry, + ) }, } } @@ -209,29 +158,29 @@ fn retry_validation(pending: PendingValidation, context: Arc) { .spawn(move || { let result = match pending.workflow { ValidatingWorkflow::HoldLink => context.block_on(hold_link_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::HoldEntry => context.block_on(hold_entry_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::RemoveLink => context.block_on(remove_link_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::UpdateEntry => context.block_on(hold_update_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::RemoveEntry => context.block_on(hold_remove_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), }; if Err(HolochainError::ValidationPending) != result { remove_pending_validation( - pending.entry_with_header.entry.address(), + pending.chain_pair.entry().address(), pending.workflow.clone(), &context, ); From 20c3921bd309fc37917ddae1a2a32eefc096b7aa Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sun, 24 Nov 2019 18:19:11 +1100 Subject: [PATCH 15/79] Move try_validate_from_entry_and_header to impl PendingValidationStruct --- crates/core/src/network/chain_pair.rs | 24 -- .../src/scheduled_jobs/pending_validations.rs | 231 ++++++++++++++++++ 2 files changed, 231 insertions(+), 24 deletions(-) create mode 100644 crates/core/src/scheduled_jobs/pending_validations.rs diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index 1ea5db19c0..195cae8816 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -1,14 +1,12 @@ use crate::{ agent::find_chain_header, content_store::GetContent, - scheduled_jobs::{PendingValidationStruct, ValidatingWorkflow}, state::{State, StateWrapper}, }; use holochain_core_types::{ chain_header::ChainHeader, entry::Entry, error::HolochainError, - network::entry_aspect::EntryAspect, }; use holochain_persistence_api::cas::content::{Address, AddressableContent}; @@ -36,28 +34,6 @@ impl ChainPair { } } - // Convenience function for returning a custom error in the context of validation. - pub fn try_validate_from_entry_and_header( - entry: Entry, - header: ChainHeader, - entry_aspect: EntryAspect, - validating_workflow: ValidatingWorkflow, - ) -> Result { - match ChainPair::try_from_header_and_entry(header, entry) { - Ok(chain_pair) => { - Ok(PendingValidationStruct::new( - chain_pair, - validating_workflow, - )), - }, - Err(error) => { - let add_err_msg = format!("Tried to process {#:?}", entry_aspect); - let error = format!("{}, {}", error, add_err_msg); - HolochainError::ValidationFailed(String::from(error)) - }, - } - } - pub fn header(&self) -> ChainHeader { self.0.clone() } diff --git a/crates/core/src/scheduled_jobs/pending_validations.rs b/crates/core/src/scheduled_jobs/pending_validations.rs new file mode 100644 index 0000000000..b7c4a0d6fb --- /dev/null +++ b/crates/core/src/scheduled_jobs/pending_validations.rs @@ -0,0 +1,231 @@ +use crate::{ + context::Context, + network::chain_pair::ChainPair, + nucleus::actions::remove_pending_validation::remove_pending_validation, + workflows::{hold_entry::hold_entry_workflow, hold_link::hold_link_workflow}, +}; +use holochain_core_types::error::HolochainError; + +use crate::workflows::{ + hold_entry_remove::hold_remove_workflow, hold_entry_update::hold_update_workflow, + remove_link::remove_link_workflow, +}; + +use holochain_core_types::{ + entry::{deletion_entry::DeletionEntry, Entry}, + network::entry_aspect::EntryAspect, +}; +use holochain_json_api::{error::JsonError, json::JsonString}; +use holochain_persistence_api::cas::content::{Address, AddressableContent}; +use std::{convert::TryFrom, fmt, sync::Arc}; + +pub type PendingValidation = Arc; + +#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize, DefaultJson)] +pub enum ValidatingWorkflow { + HoldEntry, + HoldLink, + RemoveLink, + UpdateEntry, + RemoveEntry, +} + +impl Into for ValidatingWorkflow { + fn into(self) -> String { + match self { + ValidatingWorkflow::HoldEntry => String::from("HoldEntry"), + ValidatingWorkflow::HoldLink => String::from("HoldLink"), + ValidatingWorkflow::RemoveLink => String::from("RemoveLink"), + ValidatingWorkflow::UpdateEntry => String::from("UpdateEntry"), + ValidatingWorkflow::RemoveEntry => String::from("RemoveEntry"), + } + } +} + +impl TryFrom for ValidatingWorkflow { + type Error = HolochainError; + fn try_from(s: String) -> Result { + match s.as_ref() { + "HoldEntry" => Ok(ValidatingWorkflow::HoldEntry), + "HoldLink" => Ok(ValidatingWorkflow::HoldLink), + "RemoveLink" => Ok(ValidatingWorkflow::RemoveLink), + "UpdateEntry" => Ok(ValidatingWorkflow::UpdateEntry), + "RemoveEntry" => Ok(ValidatingWorkflow::RemoveEntry), + _ => Err(HolochainError::SerializationError(String::from( + "No ValidatingWorkflow", + ))), + } + } +} + +impl fmt::Display for ValidatingWorkflow { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + ValidatingWorkflow::HoldEntry => write!(f, "HoldEntryWorkflow"), + ValidatingWorkflow::HoldLink => write!(f, "HoldLinkWorkflow"), + ValidatingWorkflow::RemoveLink => write!(f, "RemoveLinkWorkflow"), + ValidatingWorkflow::UpdateEntry => write!(f, "UpdateEntryWorkflow"),try_vali + ValidatingWorkflow::RemoveEntry => write!(f, "RemoveEntryWorkflow"), + } + } +} + +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, DefaultJson)] +pub struct PendingValidationStruct { + pub chain_pair: ChainPair, + pub dependencies: Vec
, + pub workflow: ValidatingWorkflow, +} + +impl PendingValidationStruct { + pub fn new(chain_pair: ChainPair, workflow: ValidatingWorkflow) -> Self { + Self { + chain_pair, + dependencies: Vec::new(), + workflow, + } + } + + // Convenience function for returning a custom error in the context of validation. + pub fn try_validate_from_entry_and_header( + entry: Entry, + header: ChainHeader, + entry_aspect: EntryAspect, + validating_workflow: ValidatingWorkflow, + ) -> Result { + match ChainPair::try_from_header_and_entry(header, entry) { + Ok(chain_pair) => { + Ok(PendingValidationStruct::new( + chain_pair, + validating_workflow, + )), + }, + Err(error) => { + let add_err_msg = format!("Tried to process {#:?}", entry_aspect); + let error = format!("{}, {}", error, add_err_msg); + HolochainError::ValidationFailed(String::from(error)) + }, + } + } +} + +impl TryFrom for PendingValidationStruct { + type Error = HolochainError; + fn try_from(aspect: EntryAspect) -> Result { + match aspect { + ea @ EntryAspect::Content(entry, header) => { + ChainPair::try_validate_from_entry_and_header( + entry, + header, + ea, + ValidatingWorkflow::HoldEntry, + ) + }, + EntryAspect::Header(_header) => Err(HolochainError::NotImplemented(String::from( + "EntryAspect::Header", + ))), + ea @ EntryAspect::LinkAdd(link_data, header) => { + let entry = Entry::LinkAdd(link_data); + ChainPair::try_validate_from_entry_and_header( + entry, + header, + ea, + ValidatingWorkflow::HoldLink, + ) + } + ea @ EntryAspect::LinkRemove((link_data, links_to_remove), header) => { + let entry = Entry::LinkRemove((link_data, links_to_remove)); + ChainPair::try_validate_from_entry_and_header( + entry, + header, + ea, + ValidatingWorkflow::RemoveLink, + ) + }, + ea @ EntryAspect::Update(entry, header) => { + ChainPair::try_validate_from_entry_and_header( + entry, + header, + ea, + ValidatingWorkflow::UpdateEntry, + ) + }, + ea @ EntryAspect::Deletion(header) => { + // reconstruct the deletion entry from the header. + let deleted_entry_address = header.link_update_delete().ok_or_else(|| { + HolochainError::ValidationFailed(String::from( + "Deletion header is missing deletion link", + )) + })?; + let entry = Entry::Deletion(DeletionEntry::new(deleted_entry_address)); + + ChainPair::try_validate_from_entry_and_header( + entry, + header, + ea, + ValidatingWorkflow::RemoveEntry, + ) + }, + } + } +} + + +fn retry_validation(pending: PendingValidation, context: Arc) { + thread::Builder::new() + .name(format!( + "retry_validation/{}", + ProcessUniqueId::new().to_string() + )) + .spawn(move || { + let result = match pending.workflow { + ValidatingWorkflow::HoldLink => context.block_on(hold_link_workflow( + &pending.chain_pair, + context.clone(), + )), + ValidatingWorkflow::HoldEntry => context.block_on(hold_entry_workflow( + &pending.chain_pair, + context.clone(), + )), + ValidatingWorkflow::RemoveLink => context.block_on(remove_link_workflow( + &pending.chain_pair, + context.clone(), + )), + ValidatingWorkflow::UpdateEntry => context.block_on(hold_update_workflow( + &pending.chain_pair, + context.clone(), + )), + ValidatingWorkflow::RemoveEntry => context.block_on(hold_remove_workflow( + &pending.chain_pair, + context.clone(), + )), + }; + if Err(HolochainError::ValidationPending) != result { + remove_pending_validation( + pending.chain_pair.entry().address(), + pending.workflow.clone(), + &context, + ); + } + }) + .expect("Could not spawn thread for retry_validation"); +} + +pub fn run_pending_validations(context: Arc) { + let pending_validations = context + .state() + .expect("Couldn't get state in run_pending_validations") + .nucleus() + .pending_validations + .clone(); + + pending_validations.iter().for_each(|(_, pending)| { + log_debug!( + context, + "scheduled_jobs/run_pending_validations: found pending validation for {}: {}", + pending.chain_pair.entry().entry_type(), + pending.chain_pair.entry().address() + ); + retry_validation(pending.clone(), context.clone()); + }); +} From afe3c3fa84b98ac79eadd5992712fc187c8c3407 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sun, 24 Nov 2019 21:23:25 +1100 Subject: [PATCH 16/79] Manually got hold_entry_remove and mod workflows from upstream develop, but need a more automated way --- .../core/src/workflows/hold_entry_remove.rs | 2 +- .../core/src/workflows/hold_entry_update.rs | 69 ------------------- crates/core/src/workflows/mod.rs | 24 ++++--- 3 files changed, 14 insertions(+), 81 deletions(-) delete mode 100644 crates/core/src/workflows/hold_entry_update.rs diff --git a/crates/core/src/workflows/hold_entry_remove.rs b/crates/core/src/workflows/hold_entry_remove.rs index 642c5dfb12..598ad5dbec 100644 --- a/crates/core/src/workflows/hold_entry_remove.rs +++ b/crates/core/src/workflows/hold_entry_remove.rs @@ -1,6 +1,6 @@ use crate::{ context::Context, dht::actions::remove_entry::remove_entry, - network::chain_pair::ChainPair + network::chain_pair::ChainPair, nucleus::validation::validate_entry, }; diff --git a/crates/core/src/workflows/hold_entry_update.rs b/crates/core/src/workflows/hold_entry_update.rs deleted file mode 100644 index df8827f1ed..0000000000 --- a/crates/core/src/workflows/hold_entry_update.rs +++ /dev/null @@ -1,69 +0,0 @@ -use crate::{ - context::Context, dht::actions::update_entry::update_entry, network::chain_pair::ChainPair, - nucleus::validation::validate_entry, -}; -use holochain_persistence_api::cas::content::AddressableContent; - -use crate::{nucleus::validation::ValidationError, workflows::validation_package}; -use holochain_core_types::{ - error::HolochainError, - validation::{EntryLifecycle, ValidationData}, -}; -use std::sync::Arc; - -pub async fn hold_update_workflow( - chain_pair: &ChainPair, - context: Arc, -) -> Result<(), HolochainError> { - let header = chain_pair.header(); - let entry = chain_pair.entry(); - - // 1. Get hold of validation package - let maybe_validation_package = validation_package(&chain_pair, 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); - log_debug!(context, "workflow/hold_update: Error was: {:?}", err); - HolochainError::ValidationPending - })?; - let validation_package = maybe_validation_package - .ok_or_else(|| "Could not get validation package from source".to_string())?; - - // get link from header - let link = header - .link_update_delete() - .ok_or_else(|| "Could not get link update from header".to_string())?; - - // 2. Create validation data struct - let validation_data = ValidationData { - package: validation_package, - lifecycle: EntryLifecycle::Meta, - }; - - // 3. Validate the 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); - HolochainError::ValidationPending - } else { - log_warn!(context, "workflow/hold_update: Entry update {:?} is NOT valid! Validation error: {:?}", - entry, - err, - ); - HolochainError::from(err) - } - - })?; - - // 3. If valid store the entry in the local DHT shard - update_entry(&context.clone(), link, entry.address().clone()).await?; - - Ok(()) -} diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index c62ce8fd7c..7bbb6ae964 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -15,7 +15,7 @@ use crate::{ context::Context, dht::pending_validations::{PendingValidation, ValidatingWorkflow}, network::{ - actions::get_validation_package::get_validation_package, chain_pair::ChainPair, + actions::get_validation_package::get_validation_package, entry_with_header::EntryWithHeader, }, nucleus::{ actions::build_validation_package::build_validation_package, @@ -42,11 +42,11 @@ use std::sync::Arc; /// Checks the DNA's validation package definition for the given entry type. /// Fails if this entry type needs more than just the header for validation. async fn try_make_local_validation_package( - chain_pair: &ChainPair, + entry_with_header: &EntryWithHeader, context: Arc, ) -> Result { - let entry = &chain_pair.entry(); - let entry_header = &chain_pair.header(); + let entry = &entry_with_header.entry; + let entry_header = &entry_with_header.header; let validation_package_definition = get_validation_package_definition(entry, context.clone()) .and_then(|callback_result| match callback_result { @@ -67,8 +67,8 @@ async fn try_make_local_validation_package( _ => { let agent = context.state()?.agent().get_agent()?; - let overlapping_provenance = chain_pair - .header() + let overlapping_provenance = entry_with_header + .header .provenances() .iter() .find(|p| p.source() == agent.address()); @@ -76,9 +76,9 @@ 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: build_validation_package( - &chain_pair.entry(), + &entry_with_header.entry, context.clone(), - chain_pair.header().provenances(), + entry_with_header.header.provenances(), ) .await } else { @@ -94,15 +94,17 @@ async fn try_make_local_validation_package( /// First tries to create it locally and if that fails will try to get the /// validation package from the source. async fn validation_package( - chain_pair: &ChainPair, + entry_with_header: &EntryWithHeader, context: Arc, ) -> Result, HolochainError> { // 1. Try to construct it locally: - if let Ok(package) = try_make_local_validation_package(&chain_pair, context.clone()).await { + 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 - get_validation_package(chain_pair.header().clone(), &context).await + get_validation_package(entry_with_header.header.clone(), &context).await } } From 8d815397bdcf644548459771f378a2e8b6ff0dbb Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sun, 24 Nov 2019 21:31:21 +1100 Subject: [PATCH 17/79] Add hold_entry_update.rs from upstream develop, was removed with others in a merge conflict 'fix' --- .../core/src/workflows/hold_entry_update.rs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 crates/core/src/workflows/hold_entry_update.rs diff --git a/crates/core/src/workflows/hold_entry_update.rs b/crates/core/src/workflows/hold_entry_update.rs new file mode 100644 index 0000000000..ce6e36f2d6 --- /dev/null +++ b/crates/core/src/workflows/hold_entry_update.rs @@ -0,0 +1,68 @@ +use crate::{ + context::Context, dht::actions::update_entry::update_entry, + network::entry_with_header::EntryWithHeader, nucleus::validation::validate_entry, +}; +use holochain_persistence_api::cas::content::AddressableContent; + +use crate::{nucleus::validation::ValidationError, workflows::validation_package}; +use holochain_core_types::{ + error::HolochainError, + validation::{EntryLifecycle, ValidationData}, +}; +use std::sync::Arc; + +pub async fn hold_update_workflow( + entry_with_header: &EntryWithHeader, + context: Arc, +) -> Result<(), HolochainError> { + let EntryWithHeader { entry, header } = entry_with_header; + + // 1. Get hold of validation package + 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); + log_debug!(context, "workflow/hold_update: Error was: {:?}", err); + HolochainError::ValidationPending + })?; + let validation_package = maybe_validation_package + .ok_or_else(|| "Could not get validation package from source".to_string())?; + + // get link from header + let link = header + .link_update_delete() + .ok_or_else(|| "Could not get link update from header".to_string())?; + + // 2. Create validation data struct + let validation_data = ValidationData { + package: validation_package, + lifecycle: EntryLifecycle::Meta, + }; + + // 3. Validate the 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); + HolochainError::ValidationPending + } else { + log_warn!(context, "workflow/hold_update: Entry update {:?} is NOT valid! Validation error: {:?}", + entry_with_header.entry, + err, + ); + HolochainError::from(err) + } + + })?; + + // 3. If valid store the entry in the local DHT shard + update_entry(&context.clone(), link, entry.address().clone()).await?; + + Ok(()) +} From a9dbf02847705d7a9e5aaaf4e239666e52be9d60 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Mon, 25 Nov 2019 14:20:03 +1100 Subject: [PATCH 18/79] Fixed errors, cargo build passing --- crates/core/src/consistency.rs | 7 +- crates/core/src/dht/dht_reducers.rs | 16 +- crates/core/src/dht/dht_store.rs | 23 +- crates/core/src/dht/pending_validations.rs | 74 ++++-- crates/core/src/network/chain_pair.rs | 9 +- crates/core/src/network/handler/store.rs | 17 +- crates/core/src/network/reducers/publish.rs | 4 +- .../network/reducers/publish_header_entry.rs | 4 +- .../src/scheduled_jobs/pending_validations.rs | 231 ------------------ crates/core/src/scheduled_jobs/state_dump.rs | 6 +- .../core/src/workflows/hold_entry_remove.rs | 6 +- .../core/src/workflows/hold_entry_update.rs | 11 +- crates/core/src/workflows/hold_link.rs | 3 +- crates/core/src/workflows/mod.rs | 34 +-- crates/core/src/workflows/remove_link.rs | 3 +- crates/core_types/src/network/entry_aspect.rs | 14 ++ 16 files changed, 141 insertions(+), 321 deletions(-) delete mode 100644 crates/core/src/scheduled_jobs/pending_validations.rs diff --git a/crates/core/src/consistency.rs b/crates/core/src/consistency.rs index a3ef525675..62d6ab5a89 100644 --- a/crates/core/src/consistency.rs +++ b/crates/core/src/consistency.rs @@ -1,6 +1,5 @@ use crate::{ - action::Action, context::Context, entry::CanPublish, network::chain_pair::ChainPair, - network::chain_pair::ChainPair, + action::Action, context::Context, entry::CanPublish, nucleus::ZomeFnCall, }; use holochain_core_types::{entry::Entry, link::link_data::LinkData}; @@ -161,8 +160,8 @@ impl ConsistencyModel { None }) } - Action::Hold(ChainPair(.., entry)) => { - Some(ConsistencySignal::new_terminal(Hold(entry.address()))) + Action::Hold(chain_pair) => { + Some(ConsistencySignal::new_terminal(Hold(chain_pair.entry().address()))) } Action::UpdateEntry((old, new)) => Some(ConsistencySignal::new_terminal( ConsistencyEvent::UpdateEntry(old.clone(), new.clone()), diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index f3282bd5e2..a4e27be4a7 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -68,12 +68,14 @@ pub(crate) fn reduce_hold_entry( old_store: &DhtStore, action_wrapper: &ActionWrapper, ) -> Option { - let chain_pair { entry, header } = unwrap_to!(action_wrapper.action() => Action::Hold); + let chain_pair = unwrap_to!(action_wrapper.action() => Action::Hold); + let entry = chain_pair.entry(); + let header = chain_pair.header(); let mut new_store = (*old_store).clone(); match reduce_store_entry_inner(&mut new_store, &entry) { Ok(()) => { new_store.mark_entry_as_held(&entry); - new_store.add_header_for_entry(&entry, &header).ok()?; + new_store.add_header_for_entry(entry, header).ok()?; Some(new_store) } Err(e) => { @@ -471,12 +473,12 @@ pub mod tests { fn create_pending_validation(workflow: ValidatingWorkflow) -> PendingValidation { let entry = test_entry(); - let entry_with_header = EntryWithHeader { - entry: entry.clone(), - header: test_chain_header(), - }; + let chain_pair = ChainPair::try_from_header_and_entry( + test_chain_header(), + entry.clone(), + ); - Arc::new(PendingValidationStruct::new(entry_with_header, workflow)) + Arc::new(PendingValidationStruct::new(chain_pair, workflow)) } #[test] diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index 4908a7a4d2..c395cd78ba 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -1,6 +1,7 @@ use crate::{ action::ActionWrapper, content_store::{AddContent, GetContent}, + network::chain_pair::ChainPair, }; use holochain_core_types::{ chain_header::ChainHeader, @@ -230,29 +231,35 @@ impl DhtStore { /// Add an entry and header to the CAS and EAV, respectively pub fn add_header_for_entry( &mut self, - entry: &Entry, - header: &ChainHeader, + entry: Entry, + header: ChainHeader, ) -> Result<(), HolochainError> { - match ChainPair::try_from_header_and_entry(header, entry) { + match ChainPair::try_from_header_and_entry(header.clone(), entry.clone()) { Ok(_chain_pair) => { let eavi = EntityAttributeValueIndex::new( &entry.address(), &Attribute::EntryHeader, &header.address(), )?; - self.add(header)?; + self.add(&header)?; self.meta_storage.write().unwrap().add_eavi(&eavi)?; Ok(()) } Err(err) => match err { - HolochainError::HeaderEntryMismatch(err_msg, header_entry_address, entry_address) => { - let add_err_msg = format!( + HolochainError::HeaderEntryMismatch(mut err_msg, header_entry_address, entry_address) => { + debug!( "Tried to add entry:\n{:#?}\nand header:\n{:#?}\nto the CAS and EAV, respectively", entry, header, ); - err_msg = concat!(err_msg, add_err_msg); + err_msg = format!( + "Tried to add entry and header to the CAS and EAV,\n + respectively. See the debug log for further details\n + of header and entry. {}", + err_msg + ); Err(HolochainError::HeaderEntryMismatch(err_msg, header_entry_address, entry_address)) - } + }, + _ => Err(err), }, } } diff --git a/crates/core/src/dht/pending_validations.rs b/crates/core/src/dht/pending_validations.rs index 67fb8ac509..9f0f0a83a9 100644 --- a/crates/core/src/dht/pending_validations.rs +++ b/crates/core/src/dht/pending_validations.rs @@ -1,5 +1,6 @@ -use crate::network::entry_with_header::EntryWithHeader; +use crate::network::chain_pair::ChainPair; use holochain_core_types::{ + chain_header::ChainHeader, entry::{deletion_entry::DeletionEntry, Entry}, error::HolochainError, network::entry_aspect::EntryAspect, @@ -83,50 +84,73 @@ impl PendingValidationStruct { clone.uuid = ProcessUniqueId::new(); clone } + + // Convenience function for returning a custom error in the context of validation. + pub fn try_validate_from_entry_and_header( + entry: Entry, + header: ChainHeader, + entry_aspect: EntryAspect, + validating_workflow: ValidatingWorkflow, + ) -> Result { + match ChainPair::try_from_header_and_entry(header, entry) { + Ok(chain_pair) => { + Ok(PendingValidationStruct::new( + chain_pair, + validating_workflow, + )) + }, + Err(error) => { + let error = format!("Tried to process {}; see the\n + debug output for further details of its contents. {}", entry_aspect, error); + debug!("Tried to process {:?}", entry_aspect); + Err(HolochainError::ValidationFailed(String::from(error))) + }, + } + } } impl TryFrom for PendingValidationStruct { type Error = HolochainError; fn try_from(aspect: EntryAspect) -> Result { match aspect { - ea @ EntryAspect::Content(entry, header) => { - ChainPair::try_validate_from_entry_and_header( - entry, - header, - ea, + EntryAspect::Content(entry, header) => { + PendingValidationStruct::try_validate_from_entry_and_header( + entry.clone(), + header.clone(), + EntryAspect::Content(entry, header), ValidatingWorkflow::HoldEntry, ) }, EntryAspect::Header(_header) => Err(HolochainError::NotImplemented(String::from( "EntryAspect::Header", ))), - ea @ EntryAspect::LinkAdd(link_data, header) => { - let entry = Entry::LinkAdd(link_data); - ChainPair::try_validate_from_entry_and_header( + EntryAspect::LinkAdd(link_data, header) => { + let entry = Entry::LinkAdd(link_data.clone()); + PendingValidationStruct::try_validate_from_entry_and_header( entry, - header, - ea, + header.clone(), + EntryAspect::LinkAdd(link_data, header), ValidatingWorkflow::HoldLink, ) } - ea @ EntryAspect::LinkRemove((link_data, links_to_remove), header) => { - let entry = Entry::LinkRemove((link_data, links_to_remove)); - ChainPair::try_validate_from_entry_and_header( + EntryAspect::LinkRemove((link_data, links_to_remove), header) => { + let entry = Entry::LinkRemove((link_data.clone(), links_to_remove.clone())); + PendingValidationStruct::try_validate_from_entry_and_header( entry, - header, - ea, + header.clone(), + EntryAspect::LinkRemove((link_data, links_to_remove), header), ValidatingWorkflow::RemoveLink, ) }, - ea @ EntryAspect::Update(entry, header) => { - ChainPair::try_validate_from_entry_and_header( - entry, - header, - ea, + EntryAspect::Update(entry, header) => { + PendingValidationStruct::try_validate_from_entry_and_header( + entry.clone(), + header.clone(), + EntryAspect::Update(entry, header), ValidatingWorkflow::UpdateEntry, ) }, - ea @ EntryAspect::Deletion(header) => { + EntryAspect::Deletion(header) => { // reconstruct the deletion entry from the header. let deleted_entry_address = header.link_update_delete().ok_or_else(|| { HolochainError::ValidationFailed(String::from( @@ -135,10 +159,10 @@ impl TryFrom for PendingValidationStruct { })?; let entry = Entry::Deletion(DeletionEntry::new(deleted_entry_address)); - ChainPair::try_validate_from_entry_and_header( + PendingValidationStruct::try_validate_from_entry_and_header( entry, - header, - ea, + header.clone(), + EntryAspect::Deletion(header), ValidatingWorkflow::RemoveEntry, ) }, diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index 195cae8816..1d90ec5dc6 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -22,14 +22,15 @@ impl ChainPair { header: ChainHeader, entry: Entry, ) -> Result { - let header_entry_address = *header.entry_address(); + let header_entry_address = header.entry_address(); let entry_address = entry.address(); - if header_entry_address == entry_address { + if header_entry_address.clone() == entry_address { Ok(ChainPair(header, entry)) } else { - let error_msg = format!("Tried to create a ChainPair, but got a mismatch with the header's entry address and the entry's address. Header:\n{:#?}\nEntry:{:#?}", header, entry); + let error_msg = "Tried to create a ChainPair, but got a mismatch with the header's entry address and the entry's address. See the debug log output for data for the header and entry."; + debug!("Mismatch between header's entry address and the entry's address. Header:\n{:#?}\nEntry:{:#?}", header, entry); Err(HolochainError::HeaderEntryMismatch( - error_msg, header_entry_address, entry_address + error_msg.to_string(), header_entry_address.clone(), entry_address )) } } diff --git a/crates/core/src/network/handler/store.rs b/crates/core/src/network/handler/store.rs index a541b61d47..ec3d1a7e6c 100644 --- a/crates/core/src/network/handler/store.rs +++ b/crates/core/src/network/handler/store.rs @@ -43,6 +43,7 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc) { } } +// If reusing/uncommenting, replace EntryWithHeader with ChainPair /* /// The network requests us to store meta information (links/CRUD/etc) for an /// entry that we hold. @@ -54,13 +55,13 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { log_debug!(context, "net/handle: HandleStoreMeta: got LINK. processing..."); // TODO: do a loop on content once links properly implemented assert_eq!(dht_meta_data.content_list.len(), 1); - let entry_with_header: EntryWithHeader = serde_json::from_str( + let chain_pair: ChainPair = serde_json::from_str( &serde_json::to_string(&dht_meta_data.content_list[0]) .expect("dht_meta_data should be EntryWithHeader"), ) .expect("dht_meta_data should be EntryWithHeader"); thread::spawn(move || { - match context.block_on(hold_link_workflow(&entry_with_header, &context.clone())) { + match context.block_on(hold_link_workflow(&chain_pair, &context.clone())) { Err(error) => log_error!(context, "net/dht: {}", error), _ => (), } @@ -69,7 +70,7 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { log_debug!(context, "net/handle: HandleStoreMeta: got LINK REMOVAL. processing..."); // TODO: do a loop on content once links properly implemented assert_eq!(dht_meta_data.content_list.len(), 1); - let entry_with_header: EntryWithHeader = serde_json::from_str( + let chain_pair: EntryWithHeader = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) .expect("dht_meta_data should be EntryWithHader"), @@ -77,7 +78,7 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { .expect("dht_meta_data should be EntryWithHader"); thread::spawn(move || { if let Err(error) = - context.block_on(remove_link_workflow(&entry_with_header, &context.clone())) + context.block_on(remove_link_workflow(&chain_pair, &context.clone())) { log_error!(context, "net/dht: {}", error) } @@ -88,7 +89,7 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { { log_debug!(context, "net/handle: HandleStoreMeta: got CRUD STATUS. processing..."); - let entry_with_header: EntryWithHeader = serde_json::from_str( + let chain_pair: EntryWithHeader = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) .expect("dht_meta_data should be EntryWithHader"), @@ -96,7 +97,7 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { .expect("dht_meta_data should be EntryWithHader"); thread::spawn(move || { if let Err(error) = - context.block_on(hold_remove_workflow(entry_with_header, context.clone())) + context.block_on(hold_remove_workflow(chain_pair, context.clone())) { log_error!(context, "net/dht: {}", error) } @@ -106,7 +107,7 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { == CrudStatus::Modified { log_debug!(context, "net/handle: HandleStoreMeta: got CRUD LINK. processing..."); - let entry_with_header: EntryWithHeader = serde_json::from_str( + let chain_pair: EntryWithHeader = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) .expect("dht_meta_data should be EntryWithHader"), @@ -114,7 +115,7 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { .expect("dht_meta_data should be EntryWithHader"); thread::spawn(move || { if let Err(error) = - context.block_on(hold_update_workflow(entry_with_header, context.clone())) + context.block_on(hold_update_workflow(chain_pair, context.clone())) { log_error!(context, "net/dht: {}", error) } diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index 539c1aa700..c5101781c1 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -2,7 +2,7 @@ use crate::{ action::ActionWrapper, network::{ actions::ActionResponse, - chain_pair::{fetch_chain_pair, ChainPair}, + chain_pair::ChainPair, entry_aspect::EntryAspect, reducers::send, state::NetworkState, @@ -139,7 +139,7 @@ fn reduce_publish_inner( ) -> Result<(), HolochainError> { network_state.initialized()?; - let chain_pair = fetch_chain_pair(&address, root_state)?; + let chain_pair = ChainPair::fetch_chain_pair(&address, root_state)?; match chain_pair.entry().entry_type() { EntryType::AgentId => publish_entry(network_state, &chain_pair), diff --git a/crates/core/src/network/reducers/publish_header_entry.rs b/crates/core/src/network/reducers/publish_header_entry.rs index 8b334b80d0..9c7cbeb906 100644 --- a/crates/core/src/network/reducers/publish_header_entry.rs +++ b/crates/core/src/network/reducers/publish_header_entry.rs @@ -3,7 +3,7 @@ use crate::{ agent::state::create_chain_pair_for_header, network::{ actions::ActionResponse, - chain_pair::fetch_chain_pair, + chain_pair::ChainPair, entry_aspect::EntryAspect, reducers::{publish::entry_data_to_entry_aspect_data, send}, state::NetworkState, @@ -51,7 +51,7 @@ fn reduce_publish_header_entry_inner( address: &Address, ) -> Result<(), HolochainError> { network_state.initialized()?; - let chain_pair = fetch_chain_pair(&address, root_state)?; + let chain_pair = ChainPair::fetch_chain_pair(&address, root_state)?; publish_header(network_state, root_state, chain_pair.header()) } diff --git a/crates/core/src/scheduled_jobs/pending_validations.rs b/crates/core/src/scheduled_jobs/pending_validations.rs deleted file mode 100644 index b7c4a0d6fb..0000000000 --- a/crates/core/src/scheduled_jobs/pending_validations.rs +++ /dev/null @@ -1,231 +0,0 @@ -use crate::{ - context::Context, - network::chain_pair::ChainPair, - nucleus::actions::remove_pending_validation::remove_pending_validation, - workflows::{hold_entry::hold_entry_workflow, hold_link::hold_link_workflow}, -}; -use holochain_core_types::error::HolochainError; - -use crate::workflows::{ - hold_entry_remove::hold_remove_workflow, hold_entry_update::hold_update_workflow, - remove_link::remove_link_workflow, -}; - -use holochain_core_types::{ - entry::{deletion_entry::DeletionEntry, Entry}, - network::entry_aspect::EntryAspect, -}; -use holochain_json_api::{error::JsonError, json::JsonString}; -use holochain_persistence_api::cas::content::{Address, AddressableContent}; -use std::{convert::TryFrom, fmt, sync::Arc}; - -pub type PendingValidation = Arc; - -#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize, DefaultJson)] -pub enum ValidatingWorkflow { - HoldEntry, - HoldLink, - RemoveLink, - UpdateEntry, - RemoveEntry, -} - -impl Into for ValidatingWorkflow { - fn into(self) -> String { - match self { - ValidatingWorkflow::HoldEntry => String::from("HoldEntry"), - ValidatingWorkflow::HoldLink => String::from("HoldLink"), - ValidatingWorkflow::RemoveLink => String::from("RemoveLink"), - ValidatingWorkflow::UpdateEntry => String::from("UpdateEntry"), - ValidatingWorkflow::RemoveEntry => String::from("RemoveEntry"), - } - } -} - -impl TryFrom for ValidatingWorkflow { - type Error = HolochainError; - fn try_from(s: String) -> Result { - match s.as_ref() { - "HoldEntry" => Ok(ValidatingWorkflow::HoldEntry), - "HoldLink" => Ok(ValidatingWorkflow::HoldLink), - "RemoveLink" => Ok(ValidatingWorkflow::RemoveLink), - "UpdateEntry" => Ok(ValidatingWorkflow::UpdateEntry), - "RemoveEntry" => Ok(ValidatingWorkflow::RemoveEntry), - _ => Err(HolochainError::SerializationError(String::from( - "No ValidatingWorkflow", - ))), - } - } -} - -impl fmt::Display for ValidatingWorkflow { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - ValidatingWorkflow::HoldEntry => write!(f, "HoldEntryWorkflow"), - ValidatingWorkflow::HoldLink => write!(f, "HoldLinkWorkflow"), - ValidatingWorkflow::RemoveLink => write!(f, "RemoveLinkWorkflow"), - ValidatingWorkflow::UpdateEntry => write!(f, "UpdateEntryWorkflow"),try_vali - ValidatingWorkflow::RemoveEntry => write!(f, "RemoveEntryWorkflow"), - } - } -} - -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, DefaultJson)] -pub struct PendingValidationStruct { - pub chain_pair: ChainPair, - pub dependencies: Vec
, - pub workflow: ValidatingWorkflow, -} - -impl PendingValidationStruct { - pub fn new(chain_pair: ChainPair, workflow: ValidatingWorkflow) -> Self { - Self { - chain_pair, - dependencies: Vec::new(), - workflow, - } - } - - // Convenience function for returning a custom error in the context of validation. - pub fn try_validate_from_entry_and_header( - entry: Entry, - header: ChainHeader, - entry_aspect: EntryAspect, - validating_workflow: ValidatingWorkflow, - ) -> Result { - match ChainPair::try_from_header_and_entry(header, entry) { - Ok(chain_pair) => { - Ok(PendingValidationStruct::new( - chain_pair, - validating_workflow, - )), - }, - Err(error) => { - let add_err_msg = format!("Tried to process {#:?}", entry_aspect); - let error = format!("{}, {}", error, add_err_msg); - HolochainError::ValidationFailed(String::from(error)) - }, - } - } -} - -impl TryFrom for PendingValidationStruct { - type Error = HolochainError; - fn try_from(aspect: EntryAspect) -> Result { - match aspect { - ea @ EntryAspect::Content(entry, header) => { - ChainPair::try_validate_from_entry_and_header( - entry, - header, - ea, - ValidatingWorkflow::HoldEntry, - ) - }, - EntryAspect::Header(_header) => Err(HolochainError::NotImplemented(String::from( - "EntryAspect::Header", - ))), - ea @ EntryAspect::LinkAdd(link_data, header) => { - let entry = Entry::LinkAdd(link_data); - ChainPair::try_validate_from_entry_and_header( - entry, - header, - ea, - ValidatingWorkflow::HoldLink, - ) - } - ea @ EntryAspect::LinkRemove((link_data, links_to_remove), header) => { - let entry = Entry::LinkRemove((link_data, links_to_remove)); - ChainPair::try_validate_from_entry_and_header( - entry, - header, - ea, - ValidatingWorkflow::RemoveLink, - ) - }, - ea @ EntryAspect::Update(entry, header) => { - ChainPair::try_validate_from_entry_and_header( - entry, - header, - ea, - ValidatingWorkflow::UpdateEntry, - ) - }, - ea @ EntryAspect::Deletion(header) => { - // reconstruct the deletion entry from the header. - let deleted_entry_address = header.link_update_delete().ok_or_else(|| { - HolochainError::ValidationFailed(String::from( - "Deletion header is missing deletion link", - )) - })?; - let entry = Entry::Deletion(DeletionEntry::new(deleted_entry_address)); - - ChainPair::try_validate_from_entry_and_header( - entry, - header, - ea, - ValidatingWorkflow::RemoveEntry, - ) - }, - } - } -} - - -fn retry_validation(pending: PendingValidation, context: Arc) { - thread::Builder::new() - .name(format!( - "retry_validation/{}", - ProcessUniqueId::new().to_string() - )) - .spawn(move || { - let result = match pending.workflow { - ValidatingWorkflow::HoldLink => context.block_on(hold_link_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::HoldEntry => context.block_on(hold_entry_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::RemoveLink => context.block_on(remove_link_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::UpdateEntry => context.block_on(hold_update_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::RemoveEntry => context.block_on(hold_remove_workflow( - &pending.chain_pair, - context.clone(), - )), - }; - if Err(HolochainError::ValidationPending) != result { - remove_pending_validation( - pending.chain_pair.entry().address(), - pending.workflow.clone(), - &context, - ); - } - }) - .expect("Could not spawn thread for retry_validation"); -} - -pub fn run_pending_validations(context: Arc) { - let pending_validations = context - .state() - .expect("Couldn't get state in run_pending_validations") - .nucleus() - .pending_validations - .clone(); - - pending_validations.iter().for_each(|(_, pending)| { - log_debug!( - context, - "scheduled_jobs/run_pending_validations: found pending validation for {}: {}", - pending.chain_pair.entry().entry_type(), - pending.chain_pair.entry().address() - ); - retry_validation(pending.clone(), context.clone()); - }); -} diff --git a/crates/core/src/scheduled_jobs/state_dump.rs b/crates/core/src/scheduled_jobs/state_dump.rs index 8dd5ad62ed..dbc7e5b362 100644 --- a/crates/core/src/scheduled_jobs/state_dump.rs +++ b/crates/core/src/scheduled_jobs/state_dump.rs @@ -52,9 +52,9 @@ pub fn state_dump(context: Arc) { format!( "<{}> [{}] {}: {}", pending_validation.workflow.to_string(), - pending_validation.entry_with_header.header.entry_type(), - pending_validation.entry_with_header.entry.address(), - pending_validation.entry_with_header.entry.content(), + pending_validation.chain_pair.header().entry_type(), + pending_validation.chain_pair.entry().address(), + pending_validation.chain_pair.entry().content(), ) }) .collect::>(); diff --git a/crates/core/src/workflows/hold_entry_remove.rs b/crates/core/src/workflows/hold_entry_remove.rs index 598ad5dbec..6904754fd4 100644 --- a/crates/core/src/workflows/hold_entry_remove.rs +++ b/crates/core/src/workflows/hold_entry_remove.rs @@ -55,15 +55,15 @@ pub async fn hold_remove_workflow( } })?; - - let deletion_entry = unwrap_to!(chain_pair.entry() => Entry::Deletion); + let entry = chain_pair.entry(); + let deletion_entry = unwrap_to!(entry => Entry::Deletion); let deleted_entry_address = deletion_entry.clone().deleted_entry_address(); // 3. If valid store the entry in the local DHT shard remove_entry( &context.clone(), deleted_entry_address, - chain_pair.entry().address().clone(), + entry.address().clone(), ) .await } diff --git a/crates/core/src/workflows/hold_entry_update.rs b/crates/core/src/workflows/hold_entry_update.rs index ce6e36f2d6..d2aee27108 100644 --- a/crates/core/src/workflows/hold_entry_update.rs +++ b/crates/core/src/workflows/hold_entry_update.rs @@ -1,6 +1,6 @@ use crate::{ context::Context, dht::actions::update_entry::update_entry, - network::entry_with_header::EntryWithHeader, nucleus::validation::validate_entry, + network::chain_pair::ChainPair, nucleus::validation::validate_entry, }; use holochain_persistence_api::cas::content::AddressableContent; @@ -12,13 +12,14 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn hold_update_workflow( - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, context: Arc, ) -> Result<(), HolochainError> { - let EntryWithHeader { entry, header } = entry_with_header; + let entry = chain_pair.entry(); + let header = chain_pair.header(); // 1. Get hold of validation package - let maybe_validation_package = validation_package(&entry_with_header, context.clone()) + let maybe_validation_package = validation_package(&chain_pair, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; @@ -53,7 +54,7 @@ pub async fn hold_update_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_update: Entry update {:?} is NOT valid! Validation error: {:?}", - entry_with_header.entry, + chain_pair.entry(), err, ); HolochainError::from(err) diff --git a/crates/core/src/workflows/hold_link.rs b/crates/core/src/workflows/hold_link.rs index b8bec6d812..a1550a6898 100644 --- a/crates/core/src/workflows/hold_link.rs +++ b/crates/core/src/workflows/hold_link.rs @@ -18,7 +18,8 @@ pub async fn hold_link_workflow( chain_pair: &ChainPair, context: Arc, ) -> Result<(), HolochainError> { - let link_add = match &chain_pair.entry() { + let entry = &chain_pair.entry(); + let link_add = match entry { Entry::LinkAdd(link_add) => link_add, _ => Err(HolochainError::ErrorGeneric( "hold_link_workflow expects entry to be an Entry::LinkAdd".to_string(), diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 7bbb6ae964..3f74dc893c 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -15,7 +15,7 @@ use crate::{ context::Context, dht::pending_validations::{PendingValidation, ValidatingWorkflow}, network::{ - actions::get_validation_package::get_validation_package, entry_with_header::EntryWithHeader, + actions::get_validation_package::get_validation_package, chain_pair::ChainPair, }, nucleus::{ actions::build_validation_package::build_validation_package, @@ -42,11 +42,11 @@ use std::sync::Arc; /// Checks the DNA's validation package definition for the given entry type. /// Fails if this entry type needs more than just the header for validation. async fn try_make_local_validation_package( - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, context: Arc, ) -> Result { - let entry = &entry_with_header.entry; - let entry_header = &entry_with_header.header; + let entry = &chain_pair.entry(); + let entry_header = &chain_pair.header(); let validation_package_definition = get_validation_package_definition(entry, context.clone()) .and_then(|callback_result| match callback_result { @@ -66,9 +66,9 @@ async fn try_make_local_validation_package( } _ => { let agent = context.state()?.agent().get_agent()?; - - let overlapping_provenance = entry_with_header - .header + let entry = &chain_pair.entry(); + let header = chain_pair.header(); + let overlapping_provenance = header .provenances() .iter() .find(|p| p.source() == agent.address()); @@ -76,9 +76,9 @@ 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: build_validation_package( - &entry_with_header.entry, + entry, context.clone(), - entry_with_header.header.provenances(), + header.provenances(), ) .await } else { @@ -94,17 +94,17 @@ async fn try_make_local_validation_package( /// First tries to create it locally and if that fails will try to get the /// validation package from the source. async fn validation_package( - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, context: Arc, ) -> Result, HolochainError> { // 1. Try to construct it locally: if let Ok(package) = - try_make_local_validation_package(&entry_with_header, context.clone()).await + try_make_local_validation_package(&chain_pair, context.clone()).await { Ok(Some(package)) } else { // If that is not possible, get the validation package from source - get_validation_package(entry_with_header.header.clone(), &context).await + get_validation_package(chain_pair.header().clone(), &context).await } } @@ -116,23 +116,23 @@ pub fn run_holding_workflow( ) -> Result<(), HolochainError> { match pending.workflow { ValidatingWorkflow::HoldLink => context.block_on(hold_link_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::HoldEntry => context.block_on(hold_entry_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::RemoveLink => context.block_on(remove_link_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::UpdateEntry => context.block_on(hold_update_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), ValidatingWorkflow::RemoveEntry => context.block_on(hold_remove_workflow( - &pending.entry_with_header, + &pending.chain_pair, context.clone(), )), } diff --git a/crates/core/src/workflows/remove_link.rs b/crates/core/src/workflows/remove_link.rs index e10b1d3b17..8832428bdd 100644 --- a/crates/core/src/workflows/remove_link.rs +++ b/crates/core/src/workflows/remove_link.rs @@ -15,7 +15,8 @@ pub async fn remove_link_workflow( chain_pair: &ChainPair, context: Arc, ) -> Result<(), HolochainError> { - let link_remove = match &chain_pair.entry() { + let entry = &chain_pair.entry(); + let link_remove = match entry { Entry::LinkRemove((link_remove, _)) => link_remove, _ => Err(HolochainError::ErrorGeneric( "remove_link_workflow expects entry to be an Entry::LinkRemove".to_string(), diff --git a/crates/core_types/src/network/entry_aspect.rs b/crates/core_types/src/network/entry_aspect.rs index 1f85f3bde3..3ce4b0cff3 100644 --- a/crates/core_types/src/network/entry_aspect.rs +++ b/crates/core_types/src/network/entry_aspect.rs @@ -100,6 +100,20 @@ fn format_header(header: &ChainHeader) -> String { header.link_update_delete() ) } + +impl fmt::Display for EntryAspect { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + EntryAspect::Content(_, _) => write!(f, "EntryAspect::Content(Entry, ChainHeader)"), + EntryAspect::Header(_) => write!(f, "EntryAspect::Header(ChainHeader)"), + EntryAspect::LinkAdd(_, _) => write!(f, "EntryAspect::LinkAdd(LinkData, ChainHeader)"), + EntryAspect::LinkRemove(_, _) => write!(f, "EntryAspect::LinkRemove((LinkData, Vec
), ChainHeader)"), + EntryAspect::Update(_, _) => write!(f, "EntryAspect::Update(Entry, ChainHeader)"), + EntryAspect::Deletion(_) => write!(f, "EntryAspect::Deletion(ChainHeader)"), + } + } +} + impl fmt::Debug for EntryAspect { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { From a24266ba672f220c527683644dc3139b3019f480 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Mon, 25 Nov 2019 21:12:11 +1100 Subject: [PATCH 19/79] fmt --- crates/core/src/dht/dht_reducers.rs | 5 +- crates/core/src/dht/dht_store.rs | 16 ++++-- crates/core/src/dht/pending_validations.rs | 41 +++++++-------- crates/core/src/network/chain_pair.rs | 15 ++---- crates/core/src/network/handler/lists.rs | 5 +- crates/core/src/network/handler/mod.rs | 2 +- crates/core/src/network/reducers/publish.rs | 18 +++---- crates/core/src/workflows/hold_entry.rs | 9 ++-- .../core/src/workflows/hold_entry_remove.rs | 4 +- .../core/src/workflows/hold_entry_update.rs | 5 +- crates/core/src/workflows/hold_link.rs | 4 +- crates/core/src/workflows/mod.rs | 50 +++++++------------ crates/core/src/workflows/remove_link.rs | 5 +- crates/core_types/src/error/mod.rs | 6 +-- crates/core_types/src/network/entry_aspect.rs | 5 +- crates/trycp_server/src/main.rs | 6 +-- 16 files changed, 79 insertions(+), 117 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 56f2b43511..7d2d001e45 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -506,10 +506,7 @@ pub mod tests { fn create_pending_validation(workflow: ValidatingWorkflow) -> PendingValidation { let entry = test_entry(); - let chain_pair = ChainPair::try_from_header_and_entry( - test_chain_header(), - entry.clone(), - ); + let chain_pair = ChainPair::try_from_header_and_entry(test_chain_header(), entry.clone()); Arc::new(PendingValidationStruct::new(chain_pair, workflow)) } diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index 3e81b32706..4bd1dba968 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -1,7 +1,7 @@ use crate::{ content_store::{AddContent, GetContent}, dht::aspect_map::{AspectMap, AspectMapBare}, - network::chain_pair::ChainPair + network::chain_pair::ChainPair, }; use holochain_core_types::{ chain_header::ChainHeader, @@ -244,7 +244,11 @@ impl DhtStore { Ok(()) } Err(err) => match err { - HolochainError::HeaderEntryMismatch(mut err_msg, header_entry_address, entry_address) => { + HolochainError::HeaderEntryMismatch( + mut err_msg, + header_entry_address, + entry_address, + ) => { debug!( "Tried to add entry:\n{:#?}\nand header:\n{:#?}\nto the CAS and EAV, respectively", entry, header, @@ -255,8 +259,12 @@ impl DhtStore { of header and entry. {}", err_msg ); - Err(HolochainError::HeaderEntryMismatch(err_msg, header_entry_address, entry_address)) - }, + Err(HolochainError::HeaderEntryMismatch( + err_msg, + header_entry_address, + entry_address, + )) + } _ => Err(err), }, } diff --git a/crates/core/src/dht/pending_validations.rs b/crates/core/src/dht/pending_validations.rs index 537f07d04a..2806f6ab3c 100644 --- a/crates/core/src/dht/pending_validations.rs +++ b/crates/core/src/dht/pending_validations.rs @@ -93,18 +93,19 @@ impl PendingValidationStruct { validating_workflow: ValidatingWorkflow, ) -> Result { match ChainPair::try_from_header_and_entry(header, entry) { - Ok(chain_pair) => { - Ok(PendingValidationStruct::new( - chain_pair, - validating_workflow, - )) - }, + Ok(chain_pair) => Ok(PendingValidationStruct::new( + chain_pair, + validating_workflow, + )), Err(error) => { - let error = format!("Tried to process {}; see the\n - debug output for further details of its contents. {}", entry_aspect, error); + let error = format!( + "Tried to process {}; see the\n + debug output for further details of its contents. {}", + entry_aspect, error + ); debug!("Tried to process {:?}", entry_aspect); Err(HolochainError::ValidationFailed(String::from(error))) - }, + } } } } @@ -120,7 +121,7 @@ impl TryFrom for PendingValidationStruct { EntryAspect::Content(entry, header), ValidatingWorkflow::HoldEntry, ) - }, + } EntryAspect::Header(_header) => Err(HolochainError::NotImplemented(String::from( "EntryAspect::Header", ))), @@ -141,7 +142,7 @@ impl TryFrom for PendingValidationStruct { EntryAspect::LinkRemove((link_data, links_to_remove), header), ValidatingWorkflow::RemoveLink, ) - }, + } EntryAspect::Update(entry, header) => { PendingValidationStruct::try_validate_from_entry_and_header( entry.clone(), @@ -149,7 +150,7 @@ impl TryFrom for PendingValidationStruct { EntryAspect::Update(entry, header), ValidatingWorkflow::UpdateEntry, ) - }, + } EntryAspect::Deletion(header) => { // reconstruct the deletion entry from the header. let deleted_entry_address = header.link_update_delete().ok_or_else(|| { @@ -165,7 +166,7 @@ impl TryFrom for PendingValidationStruct { EntryAspect::Deletion(header), ValidatingWorkflow::RemoveEntry, ) - }, + } } } } @@ -175,10 +176,7 @@ impl From for EntryAspect { let entry = pending.chain_pair.entry(); let header = pending.chain_pair.header(); match pending.workflow { - ValidatingWorkflow::HoldEntry => EntryAspect::Content( - entry, - header, - ), + ValidatingWorkflow::HoldEntry => EntryAspect::Content(entry, header), ValidatingWorkflow::HoldLink => { let link_data = unwrap_to!(entry => Entry::LinkAdd); EntryAspect::LinkAdd(link_data.clone(), header) @@ -187,13 +185,8 @@ impl From for EntryAspect { let link_data = unwrap_to!(entry => Entry::LinkRemove); EntryAspect::LinkRemove(link_data.clone(), header) } - ValidatingWorkflow::UpdateEntry => EntryAspect::Update( - entry, - header, - ), - ValidatingWorkflow::RemoveEntry => { - EntryAspect::Deletion(header) - } + ValidatingWorkflow::UpdateEntry => EntryAspect::Update(entry, header), + ValidatingWorkflow::RemoveEntry => EntryAspect::Deletion(header), } } } diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index 1d90ec5dc6..d5127866ad 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -3,11 +3,7 @@ use crate::{ content_store::GetContent, state::{State, StateWrapper}, }; -use holochain_core_types::{ - chain_header::ChainHeader, - entry::Entry, - error::HolochainError, -}; +use holochain_core_types::{chain_header::ChainHeader, entry::Entry, error::HolochainError}; use holochain_persistence_api::cas::content::{Address, AddressableContent}; /// A `ChainPair` cannot be constructed unless the entry address in the @@ -30,7 +26,9 @@ impl ChainPair { let error_msg = "Tried to create a ChainPair, but got a mismatch with the header's entry address and the entry's address. See the debug log output for data for the header and entry."; debug!("Mismatch between header's entry address and the entry's address. Header:\n{:#?}\nEntry:{:#?}", header, entry); Err(HolochainError::HeaderEntryMismatch( - error_msg.to_string(), header_entry_address.clone(), entry_address + error_msg.to_string(), + header_entry_address.clone(), + entry_address, )) } } @@ -43,10 +41,7 @@ impl ChainPair { self.1.clone() } - pub fn fetch_chain_pair( - address: &Address, - state: &State - ) -> Result { + pub fn fetch_chain_pair(address: &Address, state: &State) -> Result { let entry = state .agent() .chain_store() diff --git a/crates/core/src/network/handler/lists.rs b/crates/core/src/network/handler/lists.rs index 07d60e9c4d..c37fcfcf1f 100644 --- a/crates/core/src/network/handler/lists.rs +++ b/crates/core/src/network/handler/lists.rs @@ -106,10 +106,7 @@ fn create_authoring_map(context: Arc) -> AspectMap { } Ok(chain_pair) => { let entry_hash = chain_pair.entry().address(); - let content_aspect = EntryAspect::Content( - chain_pair.entry(), - chain_pair.header(), - ); + let content_aspect = EntryAspect::Content(chain_pair.entry(), chain_pair.header()); let aspect_hash = AspectHash::from(content_aspect.address()); address_map .entry(entry_hash.into()) diff --git a/crates/core/src/network/handler/mod.rs b/crates/core/src/network/handler/mod.rs index b0fca665d4..1e60c6f3ad 100644 --- a/crates/core/src/network/handler/mod.rs +++ b/crates/core/src/network/handler/mod.rs @@ -337,7 +337,7 @@ fn get_content_aspect( Err(error) => { log_error!(context, "{}", error); None - }, + } } } else { debug!( diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index c5101781c1..26b415cede 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -1,10 +1,7 @@ use crate::{ action::ActionWrapper, network::{ - actions::ActionResponse, - chain_pair::ChainPair, - entry_aspect::EntryAspect, - reducers::send, + actions::ActionResponse, chain_pair::ChainPair, entry_aspect::EntryAspect, reducers::send, state::NetworkState, }, state::State, @@ -67,10 +64,9 @@ fn publish_update_delete_meta( // publish crud-status let aspect = match crud_status { - CrudStatus::Modified => EntryAspect::Update( - chain_pair.entry().clone(), - chain_pair.header().clone() - ), + CrudStatus::Modified => { + EntryAspect::Update(chain_pair.entry().clone(), chain_pair.header().clone()) + } CrudStatus::Deleted => EntryAspect::Deletion(chain_pair.header().clone()), crud => { return Err(HolochainError::ErrorGeneric(format!( @@ -108,9 +104,7 @@ fn publish_link_meta( ), Entry::LinkRemove((link_data, links_to_remove)) => ( link_data.link().base().clone(), - EntryAspect::LinkRemove( - (link_data, links_to_remove), - chain_pair.header().clone()), + EntryAspect::LinkRemove((link_data, links_to_remove), chain_pair.header().clone()), ), _ => { return Err(HolochainError::ErrorGeneric(format!( @@ -155,7 +149,7 @@ fn reduce_publish_inner( None => Ok(()), } }) - }, + } EntryType::LinkAdd => publish_entry(network_state, &chain_pair) .and_then(|_| publish_link_meta(network_state, &chain_pair)), EntryType::LinkRemove => publish_entry(network_state, &chain_pair) diff --git a/crates/core/src/workflows/hold_entry.rs b/crates/core/src/workflows/hold_entry.rs index 4766d6f609..ffd34cb461 100644 --- a/crates/core/src/workflows/hold_entry.rs +++ b/crates/core/src/workflows/hold_entry.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, - network::chain_pair::ChainPair, nucleus::validation::validate_entry, + context::Context, dht::actions::hold_aspect::hold_aspect, network::chain_pair::ChainPair, + nucleus::validation::validate_entry, }; use crate::{nucleus::validation::ValidationError, workflows::validation_package}; @@ -71,10 +71,7 @@ pub async fn hold_entry_workflow( ); // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Content( - chain_pair.entry().clone(), - chain_pair.header().clone(), - ); + let aspect = EntryAspect::Content(chain_pair.entry().clone(), chain_pair.header().clone()); hold_aspect(aspect, context.clone()).await?; log_debug!( diff --git a/crates/core/src/workflows/hold_entry_remove.rs b/crates/core/src/workflows/hold_entry_remove.rs index 56353a1aaa..b7fde89fba 100644 --- a/crates/core/src/workflows/hold_entry_remove.rs +++ b/crates/core/src/workflows/hold_entry_remove.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, - network::chain_pair::ChainPair, nucleus::validation::validate_entry, + context::Context, dht::actions::hold_aspect::hold_aspect, network::chain_pair::ChainPair, + nucleus::validation::validate_entry, }; use crate::{nucleus::validation::ValidationError, workflows::validation_package}; diff --git a/crates/core/src/workflows/hold_entry_update.rs b/crates/core/src/workflows/hold_entry_update.rs index 2c8381e309..406e140f25 100644 --- a/crates/core/src/workflows/hold_entry_update.rs +++ b/crates/core/src/workflows/hold_entry_update.rs @@ -64,10 +64,7 @@ pub async fn hold_update_workflow( })?; // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Update( - chain_pair.entry().clone(), - chain_pair.header().clone(), - ); + let aspect = EntryAspect::Update(chain_pair.entry().clone(), chain_pair.header().clone()); hold_aspect(aspect, context.clone()).await?; Ok(()) diff --git a/crates/core/src/workflows/hold_link.rs b/crates/core/src/workflows/hold_link.rs index 639d14049c..68250d1407 100644 --- a/crates/core/src/workflows/hold_link.rs +++ b/crates/core/src/workflows/hold_link.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, - network::chain_pair::ChainPair, nucleus::validation::validate_entry, + context::Context, dht::actions::hold_aspect::hold_aspect, network::chain_pair::ChainPair, + nucleus::validation::validate_entry, }; use crate::{ diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 3f74dc893c..c161e16183 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -14,9 +14,7 @@ pub mod respond_validation_package_request; use crate::{ context::Context, dht::pending_validations::{PendingValidation, ValidatingWorkflow}, - network::{ - actions::get_validation_package::get_validation_package, chain_pair::ChainPair, - }, + network::{actions::get_validation_package::get_validation_package, chain_pair::ChainPair}, nucleus::{ actions::build_validation_package::build_validation_package, ribosome::callback::{ @@ -75,12 +73,7 @@ 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: - build_validation_package( - entry, - context.clone(), - header.provenances(), - ) - .await + build_validation_package(entry, context.clone(), header.provenances()).await } else { Err(HolochainError::ErrorGeneric(String::from( "Can't create validation package locally", @@ -98,9 +91,7 @@ async fn validation_package( context: Arc, ) -> Result, HolochainError> { // 1. Try to construct it locally: - if let Ok(package) = - try_make_local_validation_package(&chain_pair, context.clone()).await - { + if let Ok(package) = try_make_local_validation_package(&chain_pair, context.clone()).await { Ok(Some(package)) } else { // If that is not possible, get the validation package from source @@ -115,25 +106,20 @@ pub fn run_holding_workflow( context: Arc, ) -> Result<(), HolochainError> { match pending.workflow { - ValidatingWorkflow::HoldLink => context.block_on(hold_link_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::HoldEntry => context.block_on(hold_entry_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::RemoveLink => context.block_on(remove_link_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::UpdateEntry => context.block_on(hold_update_workflow( - &pending.chain_pair, - context.clone(), - )), - ValidatingWorkflow::RemoveEntry => context.block_on(hold_remove_workflow( - &pending.chain_pair, - context.clone(), - )), + ValidatingWorkflow::HoldLink => { + context.block_on(hold_link_workflow(&pending.chain_pair, context.clone())) + } + ValidatingWorkflow::HoldEntry => { + context.block_on(hold_entry_workflow(&pending.chain_pair, context.clone())) + } + ValidatingWorkflow::RemoveLink => { + context.block_on(remove_link_workflow(&pending.chain_pair, context.clone())) + } + ValidatingWorkflow::UpdateEntry => { + context.block_on(hold_update_workflow(&pending.chain_pair, context.clone())) + } + ValidatingWorkflow::RemoveEntry => { + context.block_on(hold_remove_workflow(&pending.chain_pair, context.clone())) + } } } diff --git a/crates/core/src/workflows/remove_link.rs b/crates/core/src/workflows/remove_link.rs index bc8c1da0bf..da1e103bd3 100644 --- a/crates/core/src/workflows/remove_link.rs +++ b/crates/core/src/workflows/remove_link.rs @@ -1,7 +1,6 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, - network::chain_pair::ChainPair, nucleus::validation::validate_entry, - workflows::hold_entry::hold_entry_workflow, + context::Context, dht::actions::hold_aspect::hold_aspect, network::chain_pair::ChainPair, + nucleus::validation::validate_entry, workflows::hold_entry::hold_entry_workflow, }; use crate::{nucleus::validation::ValidationError, workflows::validation_package}; diff --git a/crates/core_types/src/error/mod.rs b/crates/core_types/src/error/mod.rs index 7bc8f0b319..b3ea09ed73 100644 --- a/crates/core_types/src/error/mod.rs +++ b/crates/core_types/src/error/mod.rs @@ -163,11 +163,7 @@ impl fmt::Display for HolochainError { "Provided DNA hash does not match actual DNA hash! {} != {}", hash1, hash2 ), - HeaderEntryMismatch( - err_msg, - header_entry_address, - entry_address, - ) => write!( + HeaderEntryMismatch(err_msg, header_entry_address, entry_address) => write!( f, "Header/Entry mismatch. The entry address {} in the header does not match the address {} of the entry. {}", diff --git a/crates/core_types/src/network/entry_aspect.rs b/crates/core_types/src/network/entry_aspect.rs index cc12af6d79..9073ed15c2 100644 --- a/crates/core_types/src/network/entry_aspect.rs +++ b/crates/core_types/src/network/entry_aspect.rs @@ -111,7 +111,10 @@ impl fmt::Display for EntryAspect { EntryAspect::Content(_, _) => write!(f, "EntryAspect::Content(Entry, ChainHeader)"), EntryAspect::Header(_) => write!(f, "EntryAspect::Header(ChainHeader)"), EntryAspect::LinkAdd(_, _) => write!(f, "EntryAspect::LinkAdd(LinkData, ChainHeader)"), - EntryAspect::LinkRemove(_, _) => write!(f, "EntryAspect::LinkRemove((LinkData, Vec
), ChainHeader)"), + EntryAspect::LinkRemove(_, _) => write!( + f, + "EntryAspect::LinkRemove((LinkData, Vec
), ChainHeader)" + ), EntryAspect::Update(_, _) => write!(f, "EntryAspect::Update(Entry, ChainHeader)"), EntryAspect::Deletion(_) => write!(f, "EntryAspect::Deletion(ChainHeader)"), } diff --git a/crates/trycp_server/src/main.rs b/crates/trycp_server/src/main.rs index 4b77c438e7..2c5b6bf958 100755 --- a/crates/trycp_server/src/main.rs +++ b/crates/trycp_server/src/main.rs @@ -12,6 +12,7 @@ use nix::{ sys::signal::{self, Signal}, unistd::Pid, }; +use regex::Regex; use reqwest::{self, Url}; use serde_json::map::Map; use std::{ @@ -23,7 +24,6 @@ use std::{ sync::{Arc, RwLock}, }; use structopt::StructOpt; -use regex::Regex; const MAGIC_STRING: &str = "Done. All interfaces started."; @@ -218,9 +218,9 @@ fn get_info_as_json() -> String { // poor mans JSON convert let re = Regex::new(r"(?P[^:]+):\s+(?P.*)\n").unwrap(); let result = re.replace_all(&info_str, "\"$key\": \"$val\","); - let mut result = format!("{}",result); // pop off the final comma + let mut result = format!("{}", result); // pop off the final comma result.pop(); - format!("{{{}}}",result) + format!("{{{}}}", result) } fn main() { From d85e200fbd92d1ceb2b1e273a2c72addc8ef22b7 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Fri, 29 Nov 2019 14:35:43 +1100 Subject: [PATCH 20/79] Fix error in test --- crates/core/src/dht/dht_reducers.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 7d2d001e45..10ef1ba3bf 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -504,11 +504,15 @@ pub mod tests { assert_eq!(&entry, &result_entry,); } - fn create_pending_validation(workflow: ValidatingWorkflow) -> PendingValidation { + fn create_pending_validation(workflow: ValidatingWorkflow) -> Result { let entry = test_entry(); - let chain_pair = ChainPair::try_from_header_and_entry(test_chain_header(), entry.clone()); - - Arc::new(PendingValidationStruct::new(chain_pair, workflow)) + match ChainPair::try_from_header_and_entry(test_chain_header(), entry.clone()) { + Ok(chain_pair) => Arc::new(PendingValidationStruct::new(chain_pair, workflow)), + Err(err) => { + let err_msg = format!("Tried to create a pending validation, got an error: {}", err); + panic!(err_msg); + } + } } #[test] From d3797b7855f2930b8ac2c539983c442931748b3b Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Fri, 29 Nov 2019 14:37:47 +1100 Subject: [PATCH 21/79] Try fix the same error --- crates/core/src/dht/dht_reducers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 10ef1ba3bf..c2f9b2cec8 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -504,7 +504,7 @@ pub mod tests { assert_eq!(&entry, &result_entry,); } - fn create_pending_validation(workflow: ValidatingWorkflow) -> Result { + fn create_pending_validation(workflow: ValidatingWorkflow) -> PendingValidation { let entry = test_entry(); match ChainPair::try_from_header_and_entry(test_chain_header(), entry.clone()) { Ok(chain_pair) => Arc::new(PendingValidationStruct::new(chain_pair, workflow)), From d5faf718dddd419034da088272f43bd0ba2096c6 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Fri, 29 Nov 2019 14:39:49 +1100 Subject: [PATCH 22/79] Try fix another error --- crates/core/src/dht/dht_reducers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index c2f9b2cec8..4b33b47c1d 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -522,7 +522,7 @@ pub mod tests { assert_eq!(store.queued_holding_workflows().len(), 0); let test_entry = test_entry(); - let hold = create_pending_validation(test_entry.clone(), ValidatingWorkflow::HoldEntry); + let hold = create_pending_validation(ValidatingWorkflow::HoldEntry); let action = ActionWrapper::new(Action::QueueHoldingWorkflow(( hold.clone(), Some((SystemTime::now(), Duration::from_secs(10000))), From 4061e1a03ae351a0231821d7d1a422b680c6be4f Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Fri, 29 Nov 2019 14:42:03 +1100 Subject: [PATCH 23/79] Revert added lines --- crates/conductor_lib/src/config.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/conductor_lib/src/config.rs b/crates/conductor_lib/src/config.rs index 798b37f9a3..c1b42ceeb8 100644 --- a/crates/conductor_lib/src/config.rs +++ b/crates/conductor_lib/src/config.rs @@ -1387,8 +1387,7 @@ pub mod tests { path = "app3_spec_storage" {} - "#, - bridges + "#, bridges ) } From 254bd730d5579aeb0b284c9db660bd1b95decdfc Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Fri, 29 Nov 2019 14:43:27 +1100 Subject: [PATCH 24/79] Revert added line --- crates/conductor_lib/src/config.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/conductor_lib/src/config.rs b/crates/conductor_lib/src/config.rs index c1b42ceeb8..a7c5baea8c 100644 --- a/crates/conductor_lib/src/config.rs +++ b/crates/conductor_lib/src/config.rs @@ -1387,8 +1387,7 @@ pub mod tests { path = "app3_spec_storage" {} - "#, bridges - ) + "#, bridges) } #[test] From 30263e2255e25da2d74bcfd7f37ede3bc3f762a5 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Fri, 29 Nov 2019 14:46:06 +1100 Subject: [PATCH 25/79] Fix create_pending_validation --- crates/core/src/dht/dht_reducers.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 4b33b47c1d..c40ae567cd 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -504,8 +504,7 @@ pub mod tests { assert_eq!(&entry, &result_entry,); } - fn create_pending_validation(workflow: ValidatingWorkflow) -> PendingValidation { - let entry = test_entry(); + fn create_pending_validation(entry: Entry, workflow: ValidatingWorkflow) -> PendingValidation { match ChainPair::try_from_header_and_entry(test_chain_header(), entry.clone()) { Ok(chain_pair) => Arc::new(PendingValidationStruct::new(chain_pair, workflow)), Err(err) => { @@ -522,7 +521,7 @@ pub mod tests { assert_eq!(store.queued_holding_workflows().len(), 0); let test_entry = test_entry(); - let hold = create_pending_validation(ValidatingWorkflow::HoldEntry); + let hold = create_pending_validation(test_entry, ValidatingWorkflow::HoldEntry); let action = ActionWrapper::new(Action::QueueHoldingWorkflow(( hold.clone(), Some((SystemTime::now(), Duration::from_secs(10000))), From 4bbec8d42ecb981a48ecd47ccf9d021627353336 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Fri, 29 Nov 2019 15:19:38 +1100 Subject: [PATCH 26/79] Fix un-closed delimiter --- crates/core/src/workflows/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 5d6e858ba3..d61d2a3246 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -73,7 +73,7 @@ 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: - build_validation_package(entry, context.clone(), header.provenances() + build_validation_package(entry, context.clone(), header.provenances()) } else { Err(HolochainError::ErrorGeneric(String::from( "Can't create validation package locally", From 27c52ca916fb0fb07237b0a7491b92ed6d2de265 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Fri, 29 Nov 2019 15:49:11 +1100 Subject: [PATCH 27/79] Fix ownership error; clone test_entry --- crates/core/src/dht/dht_reducers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index c40ae567cd..c86518233c 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -521,7 +521,7 @@ pub mod tests { assert_eq!(store.queued_holding_workflows().len(), 0); let test_entry = test_entry(); - let hold = create_pending_validation(test_entry, ValidatingWorkflow::HoldEntry); + let hold = create_pending_validation(test_entry.clone(), ValidatingWorkflow::HoldEntry); let action = ActionWrapper::new(Action::QueueHoldingWorkflow(( hold.clone(), Some((SystemTime::now(), Duration::from_secs(10000))), From 1523189ab1c2b45c2bc9e519c1d4e286474278f8 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Fri, 29 Nov 2019 15:55:11 +1100 Subject: [PATCH 28/79] fmt --- crates/conductor_lib/src/config.rs | 4 +++- crates/core/src/dht/aspect_map.rs | 1 - crates/core/src/dht/dht_reducers.rs | 5 ++++- crates/core/src/network/handler/lists.rs | 1 - crates/sim2h/src/cache.rs | 1 - 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/conductor_lib/src/config.rs b/crates/conductor_lib/src/config.rs index a7c5baea8c..798b37f9a3 100644 --- a/crates/conductor_lib/src/config.rs +++ b/crates/conductor_lib/src/config.rs @@ -1387,7 +1387,9 @@ pub mod tests { path = "app3_spec_storage" {} - "#, bridges) + "#, + bridges + ) } #[test] diff --git a/crates/core/src/dht/aspect_map.rs b/crates/core/src/dht/aspect_map.rs index f0b226e8fd..64bba16e0c 100644 --- a/crates/core/src/dht/aspect_map.rs +++ b/crates/core/src/dht/aspect_map.rs @@ -224,5 +224,4 @@ mod tests { assert_eq!(merged.0.get(&EntryHash::from("a")).unwrap().len(), 3); assert_eq!(merged.0.get(&EntryHash::from("b")).unwrap().len(), 3); } - } diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index c86518233c..133aa7b401 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -508,7 +508,10 @@ pub mod tests { match ChainPair::try_from_header_and_entry(test_chain_header(), entry.clone()) { Ok(chain_pair) => Arc::new(PendingValidationStruct::new(chain_pair, workflow)), Err(err) => { - let err_msg = format!("Tried to create a pending validation, got an error: {}", err); + let err_msg = format!( + "Tried to create a pending validation, got an error: {}", + err + ); panic!(err_msg); } } diff --git a/crates/core/src/network/handler/lists.rs b/crates/core/src/network/handler/lists.rs index 3e029018e8..67aee3785c 100644 --- a/crates/core/src/network/handler/lists.rs +++ b/crates/core/src/network/handler/lists.rs @@ -177,5 +177,4 @@ pub mod tests { // to start with holding = authoring assert_eq!(authoring_map.bare().len(), 3); } - } diff --git a/crates/sim2h/src/cache.rs b/crates/sim2h/src/cache.rs index aa714b347b..45682f065e 100644 --- a/crates/sim2h/src/cache.rs +++ b/crates/sim2h/src/cache.rs @@ -385,5 +385,4 @@ mod tests { &vec![aspect_hash_1_1.clone(), aspect_hash_1_2.clone()] )); } - } From f57cd855592eb3ce37e809ea3b248d1cd053448d Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 14:47:56 +1100 Subject: [PATCH 29/79] handle error for add_header_for_entry --- crates/core/src/dht/dht_reducers.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 133aa7b401..191152e70d 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -77,8 +77,19 @@ pub(crate) fn reduce_hold_aspect( EntryAspect::Content(entry, header) => { match reduce_store_entry_inner(&mut new_store, entry) { Ok(()) => { - new_store.add_header_for_entry(&entry, &header).ok()?; - Some(new_store) + new_store.add_header_for_entry(&entry, &header) { + Ok(()) => Some(new_store), + Err(err) => { + let err_msg = format!( + "Tried to add the header for entry to the new + store in reduce_hold_aspect, got error. {}", err); + debug!( + "{}, entry:\n{:?}\nheader:\n{:?} \nnew_store:\n{:?}", err_msg, entry, header, new_store + ); + error!(err_msg); + None + } + } } Err(e) => { error!("{}", e); From e1bc59f078570fcb751331a5f135444c3ba3c70d Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 15:16:30 +1100 Subject: [PATCH 30/79] Add match, fix error --- crates/core/src/dht/dht_reducers.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 191152e70d..7fd2c16070 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -77,7 +77,7 @@ pub(crate) fn reduce_hold_aspect( EntryAspect::Content(entry, header) => { match reduce_store_entry_inner(&mut new_store, entry) { Ok(()) => { - new_store.add_header_for_entry(&entry, &header) { + match new_store.add_header_for_entry(&entry, &header) { Ok(()) => Some(new_store), Err(err) => { let err_msg = format!( @@ -88,7 +88,7 @@ pub(crate) fn reduce_hold_aspect( ); error!(err_msg); None - } + }, } } Err(e) => { From dc226c443d18797b5ee868cf6c5067de904bc891 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 15:42:18 +1100 Subject: [PATCH 31/79] Fix syntax error, add debug for a test that failed in a previous build, but will probably still fail --- crates/core/src/dht/dht_reducers.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 7fd2c16070..294e3c3fdc 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -86,7 +86,7 @@ pub(crate) fn reduce_hold_aspect( debug!( "{}, entry:\n{:?}\nheader:\n{:?} \nnew_store:\n{:?}", err_msg, entry, header, new_store ); - error!(err_msg); + error!("{}", err_msg); None }, } @@ -516,13 +516,18 @@ pub mod tests { } fn create_pending_validation(entry: Entry, workflow: ValidatingWorkflow) -> PendingValidation { - match ChainPair::try_from_header_and_entry(test_chain_header(), entry.clone()) { + let header = test_chain_header(); + match ChainPair::try_from_header_and_entry(header.clone(), entry.clone()) { Ok(chain_pair) => Arc::new(PendingValidationStruct::new(chain_pair, workflow)), Err(err) => { let err_msg = format!( "Tried to create a pending validation, got an error: {}", err ); + debug!( + "{}, entry:\n{:?}\nheader from test_chain_header():\n{:?}\n", + err_msg, entry, header + ) panic!(err_msg); } } From e007330b5b716c7120697bf4ce06b2a84c101b4d Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 15:55:41 +1100 Subject: [PATCH 32/79] Add ; --- crates/core/src/dht/dht_reducers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 294e3c3fdc..ee8b6000a6 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -527,7 +527,7 @@ pub mod tests { debug!( "{}, entry:\n{:?}\nheader from test_chain_header():\n{:?}\n", err_msg, entry, header - ) + ); panic!(err_msg); } } From 1d80926974eaed3f7132c0b19376fe27f6f05972 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 16:07:57 +1100 Subject: [PATCH 33/79] fmt --- crates/core/src/dht/dht_reducers.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index ee8b6000a6..0c343f5c37 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -76,21 +76,22 @@ pub(crate) fn reduce_hold_aspect( match aspect { EntryAspect::Content(entry, header) => { match reduce_store_entry_inner(&mut new_store, entry) { - Ok(()) => { - match new_store.add_header_for_entry(&entry, &header) { - Ok(()) => Some(new_store), - Err(err) => { - let err_msg = format!( - "Tried to add the header for entry to the new - store in reduce_hold_aspect, got error. {}", err); - debug!( - "{}, entry:\n{:?}\nheader:\n{:?} \nnew_store:\n{:?}", err_msg, entry, header, new_store - ); - error!("{}", err_msg); - None - }, + Ok(()) => match new_store.add_header_for_entry(&entry, &header) { + Ok(()) => Some(new_store), + Err(err) => { + let err_msg = format!( + "Tried to add the header for entry to the new + store in reduce_hold_aspect, got error. {}", + err + ); + debug!( + "{}, entry:\n{:?}\nheader:\n{:?} \nnew_store:\n{:?}", + err_msg, entry, header, new_store + ); + error!("{}", err_msg); + None } - } + }, Err(e) => { error!("{}", e); None From 0f5d1b5c582036370586ec5633922ec954d1346b Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 16:28:07 +1100 Subject: [PATCH 34/79] Enable logging, add extra debugging for failing tests --- crates/core/src/dht/dht_reducers.rs | 2 ++ crates/core/src/network/chain_pair.rs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 0c343f5c37..7aebdbe0a0 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -255,6 +255,7 @@ pub mod tests { #[test] fn reduce_hold_aspect_test() { + enable_logging_for_test(); let context = test_context("bob", None); let store = test_store(context); @@ -536,6 +537,7 @@ pub mod tests { #[test] pub fn test_holding_queue() { + enable_logging_for_test(); let context = test_context("test", None); let store = DhtStore::new(context.dht_storage.clone(), context.eav_storage.clone()); assert_eq!(store.queued_holding_workflows().len(), 0); diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index d5127866ad..453590f99c 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -20,11 +20,21 @@ impl ChainPair { ) -> Result { let header_entry_address = header.entry_address(); let entry_address = entry.address(); + let entry_in_header = header.entry(); if header_entry_address.clone() == entry_address { Ok(ChainPair(header, entry)) } else { - let error_msg = "Tried to create a ChainPair, but got a mismatch with the header's entry address and the entry's address. See the debug log output for data for the header and entry."; - debug!("Mismatch between header's entry address and the entry's address. Header:\n{:#?}\nEntry:{:#?}", header, entry); + let basic_error_msg = "Tried to create a ChainPair, but got a + mismatch with the header's entry address and the entry's + address."; + let error_msg = format!( + "{} See the debug log output for data for the header and entry.", + basic_error_msg + ); + debug!( + "{}\nHeader:\n{:#?}\nEntry:{:#?}\nentry in header (i.e. header.entry()=\n{:#?}", + basic_error_msg, header, entry, entry_in_header + ); Err(HolochainError::HeaderEntryMismatch( error_msg.to_string(), header_entry_address.clone(), From de65addf5b960fb0178b84121560b25771f0d20e Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 16:43:40 +1100 Subject: [PATCH 35/79] rm incorrect header.entry() --- crates/core/src/network/chain_pair.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index 453590f99c..e888426c99 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -20,7 +20,6 @@ impl ChainPair { ) -> Result { let header_entry_address = header.entry_address(); let entry_address = entry.address(); - let entry_in_header = header.entry(); if header_entry_address.clone() == entry_address { Ok(ChainPair(header, entry)) } else { @@ -33,7 +32,7 @@ impl ChainPair { ); debug!( "{}\nHeader:\n{:#?}\nEntry:{:#?}\nentry in header (i.e. header.entry()=\n{:#?}", - basic_error_msg, header, entry, entry_in_header + basic_error_msg, header, entry ); Err(HolochainError::HeaderEntryMismatch( error_msg.to_string(), From 5ef48270e0fad906c697f079d5838ea88dc311ac Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 17:02:11 +1100 Subject: [PATCH 36/79] Fix errors --- crates/core/src/dht/dht_reducers.rs | 2 ++ crates/core/src/network/chain_pair.rs | 2 +- crates/core/src/network/reducers/publish.rs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 7aebdbe0a0..826d16eae2 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -253,6 +253,7 @@ pub mod tests { .try_init(); } + #[cfg(feature = "broken-tests")] #[test] fn reduce_hold_aspect_test() { enable_logging_for_test(); @@ -535,6 +536,7 @@ pub mod tests { } } + #[cfg(feature = "broken-tests")] #[test] pub fn test_holding_queue() { enable_logging_for_test(); diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index e888426c99..4775f9d749 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -31,7 +31,7 @@ impl ChainPair { basic_error_msg ); debug!( - "{}\nHeader:\n{:#?}\nEntry:{:#?}\nentry in header (i.e. header.entry()=\n{:#?}", + "{}\nHeader:\n{:#?}\nEntry:{:#?}\nentry in header (i.e. header.entry()=\n", basic_error_msg, header, entry ); Err(HolochainError::HeaderEntryMismatch( diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index 1f65e0dd09..b9f2afbc7a 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -187,7 +187,7 @@ pub fn reduce_publish( let result = reduce_publish_inner(network_state, root_state, &address); network_state.actions.insert( action_wrapper.clone(), - Response::from(NetworkActionResponse::Publish(match result { + Response::from(ActionResponse::Publish(match result { Ok(_) => Ok(address.clone()), Err(e) => Err(HolochainError::ErrorGeneric(e.to_string())), })), From 39947884f24cfc922e07ca0e498fd1ce75eea7ed Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 17:33:28 +1100 Subject: [PATCH 37/79] Fix error with use of ActionResponse, same now as upstream develop --- crates/core/src/network/reducers/publish.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index b9f2afbc7a..e6856b70a9 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -187,7 +187,7 @@ pub fn reduce_publish( let result = reduce_publish_inner(network_state, root_state, &address); network_state.actions.insert( action_wrapper.clone(), - Response::from(ActionResponse::Publish(match result { + ActionResponse::Publish(match result { Ok(_) => Ok(address.clone()), Err(e) => Err(HolochainError::ErrorGeneric(e.to_string())), })), From abbe65272e2467985a0cd9be9be5f5a458531071 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 18:06:56 +1100 Subject: [PATCH 38/79] use test_chain_header_for_sys_entry to try fix broken test --- crates/core/src/dht/dht_reducers.rs | 3 +-- crates/core_types/src/chain_header.rs | 24 +++++++++++++++++++++-- crates/core_types/src/entry/entry_type.rs | 4 ++++ crates/core_types/src/entry/mod.rs | 8 ++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 826d16eae2..e8da1a3158 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -253,7 +253,6 @@ pub mod tests { .try_init(); } - #[cfg(feature = "broken-tests")] #[test] fn reduce_hold_aspect_test() { enable_logging_for_test(); @@ -267,7 +266,7 @@ pub mod tests { &store.dht(), &ActionWrapper::new(Action::HoldAspect(EntryAspect::Content( sys_entry.clone(), - test_chain_header(), + test_chain_header_for_sys_entry(), ))), ) .expect("there should be a new store for committing a sys entry"); diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index 29f18efb36..5c1838beec 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -5,8 +5,8 @@ use crate::{ agent::test_agent_id, entry::{ - entry_type::{test_entry_type, EntryType}, - test_entry, + entry_type::{test_entry_type, test_sys_entry_type, EntryType}, + test_entry, test_sys_entry, }, signature::{Provenance, Signature}, time::{test_iso_8601, Iso8601}, @@ -133,6 +133,10 @@ pub fn test_chain_header() -> ChainHeader { test_chain_header_with_sig("sig") } +pub fn test_chain_header_for_sys_entry() -> ChainHeader { + test_chain_header_for_sys_entry_with_sig("sig") +} + /// returns a dummy header for use in tests pub fn test_chain_header_with_sig(sig: &'static str) -> ChainHeader { ChainHeader::new( @@ -146,6 +150,21 @@ pub fn test_chain_header_with_sig(sig: &'static str) -> ChainHeader { ) } +/// returns a sys header for use in tests. +// TODO: refactor test_chain_header_for_sys_entry_with_sig +// and test_chain_header_with_sig by passing an `Entry`. +pub fn test_chain_header_for_sys_entry_with_sig(sig: &'static str) -> ChainHeader { + ChainHeader::new( + &test_sys_entry_type(), + &test_sys_entry().address(), + &test_provenances(sig), + &None, + &None, + &None, + &test_iso_8601(), + ) +} + pub fn test_provenances(sig: &'static str) -> Vec { vec![Provenance::new( test_agent_id().address(), @@ -158,6 +177,7 @@ pub mod tests { use crate::{ chain_header::{test_chain_header, test_provenances, ChainHeader}, entry::{ + Entry, entry_type::{test_entry_type, test_entry_type_a, test_entry_type_b}, test_entry, test_entry_a, test_entry_b, }, diff --git a/crates/core_types/src/entry/entry_type.rs b/crates/core_types/src/entry/entry_type.rs index b64e2f4059..fe260a22a2 100644 --- a/crates/core_types/src/entry/entry_type.rs +++ b/crates/core_types/src/entry/entry_type.rs @@ -168,6 +168,10 @@ pub fn test_entry_type() -> EntryType { EntryType::App(test_app_entry_type()) } +pub fn test_sys_entry_type() -> Entry { + EntryType::AgentId() +} + /// dummy entry type, same as test_type() #[cfg_attr(tarpaulin, skip)] pub fn test_app_entry_type_a() -> AppEntryType { diff --git a/crates/core_types/src/entry/mod.rs b/crates/core_types/src/entry/mod.rs index b299a6f477..c1213ed22d 100644 --- a/crates/core_types/src/entry/mod.rs +++ b/crates/core_types/src/entry/mod.rs @@ -218,6 +218,14 @@ pub fn test_sys_entry() -> Entry { Entry::AgentId(test_sys_entry_value()) } +// /// dummy entry +// #[cfg_attr(tarpaulin, skip)] +// pub fn test_entry() -> Entry { +// Entry::App(test_app_entry_type(), test_entry_value()) +// } + + + pub fn test_sys_entry_address() -> Address { Address::from(String::from( "QmUZ3wsC4sVdJZK2AC8Ji4HZRfkFSH2cYE6FntmfWKF8GV", From 4e178ce6a2cdbe3a635bcff67d044b7ea3482b52 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 18:08:51 +1100 Subject: [PATCH 39/79] rm delimiter --- crates/core/src/network/reducers/publish.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index e6856b70a9..0cef07d008 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -190,7 +190,7 @@ pub fn reduce_publish( ActionResponse::Publish(match result { Ok(_) => Ok(address.clone()), Err(e) => Err(HolochainError::ErrorGeneric(e.to_string())), - })), + }), ); } From 9549635a5a7107aa1942700b0daf9c724fc785f4 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 18:20:33 +1100 Subject: [PATCH 40/79] fix errors --- crates/core_types/src/entry/entry_type.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/core_types/src/entry/entry_type.rs b/crates/core_types/src/entry/entry_type.rs index fe260a22a2..2ee2578a8c 100644 --- a/crates/core_types/src/entry/entry_type.rs +++ b/crates/core_types/src/entry/entry_type.rs @@ -1,3 +1,4 @@ +use entry::Entry; use error::HolochainError; use holochain_json_api::{error::JsonError, json::JsonString}; use std::{ @@ -169,7 +170,7 @@ pub fn test_entry_type() -> EntryType { } pub fn test_sys_entry_type() -> Entry { - EntryType::AgentId() + EntryType::AgentId } /// dummy entry type, same as test_type() From 4e14193807bffbea857698a3c8e11e7eec8f5af7 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 18:27:13 +1100 Subject: [PATCH 41/79] fix error --- crates/core_types/src/entry/entry_type.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core_types/src/entry/entry_type.rs b/crates/core_types/src/entry/entry_type.rs index 2ee2578a8c..4b3a731362 100644 --- a/crates/core_types/src/entry/entry_type.rs +++ b/crates/core_types/src/entry/entry_type.rs @@ -169,7 +169,7 @@ pub fn test_entry_type() -> EntryType { EntryType::App(test_app_entry_type()) } -pub fn test_sys_entry_type() -> Entry { +pub fn test_sys_entry_type() -> EntryType { EntryType::AgentId } From 0fa1e436713f3e4aec93819eddbe24083672dfc0 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 18:34:33 +1100 Subject: [PATCH 42/79] fix error --- crates/core_types/src/entry/entry_type.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/core_types/src/entry/entry_type.rs b/crates/core_types/src/entry/entry_type.rs index 4b3a731362..f83eac5916 100644 --- a/crates/core_types/src/entry/entry_type.rs +++ b/crates/core_types/src/entry/entry_type.rs @@ -1,4 +1,3 @@ -use entry::Entry; use error::HolochainError; use holochain_json_api::{error::JsonError, json::JsonString}; use std::{ From 7d5aac4dd1c0d78a816c4cafc403150ff7dcb781 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 19:02:52 +1100 Subject: [PATCH 43/79] fix error --- crates/core/src/dht/dht_reducers.rs | 3 +++ crates/core/src/dht/pending_validations.rs | 2 +- crates/core/src/network/reducers/publish.rs | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index e8da1a3158..96dcf6be67 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -535,6 +535,9 @@ pub mod tests { } } + // Causes a header and entry mismatch when calling create_pending_validation() + // -> try_from_header_and_entry(). + // So test_entry.address() <> test_chain_header().entry_address() #[cfg(feature = "broken-tests")] #[test] pub fn test_holding_queue() { diff --git a/crates/core/src/dht/pending_validations.rs b/crates/core/src/dht/pending_validations.rs index 2806f6ab3c..0e50e26f6e 100644 --- a/crates/core/src/dht/pending_validations.rs +++ b/crates/core/src/dht/pending_validations.rs @@ -85,7 +85,7 @@ impl PendingValidationStruct { clone } - // Convenience function for returning a custom error in the context of validation. + /// Convenience function for returning a custom error in the context of validation. pub fn try_validate_from_entry_and_header( entry: Entry, header: ChainHeader, diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index 0cef07d008..25f5060a41 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -1,7 +1,7 @@ use crate::{ action::ActionWrapper, network::{ - actions::ActionResponse, + actions::NetworkActionResponse, chain_pair::ChainPair, entry_aspect::EntryAspect, reducers::send, @@ -187,7 +187,7 @@ pub fn reduce_publish( let result = reduce_publish_inner(network_state, root_state, &address); network_state.actions.insert( action_wrapper.clone(), - ActionResponse::Publish(match result { + Response::from(NetworkActionResponse::Publish(match result { Ok(_) => Ok(address.clone()), Err(e) => Err(HolochainError::ErrorGeneric(e.to_string())), }), From 32ef6d5c760bdd8fba4d2e24d57db6fbbb042919 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 19:18:30 +1100 Subject: [PATCH 44/79] re-add closing delim --- crates/core/src/network/reducers/publish.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index 25f5060a41..34fa0b05dd 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -190,7 +190,7 @@ pub fn reduce_publish( Response::from(NetworkActionResponse::Publish(match result { Ok(_) => Ok(address.clone()), Err(e) => Err(HolochainError::ErrorGeneric(e.to_string())), - }), + })), ); } From 55dca08bca93c3fe6a63a0bdfdc1821b18046338 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 19:36:26 +1100 Subject: [PATCH 45/79] Fetch upstream changes --- crates/core/src/dht/dht_reducers.rs | 18 ++++++++---------- crates/core_types/src/chain_header.rs | 5 +++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 96dcf6be67..166f876384 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -219,17 +219,15 @@ pub mod tests { content_store::{AddContent, GetContent}, dht::{ dht_reducers::{ - reduce, reduce_hold_aspect, reduce_queue_holding_workflow, - reduce_remove_queued_holding_workflow, + reduce, reduce_hold_aspect, }, - dht_store::{create_get_links_eavi_query, DhtStore}, + dht_store::{create_get_links_eavi_query}, pending_validations::{PendingValidation, PendingValidationStruct, ValidatingWorkflow}, }, instance::tests::test_context, network::chain_pair::ChainPair, state::test_store, }; - use bitflags::_core::time::Duration; use holochain_core_types::{ agent::{test_agent_id, test_agent_id_with_name}, chain_header::test_chain_header, @@ -517,7 +515,7 @@ pub mod tests { assert_eq!(&entry, &result_entry,); } - fn create_pending_validation(entry: Entry, workflow: ValidatingWorkflow) -> PendingValidation { + fn try_create_pending_validation(entry: Entry, workflow: ValidatingWorkflow) -> PendingValidation { let header = test_chain_header(); match ChainPair::try_from_header_and_entry(header.clone(), entry.clone()) { Ok(chain_pair) => Arc::new(PendingValidationStruct::new(chain_pair, workflow)), @@ -535,9 +533,9 @@ pub mod tests { } } - // Causes a header and entry mismatch when calling create_pending_validation() + // Causes a header and entry mismatch when calling try_create_pending_validation() // -> try_from_header_and_entry(). - // So test_entry.address() <> test_chain_header().entry_address() + // So test_entry.address() <> test_chain_header().entry_address(), etc. #[cfg(feature = "broken-tests")] #[test] pub fn test_holding_queue() { @@ -547,7 +545,7 @@ pub mod tests { assert_eq!(store.queued_holding_workflows().len(), 0); let test_entry = test_entry(); - let hold = create_pending_validation(test_entry.clone(), ValidatingWorkflow::HoldEntry); + let hold = try_create_pending_validation(test_entry.clone(), ValidatingWorkflow::HoldEntry); let action = ActionWrapper::new(Action::QueueHoldingWorkflow(( hold.clone(), Some((SystemTime::now(), Duration::from_secs(10000))), @@ -573,14 +571,14 @@ pub mod tests { ); let link_entry = Entry::LinkAdd(link_data.clone()); - let hold_link = create_pending_validation(link_entry, ValidatingWorkflow::HoldLink); + let hold_link = try_create_pending_validation(link_entry, ValidatingWorkflow::HoldLink); let action = ActionWrapper::new(Action::QueueHoldingWorkflow((hold_link.clone(), None))); let store = reduce_queue_holding_workflow(&store, &action).unwrap(); assert_eq!(store.queued_holding_workflows().len(), 2); assert!(store.has_queued_holding_workflow(&hold_link)); - let update = create_pending_validation(test_entry.clone(), ValidatingWorkflow::UpdateEntry); + let update = try_create_pending_validation(test_entry.clone(), ValidatingWorkflow::UpdateEntry); let action = ActionWrapper::new(Action::QueueHoldingWorkflow((update.clone(), None))); let store = reduce_queue_holding_workflow(&store, &action).unwrap(); diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index 5c1838beec..3e7724a5ea 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -175,9 +175,10 @@ pub fn test_provenances(sig: &'static str) -> Vec { #[cfg(test)] pub mod tests { use crate::{ - chain_header::{test_chain_header, test_provenances, ChainHeader}, + chain_header::{test_chain_header, test_chain_header_for_sys_entry,test_provenances, + ChainHeader + }, entry::{ - Entry, entry_type::{test_entry_type, test_entry_type_a, test_entry_type_b}, test_entry, test_entry_a, test_entry_b, }, From 9e2506fbf14e9f9f5673bee1558917188dd24f3f Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 19:39:38 +1100 Subject: [PATCH 46/79] fm unused imports, don't know and haven't checked why they've become unused --- crates/core/src/dht/dht_reducers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 166f876384..1e2e45f70e 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -237,7 +237,7 @@ pub mod tests { network::entry_aspect::EntryAspect, }; use holochain_persistence_api::cas::content::AddressableContent; - use std::{sync::Arc, time::SystemTime}; + use std::{sync::Arc}; // TODO do this for all crate tests somehow #[allow(dead_code)] fn enable_logging_for_test() { From 32e40fa669ef610ac8e71799a57bba508179f3dc Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 19:40:36 +1100 Subject: [PATCH 47/79] rm braces --- crates/core/src/dht/dht_reducers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 1e2e45f70e..bf5b9f772e 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -237,7 +237,7 @@ pub mod tests { network::entry_aspect::EntryAspect, }; use holochain_persistence_api::cas::content::AddressableContent; - use std::{sync::Arc}; + use std::sync::Arc; // TODO do this for all crate tests somehow #[allow(dead_code)] fn enable_logging_for_test() { From 079e5ea9271fa2ec9d1ebe8f4a8e812c367acc7a Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 19:53:59 +1100 Subject: [PATCH 48/79] fix import --- crates/core/src/dht/dht_reducers.rs | 9 +++++---- crates/core_types/src/chain_header.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index bf5b9f772e..e5ea47d3e5 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -216,18 +216,20 @@ pub mod tests { use crate::{ action::{Action, ActionWrapper}, + chain_header::test_chain_header_for_sys_entry, content_store::{AddContent, GetContent}, dht::{ dht_reducers::{ reduce, reduce_hold_aspect, }, - dht_store::{create_get_links_eavi_query}, + dht_store::{create_get_links_eavi_query, DhtStore}, pending_validations::{PendingValidation, PendingValidationStruct, ValidatingWorkflow}, }, instance::tests::test_context, network::chain_pair::ChainPair, state::test_store, }; + use bitflags::_core::time::Duration; use holochain_core_types::{ agent::{test_agent_id, test_agent_id_with_name}, chain_header::test_chain_header, @@ -237,7 +239,7 @@ pub mod tests { network::entry_aspect::EntryAspect, }; use holochain_persistence_api::cas::content::AddressableContent; - use std::sync::Arc; + use std::{sync::Arc, time::SystemTime}; // TODO do this for all crate tests somehow #[allow(dead_code)] fn enable_logging_for_test() { @@ -535,8 +537,7 @@ pub mod tests { // Causes a header and entry mismatch when calling try_create_pending_validation() // -> try_from_header_and_entry(). - // So test_entry.address() <> test_chain_header().entry_address(), etc. - #[cfg(feature = "broken-tests")] + // Should be since link_entry doesn't match with test chain header #[test] pub fn test_holding_queue() { enable_logging_for_test(); diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index 3e7724a5ea..dc54f2149e 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -175,7 +175,7 @@ pub fn test_provenances(sig: &'static str) -> Vec { #[cfg(test)] pub mod tests { use crate::{ - chain_header::{test_chain_header, test_chain_header_for_sys_entry,test_provenances, + chain_header::{test_chain_header,test_provenances, ChainHeader }, entry::{ From 4d9a8afd1dafdca03d7e1ec32f44a31d8f970b5b Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 20:31:13 +1100 Subject: [PATCH 49/79] use new test_link_entry and test_chain_header_for_link_entry with try_create_pending_validation --- crates/core/src/dht/dht_reducers.rs | 29 +++++--------------- crates/core_types/src/chain_header.rs | 26 ++++++++++++++++-- crates/core_types/src/entry/entry_type.rs | 4 +++ crates/core_types/src/entry/mod.rs | 32 ++++++++++++++++------- 4 files changed, 58 insertions(+), 33 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index e5ea47d3e5..8f03b7385f 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -220,7 +220,8 @@ pub mod tests { content_store::{AddContent, GetContent}, dht::{ dht_reducers::{ - reduce, reduce_hold_aspect, + reduce, reduce_hold_aspect, reduce_queue_holding_workflow, + reduce_remove_queued_holding_workflow, }, dht_store::{create_get_links_eavi_query, DhtStore}, pending_validations::{PendingValidation, PendingValidationStruct, ValidatingWorkflow}, @@ -234,7 +235,7 @@ pub mod tests { agent::{test_agent_id, test_agent_id_with_name}, chain_header::test_chain_header, eav::Attribute, - entry::{test_entry, test_sys_entry, Entry}, + entry::{test_entry, test_link_entry, test_sys_entry, Entry}, link::{link_data::LinkData, Link, LinkActionKind}, network::entry_aspect::EntryAspect, }; @@ -517,8 +518,7 @@ pub mod tests { assert_eq!(&entry, &result_entry,); } - fn try_create_pending_validation(entry: Entry, workflow: ValidatingWorkflow) -> PendingValidation { - let header = test_chain_header(); + fn try_create_pending_validation(entry: Entry, header: Header, workflow: ValidatingWorkflow) -> PendingValidation {\ match ChainPair::try_from_header_and_entry(header.clone(), entry.clone()) { Ok(chain_pair) => Arc::new(PendingValidationStruct::new(chain_pair, workflow)), Err(err) => { @@ -546,7 +546,8 @@ pub mod tests { assert_eq!(store.queued_holding_workflows().len(), 0); let test_entry = test_entry(); - let hold = try_create_pending_validation(test_entry.clone(), ValidatingWorkflow::HoldEntry); + let test_header = test_chain_header(); + let hold = try_create_pending_validation(test_entry.clone(), test_header.clone(), ValidatingWorkflow::HoldEntry); let action = ActionWrapper::new(Action::QueueHoldingWorkflow(( hold.clone(), Some((SystemTime::now(), Duration::from_secs(10000))), @@ -556,23 +557,7 @@ pub mod tests { assert_eq!(store.queued_holding_workflows().len(), 1); assert!(store.has_queued_holding_workflow(&hold)); - let test_link = String::from("test_link"); - let test_tag = String::from("test-tag"); - let link = Link::new( - &test_entry.address(), - &test_entry.address(), - &test_link.clone(), - &test_tag.clone(), - ); - let link_data = LinkData::from_link( - &link, - LinkActionKind::ADD, - test_chain_header(), - test_agent_id(), - ); - - let link_entry = Entry::LinkAdd(link_data.clone()); - let hold_link = try_create_pending_validation(link_entry, ValidatingWorkflow::HoldLink); + let hold_link = try_create_pending_validation(test_link_entry(), test_chain_header_for_link_entry(), ValidatingWorkflow::HoldLink); let action = ActionWrapper::new(Action::QueueHoldingWorkflow((hold_link.clone(), None))); let store = reduce_queue_holding_workflow(&store, &action).unwrap(); diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index dc54f2149e..68ef5c7352 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -5,7 +5,7 @@ use crate::{ agent::test_agent_id, entry::{ - entry_type::{test_entry_type, test_sys_entry_type, EntryType}, + entry_type::{test_entry_type, EntryType}, test_entry, test_sys_entry, }, signature::{Provenance, Signature}, @@ -128,6 +128,7 @@ impl AddressableContent for ChainHeader { } } +// TODO: refactor these test_chain_headers with passing the test_entry /// returns a dummy header for use in tests pub fn test_chain_header() -> ChainHeader { test_chain_header_with_sig("sig") @@ -137,6 +138,10 @@ pub fn test_chain_header_for_sys_entry() -> ChainHeader { test_chain_header_for_sys_entry_with_sig("sig") } +pub test_chain_header_for_link_entry() -> ChainHeader { + test_chain_header_for_link_entry_with_sig("sig") +} + /// returns a dummy header for use in tests pub fn test_chain_header_with_sig(sig: &'static str) -> ChainHeader { ChainHeader::new( @@ -165,6 +170,18 @@ pub fn test_chain_header_for_sys_entry_with_sig(sig: &'static str) -> ChainHeade ) } +pub fn test_chain_header_for_link_entry_with_sig(sig: &'static str) -> ChainHeader { + ChainHeader::new( + &test_link_entry_type(), + &test_link_entry().address(), + &test_provenances(sig), + &None, + &None, + &None, + &test_iso_8601(), + ) +} + pub fn test_provenances(sig: &'static str) -> Vec { vec![Provenance::new( test_agent_id().address(), @@ -179,7 +196,12 @@ pub mod tests { ChainHeader }, entry::{ - entry_type::{test_entry_type, test_entry_type_a, test_entry_type_b}, + Entry, + entry_type::{ + test_entry_type, test_sys_entry_type, + test_link_entry_type, + test_entry_type_a, test_entry_type_b + }, test_entry, test_entry_a, test_entry_b, }, time::test_iso_8601, diff --git a/crates/core_types/src/entry/entry_type.rs b/crates/core_types/src/entry/entry_type.rs index f83eac5916..e458a621e6 100644 --- a/crates/core_types/src/entry/entry_type.rs +++ b/crates/core_types/src/entry/entry_type.rs @@ -172,6 +172,10 @@ pub fn test_sys_entry_type() -> EntryType { EntryType::AgentId } +pub fn test_link_entry_type() -> EntryType { + EntryType::LinkAdd +} + /// dummy entry type, same as test_type() #[cfg_attr(tarpaulin, skip)] pub fn test_app_entry_type_a() -> AppEntryType { diff --git a/crates/core_types/src/entry/mod.rs b/crates/core_types/src/entry/mod.rs index c1213ed22d..6745472e96 100644 --- a/crates/core_types/src/entry/mod.rs +++ b/crates/core_types/src/entry/mod.rs @@ -22,7 +22,7 @@ use holochain_json_api::{ json::{JsonString, RawString}, }; use holochain_persistence_api::cas::content::{Address, AddressableContent, Content}; -use link::{link_data::LinkData, link_list::LinkList}; +use link::{Link, link_data::LinkData, link_list::LinkList, LinkActionKind}; use multihash::Hash; use serde::{ser::SerializeTuple, Deserialize, Deserializer, Serializer}; use snowflake; @@ -213,19 +213,33 @@ pub fn test_entry_unique() -> Entry { ) } +pub fn test_link_entry() -> Entry { + let test_link = String::from("test_link"); + let test_tag = String::from("test-tag"); + let link = Link::new( + &test_entry.address(), + &test_entry.address(), + &test_link.clone(), + &test_tag.clone(), + ); + let link_data = LinkData::from_link( + &link, + LinkActionKind::ADD, + test_chain_header(), + test_agent_id(), + ); + + let link_entry = Entry::LinkAdd(link_data.clone()); + + link_entry +} + +// TODO: refactor #[cfg_attr(tarpaulin, skip)] pub fn test_sys_entry() -> Entry { Entry::AgentId(test_sys_entry_value()) } -// /// dummy entry -// #[cfg_attr(tarpaulin, skip)] -// pub fn test_entry() -> Entry { -// Entry::App(test_app_entry_type(), test_entry_value()) -// } - - - pub fn test_sys_entry_address() -> Address { Address::from(String::from( "QmUZ3wsC4sVdJZK2AC8Ji4HZRfkFSH2cYE6FntmfWKF8GV", From 27321d1b881e24a8d3e698f6c97db937beb7a855 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 20:34:26 +1100 Subject: [PATCH 50/79] import test_chain_header_for_link_entry --- crates/core/src/dht/dht_reducers.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 8f03b7385f..3395c0966c 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -7,7 +7,8 @@ use crate::{ use std::sync::Arc; use super::dht_inner_reducers::{ - reduce_add_remove_link_inner, reduce_remove_entry_inner, reduce_store_entry_inner, + reduce_add_remove_link_inner, reduce_remove_entry_inner, \ + reduce_store_entry_inner, reduce_update_entry_inner, LinkModification, }; @@ -216,7 +217,7 @@ pub mod tests { use crate::{ action::{Action, ActionWrapper}, - chain_header::test_chain_header_for_sys_entry, + chain_header::{test_chain_header_for_sys_entry, test_chain_header_for_link_entry}, content_store::{AddContent, GetContent}, dht::{ dht_reducers::{ From 9d91615f828fe1d11835cdc56199ef7466043a7f Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 20:35:43 +1100 Subject: [PATCH 51/79] fmt --- crates/core/src/dht/dht_reducers.rs | 26 ++++++++++++++----- crates/core/src/network/reducers/publish.rs | 7 ++--- .../reducers/clear_zome_function_call.rs | 2 +- crates/core_types/src/chain_header.rs | 16 +++++------- crates/core_types/src/entry/mod.rs | 2 +- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 3395c0966c..7c655c0051 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -7,8 +7,7 @@ use crate::{ use std::sync::Arc; use super::dht_inner_reducers::{ - reduce_add_remove_link_inner, reduce_remove_entry_inner, \ - reduce_store_entry_inner, + reduce_add_remove_link_inner, reduce_remove_entry_inner, reduce_store_entry_inner, reduce_update_entry_inner, LinkModification, }; @@ -217,7 +216,7 @@ pub mod tests { use crate::{ action::{Action, ActionWrapper}, - chain_header::{test_chain_header_for_sys_entry, test_chain_header_for_link_entry}, + chain_header::{test_chain_header_for_link_entry, test_chain_header_for_sys_entry}, content_store::{AddContent, GetContent}, dht::{ dht_reducers::{ @@ -519,7 +518,11 @@ pub mod tests { assert_eq!(&entry, &result_entry,); } - fn try_create_pending_validation(entry: Entry, header: Header, workflow: ValidatingWorkflow) -> PendingValidation {\ + fn try_create_pending_validation( + entry: Entry, + header: Header, + workflow: ValidatingWorkflow, + ) -> PendingValidation { match ChainPair::try_from_header_and_entry(header.clone(), entry.clone()) { Ok(chain_pair) => Arc::new(PendingValidationStruct::new(chain_pair, workflow)), Err(err) => { @@ -548,7 +551,11 @@ pub mod tests { let test_entry = test_entry(); let test_header = test_chain_header(); - let hold = try_create_pending_validation(test_entry.clone(), test_header.clone(), ValidatingWorkflow::HoldEntry); + let hold = try_create_pending_validation( + test_entry.clone(), + test_header.clone(), + ValidatingWorkflow::HoldEntry, + ); let action = ActionWrapper::new(Action::QueueHoldingWorkflow(( hold.clone(), Some((SystemTime::now(), Duration::from_secs(10000))), @@ -558,14 +565,19 @@ pub mod tests { assert_eq!(store.queued_holding_workflows().len(), 1); assert!(store.has_queued_holding_workflow(&hold)); - let hold_link = try_create_pending_validation(test_link_entry(), test_chain_header_for_link_entry(), ValidatingWorkflow::HoldLink); + let hold_link = try_create_pending_validation( + test_link_entry(), + test_chain_header_for_link_entry(), + ValidatingWorkflow::HoldLink, + ); let action = ActionWrapper::new(Action::QueueHoldingWorkflow((hold_link.clone(), None))); let store = reduce_queue_holding_workflow(&store, &action).unwrap(); assert_eq!(store.queued_holding_workflows().len(), 2); assert!(store.has_queued_holding_workflow(&hold_link)); - let update = try_create_pending_validation(test_entry.clone(), ValidatingWorkflow::UpdateEntry); + let update = + try_create_pending_validation(test_entry.clone(), ValidatingWorkflow::UpdateEntry); let action = ActionWrapper::new(Action::QueueHoldingWorkflow((update.clone(), None))); let store = reduce_queue_holding_workflow(&store, &action).unwrap(); diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index 34fa0b05dd..4872b6f100 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -1,11 +1,8 @@ use crate::{ action::ActionWrapper, network::{ - actions::NetworkActionResponse, - chain_pair::ChainPair, - entry_aspect::EntryAspect, - reducers::send, - state::NetworkState, + actions::NetworkActionResponse, chain_pair::ChainPair, entry_aspect::EntryAspect, + reducers::send, state::NetworkState, }, state::State, }; diff --git a/crates/core/src/nucleus/reducers/clear_zome_function_call.rs b/crates/core/src/nucleus/reducers/clear_zome_function_call.rs index 81f8623254..92a34d295b 100644 --- a/crates/core/src/nucleus/reducers/clear_zome_function_call.rs +++ b/crates/core/src/nucleus/reducers/clear_zome_function_call.rs @@ -10,7 +10,7 @@ pub fn reduce_clear_zome_function_call( action_wrapper: &ActionWrapper, ) { let action = action_wrapper.action(); - let call = unwrap_to!(action => Action::ClearZomeFunctionCall);; + let call = unwrap_to!(action => Action::ClearZomeFunctionCall); nucleus_state.queued_zome_calls = nucleus_state .queued_zome_calls diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index 68ef5c7352..8e98afc078 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -138,7 +138,7 @@ pub fn test_chain_header_for_sys_entry() -> ChainHeader { test_chain_header_for_sys_entry_with_sig("sig") } -pub test_chain_header_for_link_entry() -> ChainHeader { +pub fn test_chain_header_for_link_entry() -> ChainHeader { test_chain_header_for_link_entry_with_sig("sig") } @@ -159,7 +159,7 @@ pub fn test_chain_header_with_sig(sig: &'static str) -> ChainHeader { // TODO: refactor test_chain_header_for_sys_entry_with_sig // and test_chain_header_with_sig by passing an `Entry`. pub fn test_chain_header_for_sys_entry_with_sig(sig: &'static str) -> ChainHeader { - ChainHeader::new( + ChainHeader::new( &test_sys_entry_type(), &test_sys_entry().address(), &test_provenances(sig), @@ -192,17 +192,13 @@ pub fn test_provenances(sig: &'static str) -> Vec { #[cfg(test)] pub mod tests { use crate::{ - chain_header::{test_chain_header,test_provenances, - ChainHeader - }, + chain_header::{test_chain_header, test_provenances, ChainHeader}, entry::{ - Entry, entry_type::{ - test_entry_type, test_sys_entry_type, - test_link_entry_type, - test_entry_type_a, test_entry_type_b + test_entry_type, test_entry_type_a, test_entry_type_b, test_link_entry_type, + test_sys_entry_type, }, - test_entry, test_entry_a, test_entry_b, + test_entry, test_entry_a, test_entry_b, Entry, }, time::test_iso_8601, }; diff --git a/crates/core_types/src/entry/mod.rs b/crates/core_types/src/entry/mod.rs index 6745472e96..6f3989bc06 100644 --- a/crates/core_types/src/entry/mod.rs +++ b/crates/core_types/src/entry/mod.rs @@ -22,7 +22,7 @@ use holochain_json_api::{ json::{JsonString, RawString}, }; use holochain_persistence_api::cas::content::{Address, AddressableContent, Content}; -use link::{Link, link_data::LinkData, link_list::LinkList, LinkActionKind}; +use link::{link_data::LinkData, link_list::LinkList, Link, LinkActionKind}; use multihash::Hash; use serde::{ser::SerializeTuple, Deserialize, Deserializer, Serializer}; use snowflake; From bc34b0a483c5ddc19c335245caadf12501276791 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 30 Nov 2019 21:55:41 +1100 Subject: [PATCH 52/79] fix errors --- crates/core_types/src/chain_header.rs | 8 ++++---- crates/core_types/src/entry/mod.rs | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index 8e98afc078..b5289aaaf9 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -5,8 +5,8 @@ use crate::{ agent::test_agent_id, entry::{ - entry_type::{test_entry_type, EntryType}, - test_entry, test_sys_entry, + entry_type::{test_entry_type, test_link_entry_type, test_sys_entry_type, EntryType}, + test_entry, test_link_entry, test_sys_entry, }, signature::{Provenance, Signature}, time::{test_iso_8601, Iso8601}, @@ -194,11 +194,11 @@ pub mod tests { use crate::{ chain_header::{test_chain_header, test_provenances, ChainHeader}, entry::{ - entry_type::{ + Entry, entry_type::{ test_entry_type, test_entry_type_a, test_entry_type_b, test_link_entry_type, test_sys_entry_type, }, - test_entry, test_entry_a, test_entry_b, Entry, + test_entry, test_entry_a, test_entry_b, test_link_entry, }, time::test_iso_8601, }; diff --git a/crates/core_types/src/entry/mod.rs b/crates/core_types/src/entry/mod.rs index 6f3989bc06..2ae7fc4f3d 100644 --- a/crates/core_types/src/entry/mod.rs +++ b/crates/core_types/src/entry/mod.rs @@ -12,7 +12,7 @@ use self::{ deletion_entry::DeletionEntry, }; use agent::{test_agent_id, AgentId}; -use chain_header::ChainHeader; +use chain_header::{ChainHeader, test_chain_header}; use chain_migrate::ChainMigrate; use crud_status::CrudStatus; use dna::Dna; @@ -214,6 +214,7 @@ pub fn test_entry_unique() -> Entry { } pub fn test_link_entry() -> Entry { + let test_entry = test_entry(); let test_link = String::from("test_link"); let test_tag = String::from("test-tag"); let link = Link::new( @@ -254,7 +255,7 @@ pub fn test_unpublishable_entry() -> Entry { #[cfg(test)] pub mod tests { use super::*; - use crate::entry::{expected_entry_address, Entry}; + use crate::{chain_header::test_chain_header, entry::{expected_entry_address, Entry}}; use holochain_persistence_api::cas::{ content::{AddressableContent, AddressableContentTestSuite}, storage::{test_content_addressable_storage, ExampleContentAddressableStorage}, From ba9e6680c8310c3045cd5a595447849a72930aea Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sun, 1 Dec 2019 16:00:25 +1100 Subject: [PATCH 53/79] fixes --- crates/core/src/dht/dht_reducers.rs | 8 +++++--- crates/core_types/src/chain_header.rs | 7 +++---- crates/core_types/src/entry/mod.rs | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 7c655c0051..a9a24e350e 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -216,7 +216,6 @@ pub mod tests { use crate::{ action::{Action, ActionWrapper}, - chain_header::{test_chain_header_for_link_entry, test_chain_header_for_sys_entry}, content_store::{AddContent, GetContent}, dht::{ dht_reducers::{ @@ -233,7 +232,10 @@ pub mod tests { use bitflags::_core::time::Duration; use holochain_core_types::{ agent::{test_agent_id, test_agent_id_with_name}, - chain_header::test_chain_header, + chain_header::{ + ChainHeader, test_chain_header, test_chain_header_for_link_entry, + test_chain_header_for_sys_entry + }, eav::Attribute, entry::{test_entry, test_link_entry, test_sys_entry, Entry}, link::{link_data::LinkData, Link, LinkActionKind}, @@ -520,7 +522,7 @@ pub mod tests { fn try_create_pending_validation( entry: Entry, - header: Header, + header: ChainHeader, workflow: ValidatingWorkflow, ) -> PendingValidation { match ChainPair::try_from_header_and_entry(header.clone(), entry.clone()) { diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index b5289aaaf9..6977a5d4bf 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -194,11 +194,10 @@ pub mod tests { use crate::{ chain_header::{test_chain_header, test_provenances, ChainHeader}, entry::{ - Entry, entry_type::{ - test_entry_type, test_entry_type_a, test_entry_type_b, test_link_entry_type, - test_sys_entry_type, + entry_type::{ + test_entry_type, test_entry_type_a, test_entry_type_b, }, - test_entry, test_entry_a, test_entry_b, test_link_entry, + test_entry, test_entry_a, test_entry_b, }, time::test_iso_8601, }; diff --git a/crates/core_types/src/entry/mod.rs b/crates/core_types/src/entry/mod.rs index 2ae7fc4f3d..7809e8c7db 100644 --- a/crates/core_types/src/entry/mod.rs +++ b/crates/core_types/src/entry/mod.rs @@ -255,7 +255,7 @@ pub fn test_unpublishable_entry() -> Entry { #[cfg(test)] pub mod tests { use super::*; - use crate::{chain_header::test_chain_header, entry::{expected_entry_address, Entry}}; + use crate::entry::{expected_entry_address, Entry}; use holochain_persistence_api::cas::{ content::{AddressableContent, AddressableContentTestSuite}, storage::{test_content_addressable_storage, ExampleContentAddressableStorage}, From 2c60dfbb50d2a500a08b03ef38ff501c8fc0bac4 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sun, 1 Dec 2019 16:03:23 +1100 Subject: [PATCH 54/79] fix --- crates/core/src/dht/dht_reducers.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index a9a24e350e..6e55335dab 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -579,7 +579,11 @@ pub mod tests { assert!(store.has_queued_holding_workflow(&hold_link)); let update = - try_create_pending_validation(test_entry.clone(), ValidatingWorkflow::UpdateEntry); + try_create_pending_validation( + test_entry.clone(), + test_header, + ValidatingWorkflow::UpdateEntry + ); let action = ActionWrapper::new(Action::QueueHoldingWorkflow((update.clone(), None))); let store = reduce_queue_holding_workflow(&store, &action).unwrap(); From a0b78105837ad97b946483d925afa73c2bb75f4d Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sun, 1 Dec 2019 17:30:30 +1100 Subject: [PATCH 55/79] fmt --- crates/core/src/dht/dht_reducers.rs | 15 +++++++-------- crates/core_types/src/chain_header.rs | 6 ++---- crates/core_types/src/entry/mod.rs | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 6e55335dab..50f47b2043 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -233,8 +233,8 @@ pub mod tests { use holochain_core_types::{ agent::{test_agent_id, test_agent_id_with_name}, chain_header::{ - ChainHeader, test_chain_header, test_chain_header_for_link_entry, - test_chain_header_for_sys_entry + test_chain_header, test_chain_header_for_link_entry, test_chain_header_for_sys_entry, + ChainHeader, }, eav::Attribute, entry::{test_entry, test_link_entry, test_sys_entry, Entry}, @@ -578,12 +578,11 @@ pub mod tests { assert_eq!(store.queued_holding_workflows().len(), 2); assert!(store.has_queued_holding_workflow(&hold_link)); - let update = - try_create_pending_validation( - test_entry.clone(), - test_header, - ValidatingWorkflow::UpdateEntry - ); + let update = try_create_pending_validation( + test_entry.clone(), + test_header, + ValidatingWorkflow::UpdateEntry, + ); let action = ActionWrapper::new(Action::QueueHoldingWorkflow((update.clone(), None))); let store = reduce_queue_holding_workflow(&store, &action).unwrap(); diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index 6977a5d4bf..edea589d57 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -194,10 +194,8 @@ pub mod tests { use crate::{ chain_header::{test_chain_header, test_provenances, ChainHeader}, entry::{ - entry_type::{ - test_entry_type, test_entry_type_a, test_entry_type_b, - }, - test_entry, test_entry_a, test_entry_b, + entry_type::{test_entry_type, test_entry_type_a, test_entry_type_b}, + test_entry, test_entry_a, test_entry_b, }, time::test_iso_8601, }; diff --git a/crates/core_types/src/entry/mod.rs b/crates/core_types/src/entry/mod.rs index 7809e8c7db..4c5f50d023 100644 --- a/crates/core_types/src/entry/mod.rs +++ b/crates/core_types/src/entry/mod.rs @@ -12,7 +12,7 @@ use self::{ deletion_entry::DeletionEntry, }; use agent::{test_agent_id, AgentId}; -use chain_header::{ChainHeader, test_chain_header}; +use chain_header::{test_chain_header, ChainHeader}; use chain_migrate::ChainMigrate; use crud_status::CrudStatus; use dna::Dna; From 8b2b95517d9ea5f8daf33aa438a3b7e49c74246b Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Sun, 1 Dec 2019 21:22:57 +1100 Subject: [PATCH 56/79] Fix clippy error --- crates/core/src/dht/pending_validations.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/dht/pending_validations.rs b/crates/core/src/dht/pending_validations.rs index 0e50e26f6e..569a569abd 100644 --- a/crates/core/src/dht/pending_validations.rs +++ b/crates/core/src/dht/pending_validations.rs @@ -104,7 +104,7 @@ impl PendingValidationStruct { entry_aspect, error ); debug!("Tried to process {:?}", entry_aspect); - Err(HolochainError::ValidationFailed(String::from(error))) + Err(HolochainError::ValidationFailed(error)) } } } From 23513ba5280e57f0d829df0250c3a3a9e912b095 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Tue, 3 Dec 2019 12:13:07 +1100 Subject: [PATCH 57/79] use ChainPair in validation_dependencies.rs tests --- .../core/src/entry/validation_dependencies.rs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/core/src/entry/validation_dependencies.rs b/crates/core/src/entry/validation_dependencies.rs index c4813884b9..946227bcf8 100644 --- a/crates/core/src/entry/validation_dependencies.rs +++ b/crates/core/src/entry/validation_dependencies.rs @@ -47,8 +47,9 @@ impl ValidationDependencies for EntryWithHeader { #[cfg(test)] pub mod tests { use super::*; + use crate::chain_pair::ChainPair; use holochain_core_types::{ - agent::AgentId, chain_header::ChainHeader, link::link_data::LinkData, time::Iso8601, + agent::AgentId, chain_header::ChainHeader, error::HolochainError,link::link_data::LinkData, time::Iso8601, }; use holochain_persistence_api::cas::content::AddressableContent; @@ -64,16 +65,16 @@ pub mod tests { ) } - fn entry_with_header_from_entry(entry: Entry) -> EntryWithHeader { + fn try_chain_pair_from_entry(entry: Entry) -> Result { let header = test_header_for_entry(&entry); - EntryWithHeader::new(entry, header) + ChainPair::try_from_header_and_entry(entry, header) } #[test] fn test_get_validation_dependencies_app_entry() { let entry = Entry::App("entry_type".into(), "content".into()); - let entry_wh = entry_with_header_from_entry(entry); - assert_eq!(entry_wh.get_validation_dependencies(), Vec::new(),) + let Ok(chain_pair) = try_chain_pair_from_entry(entry)?; + assert_eq!(chain_pair.get_validation_dependencies(), Vec::new(),) } #[test] @@ -86,9 +87,9 @@ pub mod tests { test_header_for_entry(&Entry::App("".into(), "".into())), AgentId::new("HcAgentId", "key".into()), )); - let entry_wh = entry_with_header_from_entry(entry); + let Ok(chain_pair) = try_chain_pair_from_entry(entry)?; assert_eq!( - entry_wh.get_validation_dependencies(), + chain_pair.get_validation_dependencies(), vec![ Address::from("QmBaseAddress"), Address::from("QmTargetAddress") @@ -98,7 +99,7 @@ pub mod tests { #[test] fn test_get_validation_dependencies_header_entry() { - let header_entry_conent = ChainHeader::new( + let header_entry_content = ChainHeader::new( &"some type".into(), &Address::from("QmAddressOfEntry"), &Vec::new(), // provenences @@ -107,10 +108,10 @@ pub mod tests { &None, // link update/delete &Iso8601::from(0), ); - let entry = Entry::ChainHeader(header_entry_conent); - let entry_wh = entry_with_header_from_entry(entry); + let entry = Entry::ChainHeader(header_entry_content); + let Ok(chain_pair) = try_chain_pair_from_entry(entry)?; assert_eq!( - entry_wh.get_validation_dependencies(), + chain_pair.get_validation_dependencies(), vec![Address::from("QmPreviousHeaderAddress")], ) } From 1f382968e9d219697230b2cf6419bfbcddb26046 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Tue, 3 Dec 2019 12:18:25 +1100 Subject: [PATCH 58/79] rename PendingValidationStruct::try_validate_from_entry_and_header to try_from_entry_and_header --- crates/core/src/dht/dht_store.rs | 6 +++--- crates/core/src/dht/pending_validations.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index 129af47f82..947ce6dbe8 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -426,13 +426,13 @@ pub mod tests { assert_eq!(headers, vec![header1, header2]); } - fn pending_validation_for_entry( + fn try_pending_validation_for_entry( entry: Entry, dependencies: Vec
, - ) -> PendingValidationWithTimeout { + ) -> Result { let header = test_chain_header_with_sig("sig1"); let mut pending_struct = PendingValidationStruct::new( - EntryWithHeader { entry, header }, + chain_pair, ValidatingWorkflow::HoldEntry, ); pending_struct.dependencies = dependencies; diff --git a/crates/core/src/dht/pending_validations.rs b/crates/core/src/dht/pending_validations.rs index 12f178e464..ebad669ebe 100644 --- a/crates/core/src/dht/pending_validations.rs +++ b/crates/core/src/dht/pending_validations.rs @@ -95,7 +95,7 @@ impl PendingValidationStruct { } /// Convenience function for returning a custom error in the context of validation. - pub fn try_validate_from_entry_and_header( + pub fn try_from_entry_and_header( entry: Entry, header: ChainHeader, entry_aspect: EntryAspect, @@ -124,7 +124,7 @@ impl TryFrom for PendingValidationStruct { fn try_from(aspect: EntryAspect) -> Result { match aspect { EntryAspect::Content(entry, header) => { - PendingValidationStruct::try_validate_from_entry_and_header( + PendingValidationStruct::try_from_entry_and_header( entry.clone(), header.clone(), EntryAspect::Content(entry, header), @@ -136,7 +136,7 @@ impl TryFrom for PendingValidationStruct { ))), EntryAspect::LinkAdd(link_data, header) => { let entry = Entry::LinkAdd(link_data.clone()); - PendingValidationStruct::try_validate_from_entry_and_header( + PendingValidationStruct::try_from_entry_and_header( entry, header.clone(), EntryAspect::LinkAdd(link_data, header), @@ -145,7 +145,7 @@ impl TryFrom for PendingValidationStruct { } EntryAspect::LinkRemove((link_data, links_to_remove), header) => { let entry = Entry::LinkRemove((link_data.clone(), links_to_remove.clone())); - PendingValidationStruct::try_validate_from_entry_and_header( + PendingValidationStruct::try_from_entry_and_header( entry, header.clone(), EntryAspect::LinkRemove((link_data, links_to_remove), header), @@ -153,7 +153,7 @@ impl TryFrom for PendingValidationStruct { ) } EntryAspect::Update(entry, header) => { - PendingValidationStruct::try_validate_from_entry_and_header( + PendingValidationStruct::try_from_entry_and_header( entry.clone(), header.clone(), EntryAspect::Update(entry, header), @@ -169,7 +169,7 @@ impl TryFrom for PendingValidationStruct { })?; let entry = Entry::Deletion(DeletionEntry::new(deleted_entry_address)); - PendingValidationStruct::try_validate_from_entry_and_header( + PendingValidationStruct::try_from_entry_and_header( entry, header.clone(), EntryAspect::Deletion(header), From bb6907c4069414cebdee0e760048f59d86eb3fec Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Tue, 3 Dec 2019 12:27:37 +1100 Subject: [PATCH 59/79] use try_pending_validation_for_entry instead of pending_validation_for_entry --- crates/core/src/dht/dht_store.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index 947ce6dbe8..8992ecabe1 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -431,8 +431,10 @@ pub mod tests { dependencies: Vec
, ) -> Result { let header = test_chain_header_with_sig("sig1"); - let mut pending_struct = PendingValidationStruct::new( - chain_pair, + let mut pending_struct = PendingValidationStruct::try_from_entry_and_header( + entry, + header, + EntryAspect::Content(entry, header), ValidatingWorkflow::HoldEntry, ); pending_struct.dependencies = dependencies; @@ -442,8 +444,8 @@ pub mod tests { #[test] fn test_dependency_resolution_no_dependencies() { // A and B have no dependencies. Both should be free - let a = pending_validation_for_entry(test_entry_a(), Vec::new()); - let b = pending_validation_for_entry(test_entry_b(), Vec::new()); + let Ok(a) = try_pending_validation_for_entry(test_entry_a(), Vec::new())?; + let Ok(b) = try_pending_validation_for_entry(test_entry_b(), Vec::new())?; assert_eq!( get_free_dependencies(&vec![a.clone(), b.clone()]), vec![a, b] @@ -453,9 +455,9 @@ pub mod tests { #[test] fn test_dependency_resolution_chain() { // A depends on B and B depends on C. C should be free - let a = pending_validation_for_entry(test_entry_a(), vec![test_entry_b().address()]); - let b = pending_validation_for_entry(test_entry_b(), vec![test_entry_c().address()]); - let c = pending_validation_for_entry(test_entry_c(), vec![]); + let Ok(a) = try_pending_validation_for_entry(test_entry_a(), vec![test_entry_b().address()]); + let Ok(b) = try_pending_validation_for_entry(test_entry_b(), vec![test_entry_c().address()])?; + let Ok(c) = try_pending_validation_for_entry(test_entry_c(), vec![])?; assert_eq!( get_free_dependencies(&vec![a.clone(), b.clone(), c.clone()]), @@ -466,12 +468,12 @@ pub mod tests { #[test] fn test_dependency_resolution_tree() { // A depends on B and C. B and C should be free - let a = pending_validation_for_entry( + let Ok(a) = try_pending_validation_for_entry( test_entry_a(), vec![test_entry_b().address(), test_entry_c().address()], - ); - let b = pending_validation_for_entry(test_entry_b(), vec![]); - let c = pending_validation_for_entry(test_entry_c(), vec![]); + )?; + let Ok(b) = try_pending_validation_for_entry(test_entry_b(), vec![])?; + let Ok(c) = try_pending_validation_for_entry(test_entry_c(), vec![])?; assert_eq!( get_free_dependencies(&vec![a.clone(), b.clone(), c.clone()]), From ff8fa8a186aec921466f13935494ab3e5f267ca3 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Tue, 3 Dec 2019 12:31:38 +1100 Subject: [PATCH 60/79] impl ValidationDependenies for ChainPair rather than EntryWithHeader --- crates/core/src/dht/dht_store.rs | 1 - crates/core/src/entry/validation_dependencies.rs | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index 8992ecabe1..6865e2b2c5 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -398,7 +398,6 @@ pub mod tests { use super::*; use crate::{ dht::pending_validations::{PendingValidationStruct, ValidatingWorkflow}, - network::entry_with_header::EntryWithHeader, }; use holochain_core_types::{ chain_header::test_chain_header_with_sig, diff --git a/crates/core/src/entry/validation_dependencies.rs b/crates/core/src/entry/validation_dependencies.rs index 946227bcf8..9b97797652 100644 --- a/crates/core/src/entry/validation_dependencies.rs +++ b/crates/core/src/entry/validation_dependencies.rs @@ -1,4 +1,4 @@ -use crate::network::entry_with_header::EntryWithHeader; +use crate::network::chain_pair::ChainPair; use holochain_core_types::entry::Entry; use holochain_persistence_api::cas::content::Address; @@ -6,15 +6,15 @@ pub trait ValidationDependencies { fn get_validation_dependencies(&self) -> Vec
; } -impl ValidationDependencies for EntryWithHeader { +impl ValidationDependencies for ChainPair { fn get_validation_dependencies(&self) -> Vec
{ - match &self.entry { + match &self.entry() { Entry::App(_, _) => { // In the future an entry should be dependent its previous header but // for now it can require nothing by default. // There is also potential to add a WASM function for determining dependencies as a function // of the entry content. - match self.header.link_update_delete() { + match self.header().link_update_delete() { // If it is an update, require that the original entry is validated Some(entry_to_update) => vec![entry_to_update], None => Vec::new(), From bf81355dcd7076a2f76a01ff415e0c011533aa57 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Tue, 3 Dec 2019 12:33:42 +1100 Subject: [PATCH 61/79] Replace EntryWithHeader with ChainPair in commented out code in store.rs --- crates/core/src/network/handler/store.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/core/src/network/handler/store.rs b/crates/core/src/network/handler/store.rs index 6ac168c914..088a1edb23 100644 --- a/crates/core/src/network/handler/store.rs +++ b/crates/core/src/network/handler/store.rs @@ -55,9 +55,7 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc) { aspect_json ) } -} -// If reusing/uncommenting, replace EntryWithHeader with ChainPair /* /// The network requests us to store meta information (links/CRUD/etc) for an /// entry that we hold. @@ -71,9 +69,9 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { assert_eq!(dht_meta_data.content_list.len(), 1); let chain_pair: ChainPair = serde_json::from_str( &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be EntryWithHeader"), + .expect("dht_meta_data should be ChainPair"), ) - .expect("dht_meta_data should be EntryWithHeader"); + .expect("dht_meta_data should be ChainPair"); thread::spawn(move || { match context.block_on(hold_link_workflow(&chain_pair, &context.clone())) { Err(error) => log_error!(context, "net/dht: {}", error), @@ -84,10 +82,10 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { log_debug!(context, "net/handle: HandleStoreMeta: got LINK REMOVAL. processing..."); // TODO: do a loop on content once links properly implemented assert_eq!(dht_meta_data.content_list.len(), 1); - let chain_pair: EntryWithHeader = serde_json::from_str( + let chain_pair: ChainPair = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be EntryWithHader"), + .expect("dht_meta_data should be ChainPair"), ) .expect("dht_meta_data should be EntryWithHader"); thread::spawn(move || { @@ -103,12 +101,12 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { { log_debug!(context, "net/handle: HandleStoreMeta: got CRUD STATUS. processing..."); - let chain_pair: EntryWithHeader = serde_json::from_str( + let chain_pair: ChainPair = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be EntryWithHader"), + .expect("dht_meta_data should be ChainPair"), ) - .expect("dht_meta_data should be EntryWithHader"); + .expect("dht_meta_data should be ChainPair"); thread::spawn(move || { if let Err(error) = context.block_on(hold_remove_workflow(chain_pair, context.clone())) @@ -121,12 +119,12 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { == CrudStatus::Modified { log_debug!(context, "net/handle: HandleStoreMeta: got CRUD LINK. processing..."); - let chain_pair: EntryWithHeader = serde_json::from_str( + let chain_pair: ChainPair = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be EntryWithHader"), + .expect("dht_meta_data should be ChainPair"), ) - .expect("dht_meta_data should be EntryWithHader"); + .expect("dht_meta_data should be ChainPair"); thread::spawn(move || { if let Err(error) = context.block_on(hold_update_workflow(chain_pair, context.clone())) From 5dc06d2dd57da302327abc9de92db937e41444e3 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Tue, 3 Dec 2019 14:08:39 +1100 Subject: [PATCH 62/79] fix errors, rename --- crates/core/src/network/handler/store.rs | 1 + crates/core/src/nucleus/validation/mod.rs | 24 ++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crates/core/src/network/handler/store.rs b/crates/core/src/network/handler/store.rs index 088a1edb23..e6febffa7b 100644 --- a/crates/core/src/network/handler/store.rs +++ b/crates/core/src/network/handler/store.rs @@ -55,6 +55,7 @@ pub fn handle_store(dht_data: StoreEntryAspectData, context: Arc) { aspect_json ) } +} /* /// The network requests us to store meta information (links/CRUD/etc) for an diff --git a/crates/core/src/nucleus/validation/mod.rs b/crates/core/src/nucleus/validation/mod.rs index 73c9869881..95be979335 100644 --- a/crates/core/src/nucleus/validation/mod.rs +++ b/crates/core/src/nucleus/validation/mod.rs @@ -135,12 +135,12 @@ pub fn entry_to_validation_data( match entry { Entry::App(_, _) => maybe_link_update_delete .map(|link_update| { - get_chain_pair(context.clone(), &link_update) - .map(|chain_pair| { + try_get_entry_with_meta_and_header_tuple(context.clone(), &link_update) + .map(|entry_with_meta_and_header_tuple| { Ok(EntryValidationData::Modify { - old_entry: chain_pair.0.entry.clone(), + old_entry: entry_with_meta_and_header.0.entry.clone(), new_entry: entry.clone(), - old_entry_header: chain_pair.1.clone(), + old_entry_header: entry_with_meta_and_header.1.clone(), validation_data: validation_data.clone(), }) }) @@ -158,14 +158,14 @@ pub fn entry_to_validation_data( }), Entry::Deletion(deletion_entry) => { let deletion_address = deletion_entry.clone().deleted_entry_address(); - get_chain_pair(context.clone(), &deletion_address) - .map(|chain_pair| { + try_get_entry_with_meta_and_header_tuple(context.clone(), &deletion_address) + .map(|entry_with_meta_and_header_tuple| { let deletion_address = deletion_entry.deleted_entry_address().clone(); - get_chain_pair(context.clone(), &deletion_address) - .map(|chain_pair| { + try_get_entry_with_meta_and_header_tuple(context.clone(), &deletion_address) + .map(|entry_with_meta_and_header| { Ok(EntryValidationData::Delete { - old_entry: chain_pair.0.entry.clone(), - old_entry_header: chain_pair.1.clone(), + old_entry: entry_with_meta_and_header.0.entry.clone(), + old_entry_header: entry_with_meta_and_header.1.clone(), validation_data: validation_data.clone(), }) }) @@ -174,6 +174,7 @@ pub fn entry_to_validation_data( "Could not find Entry".to_string(), )) }) + } } Entry::CapTokenGrant(_) => Ok(EntryValidationData::Create { entry: entry.clone(), @@ -185,7 +186,8 @@ pub fn entry_to_validation_data( } } -fn get_chain_pair( +// It's a long name but it avoids confusion with getting `EntryWithMetaAndHeader`, or avoiding confusion when searching. +fn try_get_entry_with_meta_and_header_tuple( context: Arc, address: &Address, ) -> Result<(EntryWithMeta, ChainHeader), HolochainError> { From 9862b541e5e294a60f0330eef38eb977d1e72347 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Tue, 3 Dec 2019 15:36:06 +1100 Subject: [PATCH 63/79] more fixes, can't build on laptop, internet still not available --- crates/core/src/dht/dht_store.rs | 4 ++-- crates/core/src/nucleus/validation/mod.rs | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index 6865e2b2c5..bf7c002dd3 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -352,14 +352,14 @@ where // add the nodes for p in pending.clone() { let node_index = graph.add_node(()); - index_map.insert(p.pending.entry_with_header.entry.address(), node_index); + index_map.insert(p.pending.chain_pair.entry().address(), node_index); index_reverse_map.insert(node_index, p); } // add the edges for p in pending.clone() { let from = index_map - .get(&p.pending.entry_with_header.entry.address()) + .get(&p.pending.chain_pair.entry().address()) .expect("we literally just added this"); for to_addr in p.pending.dependencies.clone() { // only add the dependencies that are also in the pending validation list diff --git a/crates/core/src/nucleus/validation/mod.rs b/crates/core/src/nucleus/validation/mod.rs index 95be979335..d5b90c1c87 100644 --- a/crates/core/src/nucleus/validation/mod.rs +++ b/crates/core/src/nucleus/validation/mod.rs @@ -138,9 +138,9 @@ pub fn entry_to_validation_data( try_get_entry_with_meta_and_header_tuple(context.clone(), &link_update) .map(|entry_with_meta_and_header_tuple| { Ok(EntryValidationData::Modify { - old_entry: entry_with_meta_and_header.0.entry.clone(), + old_entry: entry_with_meta_and_header_tuple.0.entry.clone(), new_entry: entry.clone(), - old_entry_header: entry_with_meta_and_header.1.clone(), + old_entry_header: entry_with_meta_and_header_tuple.1.clone(), validation_data: validation_data.clone(), }) }) @@ -157,9 +157,6 @@ pub fn entry_to_validation_data( }) }), Entry::Deletion(deletion_entry) => { - let deletion_address = deletion_entry.clone().deleted_entry_address(); - try_get_entry_with_meta_and_header_tuple(context.clone(), &deletion_address) - .map(|entry_with_meta_and_header_tuple| { let deletion_address = deletion_entry.deleted_entry_address().clone(); try_get_entry_with_meta_and_header_tuple(context.clone(), &deletion_address) .map(|entry_with_meta_and_header| { @@ -174,8 +171,7 @@ pub fn entry_to_validation_data( "Could not find Entry".to_string(), )) }) - } - } + }, Entry::CapTokenGrant(_) => Ok(EntryValidationData::Create { entry: entry.clone(), validation_data, From c004f00a56379fc95379583f59688dfb66fec9be Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Thu, 12 Dec 2019 15:56:10 +1100 Subject: [PATCH 64/79] use ChainPair and chain_pair instead of EntryWithHeader and entry_with_header; no need cloning chain_pair.entry() and chain_pair.header(). --- crates/core/src/network/reducers/publish.rs | 14 +++++------ .../src/nucleus/validation/build_from_dht.rs | 14 +++++------ crates/core/src/workflows/hold_entry.rs | 4 ++-- .../core/src/workflows/hold_entry_remove.rs | 4 ++-- .../core/src/workflows/hold_entry_update.rs | 2 +- crates/core/src/workflows/hold_link.rs | 4 ++-- crates/core/src/workflows/mod.rs | 24 +++++++++---------- crates/core/src/workflows/remove_link.rs | 4 ++-- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index 263c305863..a64b62b819 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -47,8 +47,8 @@ fn publish_entry( entry: EntryData { entry_address: chain_pair.entry().address().into(), aspect_list: vec![entry_data_to_entry_aspect_data(&EntryAspect::Content( - chain_pair.entry().clone(), - chain_pair.header().clone(), + chain_pair.entry(), + chain_pair.header(), ))], }, }), @@ -66,9 +66,9 @@ fn publish_update_delete_meta( let aspect = match crud_status { CrudStatus::Modified => { - EntryAspect::Update(chain_pair.entry().clone(), chain_pair.header().clone()) + EntryAspect::Update(chain_pair.entry(), chain_pair.header()) } - CrudStatus::Deleted => EntryAspect::Deletion(chain_pair.header().clone()), + CrudStatus::Deleted => EntryAspect::Deletion(chain_pair.header()), crud => { return Err(HolochainError::ErrorGeneric(format!( "Unexpeced CRUD variant {:?}", @@ -98,14 +98,14 @@ fn publish_link_meta( network_state: &mut NetworkState, chain_pair: &ChainPair, ) -> Result<(), HolochainError> { - let (base, aspect) = match chain_pair.entry().clone() { + let (base, aspect) = match chain_pair.entry() { Entry::LinkAdd(link_data) => ( link_data.link().base().clone(), - EntryAspect::LinkAdd(link_data, chain_pair.header().clone()), + EntryAspect::LinkAdd(link_data, chain_pair.header()), ), Entry::LinkRemove((link_data, links_to_remove)) => ( link_data.link().base().clone(), - EntryAspect::LinkRemove((link_data, links_to_remove), chain_pair.header().clone()), + EntryAspect::LinkRemove((link_data, links_to_remove), chain_pair.header()), ), _ => { return Err(HolochainError::ErrorGeneric(format!( diff --git a/crates/core/src/nucleus/validation/build_from_dht.rs b/crates/core/src/nucleus/validation/build_from_dht.rs index 596edb83eb..99d2d5a634 100644 --- a/crates/core/src/nucleus/validation/build_from_dht.rs +++ b/crates/core/src/nucleus/validation/build_from_dht.rs @@ -1,5 +1,5 @@ use crate::{ - context::Context, entry::CanPublish, network::entry_with_header::EntryWithHeader, + context::Context, entry::CanPublish, network::chain_pair::ChainPair, workflows::get_entry_result::get_entry_with_meta_workflow, }; use holochain_core_types::{ @@ -85,16 +85,16 @@ async fn public_chain_entries_from_headers_dht( } pub(crate) async fn try_make_validation_package_dht( - entry_with_header: &EntryWithHeader, + chain_pair: &ChainPair, validation_package_definition: &ValidationPackageDefinition, context: Arc, ) -> Result { + let entry_header = chain_pair.header(); log_debug!( context, "Constructing validation package from DHT for entry with address: {}", - entry_with_header.header.entry_address() + entry_header.clone().entry_address() ); - let entry_header = entry_with_header.header.clone(); log_debug!(context, "Retrieving chain headers..."); @@ -204,12 +204,12 @@ pub mod tests { .next() .expect("Must be able to get header for just published entry"); - let entry_with_header = EntryWithHeader { entry, header }; + let chain_pair = ChainPair::try_from_header_and_entry(header, entry); // jack (the author) retrieves a local validation package let local_validation_package = context2 .block_on(try_make_local_validation_package( - &entry_with_header, + &chain_pair, &ValidationPackageDefinition::ChainFull, context2.clone(), )) @@ -218,7 +218,7 @@ pub mod tests { // jill reconstructs one from published headers let dht_validation_package = context1 .block_on(try_make_validation_package_dht( - &entry_with_header, + &chain_pair, &ValidationPackageDefinition::ChainFull, context1.clone(), )) diff --git a/crates/core/src/workflows/hold_entry.rs b/crates/core/src/workflows/hold_entry.rs index ffd34cb461..0b05d17bd1 100644 --- a/crates/core/src/workflows/hold_entry.rs +++ b/crates/core/src/workflows/hold_entry.rs @@ -43,7 +43,7 @@ pub async fn hold_entry_workflow( // 3. Validate the entry validate_entry( - chain_pair.entry().clone(), + chain_pair.entry(), None, validation_data, &context @@ -71,7 +71,7 @@ pub async fn hold_entry_workflow( ); // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Content(chain_pair.entry().clone(), chain_pair.header().clone()); + let aspect = EntryAspect::Content(chain_pair.entry(), chain_pair.header()); hold_aspect(aspect, context.clone()).await?; log_debug!( diff --git a/crates/core/src/workflows/hold_entry_remove.rs b/crates/core/src/workflows/hold_entry_remove.rs index b7fde89fba..4f66509554 100644 --- a/crates/core/src/workflows/hold_entry_remove.rs +++ b/crates/core/src/workflows/hold_entry_remove.rs @@ -35,7 +35,7 @@ pub async fn hold_remove_workflow( // 3. Validate the entry validate_entry( - chain_pair.entry().clone(), + chain_pair.entry(), None, validation_data, &context @@ -55,7 +55,7 @@ pub async fn hold_remove_workflow( })?; // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Deletion(chain_pair.header().clone()); + let aspect = EntryAspect::Deletion(chain_pair.header()); hold_aspect(aspect, context.clone()).await?; Ok(()) } diff --git a/crates/core/src/workflows/hold_entry_update.rs b/crates/core/src/workflows/hold_entry_update.rs index 406e140f25..4d39bfa2c8 100644 --- a/crates/core/src/workflows/hold_entry_update.rs +++ b/crates/core/src/workflows/hold_entry_update.rs @@ -64,7 +64,7 @@ pub async fn hold_update_workflow( })?; // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Update(chain_pair.entry().clone(), chain_pair.header().clone()); + let aspect = EntryAspect::Update(chain_pair.entry(), chain_pair.header()); hold_aspect(aspect, context.clone()).await?; Ok(()) diff --git a/crates/core/src/workflows/hold_link.rs b/crates/core/src/workflows/hold_link.rs index 68250d1407..f84580f221 100644 --- a/crates/core/src/workflows/hold_link.rs +++ b/crates/core/src/workflows/hold_link.rs @@ -55,7 +55,7 @@ pub async fn hold_link_workflow( // 3. Validate the entry log_debug!(context, "workflow/hold_link: validate..."); validate_entry( - chain_pair.entry().clone(), + chain_pair.entry(), None, validation_data, &context @@ -76,7 +76,7 @@ pub async fn hold_link_workflow( log_debug!(context, "workflow/hold_link: is valid!"); // 3. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::LinkAdd(link_add.clone(), chain_pair.header().clone()); + let aspect = EntryAspect::LinkAdd(link_add.clone(), chain_pair.header()); hold_aspect(aspect, context.clone()).await?; log_debug!(context, "workflow/hold_link: added! {:?}", link); diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 2cf4c90b10..50c01d1b27 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -79,7 +79,7 @@ async fn validation_package( ) -> Result, HolochainError> { // 0. Call into the DNA to get the validation package definition for this entry // e.g. what data is needed to validate it (chain, entry, headers, etc) - let entry = &entry_with_header.entry(); + let entry = chain_pair.entry(); let validation_package_definition = get_validation_package_definition(entry, context.clone()) .and_then(|callback_result| match callback_result { CallbackResult::Fail(error_string) => Err(HolochainError::ErrorGeneric(error_string)), @@ -118,22 +118,22 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Could not build locally. Trying to retrieve from author", - entry_with_header.entry.address() + chain_pair.entry().address() ); - match get_validation_package(entry_with_header.header.clone(), &context).await { + match get_validation_package(chain_pair.header(), &context).await { Ok(Some(package)) => { log_debug!( context, "validation_package:{} - Successfully retrieved from author", - entry_with_header.entry.address() + chain_pair.entry().address() ); return Ok(Some(package)); } response => log_debug!( context, "validation_package:{} - Direct message to author responded: {:?}", - entry_with_header.entry.address(), + chain_pair.entry().address(), response, ), } @@ -142,10 +142,10 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Could not retrieve from author. Trying to build from published headers", - entry_with_header.entry.address() + chain_pair.entry().address() ); if let Ok(package) = try_make_validation_package_dht( - &entry_with_header, + &chain_pair, &validation_package_definition, context.clone(), ) @@ -154,7 +154,7 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Successfully built from published headers", - entry_with_header.entry.address() + chain_pair.entry().address() ); return Ok(Some(package)); } @@ -164,7 +164,7 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Could not get validation package!!!", - entry_with_header.entry.address() + chain_pair.entry().address() ); Err(HolochainError::ErrorGeneric( "Could not get validation package".to_string(), @@ -175,7 +175,7 @@ async fn validation_package( pub mod tests { use super::validation_package; use crate::{ - network::entry_with_header::EntryWithHeader, nucleus::actions::tests::*, + network::chain_pair::ChainPair, nucleus::actions::tests::*, workflows::author_entry::author_entry, }; use holochain_core_types::entry::Entry; @@ -211,10 +211,10 @@ pub mod tests { .next() .expect("Must be able to get header for just published entry"); - let entry_with_header = EntryWithHeader { entry, header }.clone(); + let chain_pair = ChainPair::try_from_header_and_entry(header, entry); let validation_package = context1 - .block_on(validation_package(&entry_with_header, context1.clone())) + .block_on(validation_package(&chain_pair, context1.clone())) .expect("Could not recover a validation package as the non-author"); assert_eq!( diff --git a/crates/core/src/workflows/remove_link.rs b/crates/core/src/workflows/remove_link.rs index da1e103bd3..5c7540ae32 100644 --- a/crates/core/src/workflows/remove_link.rs +++ b/crates/core/src/workflows/remove_link.rs @@ -53,7 +53,7 @@ pub async fn remove_link_workflow( // 3. Validate the entry log_debug!(context, "workflow/remove_link: validate..."); validate_entry( - chain_pair.entry().clone(), + chain_pair.entry(), None, validation_data, &context @@ -77,7 +77,7 @@ pub async fn remove_link_workflow( // 3. If valid store the entry aspect in the local DHT shard let aspect = EntryAspect::LinkRemove( (link_data.clone(), links_to_remove.clone()), - chain_pair.header().clone(), + chain_pair.header(), ); hold_aspect(aspect, context.clone()).await?; log_debug!(context, "workflow/remove_link: added! {:?}", link); From 7487a077656cb002eee958fbc26236c4ebdadd5c Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Thu, 12 Dec 2019 20:47:12 +1100 Subject: [PATCH 65/79] Fix errors from tests --- crates/core/src/scheduled_jobs/state_dump.rs | 2 +- crates/core/src/workflows/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/core/src/scheduled_jobs/state_dump.rs b/crates/core/src/scheduled_jobs/state_dump.rs index ae6eae4a06..cfba7733fb 100644 --- a/crates/core/src/scheduled_jobs/state_dump.rs +++ b/crates/core/src/scheduled_jobs/state_dump.rs @@ -59,7 +59,7 @@ pub fn state_dump(context: Arc) { .dependencies .iter() .map(|addr| addr.to_string()) - .collect::>(),ut + .collect::>(), ) }) .collect::>(); diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 50c01d1b27..d794970a67 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -80,7 +80,7 @@ async fn validation_package( // 0. Call into the DNA to get the validation package definition for this entry // e.g. what data is needed to validate it (chain, entry, headers, etc) let entry = chain_pair.entry(); - let validation_package_definition = get_validation_package_definition(entry, context.clone()) + let validation_package_definition = get_validation_package_definition(&entry, context.clone()) .and_then(|callback_result| match callback_result { CallbackResult::Fail(error_string) => Err(HolochainError::ErrorGeneric(error_string)), CallbackResult::ValidationPackageDefinition(def) => Ok(def), From bb77f039dafd1987f71ca9ab2fb4586b592d6bd6 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Fri, 13 Dec 2019 02:21:32 +1100 Subject: [PATCH 66/79] fix more tests --- crates/core/src/dht/dht_store.rs | 33 ++++++++------ .../core/src/entry/validation_dependencies.rs | 43 ++++++++++--------- .../src/nucleus/validation/build_from_dht.rs | 2 +- 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index 3b3560ac87..ee993ae577 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -427,21 +427,30 @@ pub mod tests { dependencies: Vec
, ) -> Result { let header = test_chain_header_with_sig("sig1"); - let mut pending_struct = PendingValidationStruct::try_from_entry_and_header( + match PendingValidationStruct::try_from_entry_and_header( entry, header, EntryAspect::Content(entry, header), ValidatingWorkflow::HoldEntry, - ); - pending_struct.dependencies = dependencies; - PendingValidationWithTimeout::new(Arc::new(pending_struct.clone()), None) + ) { + Ok(pending_struct) => { + pending_struct.dependencies = dependencies; + Ok(PendingValidationWithTimeout::new(Arc::new(pending_struct.clone()), None)) + }, + Err(err) => { + let err_msg = format!( + "Tried pending validation for entry from entry and header, got error: {}", err + ); + Err(HolochainError::ErrorGeneric(err_msg)) + } + } } #[test] fn test_dependency_resolution_no_dependencies() { // A and B have no dependencies. Both should be free - let Ok(a) = try_pending_validation_for_entry(test_entry_a(), Vec::new())?; - let Ok(b) = try_pending_validation_for_entry(test_entry_b(), Vec::new())?; + let a = try_pending_validation_for_entry(test_entry_a(), Vec::new())?; + let b = try_pending_validation_for_entry(test_entry_b(), Vec::new())?; assert_eq!( get_free_dependencies(&vec![a.clone(), b.clone()]), vec![a, b] @@ -451,9 +460,9 @@ pub mod tests { #[test] fn test_dependency_resolution_chain() { // A depends on B and B depends on C. C should be free - let Ok(a) = try_pending_validation_for_entry(test_entry_a(), vec![test_entry_b().address()]); - let Ok(b) = try_pending_validation_for_entry(test_entry_b(), vec![test_entry_c().address()])?; - let Ok(c) = try_pending_validation_for_entry(test_entry_c(), vec![])?; + let a = try_pending_validation_for_entry(test_entry_a(), vec![test_entry_b().address()]); + let b = try_pending_validation_for_entry(test_entry_b(), vec![test_entry_c().address()])?; + let c = try_pending_validation_for_entry(test_entry_c(), vec![])?; assert_eq!( get_free_dependencies(&vec![a.clone(), b.clone(), c.clone()]), @@ -464,12 +473,12 @@ pub mod tests { #[test] fn test_dependency_resolution_tree() { // A depends on B and C. B and C should be free - let Ok(a) = try_pending_validation_for_entry( + let a = try_pending_validation_for_entry( test_entry_a(), vec![test_entry_b().address(), test_entry_c().address()], )?; - let Ok(b) = try_pending_validation_for_entry(test_entry_b(), vec![])?; - let Ok(c) = try_pending_validation_for_entry(test_entry_c(), vec![])?; + let b = try_pending_validation_for_entry(test_entry_b(), vec![])?; + let c = try_pending_validation_for_entry(test_entry_c(), vec![])?; assert_eq!( get_free_dependencies(&vec![a.clone(), b.clone(), c.clone()]), diff --git a/crates/core/src/entry/validation_dependencies.rs b/crates/core/src/entry/validation_dependencies.rs index 9b97797652..a342efe166 100644 --- a/crates/core/src/entry/validation_dependencies.rs +++ b/crates/core/src/entry/validation_dependencies.rs @@ -47,7 +47,7 @@ impl ValidationDependencies for ChainPair { #[cfg(test)] pub mod tests { use super::*; - use crate::chain_pair::ChainPair; + use crate::network::chain_pair::ChainPair; use holochain_core_types::{ agent::AgentId, chain_header::ChainHeader, error::HolochainError,link::link_data::LinkData, time::Iso8601, }; @@ -67,18 +67,19 @@ pub mod tests { fn try_chain_pair_from_entry(entry: Entry) -> Result { let header = test_header_for_entry(&entry); - ChainPair::try_from_header_and_entry(entry, header) + ChainPair::try_from_header_and_entry(header, entry) } #[test] - fn test_get_validation_dependencies_app_entry() { + fn test_get_validation_dependencies_app_entry() -> Result<(), HolochainError> { let entry = Entry::App("entry_type".into(), "content".into()); - let Ok(chain_pair) = try_chain_pair_from_entry(entry)?; - assert_eq!(chain_pair.get_validation_dependencies(), Vec::new(),) + try_chain_pair_from_entry(entry).map(|chain_pair| { + assert_eq!(chain_pair.get_validation_dependencies(), Vec::new()) + }) } #[test] - fn test_get_validation_dependencies_link_add_entry() { + fn test_get_validation_dependencies_link_add_entry() -> Result<(), HolochainError> { let entry = Entry::LinkAdd(LinkData::new_add( &Address::from("QmBaseAddress"), &Address::from("QmTargetAddress"), @@ -87,18 +88,19 @@ pub mod tests { test_header_for_entry(&Entry::App("".into(), "".into())), AgentId::new("HcAgentId", "key".into()), )); - let Ok(chain_pair) = try_chain_pair_from_entry(entry)?; - assert_eq!( - chain_pair.get_validation_dependencies(), - vec![ - Address::from("QmBaseAddress"), - Address::from("QmTargetAddress") - ], - ) + try_chain_pair_from_entry(entry).map(|chain_pair| { + assert_eq!( + chain_pair.get_validation_dependencies(), + vec![ + Address::from("QmBaseAddress"), + Address::from("QmTargetAddress") + ], + ) + }) } #[test] - fn test_get_validation_dependencies_header_entry() { + fn test_get_validation_dependencies_header_entry() -> Result<(), HolochainError> { let header_entry_content = ChainHeader::new( &"some type".into(), &Address::from("QmAddressOfEntry"), @@ -109,10 +111,11 @@ pub mod tests { &Iso8601::from(0), ); let entry = Entry::ChainHeader(header_entry_content); - let Ok(chain_pair) = try_chain_pair_from_entry(entry)?; - assert_eq!( - chain_pair.get_validation_dependencies(), - vec![Address::from("QmPreviousHeaderAddress")], - ) + try_chain_pair_from_entry(entry).map(|chain_pair| { + assert_eq!( + chain_pair.get_validation_dependencies(), + vec![Address::from("QmPreviousHeaderAddress")], + ) + }); } } diff --git a/crates/core/src/nucleus/validation/build_from_dht.rs b/crates/core/src/nucleus/validation/build_from_dht.rs index 99d2d5a634..2ecfe89ddc 100644 --- a/crates/core/src/nucleus/validation/build_from_dht.rs +++ b/crates/core/src/nucleus/validation/build_from_dht.rs @@ -204,7 +204,7 @@ pub mod tests { .next() .expect("Must be able to get header for just published entry"); - let chain_pair = ChainPair::try_from_header_and_entry(header, entry); + let chain_pair = ChainPair::try_from_header_and_entry(header, entry)?; // jack (the author) retrieves a local validation package let local_validation_package = context2 From ce506e91cb9336607e8ec53803428243539291e0 Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Fri, 13 Dec 2019 16:29:56 +1100 Subject: [PATCH 67/79] fix err --- crates/core/src/workflows/mod.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index d794970a67..90e22e90bc 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -183,7 +183,7 @@ pub mod tests { use std::{thread, time}; #[test] - fn test_simulate_packge_direct_from_author() { + fn test_simulate_packge_direct_from_author() -> Result<(), HolochainError> { let mut dna = test_dna(); dna.uuid = "test_simulate_packge_direct_from_author".to_string(); let netname = Some("test_simulate_packge_direct_from_author, the network"); @@ -211,20 +211,20 @@ pub mod tests { .next() .expect("Must be able to get header for just published entry"); - let chain_pair = ChainPair::try_from_header_and_entry(header, entry); - - let validation_package = context1 - .block_on(validation_package(&chain_pair, context1.clone())) - .expect("Could not recover a validation package as the non-author"); - - assert_eq!( - validation_package - .unwrap() - .source_chain_headers - .unwrap() - .len(), - 2 - ); + ChainPair::try_from_header_and_entry(header, entry).map(|chain_pair| { + let validation_package = context1 + .block_on(validation_package(&chain_pair, context1.clone())) + .expect("Could not recover a validation package as the non-author"); + + assert_eq!( + validation_package + .unwrap() + .source_chain_headers + .unwrap() + .len(), + 2 + ); + }) } } From f1247656164783d41c5b14cfa58fee7e60d7de1b Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Sat, 14 Dec 2019 23:26:41 +1100 Subject: [PATCH 68/79] Fix errors, linking fails locally for compiling holochain_conductor_lib --- crates/core/src/dht/dht_store.rs | 36 +++++++++++-------- crates/core/src/dht/pending_validations.rs | 3 +- .../core/src/entry/validation_dependencies.rs | 10 +++--- crates/core/src/network/reducers/publish.rs | 4 +-- .../src/nucleus/validation/build_from_dht.rs | 5 +-- crates/core/src/nucleus/validation/mod.rs | 2 +- crates/core/src/scheduled_jobs/state_dump.rs | 2 +- crates/core/src/workflows/mod.rs | 20 +++++------ 8 files changed, 43 insertions(+), 39 deletions(-) diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index ee993ae577..8d7779f504 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -393,9 +393,7 @@ impl AddContent for DhtStore { #[cfg(test)] pub mod tests { use super::*; - use crate::{ - dht::pending_validations::{PendingValidationStruct, ValidatingWorkflow}, - }; + use crate::dht::pending_validations::{PendingValidationStruct, ValidatingWorkflow}; use holochain_core_types::{ chain_header::test_chain_header_with_sig, entry::{test_entry, test_entry_a, test_entry_b, test_entry_c}, @@ -428,18 +426,22 @@ pub mod tests { ) -> Result { let header = test_chain_header_with_sig("sig1"); match PendingValidationStruct::try_from_entry_and_header( - entry, - header, + entry.clone(), + header.clone(), EntryAspect::Content(entry, header), ValidatingWorkflow::HoldEntry, ) { - Ok(pending_struct) => { + Ok(mut pending_struct) => { pending_struct.dependencies = dependencies; - Ok(PendingValidationWithTimeout::new(Arc::new(pending_struct.clone()), None)) - }, + Ok(PendingValidationWithTimeout::new( + Arc::new(pending_struct.clone()), + None, + )) + } Err(err) => { let err_msg = format!( - "Tried pending validation for entry from entry and header, got error: {}", err + "Tried pending validation for entry from entry and header, got error: {}", + err ); Err(HolochainError::ErrorGeneric(err_msg)) } @@ -447,31 +449,33 @@ pub mod tests { } #[test] - fn test_dependency_resolution_no_dependencies() { + fn test_dependency_resolution_no_dependencies() -> Result<(), HolochainError> { // A and B have no dependencies. Both should be free let a = try_pending_validation_for_entry(test_entry_a(), Vec::new())?; let b = try_pending_validation_for_entry(test_entry_b(), Vec::new())?; assert_eq!( get_free_dependencies(&vec![a.clone(), b.clone()]), - vec![a, b] + vec![a, b], ); + Ok(()) } #[test] - fn test_dependency_resolution_chain() { + fn test_dependency_resolution_chain() -> Result<(), HolochainError> { // A depends on B and B depends on C. C should be free - let a = try_pending_validation_for_entry(test_entry_a(), vec![test_entry_b().address()]); + let a = try_pending_validation_for_entry(test_entry_a(), vec![test_entry_b().address()])?; let b = try_pending_validation_for_entry(test_entry_b(), vec![test_entry_c().address()])?; let c = try_pending_validation_for_entry(test_entry_c(), vec![])?; assert_eq!( get_free_dependencies(&vec![a.clone(), b.clone(), c.clone()]), - vec![c] + vec![c], ); + Ok(()) } #[test] - fn test_dependency_resolution_tree() { + fn test_dependency_resolution_tree() -> Result<(), HolochainError> { // A depends on B and C. B and C should be free let a = try_pending_validation_for_entry( test_entry_a(), @@ -484,5 +488,7 @@ pub mod tests { get_free_dependencies(&vec![a.clone(), b.clone(), c.clone()]), vec![b, c] ); + + Ok(()) } } diff --git a/crates/core/src/dht/pending_validations.rs b/crates/core/src/dht/pending_validations.rs index 482c6db95b..3cce660eb8 100644 --- a/crates/core/src/dht/pending_validations.rs +++ b/crates/core/src/dht/pending_validations.rs @@ -1,6 +1,5 @@ use crate::{ - entry::validation_dependencies::ValidationDependencies, - network::chain_pair::ChainPair, + entry::validation_dependencies::ValidationDependencies, network::chain_pair::ChainPair, }; use holochain_core_types::{ chain_header::ChainHeader, diff --git a/crates/core/src/entry/validation_dependencies.rs b/crates/core/src/entry/validation_dependencies.rs index a342efe166..8f4f1248e1 100644 --- a/crates/core/src/entry/validation_dependencies.rs +++ b/crates/core/src/entry/validation_dependencies.rs @@ -49,7 +49,8 @@ pub mod tests { use super::*; use crate::network::chain_pair::ChainPair; use holochain_core_types::{ - agent::AgentId, chain_header::ChainHeader, error::HolochainError,link::link_data::LinkData, time::Iso8601, + agent::AgentId, chain_header::ChainHeader, error::HolochainError, + link::link_data::LinkData, time::Iso8601, }; use holochain_persistence_api::cas::content::AddressableContent; @@ -73,9 +74,8 @@ pub mod tests { #[test] fn test_get_validation_dependencies_app_entry() -> Result<(), HolochainError> { let entry = Entry::App("entry_type".into(), "content".into()); - try_chain_pair_from_entry(entry).map(|chain_pair| { - assert_eq!(chain_pair.get_validation_dependencies(), Vec::new()) - }) + try_chain_pair_from_entry(entry) + .map(|chain_pair| assert_eq!(chain_pair.get_validation_dependencies(), Vec::new())) } #[test] @@ -116,6 +116,6 @@ pub mod tests { chain_pair.get_validation_dependencies(), vec![Address::from("QmPreviousHeaderAddress")], ) - }); + }) } } diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index a64b62b819..17a050f877 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -65,9 +65,7 @@ fn publish_update_delete_meta( // publish crud-status let aspect = match crud_status { - CrudStatus::Modified => { - EntryAspect::Update(chain_pair.entry(), chain_pair.header()) - } + CrudStatus::Modified => EntryAspect::Update(chain_pair.entry(), chain_pair.header()), CrudStatus::Deleted => EntryAspect::Deletion(chain_pair.header()), crud => { return Err(HolochainError::ErrorGeneric(format!( diff --git a/crates/core/src/nucleus/validation/build_from_dht.rs b/crates/core/src/nucleus/validation/build_from_dht.rs index 2ecfe89ddc..2b20af4950 100644 --- a/crates/core/src/nucleus/validation/build_from_dht.rs +++ b/crates/core/src/nucleus/validation/build_from_dht.rs @@ -175,7 +175,7 @@ pub mod tests { } #[test] - fn test_validation_package_same_from_author_and_other_agent() { + fn test_validation_package_same_from_author_and_other_agent() -> Result<(), HolochainError> { let mut dna = test_dna(); dna.uuid = "test_validation_package_same_from_author_and_other_agent".to_string(); let netname = Some("test_validation_package_same_from_author_and_other_agent, the network"); @@ -242,6 +242,7 @@ pub mod tests { 2 ); - assert_eq!(local_validation_package, dht_validation_package,) + assert_eq!(local_validation_package, dht_validation_package,); + Ok(()) } } diff --git a/crates/core/src/nucleus/validation/mod.rs b/crates/core/src/nucleus/validation/mod.rs index c76afd4fad..d33c5ce993 100644 --- a/crates/core/src/nucleus/validation/mod.rs +++ b/crates/core/src/nucleus/validation/mod.rs @@ -172,7 +172,7 @@ pub fn entry_to_validation_data( "Could not find Entry".to_string(), )) }) - }, + } Entry::CapTokenGrant(_) => Ok(EntryValidationData::Create { entry: entry.clone(), validation_data, diff --git a/crates/core/src/scheduled_jobs/state_dump.rs b/crates/core/src/scheduled_jobs/state_dump.rs index cfba7733fb..6ea6cbfc25 100644 --- a/crates/core/src/scheduled_jobs/state_dump.rs +++ b/crates/core/src/scheduled_jobs/state_dump.rs @@ -59,7 +59,7 @@ pub fn state_dump(context: Arc) { .dependencies .iter() .map(|addr| addr.to_string()) - .collect::>(), + .collect::>(), ) }) .collect::>(); diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 90e22e90bc..070f036a7e 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -82,15 +82,15 @@ async fn validation_package( let entry = chain_pair.entry(); let validation_package_definition = get_validation_package_definition(&entry, context.clone()) .and_then(|callback_result| match callback_result { - CallbackResult::Fail(error_string) => Err(HolochainError::ErrorGeneric(error_string)), - CallbackResult::ValidationPackageDefinition(def) => Ok(def), - CallbackResult::NotImplemented(reason) => Err(HolochainError::ErrorGeneric(format!( - "ValidationPackage callback not implemented for {:?} ({})", - entry.entry_type(), - reason - ))), - _ => unreachable!(), - })?; + CallbackResult::Fail(error_string) => Err(HolochainError::ErrorGeneric(error_string)), + CallbackResult::ValidationPackageDefinition(def) => Ok(def), + CallbackResult::NotImplemented(reason) => Err(HolochainError::ErrorGeneric(format!( + "ValidationPackage callback not implemented for {:?} ({})", + entry.entry_type(), + reason + ))), + _ => unreachable!(), + })?; // 1. Try to construct it locally. // This will work if the entry doesn't need a chain to validate or if this agent is the author: @@ -178,7 +178,7 @@ pub mod tests { network::chain_pair::ChainPair, nucleus::actions::tests::*, workflows::author_entry::author_entry, }; - use holochain_core_types::entry::Entry; + use holochain_core_types::{entry::Entry, error::HolochainError}; use holochain_json_api::json::JsonString; use std::{thread, time}; From 7257fafb90657a0d8cb745c390208905de7d372b Mon Sep 17 00:00:00 2001 From: jamesray1 <16969914+jamesray1@users.noreply.github.com> Date: Fri, 20 Dec 2019 15:22:06 +1100 Subject: [PATCH 69/79] gitignore .vscode/ --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 46dff00229..d93149ed08 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,5 @@ Cargo.lock !/Cargo.lock stress-test/passthrough-dna.dna.json + +.vscode/ From 724ca2e63244a54a8d001eecfc47fb6b6601b953 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Sat, 21 Dec 2019 18:16:45 +1100 Subject: [PATCH 70/79] fmt, nt passes --- crates/cli/src/main.rs | 2 +- crates/conductor_lib/src/conductor/admin.rs | 2 +- crates/core/src/dht/dht_store.rs | 34 ++++++++++--------- .../src/nucleus/validation/agent_entry.rs | 2 +- crates/core_types/src/chain_header.rs | 16 +++------ crates/in_stream/src/ws.rs | 6 ++-- crates/metrics/src/stats.rs | 3 +- .../src/dht/bbdht/dynamodb/api/agent/inbox.rs | 14 ++++---- .../src/dht/bbdht/dynamodb/api/aspect/read.rs | 12 +++---- crates/sim1h/src/ghost_actor/mod.rs | 2 +- 10 files changed, 43 insertions(+), 50 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 527b8cc818..f5ada6beb9 100755 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -195,7 +195,7 @@ fn run() -> HolochainResult<()> { return Err(HolochainError::Default(format_err!( "Failed to parse properties argument as JSON: {:?}", e - ))) + ))); } } } diff --git a/crates/conductor_lib/src/conductor/admin.rs b/crates/conductor_lib/src/conductor/admin.rs index c5c10f5079..04d96856a1 100644 --- a/crates/conductor_lib/src/conductor/admin.rs +++ b/crates/conductor_lib/src/conductor/admin.rs @@ -222,7 +222,7 @@ impl ConductorAdmin for Conductor { return Err(HolochainError::ConfigError(format!( "Invalid storage option: {}", s - ))) + ))); } }; diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index ffaf3399bd..26da4eb149 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -387,15 +387,10 @@ pub mod tests { use crate::dht::pending_validations::{PendingValidationStruct, ValidatingWorkflow}; use holochain_core_types::{ chain_header::{ - test_chain_header_with_sig, - test_chain_header_from_entry_with_sig_default_provs_time + test_chain_header_from_entry_with_sig_default_provs_time, test_chain_header_with_sig, }, entry::{ - entry_type::test_entry_type, - test_entry, - test_entry_a, - test_entry_b, - test_entry_c + entry_type::test_entry_type, test_entry, test_entry_a, test_entry_b, test_entry_c, }, }; @@ -450,15 +445,13 @@ pub mod tests { // Convenience function fn test_chain_header_for_entry_app(entry: Entry) -> ChainHeader { - test_chain_header_from_entry_with_sig_default_provs_time( - entry, - test_entry_type(), - "sig1" - ) + test_chain_header_from_entry_with_sig_default_provs_time(entry, test_entry_type(), "sig1") } // Convenience function, creates a header from the entry, no dependencies for app entry - fn try_pending_validation_for_app_entry_no_deps(entry: Entry) -> Result { + fn try_pending_validation_for_app_entry_no_deps( + entry: Entry, + ) -> Result { try_pending_validation_for_entry_header_and_deps( entry.clone(), test_chain_header_for_entry_app(entry), @@ -467,7 +460,10 @@ pub mod tests { } // Convenience function, creates a header from the entry, with dependencies for app entry - fn try_pending_validation_for_app_entry_with_deps(entry: Entry, deps: Vec
) -> Result { + fn try_pending_validation_for_app_entry_with_deps( + entry: Entry, + deps: Vec
, + ) -> Result { try_pending_validation_for_entry_header_and_deps( entry.clone(), test_chain_header_for_entry_app(entry), @@ -495,8 +491,14 @@ pub mod tests { #[test] fn test_dependency_resolution_chain() -> Result<(), HolochainError> { // A depends on B and B depends on C. C should be free - let a = try_pending_validation_for_app_entry_with_deps(test_entry_a(), vec![test_entry_b().address()])?; - let b = try_pending_validation_for_app_entry_with_deps(test_entry_b(), vec![test_entry_c().address()])?; + let a = try_pending_validation_for_app_entry_with_deps( + test_entry_a(), + vec![test_entry_b().address()], + )?; + let b = try_pending_validation_for_app_entry_with_deps( + test_entry_b(), + vec![test_entry_c().address()], + )?; let c = try_pending_validation_for_app_entry_no_deps(test_entry_c())?; let pending_list = vec![a.clone(), b.clone(), c.clone()]; diff --git a/crates/core/src/nucleus/validation/agent_entry.rs b/crates/core/src/nucleus/validation/agent_entry.rs index b9b20439a8..88575dca32 100644 --- a/crates/core/src/nucleus/validation/agent_entry.rs +++ b/crates/core/src/nucleus/validation/agent_entry.rs @@ -14,7 +14,7 @@ use holochain_core_types::{ use holochain_persistence_api::cas::content::AddressableContent; use holochain_wasm_utils::api_serialization::validation::AgentIdValidationArgs; -use futures::{future, future::FutureExt}; +use futures::future::{self, FutureExt}; use std::sync::Arc; pub async fn validate_agent_entry( diff --git a/crates/core_types/src/chain_header.rs b/crates/core_types/src/chain_header.rs index f0f377ca7c..9cadca799c 100644 --- a/crates/core_types/src/chain_header.rs +++ b/crates/core_types/src/chain_header.rs @@ -5,9 +5,8 @@ use crate::{ agent::test_agent_id, entry::{ - Entry, entry_type::{test_entry_type, test_link_entry_type, test_sys_entry_type, EntryType}, - test_entry, test_link_entry, test_sys_entry, + test_entry, test_link_entry, test_sys_entry, Entry, }, signature::{Provenance, Signature}, time::{test_iso_8601, Iso8601}, @@ -162,9 +161,7 @@ pub fn test_chain_header_from_entry_with_sig( } /// returns a dummy header for use in tests -pub fn test_chain_header_with_sig( - sig: &'static str -) -> ChainHeader { +pub fn test_chain_header_with_sig(sig: &'static str) -> ChainHeader { ChainHeader::new( &test_entry_type(), &test_entry().address(), @@ -180,14 +177,9 @@ pub fn test_chain_header_with_sig( pub fn test_chain_header_from_entry_with_sig_default_provs_time( entry: Entry, entry_type: EntryType, - sig: &'static str + sig: &'static str, ) -> ChainHeader { - test_chain_header_from_entry_with_sig( - entry, - entry_type, - test_provenances(sig), - test_iso_8601(), - ) + test_chain_header_from_entry_with_sig(entry, entry_type, test_provenances(sig), test_iso_8601()) } /// returns a sys header for use in tests. diff --git a/crates/in_stream/src/ws.rs b/crates/in_stream/src/ws.rs index 2d47492de5..297c3aa057 100644 --- a/crates/in_stream/src/ws.rs +++ b/crates/in_stream/src/ws.rs @@ -227,7 +227,7 @@ impl InStreamWss { // ignore would-block errors on write // tungstenite queues them in pending, they'll get sent Err(tungstenite::error::Error::Io(e)) if e.would_block() => { - return Ok(()) + return Ok(()); } Err(tungstenite::error::Error::Io(_)) => { if let Err(tungstenite::error::Error::Io(e)) = res { @@ -240,7 +240,7 @@ impl InStreamWss { return Err(Error::new( ErrorKind::Other, format!("tungstenite error: {:?}", e), - )) + )); } } } else { @@ -334,7 +334,7 @@ impl InStream<&mut WsFrame, WsFrame> for InStreamWss { return Err(Error::new( ErrorKind::Other, format!("tungstenite error: {:?}", e), - )) + )); } } } diff --git a/crates/metrics/src/stats.rs b/crates/metrics/src/stats.rs index b056daadf8..cb27225404 100644 --- a/crates/metrics/src/stats.rs +++ b/crates/metrics/src/stats.rs @@ -6,8 +6,7 @@ use stats::Commute; use std::{ collections::HashMap, error::Error, - fmt, - fmt::{Display, Formatter}, + fmt::{self, Display, Formatter}, io, iter::FromIterator, }; diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/inbox.rs b/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/inbox.rs index bee923593f..bde4105f3d 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/inbox.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/api/agent/inbox.rs @@ -215,7 +215,7 @@ pub fn item_to_direct_message_data(item: &Item) -> BbDhtResult<(DirectMessageDat return Err(BbDhtError::MissingData(format!( "message item missing content {:?}", &item - ))) + ))); } }; @@ -225,7 +225,7 @@ pub fn item_to_direct_message_data(item: &Item) -> BbDhtResult<(DirectMessageDat return Err(BbDhtError::MissingData(format!( "message item missing from {:?}", &item - ))) + ))); } }; @@ -235,7 +235,7 @@ pub fn item_to_direct_message_data(item: &Item) -> BbDhtResult<(DirectMessageDat return Err(BbDhtError::MissingData(format!( "message item missing to {:?}", &item - ))) + ))); } }; @@ -245,7 +245,7 @@ pub fn item_to_direct_message_data(item: &Item) -> BbDhtResult<(DirectMessageDat return Err(BbDhtError::MissingData(format!( "message item missing space_address {:?}", &item - ))) + ))); } }; @@ -255,7 +255,7 @@ pub fn item_to_direct_message_data(item: &Item) -> BbDhtResult<(DirectMessageDat return Err(BbDhtError::MissingData(format!( "message item missing request_id {:?}", &item - ))) + ))); } }; @@ -265,7 +265,7 @@ pub fn item_to_direct_message_data(item: &Item) -> BbDhtResult<(DirectMessageDat return Err(BbDhtError::MissingData(format!( "message item missing response flag {:?}", &item - ))) + ))); } }; @@ -317,7 +317,7 @@ pub fn request_ids_to_messages( return Err(BbDhtError::MissingData(format!( "missing message for request id: {:?}", &request_id - ))) + ))); } } } diff --git a/crates/sim1h/src/dht/bbdht/dynamodb/api/aspect/read.rs b/crates/sim1h/src/dht/bbdht/dynamodb/api/aspect/read.rs index df845baeae..b79033c2bf 100644 --- a/crates/sim1h/src/dht/bbdht/dynamodb/api/aspect/read.rs +++ b/crates/sim1h/src/dht/bbdht/dynamodb/api/aspect/read.rs @@ -40,7 +40,7 @@ fn try_aspect_from_item(item: Item) -> BbDhtResult { return Err(BbDhtError::MissingData(format!( "Missing aspect_hash: {:?}", item - ))) + ))); } }; @@ -50,7 +50,7 @@ fn try_aspect_from_item(item: Item) -> BbDhtResult { return Err(BbDhtError::MissingData(format!( "Missing aspect: {:?}", item - ))) + ))); } }; @@ -60,7 +60,7 @@ fn try_aspect_from_item(item: Item) -> BbDhtResult { return Err(BbDhtError::MissingData(format!( "Missing publish_ts: {:?}", item - ))) + ))); } }; @@ -70,7 +70,7 @@ fn try_aspect_from_item(item: Item) -> BbDhtResult { return Err(BbDhtError::MissingData(format!( "Missing type_hint: {:?}", item - ))) + ))); } }; @@ -89,7 +89,7 @@ pub fn try_aspect_list_from_item(item: Item) -> BbDhtResult> { return Err(BbDhtError::MissingData(format!( "Missing aspect_list: {:?}", item - ))) + ))); } }; @@ -132,7 +132,7 @@ pub fn get_entry_aspects( return Err(BbDhtError::MissingData(format!( "Missing entry aspect data: {:?}", &aspect_address - ))) + ))); } Err(err) => return Err(err), }, diff --git a/crates/sim1h/src/ghost_actor/mod.rs b/crates/sim1h/src/ghost_actor/mod.rs index 4993920c33..dda5b8906b 100644 --- a/crates/sim1h/src/ghost_actor/mod.rs +++ b/crates/sim1h/src/ghost_actor/mod.rs @@ -254,7 +254,7 @@ impl<'engine> /// process after the subconscious process items have run fn process_concrete(&mut self) -> GhostResult { // always run the endpoint process loop - detach_run!(&mut self.lib3h_endpoint, |cs| { cs.process(self) })?; + detach_run!(&mut self.lib3h_endpoint, |cs| cs.process(self))?; let mut work_was_done = false; // process any messages from the client to us From ea7b9c9bb3c1aabd838458b1f9b5c596de6998b5 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Sat, 21 Dec 2019 18:31:29 +1100 Subject: [PATCH 71/79] fixing clippy errors: redudant clones --- crates/core/src/dht/pending_validations.rs | 6 +++--- crates/core/src/network/chain_pair.rs | 2 +- crates/core_types/src/entry/mod.rs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/core/src/dht/pending_validations.rs b/crates/core/src/dht/pending_validations.rs index 3cce660eb8..17232e42b4 100644 --- a/crates/core/src/dht/pending_validations.rs +++ b/crates/core/src/dht/pending_validations.rs @@ -191,10 +191,10 @@ impl From for EntryAspect { } ValidatingWorkflow::RemoveLink => { let link_data = unwrap_to!(entry => Entry::LinkRemove); - EntryAspect::LinkRemove(link_data.clone(), header.clone()) + EntryAspect::LinkRemove(link_data.clone(), header) } - ValidatingWorkflow::UpdateEntry => EntryAspect::Update(entry.clone(), header), - ValidatingWorkflow::RemoveEntry => EntryAspect::Deletion(header.clone()), + ValidatingWorkflow::UpdateEntry => EntryAspect::Update(entry, header), + ValidatingWorkflow::RemoveEntry => EntryAspect::Deletion(header), } } } diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index 4775f9d749..23cd72b067 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -35,7 +35,7 @@ impl ChainPair { basic_error_msg, header, entry ); Err(HolochainError::HeaderEntryMismatch( - error_msg.to_string(), + error_msg, header_entry_address.clone(), entry_address, )) diff --git a/crates/core_types/src/entry/mod.rs b/crates/core_types/src/entry/mod.rs index 4c6d3df2f2..e105ef778f 100644 --- a/crates/core_types/src/entry/mod.rs +++ b/crates/core_types/src/entry/mod.rs @@ -221,8 +221,8 @@ pub fn test_link_entry() -> Entry { let link = Link::new( &test_entry.address(), &test_entry.address(), - &test_link.clone(), - &test_tag.clone(), + &test_link, + &test_tag, ); let link_data = LinkData::from_link( &link, @@ -231,7 +231,7 @@ pub fn test_link_entry() -> Entry { test_agent_id(), ); - let link_entry = Entry::LinkAdd(link_data.clone()); + let link_entry = Entry::LinkAdd(link_data); link_entry } From dbfd1b21c7557c3d5d7cf1ab9f573e745eef793b Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Sat, 21 Dec 2019 21:41:25 +1100 Subject: [PATCH 72/79] rename ChainPair to EntryHeaderPair; chain_pair to entry_header_pair --- crates/core/src/action.rs | 4 +- crates/core/src/agent/state.rs | 10 ++-- crates/core/src/dht/dht_reducers.rs | 8 +-- crates/core/src/dht/dht_store.rs | 12 ++-- crates/core/src/dht/pending_validations.rs | 20 +++---- .../core/src/entry/validation_dependencies.rs | 22 ++++---- crates/core/src/network/chain_pair.rs | 20 +++---- crates/core/src/network/handler/lists.rs | 10 ++-- crates/core/src/network/handler/mod.rs | 24 ++++---- crates/core/src/network/handler/store.rs | 30 +++++----- crates/core/src/network/mod.rs | 2 +- crates/core/src/network/reducers/publish.rs | 56 +++++++++---------- .../network/reducers/publish_header_entry.rs | 16 +++--- .../reducers/queue_zome_function_call.rs | 2 +- .../src/nucleus/validation/build_from_dht.rs | 12 ++-- crates/core/src/scheduled_jobs/state_dump.rs | 4 +- crates/core/src/workflows/hold_entry.rs | 22 ++++---- .../core/src/workflows/hold_entry_remove.rs | 12 ++-- .../core/src/workflows/hold_entry_update.rs | 14 ++--- crates/core/src/workflows/hold_link.rs | 22 ++++---- crates/core/src/workflows/mod.rs | 52 ++++++++--------- crates/core/src/workflows/remove_link.rs | 18 +++--- 22 files changed, 196 insertions(+), 196 deletions(-) diff --git a/crates/core/src/action.rs b/crates/core/src/action.rs index 99eff1e875..eae23c4c8c 100644 --- a/crates/core/src/action.rs +++ b/crates/core/src/action.rs @@ -2,7 +2,7 @@ use crate::{ agent::state::AgentState, dht::pending_validations::PendingValidation, network::{ - chain_pair::ChainPair, + entry_header_pair::EntryHeaderPair, direct_message::DirectMessage, entry_aspect::EntryAspect, query::{GetLinksNetworkQuery, NetworkQueryResult}, @@ -127,7 +127,7 @@ pub enum Action { HoldAspect(EntryAspect), //action for updating crudstatus - CrudStatus((ChainPair, CrudStatus)), + CrudStatus((EntryHeaderPair, CrudStatus)), // ---------------- // Network actions: diff --git a/crates/core/src/agent/state.rs b/crates/core/src/agent/state.rs index 422f9dc5ed..a58b289769 100644 --- a/crates/core/src/agent/state.rs +++ b/crates/core/src/agent/state.rs @@ -1,7 +1,7 @@ use crate::{ action::{Action, ActionWrapper, AgentReduceFn}, agent::chain_store::{ChainStore, ChainStoreIterator}, - network::chain_pair::ChainPair, + network::entry_header_pair::EntryHeaderPair, state::State, }; use holochain_persistence_api::cas::content::{Address, AddressableContent, Content}; @@ -221,13 +221,13 @@ pub fn create_new_chain_header( )) } -/// Creates a `ChainPair` for a `ChainHeader`. +/// Creates a `EntryHeaderPair` for a `ChainHeader`. /// Since published headers are treated as entries, the header must also /// have its own header! -pub fn create_chain_pair_for_header( +pub fn create_entry_header_pair_for_header( root_state: &StateWrapper, chain_header: ChainHeader, -) -> Result { +) -> Result { let timestamp = chain_header.timestamp().clone(); let entry = Entry::ChainHeader(chain_header); // This header entry needs its own header so we can publish it. @@ -251,7 +251,7 @@ pub fn create_chain_pair_for_header( &None, ×tamp, ); - ChainPair::try_from_header_and_entry(header, entry) + EntryHeaderPair::try_from_header_and_entry(header, entry) } /// Do a Commit Action against an agent state. diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index d9b4f76af8..2676b0a61b 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -203,7 +203,7 @@ pub fn reduce_prune(old_store: &DhtStore, _action_wrapper: &ActionWrapper) -> Op .unique_by(|p| { ( p.pending.workflow.clone(), - p.pending.chain_pair.header().entry_address().clone(), + p.pending.entry_header_pair.header().entry_address().clone(), ) }) .cloned() @@ -263,7 +263,7 @@ pub mod tests { pending_validations::{PendingValidation, PendingValidationStruct, ValidatingWorkflow}, }, instance::tests::test_context, - network::chain_pair::ChainPair, + network::entry_header_pair::EntryHeaderPair, state::test_store, }; use bitflags::_core::time::Duration; @@ -562,8 +562,8 @@ pub mod tests { header: ChainHeader, workflow: ValidatingWorkflow, ) -> PendingValidation { - match ChainPair::try_from_header_and_entry(header.clone(), entry.clone()) { - Ok(chain_pair) => Arc::new(PendingValidationStruct::new(chain_pair, workflow)), + match EntryHeaderPair::try_from_header_and_entry(header.clone(), entry.clone()) { + Ok(entry_header_pair) => Arc::new(PendingValidationStruct::new(entry_header_pair, workflow)), Err(err) => { let err_msg = format!( "Tried to create a pending validation, got an error: {}", diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index 26da4eb149..cda49f0bb6 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -4,7 +4,7 @@ use crate::{ aspect_map::{AspectMap, AspectMapBare}, pending_validations::{PendingValidationWithTimeout, ValidationTimeout}, }, - network::chain_pair::ChainPair, + network::entry_header_pair::EntryHeaderPair, }; use holochain_core_types::{ chain_header::ChainHeader, @@ -231,8 +231,8 @@ impl DhtStore { entry: &Entry, header: &ChainHeader, ) -> Result<(), HolochainError> { - match ChainPair::try_from_header_and_entry(header.clone(), entry.clone()) { - Ok(_chain_pair) => { + match EntryHeaderPair::try_from_header_and_entry(header.clone(), entry.clone()) { + Ok(_entry_header_pair) => { let eavi = EntityAttributeValueIndex::new( &entry.address(), &Attribute::EntryHeader, @@ -334,8 +334,8 @@ impl DhtStore { |PendingValidationWithTimeout { pending: current, .. }| { - current.chain_pair.header().entry_address() - == pending.chain_pair.header().entry_address() + current.entry_header_pair.header().entry_address() + == pending.entry_header_pair.header().entry_address() && current.workflow == pending.workflow }, ) @@ -356,7 +356,7 @@ where let unique_pending: HashSet
= pending .clone() .into_iter() - .map(|p| p.pending.chain_pair.entry().address()) + .map(|p| p.pending.entry_header_pair.entry().address()) .collect(); Box::new(move |p| { diff --git a/crates/core/src/dht/pending_validations.rs b/crates/core/src/dht/pending_validations.rs index 17232e42b4..fac9734b26 100644 --- a/crates/core/src/dht/pending_validations.rs +++ b/crates/core/src/dht/pending_validations.rs @@ -1,5 +1,5 @@ use crate::{ - entry::validation_dependencies::ValidationDependencies, network::chain_pair::ChainPair, + entry::validation_dependencies::ValidationDependencies, network::entry_header_pair::EntryHeaderPair, }; use holochain_core_types::{ chain_header::ChainHeader, @@ -70,17 +70,17 @@ impl fmt::Display for ValidatingWorkflow { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, DefaultJson)] pub struct PendingValidationStruct { - pub chain_pair: ChainPair, + pub entry_header_pair: EntryHeaderPair, pub dependencies: Vec
, pub workflow: ValidatingWorkflow, uuid: ProcessUniqueId, } impl PendingValidationStruct { - pub fn new(chain_pair: ChainPair, workflow: ValidatingWorkflow) -> Self { - let dependencies = chain_pair.get_validation_dependencies(); + pub fn new(entry_header_pair: EntryHeaderPair, workflow: ValidatingWorkflow) -> Self { + let dependencies = entry_header_pair.get_validation_dependencies(); Self { - chain_pair, + entry_header_pair, dependencies, workflow, uuid: ProcessUniqueId::new(), @@ -100,9 +100,9 @@ impl PendingValidationStruct { entry_aspect: EntryAspect, validating_workflow: ValidatingWorkflow, ) -> Result { - match ChainPair::try_from_header_and_entry(header, entry) { - Ok(chain_pair) => Ok(PendingValidationStruct::new( - chain_pair, + match EntryHeaderPair::try_from_header_and_entry(header, entry) { + Ok(entry_header_pair) => Ok(PendingValidationStruct::new( + entry_header_pair, validating_workflow, )), Err(error) => { @@ -181,8 +181,8 @@ impl TryFrom for PendingValidationStruct { impl From for EntryAspect { fn from(pending: PendingValidationStruct) -> EntryAspect { - let entry = pending.chain_pair.entry(); - let header = pending.chain_pair.header(); + let entry = pending.entry_header_pair.entry(); + let header = pending.entry_header_pair.header(); match pending.workflow { ValidatingWorkflow::HoldEntry => EntryAspect::Content(entry, header), ValidatingWorkflow::HoldLink => { diff --git a/crates/core/src/entry/validation_dependencies.rs b/crates/core/src/entry/validation_dependencies.rs index 8f4f1248e1..f23cac85c9 100644 --- a/crates/core/src/entry/validation_dependencies.rs +++ b/crates/core/src/entry/validation_dependencies.rs @@ -1,4 +1,4 @@ -use crate::network::chain_pair::ChainPair; +use crate::network::entry_header_pair::EntryHeaderPair; use holochain_core_types::entry::Entry; use holochain_persistence_api::cas::content::Address; @@ -6,7 +6,7 @@ pub trait ValidationDependencies { fn get_validation_dependencies(&self) -> Vec
; } -impl ValidationDependencies for ChainPair { +impl ValidationDependencies for EntryHeaderPair { fn get_validation_dependencies(&self) -> Vec
{ match &self.entry() { Entry::App(_, _) => { @@ -47,7 +47,7 @@ impl ValidationDependencies for ChainPair { #[cfg(test)] pub mod tests { use super::*; - use crate::network::chain_pair::ChainPair; + use crate::network::entry_header_pair::EntryHeaderPair; use holochain_core_types::{ agent::AgentId, chain_header::ChainHeader, error::HolochainError, link::link_data::LinkData, time::Iso8601, @@ -66,16 +66,16 @@ pub mod tests { ) } - fn try_chain_pair_from_entry(entry: Entry) -> Result { + fn try_entry_header_pair_from_entry(entry: Entry) -> Result { let header = test_header_for_entry(&entry); - ChainPair::try_from_header_and_entry(header, entry) + EntryHeaderPair::try_from_header_and_entry(header, entry) } #[test] fn test_get_validation_dependencies_app_entry() -> Result<(), HolochainError> { let entry = Entry::App("entry_type".into(), "content".into()); - try_chain_pair_from_entry(entry) - .map(|chain_pair| assert_eq!(chain_pair.get_validation_dependencies(), Vec::new())) + try_entry_header_pair_from_entry(entry) + .map(|entry_header_pair| assert_eq!(entry_header_pair.get_validation_dependencies(), Vec::new())) } #[test] @@ -88,9 +88,9 @@ pub mod tests { test_header_for_entry(&Entry::App("".into(), "".into())), AgentId::new("HcAgentId", "key".into()), )); - try_chain_pair_from_entry(entry).map(|chain_pair| { + try_entry_header_pair_from_entry(entry).map(|entry_header_pair| { assert_eq!( - chain_pair.get_validation_dependencies(), + entry_header_pair.get_validation_dependencies(), vec![ Address::from("QmBaseAddress"), Address::from("QmTargetAddress") @@ -111,9 +111,9 @@ pub mod tests { &Iso8601::from(0), ); let entry = Entry::ChainHeader(header_entry_content); - try_chain_pair_from_entry(entry).map(|chain_pair| { + try_entry_header_pair_from_entry(entry).map(|entry_header_pair| { assert_eq!( - chain_pair.get_validation_dependencies(), + entry_header_pair.get_validation_dependencies(), vec![Address::from("QmPreviousHeaderAddress")], ) }) diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs index 23cd72b067..5579678b0a 100644 --- a/crates/core/src/network/chain_pair.rs +++ b/crates/core/src/network/chain_pair.rs @@ -6,24 +6,24 @@ use crate::{ use holochain_core_types::{chain_header::ChainHeader, entry::Entry, error::HolochainError}; use holochain_persistence_api::cas::content::{Address, AddressableContent}; -/// A `ChainPair` cannot be constructed unless the entry address in the -/// `ChainHeader` that is within the `ChainPair` is the same as the address -/// of the `Entry` that is also within the `ChainPair`. +/// A `EntryHeaderPair` cannot be constructed unless the entry address in the +/// `ChainHeader` that is within the `EntryHeaderPair` is the same as the address +/// of the `Entry` that is also within the `EntryHeaderPair`. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct ChainPair(ChainHeader, Entry); +pub struct EntryHeaderPair(ChainHeader, Entry); -impl ChainPair { +impl EntryHeaderPair { // It seems best to not have a new method, since stylistically it is expected to return Self, whereas constructing could fail. pub fn try_from_header_and_entry( header: ChainHeader, entry: Entry, - ) -> Result { + ) -> Result { let header_entry_address = header.entry_address(); let entry_address = entry.address(); if header_entry_address.clone() == entry_address { - Ok(ChainPair(header, entry)) + Ok(EntryHeaderPair(header, entry)) } else { - let basic_error_msg = "Tried to create a ChainPair, but got a + let basic_error_msg = "Tried to create a EntryHeaderPair, but got a mismatch with the header's entry address and the entry's address."; let error_msg = format!( @@ -50,7 +50,7 @@ impl ChainPair { self.1.clone() } - pub fn fetch_chain_pair(address: &Address, state: &State) -> Result { + pub fn fetch_entry_header_pair(address: &Address, state: &State) -> Result { let entry = state .agent() .chain_store() @@ -65,6 +65,6 @@ impl ChainPair { ); HolochainError::from(error_msg) })?; - ChainPair::try_from_header_and_entry(header, entry) + EntryHeaderPair::try_from_header_and_entry(header, entry) } } diff --git a/crates/core/src/network/handler/lists.rs b/crates/core/src/network/handler/lists.rs index ce9af9a4be..ce520d5228 100644 --- a/crates/core/src/network/handler/lists.rs +++ b/crates/core/src/network/handler/lists.rs @@ -1,6 +1,6 @@ use crate::{ action::{Action, ActionWrapper}, - agent::state::create_chain_pair_for_header, + agent::state::create_entry_header_pair_for_header, context::Context, dht::aspect_map::{AspectMap, AspectMapBare}, entry::CanPublish, @@ -77,7 +77,7 @@ fn create_authoring_map(context: Arc) -> AspectMap { // So we iterate over all our source chain headers for chain_header in context.state().unwrap().agent().iter_chain() { // Create an entry that represents the header - match create_chain_pair_for_header(&state, chain_header.clone()) { + match create_entry_header_pair_for_header(&state, chain_header.clone()) { Err(e) => { log_error!( context, @@ -86,9 +86,9 @@ fn create_authoring_map(context: Arc) -> AspectMap { ); continue; } - Ok(chain_pair) => { - let entry_hash = chain_pair.entry().address(); - let content_aspect = EntryAspect::Content(chain_pair.entry(), chain_pair.header()); + Ok(entry_header_pair) => { + let entry_hash = entry_header_pair.entry().address(); + let content_aspect = EntryAspect::Content(entry_header_pair.entry(), entry_header_pair.header()); let aspect_hash = AspectHash::from(content_aspect.address()); address_map .entry(entry_hash.into()) diff --git a/crates/core/src/network/handler/mod.rs b/crates/core/src/network/handler/mod.rs index ef657bd55f..259146ae50 100644 --- a/crates/core/src/network/handler/mod.rs +++ b/crates/core/src/network/handler/mod.rs @@ -1,4 +1,4 @@ -use crate::{agent::state::create_chain_pair_for_header, content_store::GetContent}; +use crate::{agent::state::create_entry_header_pair_for_header, content_store::GetContent}; use holochain_logging::prelude::*; pub mod fetch; pub mod lists; @@ -10,7 +10,7 @@ use crate::{ context::Context, entry::CanPublish, network::{ - chain_pair::ChainPair, + entry_header_pair::EntryHeaderPair, direct_message::DirectMessage, entry_aspect::EntryAspect, handler::{ @@ -303,8 +303,8 @@ fn get_content_aspect( }); // If we have found a header for the requested entry in the chain... - let maybe_chain_pair = match maybe_chain_header { - Some((header, true)) => Some(create_chain_pair_for_header(&state, header)?), + let maybe_entry_header_pair = match maybe_chain_header { + Some((header, true)) => Some(create_entry_header_pair_for_header(&state, header)?), Some((header, false)) => { // ... we can just get the content from the chain CAS let entry = state @@ -312,8 +312,8 @@ fn get_content_aspect( .chain_store() .get(&header.entry_address())? .expect("Could not find entry in chain CAS, but header is chain"); - match ChainPair::try_from_header_and_entry(header, entry) { - Ok(chain_pair) => Some(chain_pair), + match EntryHeaderPair::try_from_header_and_entry(header, entry) { + Ok(entry_header_pair) => Some(entry_header_pair), Err(error) => return Err(error), } } @@ -334,8 +334,8 @@ fn get_content_aspect( // TODO: this is just taking the first header.. // We should actually transform all headers into EntryAspect::Headers and just the first one // into an EntryAspect content (What about ordering? Using the headers timestamp?) - match ChainPair::try_from_header_and_entry(headers[0].clone(), entry) { - Ok(chain_pair) => Some(chain_pair), + match EntryHeaderPair::try_from_header_and_entry(headers[0].clone(), entry) { + Ok(entry_header_pair) => Some(entry_header_pair), Err(error) => { log_error!(context, "{}", error); None @@ -354,17 +354,17 @@ fn get_content_aspect( } }; - let chain_pair = maybe_chain_pair.ok_or(HolochainError::EntryNotFoundLocally)?; + let entry_header_pair = maybe_entry_header_pair.ok_or(HolochainError::EntryNotFoundLocally)?; - let _ = chain_pair + let _ = entry_header_pair .entry() .entry_type() .can_publish(&context) .ok_or(HolochainError::EntryIsPrivate)?; Ok(EntryAspect::Content( - chain_pair.entry(), - chain_pair.header(), + entry_header_pair.entry(), + entry_header_pair.header(), )) } diff --git a/crates/core/src/network/handler/store.rs b/crates/core/src/network/handler/store.rs index 63d2bab9df..6435f63b91 100644 --- a/crates/core/src/network/handler/store.rs +++ b/crates/core/src/network/handler/store.rs @@ -68,13 +68,13 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { log_debug!(context, "net/handle: HandleStoreMeta: got LINK. processing..."); // TODO: do a loop on content once links properly implemented assert_eq!(dht_meta_data.content_list.len(), 1); - let chain_pair: ChainPair = serde_json::from_str( + let entry_header_pair: EntryHeaderPair = serde_json::from_str( &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be ChainPair"), + .expect("dht_meta_data should be EntryHeaderPair"), ) - .expect("dht_meta_data should be ChainPair"); + .expect("dht_meta_data should be EntryHeaderPair"); thread::spawn(move || { - match context.block_on(hold_link_workflow(&chain_pair, &context.clone())) { + match context.block_on(hold_link_workflow(&entry_header_pair, &context.clone())) { Err(error) => log_error!(context, "net/dht: {}", error), _ => (), } @@ -83,15 +83,15 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { log_debug!(context, "net/handle: HandleStoreMeta: got LINK REMOVAL. processing..."); // TODO: do a loop on content once links properly implemented assert_eq!(dht_meta_data.content_list.len(), 1); - let chain_pair: ChainPair = serde_json::from_str( + let entry_header_pair: EntryHeaderPair = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be ChainPair"), + .expect("dht_meta_data should be EntryHeaderPair"), ) .expect("dht_meta_data should be EntryWithHader"); thread::spawn(move || { if let Err(error) = - context.block_on(remove_link_workflow(&chain_pair, &context.clone())) + context.block_on(remove_link_workflow(&entry_header_pair, &context.clone())) { log_error!(context, "net/dht: {}", error) } @@ -102,15 +102,15 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { { log_debug!(context, "net/handle: HandleStoreMeta: got CRUD STATUS. processing..."); - let chain_pair: ChainPair = serde_json::from_str( + let entry_header_pair: EntryHeaderPair = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be ChainPair"), + .expect("dht_meta_data should be EntryHeaderPair"), ) - .expect("dht_meta_data should be ChainPair"); + .expect("dht_meta_data should be EntryHeaderPair"); thread::spawn(move || { if let Err(error) = - context.block_on(hold_remove_workflow(chain_pair, context.clone())) + context.block_on(hold_remove_workflow(entry_header_pair, context.clone())) { log_error!(context, "net/dht: {}", error) } @@ -120,15 +120,15 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { == CrudStatus::Modified { log_debug!(context, "net/handle: HandleStoreMeta: got CRUD LINK. processing..."); - let chain_pair: ChainPair = serde_json::from_str( + let entry_header_pair: EntryHeaderPair = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be ChainPair"), + .expect("dht_meta_data should be EntryHeaderPair"), ) - .expect("dht_meta_data should be ChainPair"); + .expect("dht_meta_data should be EntryHeaderPair"); thread::spawn(move || { if let Err(error) = - context.block_on(hold_update_workflow(chain_pair, context.clone())) + context.block_on(hold_update_workflow(entry_header_pair, context.clone())) { log_error!(context, "net/dht: {}", error) } diff --git a/crates/core/src/network/mod.rs b/crates/core/src/network/mod.rs index 94d259c798..0d0e144857 100644 --- a/crates/core/src/network/mod.rs +++ b/crates/core/src/network/mod.rs @@ -1,5 +1,5 @@ pub mod actions; -pub mod chain_pair; +pub mod entry_header_pair; pub mod direct_message; pub mod handler; pub mod reducers; diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index 17a050f877..b0422c2428 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -1,7 +1,7 @@ use crate::{ action::ActionWrapper, network::{ - actions::NetworkActionResponse, chain_pair::ChainPair, entry_aspect::EntryAspect, + actions::NetworkActionResponse, entry_header_pair::EntryHeaderPair, entry_aspect::EntryAspect, reducers::send, state::NetworkState, }, state::State, @@ -37,7 +37,7 @@ pub fn entry_data_to_entry_aspect_data(ea: &EntryAspect) -> EntryAspectData { /// Send to network a PublishDhtData message fn publish_entry( network_state: &mut NetworkState, - chain_pair: &ChainPair, + entry_header_pair: &EntryHeaderPair, ) -> Result<(), HolochainError> { send( network_state, @@ -45,10 +45,10 @@ fn publish_entry( space_address: network_state.dna_address.clone().unwrap().into(), provider_agent_id: network_state.agent_id.clone().unwrap().into(), entry: EntryData { - entry_address: chain_pair.entry().address().into(), + entry_address: entry_header_pair.entry().address().into(), aspect_list: vec![entry_data_to_entry_aspect_data(&EntryAspect::Content( - chain_pair.entry(), - chain_pair.header(), + entry_header_pair.entry(), + entry_header_pair.header(), ))], }, }), @@ -60,13 +60,13 @@ fn publish_update_delete_meta( network_state: &mut NetworkState, orig_entry_address: Address, crud_status: CrudStatus, - chain_pair: &ChainPair, + entry_header_pair: &EntryHeaderPair, ) -> Result<(), HolochainError> { // publish crud-status let aspect = match crud_status { - CrudStatus::Modified => EntryAspect::Update(chain_pair.entry(), chain_pair.header()), - CrudStatus::Deleted => EntryAspect::Deletion(chain_pair.header()), + CrudStatus::Modified => EntryAspect::Update(entry_header_pair.entry(), entry_header_pair.header()), + CrudStatus::Deleted => EntryAspect::Deletion(entry_header_pair.header()), crud => { return Err(HolochainError::ErrorGeneric(format!( "Unexpeced CRUD variant {:?}", @@ -91,24 +91,24 @@ fn publish_update_delete_meta( Ok(()) } -/// Send to network a PublishMeta message holding a link metadata to `chain_pair` +/// Send to network a PublishMeta message holding a link metadata to `entry_header_pair` fn publish_link_meta( network_state: &mut NetworkState, - chain_pair: &ChainPair, + entry_header_pair: &EntryHeaderPair, ) -> Result<(), HolochainError> { - let (base, aspect) = match chain_pair.entry() { + let (base, aspect) = match entry_header_pair.entry() { Entry::LinkAdd(link_data) => ( link_data.link().base().clone(), - EntryAspect::LinkAdd(link_data, chain_pair.header()), + EntryAspect::LinkAdd(link_data, entry_header_pair.header()), ), Entry::LinkRemove((link_data, links_to_remove)) => ( link_data.link().base().clone(), - EntryAspect::LinkRemove((link_data, links_to_remove), chain_pair.header()), + EntryAspect::LinkRemove((link_data, links_to_remove), entry_header_pair.header()), ), _ => { return Err(HolochainError::ErrorGeneric(format!( "Received bad entry type. Expected Entry::LinkAdd/Remove received {:?}", - chain_pair.entry(), + entry_header_pair.entry(), ))); } }; @@ -132,41 +132,41 @@ fn reduce_publish_inner( ) -> Result<(), HolochainError> { network_state.initialized()?; - let chain_pair = ChainPair::fetch_chain_pair(&address, root_state)?; + let entry_header_pair = EntryHeaderPair::fetch_entry_header_pair(&address, root_state)?; - match chain_pair.entry().entry_type() { - EntryType::AgentId => publish_entry(network_state, &chain_pair), + match entry_header_pair.entry().entry_type() { + EntryType::AgentId => publish_entry(network_state, &entry_header_pair), EntryType::App(_) => { - publish_entry(network_state, &chain_pair).and_then(|_| { - match chain_pair.header().link_update_delete() { + publish_entry(network_state, &entry_header_pair).and_then(|_| { + match entry_header_pair.header().link_update_delete() { Some(modified_entry) => publish_update_delete_meta( network_state, modified_entry, CrudStatus::Modified, - &chain_pair.clone(), + &entry_header_pair.clone(), ), None => Ok(()), } }) } - EntryType::LinkAdd => publish_entry(network_state, &chain_pair) - .and_then(|_| publish_link_meta(network_state, &chain_pair)), - EntryType::LinkRemove => publish_entry(network_state, &chain_pair) - .and_then(|_| publish_link_meta(network_state, &chain_pair)), - EntryType::Deletion => publish_entry(network_state, &chain_pair).and_then(|_| { - match chain_pair.header().link_update_delete() { + EntryType::LinkAdd => publish_entry(network_state, &entry_header_pair) + .and_then(|_| publish_link_meta(network_state, &entry_header_pair)), + EntryType::LinkRemove => publish_entry(network_state, &entry_header_pair) + .and_then(|_| publish_link_meta(network_state, &entry_header_pair)), + EntryType::Deletion => publish_entry(network_state, &entry_header_pair).and_then(|_| { + match entry_header_pair.header().link_update_delete() { Some(modified_entry) => publish_update_delete_meta( network_state, modified_entry, CrudStatus::Deleted, - &chain_pair.clone(), + &entry_header_pair.clone(), ), None => Ok(()), } }), _ => Err(HolochainError::NotImplemented(format!( "reduce_publish_inner not implemented for {}", - chain_pair.entry().entry_type() + entry_header_pair.entry().entry_type() ))), } } diff --git a/crates/core/src/network/reducers/publish_header_entry.rs b/crates/core/src/network/reducers/publish_header_entry.rs index f975bc5a8d..cd16ecaf99 100644 --- a/crates/core/src/network/reducers/publish_header_entry.rs +++ b/crates/core/src/network/reducers/publish_header_entry.rs @@ -1,9 +1,9 @@ use crate::{ action::ActionWrapper, - agent::state::create_chain_pair_for_header, + agent::state::create_entry_header_pair_for_header, network::{ actions::NetworkActionResponse, - chain_pair::ChainPair, + entry_header_pair::EntryHeaderPair, entry_aspect::EntryAspect, reducers::{publish::entry_data_to_entry_aspect_data, send}, state::NetworkState, @@ -26,9 +26,9 @@ fn publish_header( root_state: &State, chain_header: ChainHeader, ) -> Result<(), HolochainError> { - let chain_pair = - create_chain_pair_for_header(&StateWrapper::from(root_state.clone()), chain_header)?; - let entry = chain_pair.entry(); + let entry_header_pair = + create_entry_header_pair_for_header(&StateWrapper::from(root_state.clone()), chain_header)?; + let entry = entry_header_pair.entry(); send( network_state, Lib3hClientProtocol::PublishEntry(ProvidedEntryData { @@ -38,7 +38,7 @@ fn publish_header( entry_address: entry.address().into(), aspect_list: vec![entry_data_to_entry_aspect_data(&EntryAspect::Content( entry, - chain_pair.header(), + entry_header_pair.header(), ))], }, }), @@ -51,8 +51,8 @@ fn reduce_publish_header_entry_inner( address: &Address, ) -> Result<(), HolochainError> { network_state.initialized()?; - let chain_pair = ChainPair::fetch_chain_pair(&address, root_state)?; - publish_header(network_state, root_state, chain_pair.header()) + let entry_header_pair = EntryHeaderPair::fetch_entry_header_pair(&address, root_state)?; + publish_header(network_state, root_state, entry_header_pair.header()) } pub fn reduce_publish_header_entry( diff --git a/crates/core/src/nucleus/reducers/queue_zome_function_call.rs b/crates/core/src/nucleus/reducers/queue_zome_function_call.rs index 26f9fd212a..e72ab11d86 100644 --- a/crates/core/src/nucleus/reducers/queue_zome_function_call.rs +++ b/crates/core/src/nucleus/reducers/queue_zome_function_call.rs @@ -5,7 +5,7 @@ use crate::{ }; /// Reduce AddPendingValidation Action. -/// Inserts boxed ChainPair and dependencies into state, referenced with +/// Inserts boxed EntryHeaderPair and dependencies into state, referenced with /// the entry's address. #[allow(unknown_lints)] #[allow(clippy::needless_pass_by_value)] diff --git a/crates/core/src/nucleus/validation/build_from_dht.rs b/crates/core/src/nucleus/validation/build_from_dht.rs index 2b20af4950..187cb0992b 100644 --- a/crates/core/src/nucleus/validation/build_from_dht.rs +++ b/crates/core/src/nucleus/validation/build_from_dht.rs @@ -1,5 +1,5 @@ use crate::{ - context::Context, entry::CanPublish, network::chain_pair::ChainPair, + context::Context, entry::CanPublish, network::entry_header_pair::EntryHeaderPair, workflows::get_entry_result::get_entry_with_meta_workflow, }; use holochain_core_types::{ @@ -85,11 +85,11 @@ async fn public_chain_entries_from_headers_dht( } pub(crate) async fn try_make_validation_package_dht( - chain_pair: &ChainPair, + entry_header_pair: &EntryHeaderPair, validation_package_definition: &ValidationPackageDefinition, context: Arc, ) -> Result { - let entry_header = chain_pair.header(); + let entry_header = entry_header_pair.header(); log_debug!( context, "Constructing validation package from DHT for entry with address: {}", @@ -204,12 +204,12 @@ pub mod tests { .next() .expect("Must be able to get header for just published entry"); - let chain_pair = ChainPair::try_from_header_and_entry(header, entry)?; + let entry_header_pair = EntryHeaderPair::try_from_header_and_entry(header, entry)?; // jack (the author) retrieves a local validation package let local_validation_package = context2 .block_on(try_make_local_validation_package( - &chain_pair, + &entry_header_pair, &ValidationPackageDefinition::ChainFull, context2.clone(), )) @@ -218,7 +218,7 @@ pub mod tests { // jill reconstructs one from published headers let dht_validation_package = context1 .block_on(try_make_validation_package_dht( - &chain_pair, + &entry_header_pair, &ValidationPackageDefinition::ChainFull, context1.clone(), )) diff --git a/crates/core/src/scheduled_jobs/state_dump.rs b/crates/core/src/scheduled_jobs/state_dump.rs index 6ea6cbfc25..ef2c354382 100644 --- a/crates/core/src/scheduled_jobs/state_dump.rs +++ b/crates/core/src/scheduled_jobs/state_dump.rs @@ -53,8 +53,8 @@ pub fn state_dump(context: Arc) { format!( "<{}({})> {}: depends on : {:?}", pending.workflow.to_string(), - pending.chain_pair.header().entry_type(), - pending.chain_pair.entry().address(), + pending.entry_header_pair.header().entry_type(), + pending.entry_header_pair.entry().address(), pending .dependencies .iter() diff --git a/crates/core/src/workflows/hold_entry.rs b/crates/core/src/workflows/hold_entry.rs index 0b05d17bd1..8c2fc58b3b 100644 --- a/crates/core/src/workflows/hold_entry.rs +++ b/crates/core/src/workflows/hold_entry.rs @@ -1,5 +1,5 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, network::chain_pair::ChainPair, + context::Context, dht::actions::hold_aspect::hold_aspect, network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, }; @@ -15,11 +15,11 @@ use holochain_persistence_api::cas::content::AddressableContent; use std::sync::Arc; pub async fn hold_entry_workflow( - chain_pair: &ChainPair, + entry_header_pair: &EntryHeaderPair, context: Arc, ) -> Result<(), HolochainError> { // 1. Get hold of validation package - let maybe_validation_package = validation_package(&chain_pair, context.clone()) + let maybe_validation_package = validation_package(&entry_header_pair, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; @@ -43,7 +43,7 @@ pub async fn hold_entry_workflow( // 3. Validate the entry validate_entry( - chain_pair.entry(), + entry_header_pair.entry(), None, validation_data, &context @@ -51,13 +51,13 @@ pub async fn hold_entry_workflow( .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: {:?}", - chain_pair.entry().address(), + entry_header_pair.entry().address(), dependencies, ); HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_entry: Entry {} is NOT valid! Validation error: {:?}", - chain_pair.entry().address(), + entry_header_pair.entry().address(), err, ); HolochainError::from(err) @@ -67,17 +67,17 @@ pub async fn hold_entry_workflow( log_debug!( context, "workflow/hold_entry: is valid! {}", - chain_pair.entry().address() + entry_header_pair.entry().address() ); // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Content(chain_pair.entry(), chain_pair.header()); + let aspect = EntryAspect::Content(entry_header_pair.entry(), entry_header_pair.header()); hold_aspect(aspect, context.clone()).await?; log_debug!( context, "workflow/hold_entry: HOLDING: {}", - chain_pair.entry().address() + entry_header_pair.entry().address() ); Ok(()) @@ -127,10 +127,10 @@ pub mod tests { let header = agent1_state .get_most_recent_header_for_entry(&entry) .expect("There must be a header in the author's source chain after commit"); - let chain_pair = ChainPair::try_from_header_and_entry(header, entry)?; + let entry_header_pair = EntryHeaderPair::try_from_header_and_entry(header, entry)?; // Call hold_entry_workflow on victim DHT node - let result = context2.block_on(hold_entry_workflow(&chain_pair, &context2)); + let result = context2.block_on(hold_entry_workflow(&entry_header_pair, &context2)); // ... and expect validation to fail with message defined in test WAT: assert!(result.is_err()); diff --git a/crates/core/src/workflows/hold_entry_remove.rs b/crates/core/src/workflows/hold_entry_remove.rs index 4f66509554..0867c88e3a 100644 --- a/crates/core/src/workflows/hold_entry_remove.rs +++ b/crates/core/src/workflows/hold_entry_remove.rs @@ -1,5 +1,5 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, network::chain_pair::ChainPair, + context::Context, dht::actions::hold_aspect::hold_aspect, network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, }; @@ -12,11 +12,11 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn hold_remove_workflow( - chain_pair: &ChainPair, + entry_header_pair: &EntryHeaderPair, context: Arc, ) -> Result<(), HolochainError> { // 1. Get hold of validation package - let maybe_validation_package = validation_package(chain_pair, context.clone()) + let maybe_validation_package = validation_package(entry_header_pair, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; @@ -35,7 +35,7 @@ pub async fn hold_remove_workflow( // 3. Validate the entry validate_entry( - chain_pair.entry(), + entry_header_pair.entry(), None, validation_data, &context @@ -46,7 +46,7 @@ pub async fn hold_remove_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_remove: Entry removal {:?} is NOT valid! Validation error: {:?}", - chain_pair.entry(), + entry_header_pair.entry(), err, ); HolochainError::from(err) @@ -55,7 +55,7 @@ pub async fn hold_remove_workflow( })?; // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Deletion(chain_pair.header()); + let aspect = EntryAspect::Deletion(entry_header_pair.header()); hold_aspect(aspect, context.clone()).await?; Ok(()) } diff --git a/crates/core/src/workflows/hold_entry_update.rs b/crates/core/src/workflows/hold_entry_update.rs index 4d39bfa2c8..ebeb453df8 100644 --- a/crates/core/src/workflows/hold_entry_update.rs +++ b/crates/core/src/workflows/hold_entry_update.rs @@ -1,7 +1,7 @@ use crate::{ context::Context, dht::actions::hold_aspect::hold_aspect, - network::chain_pair::ChainPair, + network::entry_header_pair::EntryHeaderPair, nucleus::validation::{validate_entry, ValidationError}, workflows::validation_package, }; @@ -13,14 +13,14 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn hold_update_workflow( - chain_pair: &ChainPair, + entry_header_pair: &EntryHeaderPair, context: Arc, ) -> Result<(), HolochainError> { - let entry = chain_pair.entry(); - let header = chain_pair.header(); + let entry = entry_header_pair.entry(); + let header = entry_header_pair.header(); // 1. Get hold of validation package - let maybe_validation_package = validation_package(&chain_pair, context.clone()) + let maybe_validation_package = validation_package(&entry_header_pair, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; @@ -55,7 +55,7 @@ pub async fn hold_update_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_update: Entry update {:?} is NOT valid! Validation error: {:?}", - chain_pair.entry(), + entry_header_pair.entry(), err, ); HolochainError::from(err) @@ -64,7 +64,7 @@ pub async fn hold_update_workflow( })?; // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Update(chain_pair.entry(), chain_pair.header()); + let aspect = EntryAspect::Update(entry_header_pair.entry(), entry_header_pair.header()); hold_aspect(aspect, context.clone()).await?; Ok(()) diff --git a/crates/core/src/workflows/hold_link.rs b/crates/core/src/workflows/hold_link.rs index f84580f221..8462fdc703 100644 --- a/crates/core/src/workflows/hold_link.rs +++ b/crates/core/src/workflows/hold_link.rs @@ -1,5 +1,5 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, network::chain_pair::ChainPair, + context::Context, dht::actions::hold_aspect::hold_aspect, network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, }; @@ -16,10 +16,10 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn hold_link_workflow( - chain_pair: &ChainPair, + entry_header_pair: &EntryHeaderPair, context: Arc, ) -> Result<(), HolochainError> { - let entry = &chain_pair.entry(); + let entry = &entry_header_pair.entry(); let link_add = match entry { Entry::LinkAdd(link_add) => link_add, _ => Err(HolochainError::ErrorGeneric( @@ -31,7 +31,7 @@ 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 = validation_package(&chain_pair, context.clone()) + let maybe_validation_package = validation_package(&entry_header_pair, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; @@ -55,7 +55,7 @@ pub async fn hold_link_workflow( // 3. Validate the entry log_debug!(context, "workflow/hold_link: validate..."); validate_entry( - chain_pair.entry(), + entry_header_pair.entry(), None, validation_data, &context @@ -66,7 +66,7 @@ pub async fn hold_link_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_link: Link {:?} is NOT valid! Validation error: {:?}", - chain_pair.entry(), + entry_header_pair.entry(), err, ); HolochainError::from(err) @@ -76,14 +76,14 @@ pub async fn hold_link_workflow( log_debug!(context, "workflow/hold_link: is valid!"); // 3. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::LinkAdd(link_add.clone(), chain_pair.header()); + let aspect = EntryAspect::LinkAdd(link_add.clone(), entry_header_pair.header()); hold_aspect(aspect, context.clone()).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 - hold_entry_workflow(&chain_pair, context.clone()).await?; - log_debug!(context, "workflow/hold_entry: added! {:?}", chain_pair); + hold_entry_workflow(&entry_header_pair, context.clone()).await?; + log_debug!(context, "workflow/hold_entry: added! {:?}", entry_header_pair); //5. Link has been added to EAV and LinkAdd Entry has been stored on the dht Ok(()) @@ -147,10 +147,10 @@ pub mod tests { let header = agent1_state .get_most_recent_header_for_entry(&link_entry) .expect("There must be a header in the author's source chain after commit"); - let chain_pair = ChainPair::try_from_entry_and_header(header, link_entry)?; + let entry_header_pair = EntryHeaderPair::try_from_entry_and_header(header, link_entry)?; // Call hold_entry_workflow on victim DHT node - let result = context2.block_on(hold_link_workflow(&chain_pair, context2.clone())); + let result = context2.block_on(hold_link_workflow(&entry_header_pair, context2.clone())); // ... and expect validation to fail with message defined in test WAT: assert!(result.is_err()); diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 070f036a7e..2d097b6ec3 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -14,7 +14,7 @@ pub mod respond_validation_package_request; use crate::{ context::Context, dht::pending_validations::{PendingValidation, ValidatingWorkflow}, - network::{actions::get_validation_package::get_validation_package, chain_pair::ChainPair}, + network::{actions::get_validation_package::get_validation_package, entry_header_pair::EntryHeaderPair}, nucleus::{ actions::build_validation_package::build_validation_package, ribosome::callback::{ @@ -41,11 +41,11 @@ use std::sync::Arc; /// Checks the DNA's validation package definition for the given entry type. /// Fails if this entry type needs more than just the header for validation. pub(crate) async fn try_make_local_validation_package( - chain_pair: &ChainPair, + entry_header_pair: &EntryHeaderPair, validation_package_definition: &ValidationPackageDefinition, context: Arc, ) -> Result { - let entry_header = &chain_pair.header(); + let entry_header = &entry_header_pair.header(); match validation_package_definition { ValidationPackageDefinition::Entry => { @@ -53,8 +53,8 @@ pub(crate) async fn try_make_local_validation_package( } _ => { let agent = context.state()?.agent().get_agent()?; - let entry = &chain_pair.entry(); - let header = chain_pair.header(); + let entry = &entry_header_pair.entry(); + let header = entry_header_pair.header(); let overlapping_provenance = header .provenances() .iter() @@ -74,12 +74,12 @@ pub(crate) async fn try_make_local_validation_package( /// Gets hold of the validation package for the given entry by trying several different methods. async fn validation_package( - chain_pair: &ChainPair, + entry_header_pair: &EntryHeaderPair, context: Arc, ) -> Result, HolochainError> { // 0. Call into the DNA to get the validation package definition for this entry // e.g. what data is needed to validate it (chain, entry, headers, etc) - let entry = chain_pair.entry(); + let entry = entry_header_pair.entry(); let validation_package_definition = get_validation_package_definition(&entry, context.clone()) .and_then(|callback_result| match callback_result { CallbackResult::Fail(error_string) => Err(HolochainError::ErrorGeneric(error_string)), @@ -97,10 +97,10 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Trying to build locally", - chain_pair.entry().address() + entry_header_pair.entry().address() ); if let Ok(package) = try_make_local_validation_package( - &chain_pair, + &entry_header_pair, &validation_package_definition, context.clone(), ) @@ -109,7 +109,7 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Successfully built locally", - chain_pair.entry().address() + entry_header_pair.entry().address() ); return Ok(Some(package)); } @@ -118,22 +118,22 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Could not build locally. Trying to retrieve from author", - chain_pair.entry().address() + entry_header_pair.entry().address() ); - match get_validation_package(chain_pair.header(), &context).await { + match get_validation_package(entry_header_pair.header(), &context).await { Ok(Some(package)) => { log_debug!( context, "validation_package:{} - Successfully retrieved from author", - chain_pair.entry().address() + entry_header_pair.entry().address() ); return Ok(Some(package)); } response => log_debug!( context, "validation_package:{} - Direct message to author responded: {:?}", - chain_pair.entry().address(), + entry_header_pair.entry().address(), response, ), } @@ -142,10 +142,10 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Could not retrieve from author. Trying to build from published headers", - chain_pair.entry().address() + entry_header_pair.entry().address() ); if let Ok(package) = try_make_validation_package_dht( - &chain_pair, + &entry_header_pair, &validation_package_definition, context.clone(), ) @@ -154,7 +154,7 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Successfully built from published headers", - chain_pair.entry().address() + entry_header_pair.entry().address() ); return Ok(Some(package)); } @@ -164,7 +164,7 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Could not get validation package!!!", - chain_pair.entry().address() + entry_header_pair.entry().address() ); Err(HolochainError::ErrorGeneric( "Could not get validation package".to_string(), @@ -175,7 +175,7 @@ async fn validation_package( pub mod tests { use super::validation_package; use crate::{ - network::chain_pair::ChainPair, nucleus::actions::tests::*, + network::entry_header_pair::EntryHeaderPair, nucleus::actions::tests::*, workflows::author_entry::author_entry, }; use holochain_core_types::{entry::Entry, error::HolochainError}; @@ -211,9 +211,9 @@ pub mod tests { .next() .expect("Must be able to get header for just published entry"); - ChainPair::try_from_header_and_entry(header, entry).map(|chain_pair| { + EntryHeaderPair::try_from_header_and_entry(header, entry).map(|entry_header_pair| { let validation_package = context1 - .block_on(validation_package(&chain_pair, context1.clone())) + .block_on(validation_package(&entry_header_pair, context1.clone())) .expect("Could not recover a validation package as the non-author"); assert_eq!( @@ -236,19 +236,19 @@ pub async fn run_holding_workflow( ) -> Result<(), HolochainError> { match pending.workflow { ValidatingWorkflow::HoldLink => { - hold_link_workflow(&pending.chain_pair, context.clone()).await + hold_link_workflow(&pending.entry_header_pair, context.clone()).await } ValidatingWorkflow::HoldEntry => { - hold_entry_workflow(&pending.chain_pair, context.clone()).await + hold_entry_workflow(&pending.entry_header_pair, context.clone()).await } ValidatingWorkflow::RemoveLink => { - remove_link_workflow(&pending.chain_pair, context.clone()).await + remove_link_workflow(&pending.entry_header_pair, context.clone()).await } ValidatingWorkflow::UpdateEntry => { - hold_update_workflow(&pending.chain_pair, context.clone()).await + hold_update_workflow(&pending.entry_header_pair, context.clone()).await } ValidatingWorkflow::RemoveEntry => { - hold_remove_workflow(&pending.chain_pair, context.clone()).await + hold_remove_workflow(&pending.entry_header_pair, context.clone()).await } } } diff --git a/crates/core/src/workflows/remove_link.rs b/crates/core/src/workflows/remove_link.rs index 5c7540ae32..bf7a1cea7f 100644 --- a/crates/core/src/workflows/remove_link.rs +++ b/crates/core/src/workflows/remove_link.rs @@ -1,5 +1,5 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, network::chain_pair::ChainPair, + context::Context, dht::actions::hold_aspect::hold_aspect, network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, workflows::hold_entry::hold_entry_workflow, }; @@ -13,10 +13,10 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn remove_link_workflow( - chain_pair: &ChainPair, + entry_header_pair: &EntryHeaderPair, context: Arc, ) -> Result<(), HolochainError> { - let entry = &chain_pair.entry(); + let entry = &entry_header_pair.entry(); let (link_data, links_to_remove) = match entry { Entry::LinkRemove(data) => data, _ => Err(HolochainError::ErrorGeneric( @@ -31,7 +31,7 @@ pub async fn remove_link_workflow( context, "workflow/remove_link: getting validation package..." ); - let maybe_validation_package = validation_package(&chain_pair, context.clone()) + let maybe_validation_package = validation_package(&entry_header_pair, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; @@ -53,7 +53,7 @@ pub async fn remove_link_workflow( // 3. Validate the entry log_debug!(context, "workflow/remove_link: validate..."); validate_entry( - chain_pair.entry(), + entry_header_pair.entry(), None, validation_data, &context @@ -64,7 +64,7 @@ pub async fn remove_link_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/remove_link: Link {:?} is NOT valid! Validation error: {:?}", - chain_pair.entry(), + entry_header_pair.entry(), err, ); HolochainError::from(err) @@ -77,14 +77,14 @@ pub async fn remove_link_workflow( // 3. If valid store the entry aspect in the local DHT shard let aspect = EntryAspect::LinkRemove( (link_data.clone(), links_to_remove.clone()), - chain_pair.header(), + entry_header_pair.header(), ); hold_aspect(aspect, context.clone()).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``` - hold_entry_workflow(&chain_pair, context.clone()).await?; - log_debug!(context, "workflow/hold_entry: added! {:?}", chain_pair); + hold_entry_workflow(&entry_header_pair, context.clone()).await?; + log_debug!(context, "workflow/hold_entry: added! {:?}", entry_header_pair); Ok(()) } From cf6d3ece32baf12af28875047fbe50751190a197 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Sat, 21 Dec 2019 21:44:06 +1100 Subject: [PATCH 73/79] rename chain_pair.rs --- crates/core/src/network/chain_pair.rs | 70 --------------------------- 1 file changed, 70 deletions(-) delete mode 100644 crates/core/src/network/chain_pair.rs diff --git a/crates/core/src/network/chain_pair.rs b/crates/core/src/network/chain_pair.rs deleted file mode 100644 index 5579678b0a..0000000000 --- a/crates/core/src/network/chain_pair.rs +++ /dev/null @@ -1,70 +0,0 @@ -use crate::{ - agent::find_chain_header, - content_store::GetContent, - state::{State, StateWrapper}, -}; -use holochain_core_types::{chain_header::ChainHeader, entry::Entry, error::HolochainError}; -use holochain_persistence_api::cas::content::{Address, AddressableContent}; - -/// A `EntryHeaderPair` cannot be constructed unless the entry address in the -/// `ChainHeader` that is within the `EntryHeaderPair` is the same as the address -/// of the `Entry` that is also within the `EntryHeaderPair`. -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct EntryHeaderPair(ChainHeader, Entry); - -impl EntryHeaderPair { - // It seems best to not have a new method, since stylistically it is expected to return Self, whereas constructing could fail. - pub fn try_from_header_and_entry( - header: ChainHeader, - entry: Entry, - ) -> Result { - let header_entry_address = header.entry_address(); - let entry_address = entry.address(); - if header_entry_address.clone() == entry_address { - Ok(EntryHeaderPair(header, entry)) - } else { - let basic_error_msg = "Tried to create a EntryHeaderPair, but got a - mismatch with the header's entry address and the entry's - address."; - let error_msg = format!( - "{} See the debug log output for data for the header and entry.", - basic_error_msg - ); - debug!( - "{}\nHeader:\n{:#?}\nEntry:{:#?}\nentry in header (i.e. header.entry()=\n", - basic_error_msg, header, entry - ); - Err(HolochainError::HeaderEntryMismatch( - error_msg, - header_entry_address.clone(), - entry_address, - )) - } - } - - pub fn header(&self) -> ChainHeader { - self.0.clone() - } - - pub fn entry(&self) -> Entry { - self.1.clone() - } - - pub fn fetch_entry_header_pair(address: &Address, state: &State) -> Result { - let entry = state - .agent() - .chain_store() - .get(address)? - .ok_or_else(|| HolochainError::from("Entry not found"))?; - - let header = - find_chain_header(&entry, &StateWrapper::from(state.clone())).ok_or_else(|| { - let error_msg = format!( - "No header found for the address:\n{}\nEntry:\n{:#?}\n", - address, entry - ); - HolochainError::from(error_msg) - })?; - EntryHeaderPair::try_from_header_and_entry(header, entry) - } -} From 70f0c5e6561ca53ee20082520e0a235ec06c7440 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Sat, 21 Dec 2019 21:51:51 +1100 Subject: [PATCH 74/79] cargo fmt in nh --- crates/core/src/action.rs | 2 +- crates/core/src/dht/dht_reducers.rs | 4 ++- crates/core/src/dht/pending_validations.rs | 3 +- .../core/src/entry/validation_dependencies.rs | 5 +-- crates/core/src/network/handler/lists.rs | 3 +- crates/core/src/network/handler/mod.rs | 2 +- crates/core/src/network/mod.rs | 3 +- crates/core/src/network/reducers/publish.rs | 32 +++++++++---------- .../network/reducers/publish_header_entry.rs | 2 +- crates/core/src/workflows/hold_entry.rs | 4 +-- .../core/src/workflows/hold_entry_remove.rs | 4 +-- crates/core/src/workflows/hold_link.rs | 10 ++++-- crates/core/src/workflows/mod.rs | 4 ++- crates/core/src/workflows/remove_link.rs | 11 +++++-- 14 files changed, 53 insertions(+), 36 deletions(-) diff --git a/crates/core/src/action.rs b/crates/core/src/action.rs index eae23c4c8c..3fade7c669 100644 --- a/crates/core/src/action.rs +++ b/crates/core/src/action.rs @@ -2,9 +2,9 @@ use crate::{ agent::state::AgentState, dht::pending_validations::PendingValidation, network::{ - entry_header_pair::EntryHeaderPair, direct_message::DirectMessage, entry_aspect::EntryAspect, + entry_header_pair::EntryHeaderPair, query::{GetLinksNetworkQuery, NetworkQueryResult}, state::NetworkState, }, diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 2676b0a61b..c63b9a28ab 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -563,7 +563,9 @@ pub mod tests { workflow: ValidatingWorkflow, ) -> PendingValidation { match EntryHeaderPair::try_from_header_and_entry(header.clone(), entry.clone()) { - Ok(entry_header_pair) => Arc::new(PendingValidationStruct::new(entry_header_pair, workflow)), + Ok(entry_header_pair) => { + Arc::new(PendingValidationStruct::new(entry_header_pair, workflow)) + } Err(err) => { let err_msg = format!( "Tried to create a pending validation, got an error: {}", diff --git a/crates/core/src/dht/pending_validations.rs b/crates/core/src/dht/pending_validations.rs index fac9734b26..26f8971bfa 100644 --- a/crates/core/src/dht/pending_validations.rs +++ b/crates/core/src/dht/pending_validations.rs @@ -1,5 +1,6 @@ use crate::{ - entry::validation_dependencies::ValidationDependencies, network::entry_header_pair::EntryHeaderPair, + entry::validation_dependencies::ValidationDependencies, + network::entry_header_pair::EntryHeaderPair, }; use holochain_core_types::{ chain_header::ChainHeader, diff --git a/crates/core/src/entry/validation_dependencies.rs b/crates/core/src/entry/validation_dependencies.rs index f23cac85c9..7026c48e50 100644 --- a/crates/core/src/entry/validation_dependencies.rs +++ b/crates/core/src/entry/validation_dependencies.rs @@ -74,8 +74,9 @@ pub mod tests { #[test] fn test_get_validation_dependencies_app_entry() -> Result<(), HolochainError> { let entry = Entry::App("entry_type".into(), "content".into()); - try_entry_header_pair_from_entry(entry) - .map(|entry_header_pair| assert_eq!(entry_header_pair.get_validation_dependencies(), Vec::new())) + try_entry_header_pair_from_entry(entry).map(|entry_header_pair| { + assert_eq!(entry_header_pair.get_validation_dependencies(), Vec::new()) + }) } #[test] diff --git a/crates/core/src/network/handler/lists.rs b/crates/core/src/network/handler/lists.rs index ce520d5228..18acf21b35 100644 --- a/crates/core/src/network/handler/lists.rs +++ b/crates/core/src/network/handler/lists.rs @@ -88,7 +88,8 @@ fn create_authoring_map(context: Arc) -> AspectMap { } Ok(entry_header_pair) => { let entry_hash = entry_header_pair.entry().address(); - let content_aspect = EntryAspect::Content(entry_header_pair.entry(), entry_header_pair.header()); + let content_aspect = + EntryAspect::Content(entry_header_pair.entry(), entry_header_pair.header()); let aspect_hash = AspectHash::from(content_aspect.address()); address_map .entry(entry_hash.into()) diff --git a/crates/core/src/network/handler/mod.rs b/crates/core/src/network/handler/mod.rs index 259146ae50..a877094d8f 100644 --- a/crates/core/src/network/handler/mod.rs +++ b/crates/core/src/network/handler/mod.rs @@ -10,9 +10,9 @@ use crate::{ context::Context, entry::CanPublish, network::{ - entry_header_pair::EntryHeaderPair, direct_message::DirectMessage, entry_aspect::EntryAspect, + entry_header_pair::EntryHeaderPair, handler::{ fetch::*, lists::{handle_get_authoring_list, handle_get_gossip_list}, diff --git a/crates/core/src/network/mod.rs b/crates/core/src/network/mod.rs index 0d0e144857..753d05e675 100644 --- a/crates/core/src/network/mod.rs +++ b/crates/core/src/network/mod.rs @@ -1,6 +1,6 @@ pub mod actions; -pub mod entry_header_pair; pub mod direct_message; +pub mod entry_header_pair; pub mod handler; pub mod reducers; pub mod state; @@ -133,6 +133,7 @@ pub mod tests { dht1.add(&entry).unwrap(); dht1.add_header_for_entry(&entry, &header2).unwrap(); } + cf } // Get it. diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index b0422c2428..d519c9bd24 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -1,8 +1,8 @@ use crate::{ action::ActionWrapper, network::{ - actions::NetworkActionResponse, entry_header_pair::EntryHeaderPair, entry_aspect::EntryAspect, - reducers::send, state::NetworkState, + actions::NetworkActionResponse, entry_aspect::EntryAspect, + entry_header_pair::EntryHeaderPair, reducers::send, state::NetworkState, }, state::State, }; @@ -65,7 +65,9 @@ fn publish_update_delete_meta( // publish crud-status let aspect = match crud_status { - CrudStatus::Modified => EntryAspect::Update(entry_header_pair.entry(), entry_header_pair.header()), + CrudStatus::Modified => { + EntryAspect::Update(entry_header_pair.entry(), entry_header_pair.header()) + } CrudStatus::Deleted => EntryAspect::Deletion(entry_header_pair.header()), crud => { return Err(HolochainError::ErrorGeneric(format!( @@ -136,19 +138,17 @@ fn reduce_publish_inner( match entry_header_pair.entry().entry_type() { EntryType::AgentId => publish_entry(network_state, &entry_header_pair), - EntryType::App(_) => { - publish_entry(network_state, &entry_header_pair).and_then(|_| { - match entry_header_pair.header().link_update_delete() { - Some(modified_entry) => publish_update_delete_meta( - network_state, - modified_entry, - CrudStatus::Modified, - &entry_header_pair.clone(), - ), - None => Ok(()), - } - }) - } + EntryType::App(_) => publish_entry(network_state, &entry_header_pair).and_then(|_| { + match entry_header_pair.header().link_update_delete() { + Some(modified_entry) => publish_update_delete_meta( + network_state, + modified_entry, + CrudStatus::Modified, + &entry_header_pair.clone(), + ), + None => Ok(()), + } + }), EntryType::LinkAdd => publish_entry(network_state, &entry_header_pair) .and_then(|_| publish_link_meta(network_state, &entry_header_pair)), EntryType::LinkRemove => publish_entry(network_state, &entry_header_pair) diff --git a/crates/core/src/network/reducers/publish_header_entry.rs b/crates/core/src/network/reducers/publish_header_entry.rs index cd16ecaf99..3987f9ca31 100644 --- a/crates/core/src/network/reducers/publish_header_entry.rs +++ b/crates/core/src/network/reducers/publish_header_entry.rs @@ -3,8 +3,8 @@ use crate::{ agent::state::create_entry_header_pair_for_header, network::{ actions::NetworkActionResponse, - entry_header_pair::EntryHeaderPair, entry_aspect::EntryAspect, + entry_header_pair::EntryHeaderPair, reducers::{publish::entry_data_to_entry_aspect_data, send}, state::NetworkState, }, diff --git a/crates/core/src/workflows/hold_entry.rs b/crates/core/src/workflows/hold_entry.rs index 8c2fc58b3b..c316d6b4a4 100644 --- a/crates/core/src/workflows/hold_entry.rs +++ b/crates/core/src/workflows/hold_entry.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, network::entry_header_pair::EntryHeaderPair, - nucleus::validation::validate_entry, + context::Context, dht::actions::hold_aspect::hold_aspect, + network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, }; use crate::{nucleus::validation::ValidationError, workflows::validation_package}; diff --git a/crates/core/src/workflows/hold_entry_remove.rs b/crates/core/src/workflows/hold_entry_remove.rs index 0867c88e3a..2efea72476 100644 --- a/crates/core/src/workflows/hold_entry_remove.rs +++ b/crates/core/src/workflows/hold_entry_remove.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, network::entry_header_pair::EntryHeaderPair, - nucleus::validation::validate_entry, + context::Context, dht::actions::hold_aspect::hold_aspect, + network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, }; use crate::{nucleus::validation::ValidationError, workflows::validation_package}; diff --git a/crates/core/src/workflows/hold_link.rs b/crates/core/src/workflows/hold_link.rs index 8462fdc703..099d609a14 100644 --- a/crates/core/src/workflows/hold_link.rs +++ b/crates/core/src/workflows/hold_link.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, network::entry_header_pair::EntryHeaderPair, - nucleus::validation::validate_entry, + context::Context, dht::actions::hold_aspect::hold_aspect, + network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, }; use crate::{ @@ -83,7 +83,11 @@ pub async fn hold_link_workflow( //4. store link_add entry so we have all we need to respond to get links queries without any other network look-up hold_entry_workflow(&entry_header_pair, context.clone()).await?; - log_debug!(context, "workflow/hold_entry: added! {:?}", entry_header_pair); + log_debug!( + context, + "workflow/hold_entry: added! {:?}", + entry_header_pair + ); //5. Link has been added to EAV and LinkAdd Entry has been stored on the dht Ok(()) diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 2d097b6ec3..333a5cc6eb 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -14,7 +14,9 @@ pub mod respond_validation_package_request; use crate::{ context::Context, dht::pending_validations::{PendingValidation, ValidatingWorkflow}, - network::{actions::get_validation_package::get_validation_package, entry_header_pair::EntryHeaderPair}, + network::{ + actions::get_validation_package::get_validation_package, entry_header_pair::EntryHeaderPair, + }, nucleus::{ actions::build_validation_package::build_validation_package, ribosome::callback::{ diff --git a/crates/core/src/workflows/remove_link.rs b/crates/core/src/workflows/remove_link.rs index bf7a1cea7f..e58e4325cd 100644 --- a/crates/core/src/workflows/remove_link.rs +++ b/crates/core/src/workflows/remove_link.rs @@ -1,6 +1,7 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, network::entry_header_pair::EntryHeaderPair, - nucleus::validation::validate_entry, workflows::hold_entry::hold_entry_workflow, + context::Context, dht::actions::hold_aspect::hold_aspect, + network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, + workflows::hold_entry::hold_entry_workflow, }; use crate::{nucleus::validation::ValidationError, workflows::validation_package}; @@ -84,7 +85,11 @@ pub async fn remove_link_workflow( //4. store link_remove entry so we have all we need to respond to get links queries without any other network look-up``` hold_entry_workflow(&entry_header_pair, context.clone()).await?; - log_debug!(context, "workflow/hold_entry: added! {:?}", entry_header_pair); + log_debug!( + context, + "workflow/hold_entry: added! {:?}", + entry_header_pair + ); Ok(()) } From 387a526ee40f4251360f6f72f2546900b0f28b77 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Sat, 21 Dec 2019 22:01:58 +1100 Subject: [PATCH 75/79] a -> an --- crates/core/src/agent/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/agent/state.rs b/crates/core/src/agent/state.rs index a58b289769..51ee151fd0 100644 --- a/crates/core/src/agent/state.rs +++ b/crates/core/src/agent/state.rs @@ -221,7 +221,7 @@ pub fn create_new_chain_header( )) } -/// Creates a `EntryHeaderPair` for a `ChainHeader`. +/// Creates an `EntryHeaderPair` for a `ChainHeader`. /// Since published headers are treated as entries, the header must also /// have its own header! pub fn create_entry_header_pair_for_header( From 82b8cbc7d567b7c13a94181c593401802dc16e0f Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Sat, 21 Dec 2019 22:11:46 +1100 Subject: [PATCH 76/79] track crates/core/src/network/entry_header_pair.rs; nt, nc, nf all pass --- crates/core/src/network/entry_header_pair.rs | 73 ++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 crates/core/src/network/entry_header_pair.rs diff --git a/crates/core/src/network/entry_header_pair.rs b/crates/core/src/network/entry_header_pair.rs new file mode 100644 index 0000000000..6f435cd5f3 --- /dev/null +++ b/crates/core/src/network/entry_header_pair.rs @@ -0,0 +1,73 @@ +use crate::{ + agent::find_chain_header, + content_store::GetContent, + state::{State, StateWrapper}, +}; +use holochain_core_types::{chain_header::ChainHeader, entry::Entry, error::HolochainError}; +use holochain_persistence_api::cas::content::{Address, AddressableContent}; + +/// A `EntryHeaderPair` cannot be constructed unless the entry address in the +/// `ChainHeader` that is within the `EntryHeaderPair` is the same as the address +/// of the `Entry` that is also within the `EntryHeaderPair`. +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] +pub struct EntryHeaderPair(ChainHeader, Entry); + +impl EntryHeaderPair { + // It seems best to not have a new method, since stylistically it is expected to return Self, whereas constructing could fail. + pub fn try_from_header_and_entry( + header: ChainHeader, + entry: Entry, + ) -> Result { + let header_entry_address = header.entry_address(); + let entry_address = entry.address(); + if header_entry_address.clone() == entry_address { + Ok(EntryHeaderPair(header, entry)) + } else { + let basic_error_msg = "Tried to create a EntryHeaderPair, but got a + mismatch with the header's entry address and the entry's + address."; + let error_msg = format!( + "{} See the debug log output for data for the header and entry.", + basic_error_msg + ); + debug!( + "{}\nHeader:\n{:#?}\nEntry:{:#?}\nentry in header (i.e. header.entry()=\n", + basic_error_msg, header, entry + ); + Err(HolochainError::HeaderEntryMismatch( + error_msg, + header_entry_address.clone(), + entry_address, + )) + } + } + + pub fn header(&self) -> ChainHeader { + self.0.clone() + } + + pub fn entry(&self) -> Entry { + self.1.clone() + } + + pub fn fetch_entry_header_pair( + address: &Address, + state: &State, + ) -> Result { + let entry = state + .agent() + .chain_store() + .get(address)? + .ok_or_else(|| HolochainError::from("Entry not found"))?; + + let header = + find_chain_header(&entry, &StateWrapper::from(state.clone())).ok_or_else(|| { + let error_msg = format!( + "No header found for the address:\n{}\nEntry:\n{:#?}\n", + address, entry + ); + HolochainError::from(error_msg) + })?; + EntryHeaderPair::try_from_header_and_entry(header, entry) + } +} From 358f1fea6aff9f45e2ce0e0001feeb38c4db5480 Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Sat, 21 Dec 2019 22:51:41 +1100 Subject: [PATCH 77/79] rename EntryHeaderPair to HeaderWithItsEntry, etc. --- crates/core/src/action.rs | 4 +-- crates/core/src/agent/state.rs | 10 +++---- crates/core/src/dht/dht_store.rs | 12 ++++---- crates/core/src/network/handler/mod.rs | 24 +++++++-------- crates/core/src/network/handler/store.rs | 30 +++++++++---------- ...eader_pair.rs => header_with_its_entry.rs} | 0 crates/core/src/network/mod.rs | 2 +- .../network/reducers/publish_header_entry.rs | 16 +++++----- .../reducers/queue_zome_function_call.rs | 2 +- .../src/nucleus/validation/build_from_dht.rs | 12 ++++---- crates/core/src/scheduled_jobs/state_dump.rs | 4 +-- crates/core/src/workflows/hold_entry.rs | 24 +++++++-------- .../core/src/workflows/hold_entry_remove.rs | 14 ++++----- .../core/src/workflows/hold_entry_update.rs | 14 ++++----- 14 files changed, 84 insertions(+), 84 deletions(-) rename crates/core/src/network/{entry_header_pair.rs => header_with_its_entry.rs} (100%) diff --git a/crates/core/src/action.rs b/crates/core/src/action.rs index 3fade7c669..9684c23530 100644 --- a/crates/core/src/action.rs +++ b/crates/core/src/action.rs @@ -2,9 +2,9 @@ use crate::{ agent::state::AgentState, dht::pending_validations::PendingValidation, network::{ + header_with_its_entry::HeaderWithItsEntry, direct_message::DirectMessage, entry_aspect::EntryAspect, - entry_header_pair::EntryHeaderPair, query::{GetLinksNetworkQuery, NetworkQueryResult}, state::NetworkState, }, @@ -127,7 +127,7 @@ pub enum Action { HoldAspect(EntryAspect), //action for updating crudstatus - CrudStatus((EntryHeaderPair, CrudStatus)), + CrudStatus((HeaderWithItsEntry, CrudStatus)), // ---------------- // Network actions: diff --git a/crates/core/src/agent/state.rs b/crates/core/src/agent/state.rs index 51ee151fd0..495f524e42 100644 --- a/crates/core/src/agent/state.rs +++ b/crates/core/src/agent/state.rs @@ -1,7 +1,7 @@ use crate::{ action::{Action, ActionWrapper, AgentReduceFn}, agent::chain_store::{ChainStore, ChainStoreIterator}, - network::entry_header_pair::EntryHeaderPair, + network::header_with_its_entry::HeaderWithItsEntry, state::State, }; use holochain_persistence_api::cas::content::{Address, AddressableContent, Content}; @@ -221,13 +221,13 @@ pub fn create_new_chain_header( )) } -/// Creates an `EntryHeaderPair` for a `ChainHeader`. +/// Creates a `HeaderWithItsEntry` for a `ChainHeader`. /// Since published headers are treated as entries, the header must also /// have its own header! -pub fn create_entry_header_pair_for_header( +pub fn create_header_with_its_entry_for_header( root_state: &StateWrapper, chain_header: ChainHeader, -) -> Result { +) -> Result { let timestamp = chain_header.timestamp().clone(); let entry = Entry::ChainHeader(chain_header); // This header entry needs its own header so we can publish it. @@ -251,7 +251,7 @@ pub fn create_entry_header_pair_for_header( &None, ×tamp, ); - EntryHeaderPair::try_from_header_and_entry(header, entry) + HeaderWithItsEntry::try_from_header_and_entry(header, entry) } /// Do a Commit Action against an agent state. diff --git a/crates/core/src/dht/dht_store.rs b/crates/core/src/dht/dht_store.rs index cda49f0bb6..face00b838 100644 --- a/crates/core/src/dht/dht_store.rs +++ b/crates/core/src/dht/dht_store.rs @@ -4,7 +4,7 @@ use crate::{ aspect_map::{AspectMap, AspectMapBare}, pending_validations::{PendingValidationWithTimeout, ValidationTimeout}, }, - network::entry_header_pair::EntryHeaderPair, + network::header_with_its_entry::HeaderWithItsEntry, }; use holochain_core_types::{ chain_header::ChainHeader, @@ -231,8 +231,8 @@ impl DhtStore { entry: &Entry, header: &ChainHeader, ) -> Result<(), HolochainError> { - match EntryHeaderPair::try_from_header_and_entry(header.clone(), entry.clone()) { - Ok(_entry_header_pair) => { + match HeaderWithItsEntry::try_from_header_and_entry(header.clone(), entry.clone()) { + Ok(_header_with_its_entry) => { let eavi = EntityAttributeValueIndex::new( &entry.address(), &Attribute::EntryHeader, @@ -334,8 +334,8 @@ impl DhtStore { |PendingValidationWithTimeout { pending: current, .. }| { - current.entry_header_pair.header().entry_address() - == pending.entry_header_pair.header().entry_address() + current.header_with_its_entry.header().entry_address() + == pending.header_with_its_entry.header().entry_address() && current.workflow == pending.workflow }, ) @@ -356,7 +356,7 @@ where let unique_pending: HashSet
= pending .clone() .into_iter() - .map(|p| p.pending.entry_header_pair.entry().address()) + .map(|p| p.pending.header_with_its_entry.entry().address()) .collect(); Box::new(move |p| { diff --git a/crates/core/src/network/handler/mod.rs b/crates/core/src/network/handler/mod.rs index a877094d8f..7bbd3f7f35 100644 --- a/crates/core/src/network/handler/mod.rs +++ b/crates/core/src/network/handler/mod.rs @@ -1,4 +1,4 @@ -use crate::{agent::state::create_entry_header_pair_for_header, content_store::GetContent}; +use crate::{agent::state::create_header_with_its_entry_for_header, content_store::GetContent}; use holochain_logging::prelude::*; pub mod fetch; pub mod lists; @@ -10,9 +10,9 @@ use crate::{ context::Context, entry::CanPublish, network::{ + header_with_its_entry::HeaderWithItsEntry, direct_message::DirectMessage, entry_aspect::EntryAspect, - entry_header_pair::EntryHeaderPair, handler::{ fetch::*, lists::{handle_get_authoring_list, handle_get_gossip_list}, @@ -303,8 +303,8 @@ fn get_content_aspect( }); // If we have found a header for the requested entry in the chain... - let maybe_entry_header_pair = match maybe_chain_header { - Some((header, true)) => Some(create_entry_header_pair_for_header(&state, header)?), + let maybe_header_with_its_entry = match maybe_chain_header { + Some((header, true)) => Some(create_header_with_its_entry_for_header(&state, header)?), Some((header, false)) => { // ... we can just get the content from the chain CAS let entry = state @@ -312,8 +312,8 @@ fn get_content_aspect( .chain_store() .get(&header.entry_address())? .expect("Could not find entry in chain CAS, but header is chain"); - match EntryHeaderPair::try_from_header_and_entry(header, entry) { - Ok(entry_header_pair) => Some(entry_header_pair), + match HeaderWithItsEntry::try_from_header_and_entry(header, entry) { + Ok(header_with_its_entry) => Some(header_with_its_entry), Err(error) => return Err(error), } } @@ -334,8 +334,8 @@ fn get_content_aspect( // TODO: this is just taking the first header.. // We should actually transform all headers into EntryAspect::Headers and just the first one // into an EntryAspect content (What about ordering? Using the headers timestamp?) - match EntryHeaderPair::try_from_header_and_entry(headers[0].clone(), entry) { - Ok(entry_header_pair) => Some(entry_header_pair), + match HeaderWithItsEntry::try_from_header_and_entry(headers[0].clone(), entry) { + Ok(header_with_its_entry) => Some(header_with_its_entry), Err(error) => { log_error!(context, "{}", error); None @@ -354,17 +354,17 @@ fn get_content_aspect( } }; - let entry_header_pair = maybe_entry_header_pair.ok_or(HolochainError::EntryNotFoundLocally)?; + let header_with_its_entry = maybe_header_with_its_entry.ok_or(HolochainError::EntryNotFoundLocally)?; - let _ = entry_header_pair + let _ = header_with_its_entry .entry() .entry_type() .can_publish(&context) .ok_or(HolochainError::EntryIsPrivate)?; Ok(EntryAspect::Content( - entry_header_pair.entry(), - entry_header_pair.header(), + header_with_its_entry.entry(), + header_with_its_entry.header(), )) } diff --git a/crates/core/src/network/handler/store.rs b/crates/core/src/network/handler/store.rs index 6435f63b91..26eaa76374 100644 --- a/crates/core/src/network/handler/store.rs +++ b/crates/core/src/network/handler/store.rs @@ -68,13 +68,13 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { log_debug!(context, "net/handle: HandleStoreMeta: got LINK. processing..."); // TODO: do a loop on content once links properly implemented assert_eq!(dht_meta_data.content_list.len(), 1); - let entry_header_pair: EntryHeaderPair = serde_json::from_str( + let header_with_its_entry: HeaderWithItsEntry = serde_json::from_str( &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be EntryHeaderPair"), + .expect("dht_meta_data should be HeaderWithItsEntry"), ) - .expect("dht_meta_data should be EntryHeaderPair"); + .expect("dht_meta_data should be HeaderWithItsEntry"); thread::spawn(move || { - match context.block_on(hold_link_workflow(&entry_header_pair, &context.clone())) { + match context.block_on(hold_link_workflow(&header_with_its_entry, &context.clone())) { Err(error) => log_error!(context, "net/dht: {}", error), _ => (), } @@ -83,15 +83,15 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { log_debug!(context, "net/handle: HandleStoreMeta: got LINK REMOVAL. processing..."); // TODO: do a loop on content once links properly implemented assert_eq!(dht_meta_data.content_list.len(), 1); - let entry_header_pair: EntryHeaderPair = serde_json::from_str( + let header_with_its_entry: HeaderWithItsEntry = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be EntryHeaderPair"), + .expect("dht_meta_data should be HeaderWithItsEntry"), ) .expect("dht_meta_data should be EntryWithHader"); thread::spawn(move || { if let Err(error) = - context.block_on(remove_link_workflow(&entry_header_pair, &context.clone())) + context.block_on(remove_link_workflow(&header_with_its_entry, &context.clone())) { log_error!(context, "net/dht: {}", error) } @@ -102,15 +102,15 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { { log_debug!(context, "net/handle: HandleStoreMeta: got CRUD STATUS. processing..."); - let entry_header_pair: EntryHeaderPair = serde_json::from_str( + let header_with_its_entry: HeaderWithItsEntry = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be EntryHeaderPair"), + .expect("dht_meta_data should be HeaderWithItsEntry"), ) - .expect("dht_meta_data should be EntryHeaderPair"); + .expect("dht_meta_data should be HeaderWithItsEntry"); thread::spawn(move || { if let Err(error) = - context.block_on(hold_remove_workflow(entry_header_pair, context.clone())) + context.block_on(hold_remove_workflow(header_with_its_entry, context.clone())) { log_error!(context, "net/dht: {}", error) } @@ -120,15 +120,15 @@ pub fn handle_store_meta(dht_meta_data: DhtMetaData, context: Arc) { == CrudStatus::Modified { log_debug!(context, "net/handle: HandleStoreMeta: got CRUD LINK. processing..."); - let entry_header_pair: EntryHeaderPair = serde_json::from_str( + let header_with_its_entry: HeaderWithItsEntry = serde_json::from_str( //should be careful doing slice access, it might panic &serde_json::to_string(&dht_meta_data.content_list[0]) - .expect("dht_meta_data should be EntryHeaderPair"), + .expect("dht_meta_data should be HeaderWithItsEntry"), ) - .expect("dht_meta_data should be EntryHeaderPair"); + .expect("dht_meta_data should be HeaderWithItsEntry"); thread::spawn(move || { if let Err(error) = - context.block_on(hold_update_workflow(entry_header_pair, context.clone())) + context.block_on(hold_update_workflow(header_with_its_entry, context.clone())) { log_error!(context, "net/dht: {}", error) } diff --git a/crates/core/src/network/entry_header_pair.rs b/crates/core/src/network/header_with_its_entry.rs similarity index 100% rename from crates/core/src/network/entry_header_pair.rs rename to crates/core/src/network/header_with_its_entry.rs diff --git a/crates/core/src/network/mod.rs b/crates/core/src/network/mod.rs index 753d05e675..1e0da8b38f 100644 --- a/crates/core/src/network/mod.rs +++ b/crates/core/src/network/mod.rs @@ -1,6 +1,6 @@ pub mod actions; pub mod direct_message; -pub mod entry_header_pair; +pub mod header_with_its_entry; pub mod handler; pub mod reducers; pub mod state; diff --git a/crates/core/src/network/reducers/publish_header_entry.rs b/crates/core/src/network/reducers/publish_header_entry.rs index 3987f9ca31..af4322b853 100644 --- a/crates/core/src/network/reducers/publish_header_entry.rs +++ b/crates/core/src/network/reducers/publish_header_entry.rs @@ -1,10 +1,10 @@ use crate::{ action::ActionWrapper, - agent::state::create_entry_header_pair_for_header, + agent::state::create_header_with_its_entry_for_header, network::{ actions::NetworkActionResponse, + header_with_its_entry::HeaderWithItsEntry, entry_aspect::EntryAspect, - entry_header_pair::EntryHeaderPair, reducers::{publish::entry_data_to_entry_aspect_data, send}, state::NetworkState, }, @@ -26,9 +26,9 @@ fn publish_header( root_state: &State, chain_header: ChainHeader, ) -> Result<(), HolochainError> { - let entry_header_pair = - create_entry_header_pair_for_header(&StateWrapper::from(root_state.clone()), chain_header)?; - let entry = entry_header_pair.entry(); + let header_with_its_entry = + create_header_with_its_entry_for_header(&StateWrapper::from(root_state.clone()), chain_header)?; + let entry = header_with_its_entry.entry(); send( network_state, Lib3hClientProtocol::PublishEntry(ProvidedEntryData { @@ -38,7 +38,7 @@ fn publish_header( entry_address: entry.address().into(), aspect_list: vec![entry_data_to_entry_aspect_data(&EntryAspect::Content( entry, - entry_header_pair.header(), + header_with_its_entry.header(), ))], }, }), @@ -51,8 +51,8 @@ fn reduce_publish_header_entry_inner( address: &Address, ) -> Result<(), HolochainError> { network_state.initialized()?; - let entry_header_pair = EntryHeaderPair::fetch_entry_header_pair(&address, root_state)?; - publish_header(network_state, root_state, entry_header_pair.header()) + let header_with_its_entry = HeaderWithItsEntry::fetch_header_with_its_entry(&address, root_state)?; + publish_header(network_state, root_state, header_with_its_entry.header()) } pub fn reduce_publish_header_entry( diff --git a/crates/core/src/nucleus/reducers/queue_zome_function_call.rs b/crates/core/src/nucleus/reducers/queue_zome_function_call.rs index e72ab11d86..c2c5a9b6e6 100644 --- a/crates/core/src/nucleus/reducers/queue_zome_function_call.rs +++ b/crates/core/src/nucleus/reducers/queue_zome_function_call.rs @@ -5,7 +5,7 @@ use crate::{ }; /// Reduce AddPendingValidation Action. -/// Inserts boxed EntryHeaderPair and dependencies into state, referenced with +/// Inserts boxed HeaderWithItsEntry and dependencies into state, referenced with /// the entry's address. #[allow(unknown_lints)] #[allow(clippy::needless_pass_by_value)] diff --git a/crates/core/src/nucleus/validation/build_from_dht.rs b/crates/core/src/nucleus/validation/build_from_dht.rs index 187cb0992b..99c8fa2005 100644 --- a/crates/core/src/nucleus/validation/build_from_dht.rs +++ b/crates/core/src/nucleus/validation/build_from_dht.rs @@ -1,5 +1,5 @@ use crate::{ - context::Context, entry::CanPublish, network::entry_header_pair::EntryHeaderPair, + context::Context, entry::CanPublish, network::header_with_its_entry::HeaderWithItsEntry, workflows::get_entry_result::get_entry_with_meta_workflow, }; use holochain_core_types::{ @@ -85,11 +85,11 @@ async fn public_chain_entries_from_headers_dht( } pub(crate) async fn try_make_validation_package_dht( - entry_header_pair: &EntryHeaderPair, + header_with_its_entry: &HeaderWithItsEntry, validation_package_definition: &ValidationPackageDefinition, context: Arc, ) -> Result { - let entry_header = entry_header_pair.header(); + let entry_header = header_with_its_entry.header(); log_debug!( context, "Constructing validation package from DHT for entry with address: {}", @@ -204,12 +204,12 @@ pub mod tests { .next() .expect("Must be able to get header for just published entry"); - let entry_header_pair = EntryHeaderPair::try_from_header_and_entry(header, entry)?; + let header_with_its_entry = HeaderWithItsEntry::try_from_header_and_entry(header, entry)?; // jack (the author) retrieves a local validation package let local_validation_package = context2 .block_on(try_make_local_validation_package( - &entry_header_pair, + &header_with_its_entry, &ValidationPackageDefinition::ChainFull, context2.clone(), )) @@ -218,7 +218,7 @@ pub mod tests { // jill reconstructs one from published headers let dht_validation_package = context1 .block_on(try_make_validation_package_dht( - &entry_header_pair, + &header_with_its_entry, &ValidationPackageDefinition::ChainFull, context1.clone(), )) diff --git a/crates/core/src/scheduled_jobs/state_dump.rs b/crates/core/src/scheduled_jobs/state_dump.rs index ef2c354382..1336528b44 100644 --- a/crates/core/src/scheduled_jobs/state_dump.rs +++ b/crates/core/src/scheduled_jobs/state_dump.rs @@ -53,8 +53,8 @@ pub fn state_dump(context: Arc) { format!( "<{}({})> {}: depends on : {:?}", pending.workflow.to_string(), - pending.entry_header_pair.header().entry_type(), - pending.entry_header_pair.entry().address(), + pending.header_with_its_entry.header().entry_type(), + pending.header_with_its_entry.entry().address(), pending .dependencies .iter() diff --git a/crates/core/src/workflows/hold_entry.rs b/crates/core/src/workflows/hold_entry.rs index c316d6b4a4..3ac3acb9e4 100644 --- a/crates/core/src/workflows/hold_entry.rs +++ b/crates/core/src/workflows/hold_entry.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, - network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, + context::Context, dht::actions::hold_aspect::hold_aspect, network::header_with_its_entry::HeaderWithItsEntry, + nucleus::validation::validate_entry, }; use crate::{nucleus::validation::ValidationError, workflows::validation_package}; @@ -15,11 +15,11 @@ use holochain_persistence_api::cas::content::AddressableContent; use std::sync::Arc; pub async fn hold_entry_workflow( - entry_header_pair: &EntryHeaderPair, + header_with_its_entry: &HeaderWithItsEntry, context: Arc, ) -> Result<(), HolochainError> { // 1. Get hold of validation package - let maybe_validation_package = validation_package(&entry_header_pair, context.clone()) + let maybe_validation_package = validation_package(&header_with_its_entry, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; @@ -43,7 +43,7 @@ pub async fn hold_entry_workflow( // 3. Validate the entry validate_entry( - entry_header_pair.entry(), + header_with_its_entry.entry(), None, validation_data, &context @@ -51,13 +51,13 @@ pub async fn hold_entry_workflow( .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: {:?}", - entry_header_pair.entry().address(), + header_with_its_entry.entry().address(), dependencies, ); HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_entry: Entry {} is NOT valid! Validation error: {:?}", - entry_header_pair.entry().address(), + header_with_its_entry.entry().address(), err, ); HolochainError::from(err) @@ -67,17 +67,17 @@ pub async fn hold_entry_workflow( log_debug!( context, "workflow/hold_entry: is valid! {}", - entry_header_pair.entry().address() + header_with_its_entry.entry().address() ); // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Content(entry_header_pair.entry(), entry_header_pair.header()); + let aspect = EntryAspect::Content(header_with_its_entry.entry(), header_with_its_entry.header()); hold_aspect(aspect, context.clone()).await?; log_debug!( context, "workflow/hold_entry: HOLDING: {}", - entry_header_pair.entry().address() + header_with_its_entry.entry().address() ); Ok(()) @@ -127,10 +127,10 @@ pub mod tests { let header = agent1_state .get_most_recent_header_for_entry(&entry) .expect("There must be a header in the author's source chain after commit"); - let entry_header_pair = EntryHeaderPair::try_from_header_and_entry(header, entry)?; + let header_with_its_entry = HeaderWithItsEntry::try_from_header_and_entry(header, entry)?; // Call hold_entry_workflow on victim DHT node - let result = context2.block_on(hold_entry_workflow(&entry_header_pair, &context2)); + let result = context2.block_on(hold_entry_workflow(&header_with_its_entry, &context2)); // ... and expect validation to fail with message defined in test WAT: assert!(result.is_err()); diff --git a/crates/core/src/workflows/hold_entry_remove.rs b/crates/core/src/workflows/hold_entry_remove.rs index 2efea72476..18d9052c25 100644 --- a/crates/core/src/workflows/hold_entry_remove.rs +++ b/crates/core/src/workflows/hold_entry_remove.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, - network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, + context::Context, dht::actions::hold_aspect::hold_aspect, network::header_with_its_entry::HeaderWithItsEntry, + nucleus::validation::validate_entry, }; use crate::{nucleus::validation::ValidationError, workflows::validation_package}; @@ -12,11 +12,11 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn hold_remove_workflow( - entry_header_pair: &EntryHeaderPair, + header_with_its_entry: &HeaderWithItsEntry, context: Arc, ) -> Result<(), HolochainError> { // 1. Get hold of validation package - let maybe_validation_package = validation_package(entry_header_pair, context.clone()) + let maybe_validation_package = validation_package(header_with_its_entry, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; @@ -35,7 +35,7 @@ pub async fn hold_remove_workflow( // 3. Validate the entry validate_entry( - entry_header_pair.entry(), + header_with_its_entry.entry(), None, validation_data, &context @@ -46,7 +46,7 @@ pub async fn hold_remove_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_remove: Entry removal {:?} is NOT valid! Validation error: {:?}", - entry_header_pair.entry(), + header_with_its_entry.entry(), err, ); HolochainError::from(err) @@ -55,7 +55,7 @@ pub async fn hold_remove_workflow( })?; // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Deletion(entry_header_pair.header()); + let aspect = EntryAspect::Deletion(header_with_its_entry.header()); hold_aspect(aspect, context.clone()).await?; Ok(()) } diff --git a/crates/core/src/workflows/hold_entry_update.rs b/crates/core/src/workflows/hold_entry_update.rs index ebeb453df8..fc3a9518be 100644 --- a/crates/core/src/workflows/hold_entry_update.rs +++ b/crates/core/src/workflows/hold_entry_update.rs @@ -1,7 +1,7 @@ use crate::{ context::Context, dht::actions::hold_aspect::hold_aspect, - network::entry_header_pair::EntryHeaderPair, + network::header_with_its_entry::HeaderWithItsEntry, nucleus::validation::{validate_entry, ValidationError}, workflows::validation_package, }; @@ -13,14 +13,14 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn hold_update_workflow( - entry_header_pair: &EntryHeaderPair, + header_with_its_entry: &HeaderWithItsEntry, context: Arc, ) -> Result<(), HolochainError> { - let entry = entry_header_pair.entry(); - let header = entry_header_pair.header(); + let entry = header_with_its_entry.entry(); + let header = header_with_its_entry.header(); // 1. Get hold of validation package - let maybe_validation_package = validation_package(&entry_header_pair, context.clone()) + let maybe_validation_package = validation_package(&header_with_its_entry, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; @@ -55,7 +55,7 @@ pub async fn hold_update_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_update: Entry update {:?} is NOT valid! Validation error: {:?}", - entry_header_pair.entry(), + header_with_its_entry.entry(), err, ); HolochainError::from(err) @@ -64,7 +64,7 @@ pub async fn hold_update_workflow( })?; // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Update(entry_header_pair.entry(), entry_header_pair.header()); + let aspect = EntryAspect::Update(header_with_its_entry.entry(), header_with_its_entry.header()); hold_aspect(aspect, context.clone()).await?; Ok(()) From 5e5713598f4a7ecf117b1098ff05600a89ccbbcb Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Sat, 21 Dec 2019 23:00:47 +1100 Subject: [PATCH 78/79] actually rename entry_header_pair, EntryHeaderPair to header_with_its_entry, HeaderWithItsEntry. nc, nt, nf all pass --- crates/core/src/action.rs | 2 +- crates/core/src/dht/dht_reducers.rs | 17 ++-- crates/core/src/dht/pending_validations.rs | 20 ++--- .../core/src/entry/validation_dependencies.rs | 27 ++++--- crates/core/src/network/handler/lists.rs | 14 ++-- crates/core/src/network/handler/mod.rs | 5 +- .../core/src/network/header_with_its_entry.rs | 22 ++--- crates/core/src/network/mod.rs | 2 +- crates/core/src/network/reducers/publish.rs | 80 ++++++++++--------- .../network/reducers/publish_header_entry.rs | 11 ++- crates/core/src/workflows/hold_entry.rs | 9 ++- .../core/src/workflows/hold_entry_remove.rs | 4 +- .../core/src/workflows/hold_entry_update.rs | 5 +- crates/core/src/workflows/hold_link.rs | 24 +++--- crates/core/src/workflows/mod.rs | 53 ++++++------ crates/core/src/workflows/remove_link.rs | 18 ++--- 16 files changed, 171 insertions(+), 142 deletions(-) diff --git a/crates/core/src/action.rs b/crates/core/src/action.rs index 9684c23530..e501cf2f70 100644 --- a/crates/core/src/action.rs +++ b/crates/core/src/action.rs @@ -2,9 +2,9 @@ use crate::{ agent::state::AgentState, dht::pending_validations::PendingValidation, network::{ - header_with_its_entry::HeaderWithItsEntry, direct_message::DirectMessage, entry_aspect::EntryAspect, + header_with_its_entry::HeaderWithItsEntry, query::{GetLinksNetworkQuery, NetworkQueryResult}, state::NetworkState, }, diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index c63b9a28ab..7448a65315 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -203,7 +203,11 @@ pub fn reduce_prune(old_store: &DhtStore, _action_wrapper: &ActionWrapper) -> Op .unique_by(|p| { ( p.pending.workflow.clone(), - p.pending.entry_header_pair.header().entry_address().clone(), + p.pending + .header_with_its_entry + .header() + .entry_address() + .clone(), ) }) .cloned() @@ -263,7 +267,7 @@ pub mod tests { pending_validations::{PendingValidation, PendingValidationStruct, ValidatingWorkflow}, }, instance::tests::test_context, - network::entry_header_pair::EntryHeaderPair, + network::header_with_its_entry::HeaderWithItsEntry, state::test_store, }; use bitflags::_core::time::Duration; @@ -562,10 +566,11 @@ pub mod tests { header: ChainHeader, workflow: ValidatingWorkflow, ) -> PendingValidation { - match EntryHeaderPair::try_from_header_and_entry(header.clone(), entry.clone()) { - Ok(entry_header_pair) => { - Arc::new(PendingValidationStruct::new(entry_header_pair, workflow)) - } + match HeaderWithItsEntry::try_from_header_and_entry(header.clone(), entry.clone()) { + Ok(header_with_its_entry) => Arc::new(PendingValidationStruct::new( + header_with_its_entry, + workflow, + )), Err(err) => { let err_msg = format!( "Tried to create a pending validation, got an error: {}", diff --git a/crates/core/src/dht/pending_validations.rs b/crates/core/src/dht/pending_validations.rs index 26f8971bfa..0c08c71e7c 100644 --- a/crates/core/src/dht/pending_validations.rs +++ b/crates/core/src/dht/pending_validations.rs @@ -1,6 +1,6 @@ use crate::{ entry::validation_dependencies::ValidationDependencies, - network::entry_header_pair::EntryHeaderPair, + network::header_with_its_entry::HeaderWithItsEntry, }; use holochain_core_types::{ chain_header::ChainHeader, @@ -71,17 +71,17 @@ impl fmt::Display for ValidatingWorkflow { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, DefaultJson)] pub struct PendingValidationStruct { - pub entry_header_pair: EntryHeaderPair, + pub header_with_its_entry: HeaderWithItsEntry, pub dependencies: Vec
, pub workflow: ValidatingWorkflow, uuid: ProcessUniqueId, } impl PendingValidationStruct { - pub fn new(entry_header_pair: EntryHeaderPair, workflow: ValidatingWorkflow) -> Self { - let dependencies = entry_header_pair.get_validation_dependencies(); + pub fn new(header_with_its_entry: HeaderWithItsEntry, workflow: ValidatingWorkflow) -> Self { + let dependencies = header_with_its_entry.get_validation_dependencies(); Self { - entry_header_pair, + header_with_its_entry, dependencies, workflow, uuid: ProcessUniqueId::new(), @@ -101,9 +101,9 @@ impl PendingValidationStruct { entry_aspect: EntryAspect, validating_workflow: ValidatingWorkflow, ) -> Result { - match EntryHeaderPair::try_from_header_and_entry(header, entry) { - Ok(entry_header_pair) => Ok(PendingValidationStruct::new( - entry_header_pair, + match HeaderWithItsEntry::try_from_header_and_entry(header, entry) { + Ok(header_with_its_entry) => Ok(PendingValidationStruct::new( + header_with_its_entry, validating_workflow, )), Err(error) => { @@ -182,8 +182,8 @@ impl TryFrom for PendingValidationStruct { impl From for EntryAspect { fn from(pending: PendingValidationStruct) -> EntryAspect { - let entry = pending.entry_header_pair.entry(); - let header = pending.entry_header_pair.header(); + let entry = pending.header_with_its_entry.entry(); + let header = pending.header_with_its_entry.header(); match pending.workflow { ValidatingWorkflow::HoldEntry => EntryAspect::Content(entry, header), ValidatingWorkflow::HoldLink => { diff --git a/crates/core/src/entry/validation_dependencies.rs b/crates/core/src/entry/validation_dependencies.rs index 7026c48e50..16604654af 100644 --- a/crates/core/src/entry/validation_dependencies.rs +++ b/crates/core/src/entry/validation_dependencies.rs @@ -1,4 +1,4 @@ -use crate::network::entry_header_pair::EntryHeaderPair; +use crate::network::header_with_its_entry::HeaderWithItsEntry; use holochain_core_types::entry::Entry; use holochain_persistence_api::cas::content::Address; @@ -6,7 +6,7 @@ pub trait ValidationDependencies { fn get_validation_dependencies(&self) -> Vec
; } -impl ValidationDependencies for EntryHeaderPair { +impl ValidationDependencies for HeaderWithItsEntry { fn get_validation_dependencies(&self) -> Vec
{ match &self.entry() { Entry::App(_, _) => { @@ -47,7 +47,7 @@ impl ValidationDependencies for EntryHeaderPair { #[cfg(test)] pub mod tests { use super::*; - use crate::network::entry_header_pair::EntryHeaderPair; + use crate::network::header_with_its_entry::HeaderWithItsEntry; use holochain_core_types::{ agent::AgentId, chain_header::ChainHeader, error::HolochainError, link::link_data::LinkData, time::Iso8601, @@ -66,16 +66,21 @@ pub mod tests { ) } - fn try_entry_header_pair_from_entry(entry: Entry) -> Result { + fn try_header_with_its_entry_from_entry( + entry: Entry, + ) -> Result { let header = test_header_for_entry(&entry); - EntryHeaderPair::try_from_header_and_entry(header, entry) + HeaderWithItsEntry::try_from_header_and_entry(header, entry) } #[test] fn test_get_validation_dependencies_app_entry() -> Result<(), HolochainError> { let entry = Entry::App("entry_type".into(), "content".into()); - try_entry_header_pair_from_entry(entry).map(|entry_header_pair| { - assert_eq!(entry_header_pair.get_validation_dependencies(), Vec::new()) + try_header_with_its_entry_from_entry(entry).map(|header_with_its_entry| { + assert_eq!( + header_with_its_entry.get_validation_dependencies(), + Vec::new() + ) }) } @@ -89,9 +94,9 @@ pub mod tests { test_header_for_entry(&Entry::App("".into(), "".into())), AgentId::new("HcAgentId", "key".into()), )); - try_entry_header_pair_from_entry(entry).map(|entry_header_pair| { + try_header_with_its_entry_from_entry(entry).map(|header_with_its_entry| { assert_eq!( - entry_header_pair.get_validation_dependencies(), + header_with_its_entry.get_validation_dependencies(), vec![ Address::from("QmBaseAddress"), Address::from("QmTargetAddress") @@ -112,9 +117,9 @@ pub mod tests { &Iso8601::from(0), ); let entry = Entry::ChainHeader(header_entry_content); - try_entry_header_pair_from_entry(entry).map(|entry_header_pair| { + try_header_with_its_entry_from_entry(entry).map(|header_with_its_entry| { assert_eq!( - entry_header_pair.get_validation_dependencies(), + header_with_its_entry.get_validation_dependencies(), vec![Address::from("QmPreviousHeaderAddress")], ) }) diff --git a/crates/core/src/network/handler/lists.rs b/crates/core/src/network/handler/lists.rs index 18acf21b35..0bbcb3ec90 100644 --- a/crates/core/src/network/handler/lists.rs +++ b/crates/core/src/network/handler/lists.rs @@ -1,6 +1,6 @@ use crate::{ action::{Action, ActionWrapper}, - agent::state::create_entry_header_pair_for_header, + agent::state::create_header_with_its_entry_for_header, context::Context, dht::aspect_map::{AspectMap, AspectMapBare}, entry::CanPublish, @@ -77,7 +77,7 @@ fn create_authoring_map(context: Arc) -> AspectMap { // So we iterate over all our source chain headers for chain_header in context.state().unwrap().agent().iter_chain() { // Create an entry that represents the header - match create_entry_header_pair_for_header(&state, chain_header.clone()) { + match create_header_with_its_entry_for_header(&state, chain_header.clone()) { Err(e) => { log_error!( context, @@ -86,10 +86,12 @@ fn create_authoring_map(context: Arc) -> AspectMap { ); continue; } - Ok(entry_header_pair) => { - let entry_hash = entry_header_pair.entry().address(); - let content_aspect = - EntryAspect::Content(entry_header_pair.entry(), entry_header_pair.header()); + Ok(header_with_its_entry) => { + let entry_hash = header_with_its_entry.entry().address(); + let content_aspect = EntryAspect::Content( + header_with_its_entry.entry(), + header_with_its_entry.header(), + ); let aspect_hash = AspectHash::from(content_aspect.address()); address_map .entry(entry_hash.into()) diff --git a/crates/core/src/network/handler/mod.rs b/crates/core/src/network/handler/mod.rs index 7bbd3f7f35..77e1f9883f 100644 --- a/crates/core/src/network/handler/mod.rs +++ b/crates/core/src/network/handler/mod.rs @@ -10,7 +10,6 @@ use crate::{ context::Context, entry::CanPublish, network::{ - header_with_its_entry::HeaderWithItsEntry, direct_message::DirectMessage, entry_aspect::EntryAspect, handler::{ @@ -20,6 +19,7 @@ use crate::{ send::*, store::*, }, + header_with_its_entry::HeaderWithItsEntry, }, workflows::get_entry_result::get_entry_with_meta_workflow, }; @@ -354,7 +354,8 @@ fn get_content_aspect( } }; - let header_with_its_entry = maybe_header_with_its_entry.ok_or(HolochainError::EntryNotFoundLocally)?; + let header_with_its_entry = + maybe_header_with_its_entry.ok_or(HolochainError::EntryNotFoundLocally)?; let _ = header_with_its_entry .entry() diff --git a/crates/core/src/network/header_with_its_entry.rs b/crates/core/src/network/header_with_its_entry.rs index 6f435cd5f3..5646a8f0e9 100644 --- a/crates/core/src/network/header_with_its_entry.rs +++ b/crates/core/src/network/header_with_its_entry.rs @@ -6,24 +6,24 @@ use crate::{ use holochain_core_types::{chain_header::ChainHeader, entry::Entry, error::HolochainError}; use holochain_persistence_api::cas::content::{Address, AddressableContent}; -/// A `EntryHeaderPair` cannot be constructed unless the entry address in the -/// `ChainHeader` that is within the `EntryHeaderPair` is the same as the address -/// of the `Entry` that is also within the `EntryHeaderPair`. +/// A `HeaderWithItsEntry` cannot be constructed unless the entry address in the +/// `ChainHeader` that is within the `HeaderWithItsEntry` is the same as the address +/// of the `Entry` that is also within the `HeaderWithItsEntry`. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] -pub struct EntryHeaderPair(ChainHeader, Entry); +pub struct HeaderWithItsEntry(ChainHeader, Entry); -impl EntryHeaderPair { +impl HeaderWithItsEntry { // It seems best to not have a new method, since stylistically it is expected to return Self, whereas constructing could fail. pub fn try_from_header_and_entry( header: ChainHeader, entry: Entry, - ) -> Result { + ) -> Result { let header_entry_address = header.entry_address(); let entry_address = entry.address(); if header_entry_address.clone() == entry_address { - Ok(EntryHeaderPair(header, entry)) + Ok(HeaderWithItsEntry(header, entry)) } else { - let basic_error_msg = "Tried to create a EntryHeaderPair, but got a + let basic_error_msg = "Tried to create a HeaderWithItsEntry, but got a mismatch with the header's entry address and the entry's address."; let error_msg = format!( @@ -50,10 +50,10 @@ impl EntryHeaderPair { self.1.clone() } - pub fn fetch_entry_header_pair( + pub fn fetch_header_with_its_entry( address: &Address, state: &State, - ) -> Result { + ) -> Result { let entry = state .agent() .chain_store() @@ -68,6 +68,6 @@ impl EntryHeaderPair { ); HolochainError::from(error_msg) })?; - EntryHeaderPair::try_from_header_and_entry(header, entry) + HeaderWithItsEntry::try_from_header_and_entry(header, entry) } } diff --git a/crates/core/src/network/mod.rs b/crates/core/src/network/mod.rs index 1e0da8b38f..0c0206d88a 100644 --- a/crates/core/src/network/mod.rs +++ b/crates/core/src/network/mod.rs @@ -1,7 +1,7 @@ pub mod actions; pub mod direct_message; -pub mod header_with_its_entry; pub mod handler; +pub mod header_with_its_entry; pub mod reducers; pub mod state; #[cfg(test)] diff --git a/crates/core/src/network/reducers/publish.rs b/crates/core/src/network/reducers/publish.rs index d519c9bd24..e23390e867 100644 --- a/crates/core/src/network/reducers/publish.rs +++ b/crates/core/src/network/reducers/publish.rs @@ -2,7 +2,7 @@ use crate::{ action::ActionWrapper, network::{ actions::NetworkActionResponse, entry_aspect::EntryAspect, - entry_header_pair::EntryHeaderPair, reducers::send, state::NetworkState, + header_with_its_entry::HeaderWithItsEntry, reducers::send, state::NetworkState, }, state::State, }; @@ -37,7 +37,7 @@ pub fn entry_data_to_entry_aspect_data(ea: &EntryAspect) -> EntryAspectData { /// Send to network a PublishDhtData message fn publish_entry( network_state: &mut NetworkState, - entry_header_pair: &EntryHeaderPair, + header_with_its_entry: &HeaderWithItsEntry, ) -> Result<(), HolochainError> { send( network_state, @@ -45,10 +45,10 @@ fn publish_entry( space_address: network_state.dna_address.clone().unwrap().into(), provider_agent_id: network_state.agent_id.clone().unwrap().into(), entry: EntryData { - entry_address: entry_header_pair.entry().address().into(), + entry_address: header_with_its_entry.entry().address().into(), aspect_list: vec![entry_data_to_entry_aspect_data(&EntryAspect::Content( - entry_header_pair.entry(), - entry_header_pair.header(), + header_with_its_entry.entry(), + header_with_its_entry.header(), ))], }, }), @@ -60,15 +60,16 @@ fn publish_update_delete_meta( network_state: &mut NetworkState, orig_entry_address: Address, crud_status: CrudStatus, - entry_header_pair: &EntryHeaderPair, + header_with_its_entry: &HeaderWithItsEntry, ) -> Result<(), HolochainError> { // publish crud-status let aspect = match crud_status { - CrudStatus::Modified => { - EntryAspect::Update(entry_header_pair.entry(), entry_header_pair.header()) - } - CrudStatus::Deleted => EntryAspect::Deletion(entry_header_pair.header()), + CrudStatus::Modified => EntryAspect::Update( + header_with_its_entry.entry(), + header_with_its_entry.header(), + ), + CrudStatus::Deleted => EntryAspect::Deletion(header_with_its_entry.header()), crud => { return Err(HolochainError::ErrorGeneric(format!( "Unexpeced CRUD variant {:?}", @@ -93,24 +94,24 @@ fn publish_update_delete_meta( Ok(()) } -/// Send to network a PublishMeta message holding a link metadata to `entry_header_pair` +/// Send to network a PublishMeta message holding a link metadata to `header_with_its_entry` fn publish_link_meta( network_state: &mut NetworkState, - entry_header_pair: &EntryHeaderPair, + header_with_its_entry: &HeaderWithItsEntry, ) -> Result<(), HolochainError> { - let (base, aspect) = match entry_header_pair.entry() { + let (base, aspect) = match header_with_its_entry.entry() { Entry::LinkAdd(link_data) => ( link_data.link().base().clone(), - EntryAspect::LinkAdd(link_data, entry_header_pair.header()), + EntryAspect::LinkAdd(link_data, header_with_its_entry.header()), ), Entry::LinkRemove((link_data, links_to_remove)) => ( link_data.link().base().clone(), - EntryAspect::LinkRemove((link_data, links_to_remove), entry_header_pair.header()), + EntryAspect::LinkRemove((link_data, links_to_remove), header_with_its_entry.header()), ), _ => { return Err(HolochainError::ErrorGeneric(format!( "Received bad entry type. Expected Entry::LinkAdd/Remove received {:?}", - entry_header_pair.entry(), + header_with_its_entry.entry(), ))); } }; @@ -134,39 +135,42 @@ fn reduce_publish_inner( ) -> Result<(), HolochainError> { network_state.initialized()?; - let entry_header_pair = EntryHeaderPair::fetch_entry_header_pair(&address, root_state)?; + let header_with_its_entry = + HeaderWithItsEntry::fetch_header_with_its_entry(&address, root_state)?; - match entry_header_pair.entry().entry_type() { - EntryType::AgentId => publish_entry(network_state, &entry_header_pair), - EntryType::App(_) => publish_entry(network_state, &entry_header_pair).and_then(|_| { - match entry_header_pair.header().link_update_delete() { + match header_with_its_entry.entry().entry_type() { + EntryType::AgentId => publish_entry(network_state, &header_with_its_entry), + EntryType::App(_) => publish_entry(network_state, &header_with_its_entry).and_then(|_| { + match header_with_its_entry.header().link_update_delete() { Some(modified_entry) => publish_update_delete_meta( network_state, modified_entry, CrudStatus::Modified, - &entry_header_pair.clone(), - ), - None => Ok(()), - } - }), - EntryType::LinkAdd => publish_entry(network_state, &entry_header_pair) - .and_then(|_| publish_link_meta(network_state, &entry_header_pair)), - EntryType::LinkRemove => publish_entry(network_state, &entry_header_pair) - .and_then(|_| publish_link_meta(network_state, &entry_header_pair)), - EntryType::Deletion => publish_entry(network_state, &entry_header_pair).and_then(|_| { - match entry_header_pair.header().link_update_delete() { - Some(modified_entry) => publish_update_delete_meta( - network_state, - modified_entry, - CrudStatus::Deleted, - &entry_header_pair.clone(), + &header_with_its_entry.clone(), ), None => Ok(()), } }), + EntryType::LinkAdd => publish_entry(network_state, &header_with_its_entry) + .and_then(|_| publish_link_meta(network_state, &header_with_its_entry)), + EntryType::LinkRemove => publish_entry(network_state, &header_with_its_entry) + .and_then(|_| publish_link_meta(network_state, &header_with_its_entry)), + EntryType::Deletion => { + publish_entry(network_state, &header_with_its_entry).and_then(|_| { + match header_with_its_entry.header().link_update_delete() { + Some(modified_entry) => publish_update_delete_meta( + network_state, + modified_entry, + CrudStatus::Deleted, + &header_with_its_entry.clone(), + ), + None => Ok(()), + } + }) + } _ => Err(HolochainError::NotImplemented(format!( "reduce_publish_inner not implemented for {}", - entry_header_pair.entry().entry_type() + header_with_its_entry.entry().entry_type() ))), } } diff --git a/crates/core/src/network/reducers/publish_header_entry.rs b/crates/core/src/network/reducers/publish_header_entry.rs index af4322b853..8f6fb9b949 100644 --- a/crates/core/src/network/reducers/publish_header_entry.rs +++ b/crates/core/src/network/reducers/publish_header_entry.rs @@ -3,8 +3,8 @@ use crate::{ agent::state::create_header_with_its_entry_for_header, network::{ actions::NetworkActionResponse, - header_with_its_entry::HeaderWithItsEntry, entry_aspect::EntryAspect, + header_with_its_entry::HeaderWithItsEntry, reducers::{publish::entry_data_to_entry_aspect_data, send}, state::NetworkState, }, @@ -26,8 +26,10 @@ fn publish_header( root_state: &State, chain_header: ChainHeader, ) -> Result<(), HolochainError> { - let header_with_its_entry = - create_header_with_its_entry_for_header(&StateWrapper::from(root_state.clone()), chain_header)?; + let header_with_its_entry = create_header_with_its_entry_for_header( + &StateWrapper::from(root_state.clone()), + chain_header, + )?; let entry = header_with_its_entry.entry(); send( network_state, @@ -51,7 +53,8 @@ fn reduce_publish_header_entry_inner( address: &Address, ) -> Result<(), HolochainError> { network_state.initialized()?; - let header_with_its_entry = HeaderWithItsEntry::fetch_header_with_its_entry(&address, root_state)?; + let header_with_its_entry = + HeaderWithItsEntry::fetch_header_with_its_entry(&address, root_state)?; publish_header(network_state, root_state, header_with_its_entry.header()) } diff --git a/crates/core/src/workflows/hold_entry.rs b/crates/core/src/workflows/hold_entry.rs index 3ac3acb9e4..00d9377a8b 100644 --- a/crates/core/src/workflows/hold_entry.rs +++ b/crates/core/src/workflows/hold_entry.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, network::header_with_its_entry::HeaderWithItsEntry, - nucleus::validation::validate_entry, + context::Context, dht::actions::hold_aspect::hold_aspect, + network::header_with_its_entry::HeaderWithItsEntry, nucleus::validation::validate_entry, }; use crate::{nucleus::validation::ValidationError, workflows::validation_package}; @@ -71,7 +71,10 @@ pub async fn hold_entry_workflow( ); // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Content(header_with_its_entry.entry(), header_with_its_entry.header()); + let aspect = EntryAspect::Content( + header_with_its_entry.entry(), + header_with_its_entry.header(), + ); hold_aspect(aspect, context.clone()).await?; log_debug!( diff --git a/crates/core/src/workflows/hold_entry_remove.rs b/crates/core/src/workflows/hold_entry_remove.rs index 18d9052c25..b51d10ae5c 100644 --- a/crates/core/src/workflows/hold_entry_remove.rs +++ b/crates/core/src/workflows/hold_entry_remove.rs @@ -1,6 +1,6 @@ use crate::{ - context::Context, dht::actions::hold_aspect::hold_aspect, network::header_with_its_entry::HeaderWithItsEntry, - nucleus::validation::validate_entry, + context::Context, dht::actions::hold_aspect::hold_aspect, + network::header_with_its_entry::HeaderWithItsEntry, nucleus::validation::validate_entry, }; use crate::{nucleus::validation::ValidationError, workflows::validation_package}; diff --git a/crates/core/src/workflows/hold_entry_update.rs b/crates/core/src/workflows/hold_entry_update.rs index fc3a9518be..7246b8dd78 100644 --- a/crates/core/src/workflows/hold_entry_update.rs +++ b/crates/core/src/workflows/hold_entry_update.rs @@ -64,7 +64,10 @@ pub async fn hold_update_workflow( })?; // 4. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::Update(header_with_its_entry.entry(), header_with_its_entry.header()); + let aspect = EntryAspect::Update( + header_with_its_entry.entry(), + header_with_its_entry.header(), + ); hold_aspect(aspect, context.clone()).await?; Ok(()) diff --git a/crates/core/src/workflows/hold_link.rs b/crates/core/src/workflows/hold_link.rs index 099d609a14..c1a7ebd770 100644 --- a/crates/core/src/workflows/hold_link.rs +++ b/crates/core/src/workflows/hold_link.rs @@ -1,6 +1,6 @@ use crate::{ context::Context, dht::actions::hold_aspect::hold_aspect, - network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, + network::header_with_its_entry::HeaderWithItsEntry, nucleus::validation::validate_entry, }; use crate::{ @@ -16,10 +16,10 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn hold_link_workflow( - entry_header_pair: &EntryHeaderPair, + header_with_its_entry: &HeaderWithItsEntry, context: Arc, ) -> Result<(), HolochainError> { - let entry = &entry_header_pair.entry(); + let entry = &header_with_its_entry.entry(); let link_add = match entry { Entry::LinkAdd(link_add) => link_add, _ => Err(HolochainError::ErrorGeneric( @@ -31,7 +31,7 @@ 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 = validation_package(&entry_header_pair, context.clone()) + let maybe_validation_package = validation_package(&header_with_its_entry, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; @@ -55,7 +55,7 @@ pub async fn hold_link_workflow( // 3. Validate the entry log_debug!(context, "workflow/hold_link: validate..."); validate_entry( - entry_header_pair.entry(), + header_with_its_entry.entry(), None, validation_data, &context @@ -66,7 +66,7 @@ pub async fn hold_link_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/hold_link: Link {:?} is NOT valid! Validation error: {:?}", - entry_header_pair.entry(), + header_with_its_entry.entry(), err, ); HolochainError::from(err) @@ -76,17 +76,17 @@ pub async fn hold_link_workflow( log_debug!(context, "workflow/hold_link: is valid!"); // 3. If valid store the entry aspect in the local DHT shard - let aspect = EntryAspect::LinkAdd(link_add.clone(), entry_header_pair.header()); + let aspect = EntryAspect::LinkAdd(link_add.clone(), header_with_its_entry.header()); hold_aspect(aspect, context.clone()).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 - hold_entry_workflow(&entry_header_pair, context.clone()).await?; + hold_entry_workflow(&header_with_its_entry, context.clone()).await?; log_debug!( context, "workflow/hold_entry: added! {:?}", - entry_header_pair + header_with_its_entry ); //5. Link has been added to EAV and LinkAdd Entry has been stored on the dht @@ -151,10 +151,12 @@ pub mod tests { let header = agent1_state .get_most_recent_header_for_entry(&link_entry) .expect("There must be a header in the author's source chain after commit"); - let entry_header_pair = EntryHeaderPair::try_from_entry_and_header(header, link_entry)?; + let header_with_its_entry = + HeaderWithItsEntry::try_from_entry_and_header(header, link_entry)?; // Call hold_entry_workflow on victim DHT node - let result = context2.block_on(hold_link_workflow(&entry_header_pair, context2.clone())); + let result = + context2.block_on(hold_link_workflow(&header_with_its_entry, context2.clone())); // ... and expect validation to fail with message defined in test WAT: assert!(result.is_err()); diff --git a/crates/core/src/workflows/mod.rs b/crates/core/src/workflows/mod.rs index 333a5cc6eb..5faa7080f8 100644 --- a/crates/core/src/workflows/mod.rs +++ b/crates/core/src/workflows/mod.rs @@ -15,7 +15,8 @@ use crate::{ context::Context, dht::pending_validations::{PendingValidation, ValidatingWorkflow}, network::{ - actions::get_validation_package::get_validation_package, entry_header_pair::EntryHeaderPair, + actions::get_validation_package::get_validation_package, + header_with_its_entry::HeaderWithItsEntry, }, nucleus::{ actions::build_validation_package::build_validation_package, @@ -43,11 +44,11 @@ use std::sync::Arc; /// Checks the DNA's validation package definition for the given entry type. /// Fails if this entry type needs more than just the header for validation. pub(crate) async fn try_make_local_validation_package( - entry_header_pair: &EntryHeaderPair, + header_with_its_entry: &HeaderWithItsEntry, validation_package_definition: &ValidationPackageDefinition, context: Arc, ) -> Result { - let entry_header = &entry_header_pair.header(); + let entry_header = &header_with_its_entry.header(); match validation_package_definition { ValidationPackageDefinition::Entry => { @@ -55,8 +56,8 @@ pub(crate) async fn try_make_local_validation_package( } _ => { let agent = context.state()?.agent().get_agent()?; - let entry = &entry_header_pair.entry(); - let header = entry_header_pair.header(); + let entry = &header_with_its_entry.entry(); + let header = header_with_its_entry.header(); let overlapping_provenance = header .provenances() .iter() @@ -76,12 +77,12 @@ pub(crate) async fn try_make_local_validation_package( /// Gets hold of the validation package for the given entry by trying several different methods. async fn validation_package( - entry_header_pair: &EntryHeaderPair, + header_with_its_entry: &HeaderWithItsEntry, context: Arc, ) -> Result, HolochainError> { // 0. Call into the DNA to get the validation package definition for this entry // e.g. what data is needed to validate it (chain, entry, headers, etc) - let entry = entry_header_pair.entry(); + let entry = header_with_its_entry.entry(); let validation_package_definition = get_validation_package_definition(&entry, context.clone()) .and_then(|callback_result| match callback_result { CallbackResult::Fail(error_string) => Err(HolochainError::ErrorGeneric(error_string)), @@ -99,10 +100,10 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Trying to build locally", - entry_header_pair.entry().address() + header_with_its_entry.entry().address() ); if let Ok(package) = try_make_local_validation_package( - &entry_header_pair, + &header_with_its_entry, &validation_package_definition, context.clone(), ) @@ -111,7 +112,7 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Successfully built locally", - entry_header_pair.entry().address() + header_with_its_entry.entry().address() ); return Ok(Some(package)); } @@ -120,22 +121,22 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Could not build locally. Trying to retrieve from author", - entry_header_pair.entry().address() + header_with_its_entry.entry().address() ); - match get_validation_package(entry_header_pair.header(), &context).await { + match get_validation_package(header_with_its_entry.header(), &context).await { Ok(Some(package)) => { log_debug!( context, "validation_package:{} - Successfully retrieved from author", - entry_header_pair.entry().address() + header_with_its_entry.entry().address() ); return Ok(Some(package)); } response => log_debug!( context, "validation_package:{} - Direct message to author responded: {:?}", - entry_header_pair.entry().address(), + header_with_its_entry.entry().address(), response, ), } @@ -144,10 +145,10 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Could not retrieve from author. Trying to build from published headers", - entry_header_pair.entry().address() + header_with_its_entry.entry().address() ); if let Ok(package) = try_make_validation_package_dht( - &entry_header_pair, + &header_with_its_entry, &validation_package_definition, context.clone(), ) @@ -156,7 +157,7 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Successfully built from published headers", - entry_header_pair.entry().address() + header_with_its_entry.entry().address() ); return Ok(Some(package)); } @@ -166,7 +167,7 @@ async fn validation_package( log_debug!( context, "validation_package:{} - Could not get validation package!!!", - entry_header_pair.entry().address() + header_with_its_entry.entry().address() ); Err(HolochainError::ErrorGeneric( "Could not get validation package".to_string(), @@ -177,7 +178,7 @@ async fn validation_package( pub mod tests { use super::validation_package; use crate::{ - network::entry_header_pair::EntryHeaderPair, nucleus::actions::tests::*, + network::header_with_its_entry::HeaderWithItsEntry, nucleus::actions::tests::*, workflows::author_entry::author_entry, }; use holochain_core_types::{entry::Entry, error::HolochainError}; @@ -213,9 +214,9 @@ pub mod tests { .next() .expect("Must be able to get header for just published entry"); - EntryHeaderPair::try_from_header_and_entry(header, entry).map(|entry_header_pair| { + HeaderWithItsEntry::try_from_header_and_entry(header, entry).map(|header_with_its_entry| { let validation_package = context1 - .block_on(validation_package(&entry_header_pair, context1.clone())) + .block_on(validation_package(&header_with_its_entry, context1.clone())) .expect("Could not recover a validation package as the non-author"); assert_eq!( @@ -238,19 +239,19 @@ pub async fn run_holding_workflow( ) -> Result<(), HolochainError> { match pending.workflow { ValidatingWorkflow::HoldLink => { - hold_link_workflow(&pending.entry_header_pair, context.clone()).await + hold_link_workflow(&pending.header_with_its_entry, context.clone()).await } ValidatingWorkflow::HoldEntry => { - hold_entry_workflow(&pending.entry_header_pair, context.clone()).await + hold_entry_workflow(&pending.header_with_its_entry, context.clone()).await } ValidatingWorkflow::RemoveLink => { - remove_link_workflow(&pending.entry_header_pair, context.clone()).await + remove_link_workflow(&pending.header_with_its_entry, context.clone()).await } ValidatingWorkflow::UpdateEntry => { - hold_update_workflow(&pending.entry_header_pair, context.clone()).await + hold_update_workflow(&pending.header_with_its_entry, context.clone()).await } ValidatingWorkflow::RemoveEntry => { - hold_remove_workflow(&pending.entry_header_pair, context.clone()).await + hold_remove_workflow(&pending.header_with_its_entry, context.clone()).await } } } diff --git a/crates/core/src/workflows/remove_link.rs b/crates/core/src/workflows/remove_link.rs index e58e4325cd..eb3cc9b70e 100644 --- a/crates/core/src/workflows/remove_link.rs +++ b/crates/core/src/workflows/remove_link.rs @@ -1,6 +1,6 @@ use crate::{ context::Context, dht::actions::hold_aspect::hold_aspect, - network::entry_header_pair::EntryHeaderPair, nucleus::validation::validate_entry, + network::header_with_its_entry::HeaderWithItsEntry, nucleus::validation::validate_entry, workflows::hold_entry::hold_entry_workflow, }; @@ -14,10 +14,10 @@ use holochain_core_types::{ use std::sync::Arc; pub async fn remove_link_workflow( - entry_header_pair: &EntryHeaderPair, + header_with_its_entry: &HeaderWithItsEntry, context: Arc, ) -> Result<(), HolochainError> { - let entry = &entry_header_pair.entry(); + let entry = &header_with_its_entry.entry(); let (link_data, links_to_remove) = match entry { Entry::LinkRemove(data) => data, _ => Err(HolochainError::ErrorGeneric( @@ -32,7 +32,7 @@ pub async fn remove_link_workflow( context, "workflow/remove_link: getting validation package..." ); - let maybe_validation_package = validation_package(&entry_header_pair, context.clone()) + let maybe_validation_package = validation_package(&header_with_its_entry, context.clone()) .await .map_err(|err| { let message = "Could not get validation package from source! -> Add to pending..."; @@ -54,7 +54,7 @@ pub async fn remove_link_workflow( // 3. Validate the entry log_debug!(context, "workflow/remove_link: validate..."); validate_entry( - entry_header_pair.entry(), + header_with_its_entry.entry(), None, validation_data, &context @@ -65,7 +65,7 @@ pub async fn remove_link_workflow( HolochainError::ValidationPending } else { log_warn!(context, "workflow/remove_link: Link {:?} is NOT valid! Validation error: {:?}", - entry_header_pair.entry(), + header_with_its_entry.entry(), err, ); HolochainError::from(err) @@ -78,17 +78,17 @@ pub async fn remove_link_workflow( // 3. If valid store the entry aspect in the local DHT shard let aspect = EntryAspect::LinkRemove( (link_data.clone(), links_to_remove.clone()), - entry_header_pair.header(), + header_with_its_entry.header(), ); hold_aspect(aspect, context.clone()).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``` - hold_entry_workflow(&entry_header_pair, context.clone()).await?; + hold_entry_workflow(&header_with_its_entry, context.clone()).await?; log_debug!( context, "workflow/hold_entry: added! {:?}", - entry_header_pair + header_with_its_entry ); Ok(()) From 960b28f054f33ca7e4168e8e9e1d65822fc1129b Mon Sep 17 00:00:00 2001 From: James Ray <16969914+jamesray1@users.noreply.github.com> Date: Tue, 17 Mar 2020 11:32:32 +1100 Subject: [PATCH 79/79] return result --- crates/core/src/dht/dht_reducers.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/core/src/dht/dht_reducers.rs b/crates/core/src/dht/dht_reducers.rs index 7448a65315..777f58dbc9 100644 --- a/crates/core/src/dht/dht_reducers.rs +++ b/crates/core/src/dht/dht_reducers.rs @@ -6,6 +6,7 @@ use crate::{ dht_store::DhtStore, pending_validations::{PendingValidationWithTimeout, ValidationTimeout}, }, + error::HolochainError, }; use std::sync::Arc; @@ -565,7 +566,7 @@ pub mod tests { entry: Entry, header: ChainHeader, workflow: ValidatingWorkflow, - ) -> PendingValidation { + ) -> Result { match HeaderWithItsEntry::try_from_header_and_entry(header.clone(), entry.clone()) { Ok(header_with_its_entry) => Arc::new(PendingValidationStruct::new( header_with_its_entry, @@ -580,7 +581,7 @@ pub mod tests { "{}, entry:\n{:?}\nheader from test_chain_header():\n{:?}\n", err_msg, entry, header ); - panic!(err_msg); + Err(err_msg) } } }