Function holochain::core::workflow::call_zome_workflow::inline_validation
source · pub async fn inline_validation<Ribosome>(
workspace: SourceChainWorkspace,
network: HolochainP2pDna,
conductor_handle: ConductorHandle,
ribosome: Ribosome
) -> WorkflowResult<()>where
Ribosome: RibosomeT + 'static,
Expand description
Run validation inline and wait for the result.
Examples found in repository?
src/core/workflow/initialize_zomes_workflow.rs (line 123)
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 125 126
async fn initialize_zomes_workflow_inner<Ribosome>(
workspace: SourceChainWorkspace,
network: HolochainP2pDna,
keystore: MetaLairClient,
args: InitializeZomesWorkflowArgs<Ribosome>,
) -> WorkflowResult<InitResult>
where
Ribosome: RibosomeT + 'static,
{
let dna_def = args.dna_def().clone();
let InitializeZomesWorkflowArgs {
ribosome,
conductor_handle,
signal_tx,
cell_id,
} = args;
let call_zome_handle =
CellConductorApi::new(conductor_handle.clone(), cell_id.clone()).into_call_zome_handle();
// Call the init callback
let result = {
let host_access = InitHostAccess::new(
workspace.clone().into(),
keystore,
network.clone(),
signal_tx,
call_zome_handle,
);
let invocation = InitInvocation { dna_def };
ribosome.run_init(host_access, invocation)?
};
// Insert the init marker
// FIXME: For some reason if we don't spawn here
// this future never gets polled again.
let ws = workspace.clone();
tokio::task::spawn(async move {
ws.source_chain()
.put(
builder::InitZomesComplete {},
None,
ChainTopOrdering::Strict,
)
.await
})
.await??;
// TODO: Validate scratch items
super::inline_validation(workspace, network, conductor_handle, ribosome).await?;
Ok(result)
}
More examples
src/conductor/conductor/graft_records_onto_source_chain.rs (lines 165-170)
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
async fn validate_records(
handle: ConductorHandle,
cell_id: &CellId,
chain_top: &Option<(ActionHash, u32)>,
records: &[Record],
) -> ConductorApiResult<()> {
let space = handle.get_or_create_space(cell_id.dna_hash())?;
let ribosome = handle.get_ribosome(cell_id.dna_hash())?;
let chc = None;
let network = handle
.holochain_p2p()
.to_dna(cell_id.dna_hash().clone(), chc);
// Create a raw source chain to validate against because
// genesis may not have been run yet.
let workspace = SourceChainWorkspace::raw_empty(
space.authored_db.clone(),
space.dht_db.clone(),
space.dht_query_cache.clone(),
space.cache_db.clone(),
handle.keystore().clone(),
cell_id.agent_pubkey().clone(),
Arc::new(ribosome.dna_def().as_content().clone()),
)
.await?;
let sc = workspace.source_chain();
// Validate the chain.
crate::core::validate_chain(records.iter().map(|e| e.signed_action()), chain_top)
.map_err(|e| SourceChainError::InvalidCommit(e.to_string()))?;
// Add the records to the source chain so we can validate them.
sc.scratch()
.apply(|scratch| {
for r in records {
holochain_state::prelude::insert_record_scratch(
scratch,
r.clone(),
Default::default(),
);
}
})
.map_err(SourceChainError::from)?;
// Run the individual record validations.
crate::core::workflow::inline_validation(
workspace.clone(),
network.clone(),
handle.clone(),
ribosome,
)
.await?;
Ok(())
}
src/core/workflow/call_zome_workflow.rs (line 165)
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
async fn call_zome_workflow_inner<Ribosome>(
workspace: SourceChainWorkspace,
network: HolochainP2pDna,
keystore: MetaLairClient,
args: CallZomeWorkflowArgs<Ribosome>,
) -> WorkflowResult<ZomeCallResult>
where
Ribosome: RibosomeT + 'static,
{
let CallZomeWorkflowArgs {
ribosome,
invocation,
signal_tx,
conductor_handle,
cell_id,
..
} = args;
let call_zome_handle =
CellConductorApi::new(conductor_handle.clone(), cell_id).into_call_zome_handle();
tracing::trace!("Before zome call");
let host_access = ZomeCallHostAccess::new(
workspace.clone().into(),
keystore,
network.clone(),
signal_tx,
call_zome_handle,
);
let (ribosome, result) =
call_zome_function_authorized(ribosome, host_access, invocation).await?;
tracing::trace!("After zome call");
let validation_result =
inline_validation(workspace.clone(), network, conductor_handle, ribosome).await;
if matches!(
validation_result,
Err(WorkflowError::SourceChainError(
SourceChainError::InvalidCommit(_)
))
) {
let scratch_records = workspace.source_chain().scratch_records()?;
if scratch_records.len() == 1 {
let lock = holochain_state::source_chain::lock_for_entry(
scratch_records[0].entry().as_option(),
)?;
if !lock.is_empty()
&& workspace
.source_chain()
.is_chain_locked(Vec::with_capacity(0))
.await?
&& !workspace.source_chain().is_chain_locked(lock).await?
{
if let Err(error) = workspace.source_chain().unlock_chain().await {
tracing::error!(?error);
}
}
}
}
validation_result?;
Ok(result)
}