Struct holochain::core::workflow::genesis_workflow::GenesisWorkspace
source · pub struct GenesisWorkspace { /* private fields */ }
Expand description
The workspace for Genesis
Implementations§
source§impl GenesisWorkspace
impl GenesisWorkspace
sourcepub fn new(
env: DbWrite<DbKindAuthored>,
dht_db: DbWrite<DbKindDht>
) -> WorkspaceResult<Self>
pub fn new(
env: DbWrite<DbKindAuthored>,
dht_db: DbWrite<DbKindDht>
) -> WorkspaceResult<Self>
Constructor
Examples found in repository?
src/conductor/cell.rs (line 129)
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
pub async fn create(
id: CellId,
conductor_handle: ConductorHandle,
space: Space,
holochain_p2p_cell: holochain_p2p::HolochainP2pDna,
managed_task_add_sender: sync::mpsc::Sender<ManagedTaskAdd>,
managed_task_stop_broadcaster: sync::broadcast::Sender<()>,
) -> CellResult<(Self, InitialQueueTriggers)> {
let conductor_api = Arc::new(CellConductorApi::new(conductor_handle.clone(), id.clone()));
// check if genesis has been run
let has_genesis = {
// check if genesis ran.
GenesisWorkspace::new(space.authored_db.clone(), space.dht_db.clone())?
.has_genesis(id.agent_pubkey().clone())
.await?
};
if has_genesis {
let (queue_triggers, initial_queue_triggers) = spawn_queue_consumer_tasks(
id.clone(),
holochain_p2p_cell.clone(),
&space,
conductor_handle.clone(),
managed_task_add_sender,
managed_task_stop_broadcaster,
)
.await;
Ok((
Self {
id,
conductor_api,
conductor_handle,
space,
holochain_p2p_cell,
queue_triggers,
init_mutex: Default::default(),
},
initial_queue_triggers,
))
} else {
Err(CellError::CellWithoutGenesis(id))
}
}
/// Performs the Genesis workflow for the Cell, ensuring that its initial
/// records are committed. This is a prerequisite for any other interaction
/// with the SourceChain
#[allow(clippy::too_many_arguments)]
pub async fn genesis<Ribosome>(
id: CellId,
conductor_handle: ConductorHandle,
authored_db: DbWrite<DbKindAuthored>,
dht_db: DbWrite<DbKindDht>,
dht_db_cache: DhtDbQueryCache,
ribosome: Ribosome,
membrane_proof: Option<MembraneProof>,
chc: Option<ChcImpl>,
) -> CellResult<()>
where
Ribosome: RibosomeT + 'static,
{
// get the dna
let dna_file = conductor_handle
.get_dna_file(id.dna_hash())
.ok_or_else(|| DnaError::DnaMissing(id.dna_hash().to_owned()))?;
let conductor_api = CellConductorApi::new(conductor_handle.clone(), id.clone());
// run genesis
let workspace = GenesisWorkspace::new(authored_db, dht_db)
.map_err(ConductorApiError::from)
.map_err(Box::new)?;
// exit early if genesis has already run
if workspace.has_genesis(id.agent_pubkey().clone()).await? {
return Ok(());
}
let args = GenesisWorkflowArgs::new(
dna_file,
id.agent_pubkey().clone(),
membrane_proof,
ribosome,
dht_db_cache,
chc,
);
genesis_workflow(workspace, conductor_api, args)
.await
.map_err(ConductorApiError::from)
.map_err(Box::new)?;
if let Some(trigger) = conductor_handle
.get_queue_consumer_workflows()
.integration_trigger(Arc::new(id.dna_hash().clone()))
{
trigger.trigger(&"genesis");
}
Ok(())
}
sourcepub async fn has_genesis(&self, author: AgentPubKey) -> DatabaseResult<bool>
pub async fn has_genesis(&self, author: AgentPubKey) -> DatabaseResult<bool>
Examples found in repository?
src/conductor/cell.rs (line 130)
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
pub async fn create(
id: CellId,
conductor_handle: ConductorHandle,
space: Space,
holochain_p2p_cell: holochain_p2p::HolochainP2pDna,
managed_task_add_sender: sync::mpsc::Sender<ManagedTaskAdd>,
managed_task_stop_broadcaster: sync::broadcast::Sender<()>,
) -> CellResult<(Self, InitialQueueTriggers)> {
let conductor_api = Arc::new(CellConductorApi::new(conductor_handle.clone(), id.clone()));
// check if genesis has been run
let has_genesis = {
// check if genesis ran.
GenesisWorkspace::new(space.authored_db.clone(), space.dht_db.clone())?
.has_genesis(id.agent_pubkey().clone())
.await?
};
if has_genesis {
let (queue_triggers, initial_queue_triggers) = spawn_queue_consumer_tasks(
id.clone(),
holochain_p2p_cell.clone(),
&space,
conductor_handle.clone(),
managed_task_add_sender,
managed_task_stop_broadcaster,
)
.await;
Ok((
Self {
id,
conductor_api,
conductor_handle,
space,
holochain_p2p_cell,
queue_triggers,
init_mutex: Default::default(),
},
initial_queue_triggers,
))
} else {
Err(CellError::CellWithoutGenesis(id))
}
}
/// Performs the Genesis workflow for the Cell, ensuring that its initial
/// records are committed. This is a prerequisite for any other interaction
/// with the SourceChain
#[allow(clippy::too_many_arguments)]
pub async fn genesis<Ribosome>(
id: CellId,
conductor_handle: ConductorHandle,
authored_db: DbWrite<DbKindAuthored>,
dht_db: DbWrite<DbKindDht>,
dht_db_cache: DhtDbQueryCache,
ribosome: Ribosome,
membrane_proof: Option<MembraneProof>,
chc: Option<ChcImpl>,
) -> CellResult<()>
where
Ribosome: RibosomeT + 'static,
{
// get the dna
let dna_file = conductor_handle
.get_dna_file(id.dna_hash())
.ok_or_else(|| DnaError::DnaMissing(id.dna_hash().to_owned()))?;
let conductor_api = CellConductorApi::new(conductor_handle.clone(), id.clone());
// run genesis
let workspace = GenesisWorkspace::new(authored_db, dht_db)
.map_err(ConductorApiError::from)
.map_err(Box::new)?;
// exit early if genesis has already run
if workspace.has_genesis(id.agent_pubkey().clone()).await? {
return Ok(());
}
let args = GenesisWorkflowArgs::new(
dna_file,
id.agent_pubkey().clone(),
membrane_proof,
ribosome,
dht_db_cache,
chc,
);
genesis_workflow(workspace, conductor_api, args)
.await
.map_err(ConductorApiError::from)
.map_err(Box::new)?;
if let Some(trigger) = conductor_handle
.get_queue_consumer_workflows()
.integration_trigger(Arc::new(id.dna_hash().clone()))
{
trigger.trigger(&"genesis");
}
Ok(())
}
More examples
src/core/workflow/genesis_workflow.rs (line 68)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
async fn genesis_workflow_inner<Api: CellConductorApiT, Ribosome>(
workspace: &mut GenesisWorkspace,
args: GenesisWorkflowArgs<Ribosome>,
api: Api,
) -> WorkflowResult<()>
where
Ribosome: RibosomeT + 'static,
{
let GenesisWorkflowArgs {
dna_file,
agent_pubkey,
membrane_proof,
ribosome,
dht_db_cache,
chc,
} = args;
if workspace.has_genesis(agent_pubkey.clone()).await? {
return Ok(());
}
let dna_hash = ribosome.dna_def().to_hash();
let DnaDef {
name,
modifiers: DnaModifiers { properties, .. },
integrity_zomes,
..
} = &ribosome.dna_def().content;
let dna_info = DnaInfo {
zome_names: integrity_zomes.iter().map(|(n, _)| n.clone()).collect(),
name: name.clone(),
hash: dna_hash,
properties: properties.clone(),
};
let result = ribosome.run_genesis_self_check(
GenesisSelfCheckHostAccess,
GenesisSelfCheckInvocation {
payload: Arc::new(GenesisSelfCheckData {
dna_info,
membrane_proof: membrane_proof.clone(),
agent_key: agent_pubkey.clone(),
}),
},
)?;
// If the self-check fails, fail genesis, and don't create the source chain.
if let GenesisSelfCheckResult::Invalid(reason) = result {
return Err(WorkflowError::GenesisFailure(reason));
}
// NB: this is just a placeholder for a real DPKI request to show intent
if api
.dpki_request("is_agent_pubkey_valid".into(), agent_pubkey.to_string())
.await
.expect("TODO: actually implement this")
== "INVALID"
{
return Err(WorkflowError::AgentInvalid(agent_pubkey.clone()));
}
source_chain::genesis(
workspace.vault.clone(),
workspace.dht_db.clone(),
&dht_db_cache,
api.keystore().clone(),
dna_file.dna_hash().clone(),
agent_pubkey,
membrane_proof,
chc,
)
.await?;
Ok(())
}
Auto Trait Implementations§
impl !RefUnwindSafe for GenesisWorkspace
impl Send for GenesisWorkspace
impl Sync for GenesisWorkspace
impl Unpin for GenesisWorkspace
impl !UnwindSafe for GenesisWorkspace
Blanket Implementations§
§impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
§fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
TODO: once 1.33.0 is the minimum supported compiler version, remove
Any::type_id_compat and use StdAny::type_id instead.
https://github.com/rust-lang/rust/issues/27745
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.§impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
§fn upcast_any_ref(&self) -> &(dyn Any + 'static)
fn upcast_any_ref(&self) -> &(dyn Any + 'static)
upcast ref
§fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
upcast mut ref