MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / compute_state_after_unrecord

Function compute_state_after_unrecord

atomic-repository/src/unrecord.rs:568–601  ·  view source on GitHub ↗

Compute the new Merkle state after unrecording changes. This recomputes the state by re-hashing the remaining changes. # Arguments `txn` - Read transaction `view` - View being modified `removed` - Set of change hashes being removed # Returns The new Merkle state after removal.

(
    txn: &T,
    view: &ViewState,
    removed: &HashSet<Hash>,
)

Source from the content-addressed store, hash-verified

566///
567/// The new Merkle state after removal.
568pub fn compute_state_after_unrecord<T: ViewTxnT>(
569 txn: &T,
570 view: &ViewState,
571 removed: &HashSet<Hash>,
572) -> UnrecordResult<Merkle> {
573 let mut state = Merkle::ZERO;
574
575 // Iterate through all changes and recompute state without the removed ones
576 let iter = txn
577 .iter_changes(view, 0)
578 .map_err(|e| UnrecordError::Database(e.to_string()))?;
579
580 for result in iter {
581 let (_, change_id, _) = result.map_err(|e| UnrecordError::Database(e.to_string()))?;
582
583 // Get external hash
584 let hash = txn
585 .get_external(change_id)
586 .map_err(|e| UnrecordError::Database(e.to_string()))?
587 .ok_or_else(|| UnrecordError::ChangeNotFound {
588 hash: format!("{:?}", change_id),
589 })?;
590
591 // Skip removed changes
592 if removed.contains(&hash) {
593 continue;
594 }
595
596 // Update state
597 state = state.next(&hash);
598 }
599
600 Ok(state)
601}
602
603/// Preview what would be unrecorded without actually doing it.
604///

Callers 1

preview_unrecordFunction · 0.85

Calls 4

iter_changesMethod · 0.45
get_externalMethod · 0.45
containsMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected