Function holochain::core::validate_chain

source ·
pub fn validate_chain<'iter, A: 'iter + ChainItem>(
    actions: impl Iterator<Item = &'iter A>,
    persisted_chain_head: &Option<(A::Hash, u32)>
) -> SysValidationResult<()>
Expand description

Validate a chain of actions with an optional starting point.

Examples found in repository?
src/conductor/conductor/graft_records_onto_source_chain.rs (line 148)
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(())
}