Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
mark agent id aspect as held durin initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Jun 9, 2020
1 parent bb0fbf0 commit 2063352
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
20 changes: 20 additions & 0 deletions crates/core/src/dht/actions/hold_aspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ pub fn ack_single(context: Arc<Context>, aspect: EntryAspect) {
dispatch_action(context.action_channel(), ActionWrapper::new(action));
}

pub async fn hold_aspect_no_ack(
pending_id: &ProcessUniqueId,
aspect: EntryAspect,
context: Arc<Context>,
) -> Result<(), HolochainError> {
let id = (*pending_id, ProcessUniqueId::new());
let action_wrapper = ActionWrapper::new(Action::HoldAspect((aspect.clone(), id)));
dispatch_action(context.action_channel(), action_wrapper.clone());
let r = HoldAspectFuture {
context: context.clone(),
// aspect,
id,
}
.await;
if r.is_err() {
error!("HoldAspect action completed with error: {:?}", r);
}
r
}

pub async fn hold_aspect(
pending_id: &ProcessUniqueId,
aspect: EntryAspect,
Expand Down
14 changes: 12 additions & 2 deletions crates/core/src/nucleus/actions/initialize.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::{
action::{Action, ActionWrapper},
agent::actions::commit::commit_entry,
agent::{actions::commit::commit_entry, find_chain_header},
context::Context,
dht::actions::hold_aspect::hold_aspect_no_ack,
network::entry_aspect::EntryAspect,
nucleus::state::NucleusStatus,
};
use futures::{future::Future, task::Poll};
Expand Down Expand Up @@ -98,7 +100,7 @@ pub async fn initialize_chain(

// Commit AgentId to chain
let agent_id_entry = Entry::AgentId(context_clone.agent_id.clone());
let agent_id_commit = commit_entry(agent_id_entry, None, &context_clone).await;
let agent_id_commit = commit_entry(agent_id_entry.clone(), None, &context_clone).await;

// Let initialization fail if AgentId could not be committed.
// Currently this cannot happen since ToEntry for Agent always creates
Expand All @@ -109,6 +111,14 @@ pub async fn initialize_chain(
return Err(HolochainError::InitializationFailed(
"error committing Agent".to_string(),
));
} else {
let agent_id_header = find_chain_header(&agent_id_entry, &context.state().unwrap())
.ok_or_else(|| HolochainError::from("No header found for agent id entry"))?;

// mark the entry as held in the dht store because we always hold ourselves.
let entry_aspect = EntryAspect::Content(agent_id_entry, agent_id_header);

hold_aspect_no_ack(&ProcessUniqueId::new(), entry_aspect, context.clone()).await?;
}

let mut cap_functions = CapFunctions::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/holochain/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn main() {
if held_list_aspect_map != actually_held_aspect_map {
let actually_held_aspects : HashSet<(AspectHash, EntryAspect)> = aspects.into_iter().map(|aspect| (AspectHash::from(aspect.address()), aspect)).collect();

writeln!(io, "mismatch: held aspects for {:?} is:\n{:?}\n but actual aspects held are:\n{:?}", entry_hash, held_list_aspect_map, actually_held_aspects)?;
writeln!(io, "mismatch: held aspects for {:?} is:\n{:?}\n but actual aspects held are:\n{:?}\n\n\n", entry_hash, held_list_aspect_map, actually_held_aspects)?;
}
}
}
Expand Down

0 comments on commit 2063352

Please sign in to comment.