This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
Header Publishing (The Return Of) #1640
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
5bf604a
ensure dna/agent entries are only published on first startup, also ad…
willemolding 21898f7
use iter_chain in get_all_public_chain_entries
willemolding 602e839
split out new action for PublishHeaderEntry. Tests passing with this …
willemolding 2470138
merge develop and fix conflicts
willemolding e475d03
header publishing implemented again. Tests seem to have been dropped …
willemolding 1d944eb
adds tests back for author_entry
willemolding 3db0e65
add special validation case and AddressableContent for ChainHeader
willemolding a5a8f76
add validation package for ChainHeader entry
willemolding f50b9dd
Merge branch 'develop' of https://github.com/holochain/holochain-rust…
willemolding 041779d
adds chain headers to author list
willemolding 9a22ac4
fmt
willemolding 58b6d56
changelog
willemolding 6d2a888
Merge branch 'develop' into feature-add-header-publishing
willemolding b9d7d6a
adds tests for retrieving header aspects in author_list
willemolding e5865f4
logs errors getting aspects rather than panic
willemolding 17d1759
Merge branch 'feature-add-header-publishing' of https://github.com/ho…
willemolding 18d2028
Merge branch 'develop' into feature-add-header-publishing
willemolding e776314
Merge branch 'develop' into feature-add-header-publishing
willemolding e5da930
Merge branch 'develop' into feature-add-header-publishing
willemolding cbd139b
Fix construction content aspects for authoring list
lucksus ff89573
Update CHANGELOG-UNRELEASED.md
willemolding 1883e9d
fix changelog merge conflict
willemolding 881cee4
Merge branch 'develop' into feature-add-header-publishing
willemolding 5fbbbc1
Merge branch 'develop' into feature-add-header-publishing
willemolding 4fb485c
merge develop
willemolding faeafe9
adds agent publish to initialize
willemolding 2387010
OMerge branch 'develop' of https://github.com/holochain/holochain-rus…
willemolding 0825172
merge latest develop
willemolding c22195a
Merge branch 'entry-migrate-app-spec' of github.com:holochain/holocha…
willemolding 0aec61e
merge and fmt
willemolding 2914e08
adds further testing on link deletion but it turns out its just a fla…
willemolding 21dce51
Merge branch 'develop' of github.com:holochain/holochain-rust into fe…
willemolding 6daa9e7
fmt
willemolding ed0b404
clippify
willemolding 9c340b1
Merge branch 'develop' into feature-add-header-publishing
willemolding File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use crate::{ | ||
action::{Action, ActionWrapper}, | ||
context::Context, | ||
instance::dispatch_action, | ||
network::actions::ActionResponse, | ||
}; | ||
use futures::{future::Future, task::Poll}; | ||
use holochain_core_types::error::HcResult; | ||
use holochain_persistence_api::cas::content::Address; | ||
use std::{pin::Pin, sync::Arc}; | ||
|
||
/// Publish Header Entry Action Creator | ||
/// Returns a future that resolves to an ActionResponse. | ||
pub async fn publish_header_entry(address: Address, context: &Arc<Context>) -> HcResult<Address> { | ||
let action_wrapper = ActionWrapper::new(Action::PublishHeaderEntry(address)); | ||
dispatch_action(context.action_channel(), action_wrapper.clone()); | ||
await!(PublishHeaderEntryFuture { | ||
context: context.clone(), | ||
action: action_wrapper, | ||
}) | ||
} | ||
|
||
/// PublishFuture resolves to ActionResponse | ||
/// Tracks the state for a response to its ActionWrapper | ||
pub struct PublishHeaderEntryFuture { | ||
context: Arc<Context>, | ||
action: ActionWrapper, | ||
} | ||
|
||
impl Future for PublishHeaderEntryFuture { | ||
type Output = HcResult<Address>; | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context) -> Poll<Self::Output> { | ||
if let Some(err) = self.context.action_channel_error("PublishHeaderEntryFuture") { | ||
return Poll::Ready(Err(err)); | ||
} | ||
let state = self.context.state().unwrap().network(); | ||
if let Err(error) = state.initialized() { | ||
return Poll::Ready(Err(error)); | ||
} | ||
// | ||
// TODO: connect the waker to state updates for performance reasons | ||
// See: https://github.com/holochain/holochain-rust/issues/314 | ||
// | ||
cx.waker().clone().wake(); | ||
match state.actions().get(&self.action) { | ||
Some(ActionResponse::PublishHeaderEntry(result)) => match result { | ||
Ok(address) => Poll::Ready(Ok(address.to_owned())), | ||
Err(error) => Poll::Ready(Err(error.clone())), | ||
}, | ||
_ => Poll::Pending, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,16 @@ use crate::{ | |
instance::dispatch_action, | ||
network::handler::{get_content_aspect, get_meta_aspects}, | ||
}; | ||
use holochain_core_types::error::HcResult; | ||
use holochain_core_types::{ | ||
error::HcResult, | ||
entry::Entry, | ||
}; | ||
use holochain_persistence_api::cas::content::{Address, AddressableContent}; | ||
use lib3h_protocol::data_types::{EntryListData, GetListData}; | ||
use snowflake::ProcessUniqueId; | ||
use std::{collections::HashMap, sync::Arc, thread}; | ||
use crate::network::entry_aspect::EntryAspect; | ||
use crate::agent::state::create_new_chain_header; | ||
|
||
pub fn handle_get_authoring_list(get_list_data: GetListData, context: Arc<Context>) { | ||
thread::Builder::new() | ||
|
@@ -20,11 +25,32 @@ pub fn handle_get_authoring_list(get_list_data: GetListData, context: Arc<Contex | |
.spawn(move || { | ||
let mut address_map = HashMap::new(); | ||
for entry in get_all_public_chain_entries(context.clone()) { | ||
let content_aspect = get_content_aspect(&entry, context.clone()) | ||
.expect("Must be able to get content aspect of entry that is in our source chain"); | ||
address_map.insert( | ||
entry.clone(), | ||
get_all_aspect_addresses(&entry, context.clone()) | ||
.expect("Error getting entry aspects of authoring list"), | ||
vec![content_aspect.address()] | ||
); | ||
} | ||
|
||
// chain header entries also should be communicated on the authoring list | ||
// In future make this depend if header publishing is enabled | ||
let state = context.state() | ||
.expect("There must be a state in context when we are responding to a HandleGetAuthoringEntryList"); | ||
for chain_header_entry in get_all_chain_header_entries(context.clone()) { | ||
let address = chain_header_entry.address(); | ||
let header_entry_header = create_new_chain_header( | ||
&chain_header_entry, | ||
&state.agent(), | ||
&*state, | ||
&None, | ||
&Vec::new(), | ||
).expect("Must be able to create dummy header header when responding to HandleGetAuthoringEntryList"); | ||
let content_aspect = EntryAspect::Content( | ||
chain_header_entry, | ||
header_entry_header, | ||
); | ||
address_map.insert(address, vec![content_aspect.address()]); | ||
} | ||
|
||
let action = Action::RespondAuthoringList(EntryListData { | ||
|
@@ -39,15 +65,20 @@ pub fn handle_get_authoring_list(get_list_data: GetListData, context: Arc<Contex | |
} | ||
|
||
fn get_all_public_chain_entries(context: Arc<Context>) -> Vec<Address> { | ||
let chain = context.state().unwrap().agent().chain_store(); | ||
let top_header = context.state().unwrap().agent().top_chain_header(); | ||
let chain = context.state().unwrap().agent().iter_chain(); | ||
chain | ||
.iter(&top_header) | ||
.filter(|ref chain_header| chain_header.entry_type().can_publish(&context)) | ||
.map(|chain_header| chain_header.entry_address().clone()) | ||
.collect() | ||
} | ||
|
||
fn get_all_chain_header_entries(context: Arc<Context>) -> Vec<Entry> { | ||
let chain = context.state().unwrap().agent().iter_chain(); | ||
chain | ||
.map(|chain_header| Entry::ChainHeader(chain_header)) | ||
.collect() | ||
} | ||
|
||
fn get_all_aspect_addresses(entry: &Address, context: Arc<Context>) -> HcResult<Vec<Address>> { | ||
let mut address_list: Vec<Address> = get_meta_aspects(entry, context.clone())? | ||
.iter() | ||
|
@@ -90,3 +121,67 @@ pub fn handle_get_gossip_list(get_list_data: GetListData, context: Arc<Context>) | |
}) | ||
.expect("Could not spawn thread for creating of gossip list"); | ||
} | ||
|
||
#[cfg(test)] | ||
pub mod tests { | ||
use super::*; | ||
use crate::workflows::author_entry::author_entry; | ||
use crate::nucleus::actions::tests::*; | ||
use holochain_core_types::{ | ||
entry::{Entry, test_entry_with_value}, | ||
}; | ||
use holochain_persistence_api::cas::content::AddressableContent; | ||
use std::{thread, time}; | ||
|
||
#[test] | ||
fn test_can_get_chain_header_list() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lucksus These two tests show the loading of the header entries and their aspects working fine. I am wondering if the issue is happening only at startup when the Dna and Agent headers are in the chain but the header entries are not committed yet. |
||
let mut dna = test_dna(); | ||
dna.uuid = "test_can_get_chain_header_list".to_string(); | ||
let (_instance, context) = instance_by_name("jill", dna, None); | ||
|
||
context | ||
.block_on(author_entry( | ||
&test_entry_with_value("{\"stuff\":\"test entry value\"}"), | ||
None, | ||
&context, | ||
&vec![], | ||
)) | ||
.unwrap() | ||
.address(); | ||
|
||
thread::sleep(time::Duration::from_millis(500)); | ||
|
||
let chain = context.state().unwrap().agent().iter_chain(); | ||
let header_entries: Vec<Entry> = chain.map(|header| Entry::ChainHeader(header)).collect(); | ||
|
||
assert_eq!( | ||
get_all_chain_header_entries(context), | ||
header_entries, | ||
) | ||
|
||
} | ||
|
||
#[test] | ||
fn test_can_get_all_aspect_addr_for_headers() { | ||
let mut dna = test_dna(); | ||
dna.uuid = "test_can_get_chain_header_list".to_string(); | ||
let (_instance, context) = instance_by_name("jill", dna, None); | ||
|
||
context | ||
.block_on(author_entry( | ||
&test_entry_with_value("{\"stuff\":\"test entry value\"}"), | ||
None, | ||
&context, | ||
&vec![], | ||
)) | ||
.unwrap() | ||
.address(); | ||
|
||
thread::sleep(time::Duration::from_millis(500)); | ||
|
||
assert!(get_all_chain_header_entries(context.clone()).iter().all(|chain_header| { | ||
get_all_aspect_addresses(&chain_header.address(), context.clone()).is_ok() | ||
})); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the same publish for this? They seem to share the same type